/* ============================================================================
 * theme.css — the shared design system for the owner dashboard and the
 * customer booking page. Tokens, primitives, motion. Page-specific layout
 * lives in dashboard.css / booking.css, which both load this first.
 *
 * DIRECTION — "yellow plate".
 * Every commercial vehicle in India carries a yellow number plate with black
 * lettering. That is the single most recognisable mark of this business, so
 * it is the accent: warm plate yellow on plate black, used sparingly, against
 * a warm paper surface that reads like the duty slip a driver actually fills
 * in. Registration numbers, booking IDs, fares and distances are set in a
 * monospace face because they are register values, not prose — that
 * distinction is real and worth showing.
 * ========================================================================== */

/* ── Tokens ──────────────────────────────────────────────────────────────── */

:root {
  /* Brand constants — identical in both themes so the accent never drifts. */
  --plate-yellow:   #F4B92E;
  --plate-yellow-d: #D99A12;
  --plate-black:    #101318;

  /* Type */
  --font-ui: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Archivo Expanded", "Archivo", var(--font-ui);
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;

  --text-xs:   11.5px;
  --text-sm:   12.5px;
  --text-base: 14px;
  --text-md:   15.5px;
  --text-lg:   18px;
  --text-xl:   22px;
  --text-2xl:  28px;
  --text-3xl:  36px;

  /* Spacing — 4px base, named so layout reads as intent not arithmetic. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s7: 32px; --s8: 40px; --s9: 56px;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-pill: 999px;

  /* Motion */
  --ease: cubic-bezier(.2, .7, .3, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --fast: 120ms;
  --mid: 200ms;
  --slow: 340ms;

  --header-h: 60px;
  --rail-w: 232px;
}

/* Light — duty-slip paper. */
:root, :root[data-theme="light"] {
  --bg:            #F1EDE4;
  --surface:       #FBF9F4;
  --surface-2:     #F4F0E7;
  --surface-sunk:  #EDE8DC;
  --border:        #E0D9C9;
  --border-strong: #C9C0AC;

  --text:      #14171C;
  --text-mid:  #5E6470;
  --text-dim:  #8A8F9B;

  --accent:      var(--plate-yellow);
  --accent-hover: var(--plate-yellow-d);
  --accent-ink:  #1A1500;         /* text that sits on the accent */
  --accent-soft: #FDF2D6;
  --accent-line: #E8B72A;

  --ok:     #1B7A5A;  --ok-soft:     #DCF2E9;
  --warn:   #A96A05;  --warn-soft:   #FBEDD3;
  --danger: #B32D26;  --danger-soft: #FBE2E0;
  --info:   #21578F;  --info-soft:   #DEEAF7;

  --shadow-1: 0 1px 2px rgba(28, 24, 12, .06);
  --shadow-2: 0 2px 4px rgba(28, 24, 12, .06), 0 8px 20px -8px rgba(28, 24, 12, .14);
  --shadow-3: 0 24px 60px -18px rgba(20, 18, 10, .34);
  --rail-bg: #171A20;
  --rail-text: #C9CDD6;
  --rail-text-dim: #7C8291;
}

/* Dark — night drive. */
:root[data-theme="dark"] {
  --bg:            #0C0E12;
  --surface:       #14171D;
  --surface-2:     #1A1E25;
  --surface-sunk:  #101319;
  --border:        #262B34;
  --border-strong: #39414D;

  --text:      #EDEFF3;
  --text-mid:  #A2A9B6;
  --text-dim:  #737B89;

  --accent:      var(--plate-yellow);
  --accent-hover: #FFCB4A;
  --accent-ink:  #17130A;
  --accent-soft: #2A2314;
  --accent-line: #6B5A25;

  --ok:     #4FCFA3;  --ok-soft:     #122C24;
  --warn:   #F0B049;  --warn-soft:   #33270F;
  --danger: #F2837B;  --danger-soft: #34191A;
  --info:   #79B2F0;  --info-soft:   #15263A;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, .4), 0 10px 26px -10px rgba(0, 0, 0, .7);
  --shadow-3: 0 26px 64px -18px rgba(0, 0, 0, .8);
  --rail-bg: #10131A;
  --rail-text: #C4CAD5;
  --rail-text-dim: #6E7684;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: 1.5;
  font-feature-settings: "cv05" 1;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-weight: 600; letter-spacing: -.015em; line-height: 1.25; }
p { margin: 0; }
a { color: inherit; }
img { max-width: 100%; display: block; }
svg { flex: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
::selection { background: var(--accent); color: var(--accent-ink); }

/* Values that belong to a register rather than a sentence: plate numbers,
   booking IDs, fares, distances. Tabular so columns of them line up. */
.mono, .num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: .94em;
  letter-spacing: -.01em;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */

button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: var(--text-base);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  cursor: pointer;
  background: var(--accent);
  color: var(--accent-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 38px;
  white-space: nowrap;
  position: relative;
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease),
              color var(--fast) var(--ease), transform var(--fast) var(--ease),
              box-shadow var(--fast) var(--ease), opacity var(--fast) var(--ease);
}
button:hover, .btn:hover { background: var(--accent-hover); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-1);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--text-dim); }

.btn-ghost {
  background: transparent;
  color: var(--text-mid);
  border-color: transparent;
  box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(1.08); }

.btn-sm { padding: 5px 10px; min-height: 30px; font-size: var(--text-sm); border-radius: var(--radius-sm); }
.btn-lg { padding: 13px 22px; min-height: 48px; font-size: var(--text-md); border-radius: var(--radius-lg); }
.btn-block { width: 100%; }

/* Icon-only row action. Colour arrives on hover so a table of six of them
   isn't a fruit salad at rest. */
.icon-action {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  padding: 0;
  width: 30px; height: 30px;
  min-height: 0;
  border-radius: var(--radius-sm);
}
.icon-action svg { width: 15px; height: 15px; }
.icon-action:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.icon-action.act-delete:hover, .icon-action.act-cancel:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-soft); }
.icon-action.act-paid:hover  { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.icon-action.act-rates:hover, .icon-action.act-fare:hover { color: var(--warn); border-color: var(--accent); background: var(--accent-soft); }
.icon-action.act-invoice:hover, .icon-action.act-edit:hover { color: var(--info); border-color: var(--info); background: var(--info-soft); }

.icon-btn {
  background: transparent;
  color: var(--text-mid);
  border: 1px solid var(--border);
  width: 36px; height: 36px;
  min-height: 0;
  padding: 0;
  border-radius: var(--radius);
}
.icon-btn svg { width: 17px; height: 17px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Form controls ───────────────────────────────────────────────────────── */

label { display: block; font-size: var(--text-sm); font-weight: 600; color: var(--text-mid); margin-bottom: 6px; }

input, select, textarea {
  font: inherit;
  font-size: var(--text-base);
  width: 100%;
  padding: 9px 12px;
  min-height: 40px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), background var(--fast) var(--ease);
}
textarea { min-height: 76px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-dim); }
input:hover, select:hover, textarea:hover { border-color: var(--text-dim); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="date"], input[type="time"], input[type="number"] { font-variant-numeric: tabular-nums; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238A8F9B' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 15px;
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
:root[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.65); }

/* A field that failed validation. Paired with .field-error text so the reason
   is always stated, never just implied by a red edge. */
input.invalid, select.invalid, textarea.invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}
input.invalid:focus, select.invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.field-error {
  display: none;
  font-size: var(--text-sm);
  color: var(--danger);
  margin-top: 5px;
  font-weight: 500;
}
.field-error.show { display: block; animation: nudge var(--mid) var(--ease); }
.field-hint { font-size: var(--text-sm); color: var(--text-dim); margin-top: 5px; }

.checkbox-label {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--text-base); font-weight: 500; color: var(--text);
  margin: 0; cursor: pointer; user-select: none;
}
.checkbox-label input[type="checkbox"] {
  width: 17px; height: 17px; min-height: 0; margin: 0;
  accent-color: var(--accent); cursor: pointer; flex: none;
}

/* Segmented control — for small mutually-exclusive choices (payment status)
   where a dropdown hides the options that matter. */
.segmented {
  display: inline-flex;
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  background: transparent; color: var(--text-mid);
  border: none; box-shadow: none;
  padding: 6px 14px; min-height: 30px;
  border-radius: 7px;
  font-size: var(--text-sm);
}
.segmented button:hover { background: var(--surface); color: var(--text); }
.segmented button[aria-pressed="true"] {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: var(--shadow-1);
}

/* ── Badges, chips, plates ───────────────────────────────────────────────── */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 700;
  letter-spacing: .02em;
  padding: 3px 9px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge-green  { background: var(--ok-soft);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 28%, transparent); }
.badge-orange { background: var(--warn-soft);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 28%, transparent); }
.badge-red    { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 28%, transparent); }
.badge-blue   { background: var(--info-soft);   color: var(--info);   border-color: color-mix(in srgb, var(--info) 28%, transparent); }
.badge-grey   { background: var(--surface-2);   color: var(--text-mid); border-color: var(--border); }

/* The signature mark: a vehicle's registration, set the way it appears on the
   vehicle. Commercial plates in India are black on yellow. */
.plate {
  display: inline-flex; align-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: var(--text-xs);
  letter-spacing: .04em;
  color: var(--plate-black);
  background: var(--plate-yellow);
  border: 1.5px solid var(--plate-black);
  border-radius: 4px;
  padding: 2px 7px;
  white-space: nowrap;
}
.plate-lg { font-size: var(--text-base); padding: 4px 11px; border-radius: 5px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 600;
  color: var(--text-mid);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 8px;
}

/* Where the money came from. Small, quiet, but always visible — an owner
   should never have to wonder why one trip is priced unlike the rate card. */
.source-chip { font-size: var(--text-xs); font-weight: 600; color: var(--text-dim); }
.source-chip.src-manual      { color: var(--warn); }
.source-chip.src-price_chart { color: var(--info); }
.source-chip.src-distance_calc { color: var(--ok); }

/* ── The route ladder ────────────────────────────────────────────────────── */
/* Pickup above drop, joined by a line. Used in duty slips, availability
   results and the booking summary, so a journey always looks like a journey. */

.route {
  display: grid;
  grid-template-columns: 12px 1fr;
  gap: 0 var(--s3);
  font-size: var(--text-sm);
  align-items: start;
}
.route-mark { display: grid; justify-items: center; padding-top: 5px; }
.route-mark i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); border: 1.5px solid var(--accent-line);
  display: block;
}
.route-mark span { width: 1.5px; flex: 1; background: var(--border-strong); min-height: 14px; margin: 3px 0; }
.route-mark.to i { background: transparent; border-color: var(--text-mid); }
.route-leg { color: var(--text); min-width: 0; overflow-wrap: anywhere; }
.route-leg small { display: block; font-size: var(--text-xs); color: var(--text-dim); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

/* ── Cards & panels ──────────────────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s4); flex-wrap: wrap;
  padding: var(--s5) var(--s5) 0;
}
.card-head h2 { font-size: var(--text-lg); }
.card-body { padding: var(--s5); }
.card-sub { font-size: var(--text-sm); color: var(--text-mid); margin-top: 4px; }

.panel {
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s4);
}

/* ── Modals ──────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(12, 10, 4, .5);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s4);
  animation: fade var(--mid) var(--ease);
  overflow-y: auto;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-3);
  width: 100%; max-width: 520px;
  max-height: calc(100vh - var(--s7));
  display: flex; flex-direction: column;
  animation: modal-in var(--slow) var(--ease-out);
}
.modal-wide { max-width: 760px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s4);
  padding: var(--s5) var(--s5) var(--s3);
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: var(--text-md); }
.modal-close {
  background: transparent; border: none; color: var(--text-dim);
  font-size: 17px; width: 30px; height: 30px; min-height: 0; padding: 0;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: var(--s5); overflow-y: auto; display: grid; gap: var(--s4); }
.modal-actions {
  display: flex; justify-content: flex-end; gap: var(--s3);
  padding: var(--s3) var(--s5) var(--s5);
  border-top: 1px solid var(--border);
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */

#toast-stack {
  position: fixed; z-index: 120;
  right: var(--s5); bottom: var(--s5);
  display: flex; flex-direction: column; gap: var(--s2);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--plate-black);
  color: #F4F5F7;
  font-size: var(--text-base); font-weight: 500;
  padding: 11px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  border-left: 3px solid var(--accent);
  max-width: min(360px, calc(100vw - var(--s8)));
  animation: toast-in var(--slow) var(--ease-out);
}
.toast-success { border-left-color: #4FCFA3; }
.toast-error   { border-left-color: #F2837B; }
.toast-out { animation: toast-out 200ms var(--ease) forwards; }

/* ── Loading, empty, feedback ────────────────────────────────────────────── */

.spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%;
  animation: spin 620ms linear infinite;
  vertical-align: -2px;
}
.skel {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-sunk) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
  height: 14px;
}

.empty-state {
  text-align: center;
  padding: var(--s8) var(--s5);
  color: var(--text-mid);
}
.empty-state .empty-icon {
  width: 44px; height: 44px; margin: 0 auto var(--s3);
  display: grid; place-items: center;
  border-radius: var(--radius);
  background: var(--accent-soft); color: var(--warn);
  border: 1px solid var(--accent-line);
}
.empty-state .empty-icon svg { width: 20px; height: 20px; }
.empty-title { font-family: var(--font-display); font-weight: 600; font-size: var(--text-md); color: var(--text); }
.empty-sub { font-size: var(--text-sm); color: var(--text-mid); margin-top: 4px; }

.err { color: var(--danger); font-size: var(--text-base); font-weight: 500; }
.ok  { color: var(--ok);     font-size: var(--text-base); font-weight: 500; }
.result-box:empty { display: none; }
.result-box {
  margin-top: var(--s4);
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  background: var(--surface-sunk);
  border: 1px solid var(--border);
  font-size: var(--text-base);
}

/* ── Motion ──────────────────────────────────────────────────────────────── */

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(14px); } }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.rise { animation: rise var(--slow) var(--ease-out) backwards; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ── Utilities ───────────────────────────────────────────────────────────── */

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.stack { display: grid; gap: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--text-mid); }
.dim { color: var(--text-dim); }
.nowrap { white-space: nowrap; }
