/* ==========================================================================
   Moto Rentals Design System
   Apple-inspired design language
   ========================================================================== */

/* Google Fonts - must be first for iOS compatibility */
@import url('https://fonts.googleapis.com/css2?family=Familjen+Grotesk:wght@400;500;600;700&family=Staatliches&display=swap');

/* --------------------------------------------------------------------------
   CSS Custom Properties
   -------------------------------------------------------------------------- */
:root {
  /* Colors - Apple style */
  --color-bg: #f5f5f7;
  --color-surface: #ffffff;
  --color-surface-elevated: #ffffff;
  --color-text: #1d1d1f;
  --color-text-secondary: #86868b;
  --color-accent: #0071e3;
  --color-accent-hover: #0077ed;
  --color-success: #34c759;
  --color-warning: #ff9f0a;
  --color-danger: #ff3b30;
  --color-border: rgba(0, 0, 0, 0.08);

  /* Legacy aliases for backward compatibility */
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --border: var(--color-border);
  --text: var(--color-text);
  --text-muted: var(--color-text-secondary);
  --accent: var(--color-accent);
  --accent-hover: var(--color-accent-hover);
  --success: var(--color-success);
  --warning: var(--color-warning);
  --danger: var(--color-danger);
  --radius: var(--radius-sm);

  /* Spacing (8px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);

  /* Typography */
  --font-family: 'Familjen Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Staatliches', sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 13px;
  --font-size-base: 15px;
  --font-size-lg: 17px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 28px;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* Dark Mode */
[data-theme="dark"] {
  --color-bg: #000000;
  --color-surface: #1c1c1e;
  --color-surface-elevated: #2c2c2e;
  --color-text: #f5f5f7;
  --color-text-secondary: #98989d;
  --color-border: rgba(255, 255, 255, 0.1);

  /* Legacy aliases */
  --bg: var(--color-bg);
  --surface: var(--color-surface);
  --border: var(--color-border);
  --text: var(--color-text);
  --text-muted: var(--color-text-secondary);
}

/* --------------------------------------------------------------------------
   Base Reset & Typography
   -------------------------------------------------------------------------- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover { color: var(--color-accent-hover); }

/* --------------------------------------------------------------------------
   Layout
   -------------------------------------------------------------------------- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: var(--space-4);
  display: none;
}

.main-content {
  flex: 1;
  padding: var(--space-4);
  max-width: 100%;
  overflow-x: hidden;
}

.header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  background: rgba(255, 255, 255, 0.8);
}

[data-theme="dark"] .header {
  background: rgba(28, 28, 30, 0.8);
}

@media (min-width: 768px) {
  .app { flex-direction: row; }
  .sidebar { display: block; width: 260px; flex-shrink: 0; }
  .main-content { padding: var(--space-6); }
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  transition: box-shadow var(--transition-base);
}

.card:hover { box-shadow: var(--shadow-md); }

.card-title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-3);
}

.card-body { color: var(--color-text-secondary); }

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 500;
  line-height: 1;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) { background: var(--color-accent-hover); }
.btn-primary:active:not(:disabled) { transform: scale(0.98); }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-secondary:hover:not(:disabled) { background: rgba(0, 0, 0, 0.06); }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) { background: #e6352b; }

.btn-ghost {
  background: transparent;
  color: var(--color-accent);
}

.btn-ghost:hover:not(:disabled) { background: rgba(0, 113, 227, 0.08); }

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: var(--font-size-sm);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-full);
}

.btn-icon.btn-sm { width: 32px; height: 32px; }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.form-group { margin-bottom: var(--space-4); }

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 400;
  color: var(--color-text-secondary);
  margin-bottom: var(--space-2);
}

.form-input, .form-select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
}

.form-input::placeholder { color: var(--color-text-secondary); }

.form-checkbox {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent);
}

.form-grid {
  display: grid;
  gap: var(--space-4);
}

@media (min-width: 768px) {
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* --------------------------------------------------------------------------
   Tables
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

th, td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}

th {
  font-weight: 600;
  color: var(--color-text-secondary);
  font-size: var(--font-size-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(0, 0, 0, 0.02); }

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable:hover { color: var(--color-text); }

/* --------------------------------------------------------------------------
   Data Lists (Mobile)
   -------------------------------------------------------------------------- */
.data-list { display: flex; flex-direction: column; gap: var(--space-3); }

.data-item {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
}

.data-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-2) 0;
}

.data-item-row:not(:last-child) { border-bottom: 1px solid var(--color-border); }

.data-item-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.data-item-value { font-weight: 500; }

/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal.active { opacity: 1; visibility: visible; }

.modal-content {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition-base);
}

.modal.active .modal-content { transform: scale(1); }

.modal-header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
}

.modal-body { padding: var(--space-4); }

.modal-footer {
  padding: var(--space-4);
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* Bottom Sheet (Mobile) */
.bottom-sheet .modal-content {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 100%;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(100%);
  padding-bottom: env(safe-area-inset-bottom);
}

.bottom-sheet.active .modal-content { transform: translateY(0); }

/* --------------------------------------------------------------------------
   Badges
   -------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--radius-full);
  background: var(--color-bg);
  color: var(--color-text-secondary);
}

.badge-success { background: rgba(52, 199, 89, 0.15); color: var(--color-success); }
.badge-warning { background: rgba(255, 159, 10, 0.15); color: var(--color-warning); }
.badge-danger { background: rgba(255, 59, 48, 0.15); color: var(--color-danger); }
.badge-info { background: rgba(0, 113, 227, 0.15); color: var(--color-accent); }

/* --------------------------------------------------------------------------
   Stats
   -------------------------------------------------------------------------- */
.stats {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 768px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--color-surface);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-card);
}

.stat-label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-1);
}

.stat-value {
  font-size: var(--font-size-2xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* --------------------------------------------------------------------------
   Navigation
   -------------------------------------------------------------------------- */
.nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--color-text-secondary);
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.nav-link:hover { background: rgba(0, 0, 0, 0.04); color: var(--color-text); }
.nav-link.active { background: rgba(0, 113, 227, 0.1); color: var(--color-accent); }

.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  border-bottom: 2px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover { color: var(--color-text); }
.tab.active { color: var(--color-accent); border-color: var(--color-accent); }

/* --------------------------------------------------------------------------
   Utilities
   -------------------------------------------------------------------------- */
.text-muted { color: var(--color-text-secondary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.p-4 { padding: var(--space-4); }
.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

.hidden { display: none !important; }
.visible-mobile { display: block; }
.visible-desktop { display: none; }

@media (min-width: 768px) {
  .hidden-desktop { display: none !important; }
  .visible-mobile { display: none; }
  .visible-desktop { display: block; }
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.animate-fade-in { animation: fade-in var(--transition-base) ease-out; }
.animate-slide-up { animation: slide-up var(--transition-slow) ease-out; }

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------------------
   Scrollbar Styling
   -------------------------------------------------------------------------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.25); }

[data-theme="dark"]::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); }
[data-theme="dark"]::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.25); }
