/* =========================================================================
   7GO design system
   =========================================================================
   Built mobile first at 375px, then grown. Drivers use this one handed,
   outdoors, in bright sun, in a hurry. That decides almost every choice here.

   Rules that do not bend:
     - Nothing tappable is smaller than 48px.
     - No input font is under 16px, or iPhone zooms in and breaks the layout.
     - Every number that can be compared is tabular, so digits line up.
     - Colour is never the only way a status is shown. There is always a word.
   ========================================================================= */

/* -------------------------------------------------------------------------
   1. Tokens
   ------------------------------------------------------------------------- */

:root {
  /* Brand */
  --blue-700: #0F3FC2;
  --blue-600: #1750E8;   /* primary */
  --blue-50:  #EEF3FE;

  --red-600:  #E02424;
  --red-50:   #FEF2F2;

  --green-600:#059669;
  --green-50: #ECFDF5;

  --amber-600:#B45309;
  --amber-50: #FFFBEB;

  /* Neutrals */
  --n-900: #0F172A;
  --n-700: #334155;
  --n-500: #64748B;
  --n-300: #CBD5E1;
  --n-200: #E2E8F0;
  --n-100: #F1F5F9;
  --n-50:  #F8FAFC;
  --white: #FFFFFF;

  /* Semantic */
  --ink:          var(--n-900);
  --ink-soft:     var(--n-700);
  --ink-muted:    var(--n-500);
  --surface:      var(--white);
  --surface-sunk: var(--n-50);
  --line:         var(--n-200);
  --line-strong:  var(--n-300);
  --primary:      var(--blue-600);
  --primary-dark: var(--blue-700);
  --primary-wash: var(--blue-50);

  /* Type */
  --font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-head: 'Outfit', var(--font);

  /* Space. One scale, used everywhere. */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  --radius:    12px;
  --radius-lg: 16px;
  --radius-sm: 8px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);

  --tap: 48px;
  --appbar-h: 56px;
  --tabbar-h: 60px;
  --measure: 640px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E2E8F0;
    --ink-soft: #CBD5E1;
    --ink-muted: #94A3B8;
    --surface: #131C2E;
    --surface-sunk: #0B1220;
    --line: rgba(255, 255, 255, 0.10);
    --line-strong: rgba(255, 255, 255, 0.18);
    --primary-wash: rgba(23, 80, 232, 0.16);
    --blue-50:  rgba(23, 80, 232, 0.16);
    --green-50: rgba(5, 150, 105, 0.16);
    --red-50:   rgba(224, 36, 36, 0.16);
    --amber-50: rgba(180, 83, 9, 0.18);
    --shadow-sm: none;
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  }
}

/* -------------------------------------------------------------------------
   2. Base
   ------------------------------------------------------------------------- */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface-sunk);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-head); line-height: 1.25; margin: 0; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p  { margin: 0 0 var(--s3); color: var(--ink-soft); }
a  { color: var(--primary); }

/* Prices, distances, order references. Digits must line up in a column. */
.num, .price, .money, td.num, .badge__count {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

.price {
  font-family: var(--font-head);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.price--lg { font-size: 28px; }
.price--md { font-size: 20px; }

.ref {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  font-weight: 600;
}

/* -------------------------------------------------------------------------
   3. Layout
   ------------------------------------------------------------------------- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: calc(var(--appbar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) var(--s4) 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.app-bar__title { font-family: var(--font-head); font-weight: 700; font-size: 17px; }
.app-bar__sub   { font-size: 12px; color: var(--ink-muted); }
.app-bar__right { margin-left: auto; display: flex; gap: var(--s2); align-items: center; }

.mark {
  width: 34px; height: 34px;
  flex: none;
  border-radius: 9px;
  background: var(--primary);
  color: #fff;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 13px;
  display: grid;
  place-items: center;
}
.mark--dark { background: var(--n-900); }

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: var(--s4) var(--s4) var(--s10);
}
/* Leave room for the bottom bar so nothing hides behind it. */
.wrap--tabbed { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s6)); }

.stack > * + * { margin-top: var(--s3); }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s3); margin: var(--s6) 0 var(--s3);
}
.section-head:first-child { margin-top: 0; }
.section-head h2 { font-size: 15px; text-transform: none; }

/* Bottom navigation. Thumb reach beats a top menu on a phone. */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar__item {
  flex: 1;
  min-height: var(--tabbar-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar__item[aria-current="page"] { color: var(--primary); }
.tabbar__icon { font-size: 19px; line-height: 1; }

/* Admin runs on a desktop. Sidebar from 900px, bottom bar below that. */
.shell { display: block; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
  .sidebar {
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: var(--s5) var(--s3);
    position: sticky; top: 0; height: 100vh;
  }
  .sidebar__item {
    display: flex; align-items: center; gap: var(--s3);
    min-height: 44px; padding: 0 var(--s3);
    border-radius: var(--radius-sm);
    color: var(--ink-soft); text-decoration: none;
    font-size: 14px; font-weight: 600;
  }
  .sidebar__item[aria-current="page"] { background: var(--primary-wash); color: var(--primary); }
  .shell .tabbar { display: none; }
  .shell .wrap { padding: var(--s6); max-width: 1100px; margin: 0; }
  .shell .app-bar { display: none; }
}
.sidebar { display: none; }
@media (min-width: 900px) { .sidebar { display: block; } }

/* -------------------------------------------------------------------------
   4. Surfaces
   ------------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--s3); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.card--flat { box-shadow: none; }
.card--pad0 { padding: 0; overflow: hidden; }

/* Summary tiles. Two across on a phone, four on a desktop. */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4);
}
.stat__label { font-size: 12px; font-weight: 600; color: var(--ink-muted); }
.stat__value {
  font-family: var(--font-head);
  font-size: 26px; font-weight: 700; line-height: 1.1;
  margin-top: var(--s1);
  font-variant-numeric: tabular-nums;
}
.stat__note { font-size: 12px; color: var(--ink-muted); margin-top: 2px; }

/* -------------------------------------------------------------------------
   5. Lists and tables
   ------------------------------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; }
.list__item {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
  text-decoration: none; color: inherit;
  min-height: var(--tap);
}
.list__item:last-child { border-bottom: none; }
.list__item:active { background: var(--surface-sunk); }
.list__body { flex: 1; min-width: 0; }
.list__title { font-weight: 600; font-size: 15px; }
.list__meta  { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }
.list__end   { text-align: right; flex: none; }

/* A delivery: where from, where to, what it pays. */
.route { font-size: 13px; color: var(--ink-soft); }
.route__leg { display: flex; align-items: flex-start; gap: var(--s2); }
.route__dot {
  width: 9px; height: 9px; border-radius: 50%; margin-top: 6px; flex: none;
  background: var(--primary);
}
.route__dot--end { background: var(--green-600); border-radius: 2px; }
.route__line { width: 1px; height: 14px; background: var(--line-strong); margin-left: 4px; }

/* Wide tables scroll inside themselves. The page never scrolls sideways. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-muted);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }

/* -------------------------------------------------------------------------
   6. Status
   ------------------------------------------------------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--n-100); color: var(--ink-soft);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--waiting   { background: var(--amber-50); color: var(--amber-600); }
.badge--live      { background: var(--blue-50);  color: var(--primary); }
.badge--done      { background: var(--green-50); color: var(--green-600); }
.badge--failed    { background: var(--red-50);   color: var(--red-600); }
.badge--off       { background: var(--n-100);    color: var(--ink-muted); }
.badge--plain::before { display: none; }

/* The order timeline. One line per step, newest last. */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__step { display: flex; gap: var(--s3); padding-bottom: var(--s4); position: relative; }
.timeline__step:last-child { padding-bottom: 0; }
.timeline__step::before {
  content: ''; position: absolute; left: 5px; top: 16px; bottom: 0;
  width: 2px; background: var(--line);
}
.timeline__step:last-child::before { display: none; }
.timeline__dot {
  width: 12px; height: 12px; border-radius: 50%; flex: none; margin-top: 4px;
  background: var(--line-strong); z-index: 1;
}
.timeline__step--done .timeline__dot { background: var(--green-600); }
.timeline__step--now  .timeline__dot { background: var(--primary); box-shadow: 0 0 0 4px var(--primary-wash); }
.timeline__label { font-weight: 600; font-size: 14px; }
.timeline__time  { font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------------------
   7. Forms
   ------------------------------------------------------------------------- */

.field { margin-bottom: var(--s4); }
label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--ink-muted); margin-top: 6px; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  font-family: var(--font);
  font-size: 16px;              /* never lower. iPhone zooms below 16. */
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  appearance: none;
}
textarea { min-height: 96px; resize: vertical; }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%),
                    linear-gradient(135deg, var(--ink-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 22px, calc(100% - 14px) 22px;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 40px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-wash);
}
input[aria-invalid="true"] { border-color: var(--red-600); }

/* Choosing one of a few things: vehicle, item size, how to pay. */
.choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: var(--s2); }
.choice {
  position: relative;
  min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; padding: var(--s3) var(--s2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
}
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice:has(input:checked) {
  border-color: var(--primary);
  background: var(--primary-wash);
  color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}
.choice__note { font-size: 11px; font-weight: 500; color: var(--ink-muted); }

/* -------------------------------------------------------------------------
   8. Buttons
   ------------------------------------------------------------------------- */

.btn, button {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  width: 100%;
  min-height: var(--tap);
  padding: 12px 20px;
  font-family: var(--font);
  font-size: 16px; font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active, button:active { background: var(--primary-dark); }
button:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

.btn--quiet {
  color: var(--ink); background: var(--surface); border-color: var(--line-strong);
}
.btn--quiet:active { background: var(--surface-sunk); }

.btn--danger { background: var(--red-600); }
.btn--go     { background: var(--green-600); }
.btn--auto   { width: auto; }
.btn--sm     { min-height: 40px; padding: 8px 14px; font-size: 14px; width: auto; }

/* The one action a driver must hit while moving. Big, and out of the way of
   an accidental tap on something else. */
.btn--primary-action { min-height: 56px; font-size: 17px; }

.row { display: flex; gap: var(--s2); }
.row > * { flex: 1; }

.sticky-action {
  position: sticky; bottom: 0;
  padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  margin: var(--s4) calc(var(--s4) * -1) 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* -------------------------------------------------------------------------
   9. Messages and empty states
   ------------------------------------------------------------------------- */

.notice {
  padding: var(--s3) var(--s4);
  border-radius: var(--radius);
  font-size: 14px;
  border: 1px solid transparent;
}
.notice + * { margin-top: var(--s3); }
.notice--warn { background: var(--amber-50); color: var(--amber-600); border-color: currentColor; }
.notice--bad  { background: var(--red-50);   color: var(--red-600);   border-color: currentColor; }
.notice--ok   { background: var(--green-50); color: var(--green-600); border-color: currentColor; }
.notice--info { background: var(--primary-wash); color: var(--primary); border-color: currentColor; }

.empty { text-align: center; padding: var(--s8) var(--s4); }
.empty__title { font-family: var(--font-head); font-weight: 700; font-size: 16px; }
.empty__note  { font-size: 14px; color: var(--ink-muted); margin-top: var(--s1); }

/* -------------------------------------------------------------------------
   10. Utilities. Kept few on purpose.
   ------------------------------------------------------------------------- */

.muted { color: var(--ink-muted); font-size: 13px; }
.right { text-align: right; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.divider { height: 1px; background: var(--line); margin: var(--s4) 0; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* Kept so the earlier pages keep working while they are brought across. */
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: var(--s5); }
.brand__mark {
  width: 36px; height: 36px; border-radius: 10px; background: var(--primary);
  color: #fff; font-family: var(--font-head); font-weight: 700;
  display: grid; place-items: center; font-size: 14px;
}
.check {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line);
}
.check:last-child { border-bottom: none; }
.check__name { font-weight: 600; font-size: 15px; }
.check__note { font-size: 13px; color: var(--ink-muted); margin-top: 2px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill--ok { background: var(--green-50); color: var(--green-600); }
.pill--bad { background: var(--red-50); color: var(--red-600); }
.pill--wait { background: var(--amber-50); color: var(--amber-600); }
.pill--unknown { background: var(--n-100); color: var(--ink-muted); }
.log {
  background: var(--n-900); color: #E2E8F0; border-radius: var(--radius-sm);
  padding: var(--s3); font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; line-height: 1.5; max-height: 240px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
