/* RouteCore staff app: the design system.
   Section 1 holds every value the app uses. Everything after it composes those tokens; a component
   that needs a size, colour, gap or timing the tokens don't have gets a new token, never a literal.
   Tones mean the same thing everywhere: staff = warning (our turn), customer = info (their turn),
   done = success, closed = neutral, blocked = danger. */

/* 1. Tokens ------------------------------------------------------------------------------------ */
/* Inter, self-hosted (OFL, fonts/OFL.txt): the same letterforms on every staff device. */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("fonts/inter-latin-wght.woff2") format("woff2");
}

:root {
  color-scheme: dark;

  /* Colour. One primary for "you can act here"; warm stone neutrals for all structure; four quiet
     semantic hues that only ever carry meaning. Calm, not sterile: nothing is coloured to decorate. */
  --primary: #5aa897;     --on-primary: #0b1311;
  --bg: #141312;          /* the page */
  --surface: #1c1b19;     /* cards and rows: elevation 1 */
  --surface-2: #262421;   /* selected and floating things: elevation 2 */
  --surface-sunken: #100f0e;  /* set into the page: table footers, notes, key caps */
  --line: #2e2b28;        /* hairline dividers only */
  --field-line: #716c64;  /* edges of controls: 3:1 against the page (WCAG 1.4.11) */
  --text: #ece9e4;
  --muted: #a39e95;       /* supporting text, labels, metadata */
  --success: #63b783;
  --warning: #e2b25a;
  --danger: #f07167;      --on-danger: #1a0505;
  --info: #7ea9ee;
  --neutral: #9a958c;
  --tint: 14%;            /* a hue's strength as a background behind text in that hue */

  /* Type. One family; five sizes; one line height for reading, one for headings. */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  --font-features: "cv11", "ss01";  /* Inter's plainer 1/a/l: digits and names read at a glance */
  --text-root: 15px;
  --text-xs: .8rem;   /* metadata, chips */
  --text-sm: .875rem; /* supporting text, labels, section headings, tables */
  --text-md: 1rem;    /* body, controls, subheadings */
  --text-lg: 1.25rem; /* the case's name */
  --text-xl: 1.5rem;  /* page titles */
  --text-display: clamp(1.5rem, 1rem + 1.5vw, 2rem);  /* the sign-in headline only: the door, not a page */
  --weight-regular: 400; --weight-medium: 500; --weight-semibold: 600; --weight-bold: 700;
  --leading-body: 1.5; --leading-tight: 1.25;
  --tracking-tight: -.015em;  /* large type set tighter, as it is optically */
  --tracking-heading: -.025em;  /* headings, a step tighter still */
  --tracking-label: .04em;  /* small capital labels (table heads, money cells) need air */
  --tracking-kicker: .08em;  /* the sign-in kicker: a short line of capitals over the headline */
  --leading-field: 1.4;

  /* Spacing: a 4px scale. Gaps inside a component are 1-3; between components 4; page edges 5+. */
  --space-0: 2px; --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-8: 32px; --space-16: 64px;
  --gutter: var(--space-4);

  /* Shape and borders */
  --radius-sm: 4px; --radius: 8px; --radius-lg: 12px; --radius-pill: 999px;
  --border: 1px;        /* every outline and divider */
  --border-thick: 2px;  /* the timeline rail */
  --border-accent: 4px; /* the coloured edge that says what a toast is about */
  --focus-ring: 2px; --focus-offset: 2px;

  /* Elevation: surfaces step up in colour. Shadows only where something floats (the toast) or
     answers the pointer (a case row lifting under it). */
  --shadow-overlay: 0 8px 28px rgb(0 0 0 / .35);
  --shadow-raise: 0 1px 2px rgb(0 0 0 / .25), 0 2px 8px rgb(0 0 0 / .18);
  --z-bar: 5;  /* the sticky top bar: above the page, below the toast */
  --z-overlay: 10;

  /* Component dimensions */
  --content-max: 980px;  /* every page */
  --form-max: 560px;     /* a form that is the whole page */
  --auth-shell-max: 880px;  /* staff sign in: the two-panel frame */
  --auth-lift: 6vh;  /* sign in: the content sits a little above the window's middle, where the eye rests */
  --auth-pad: var(--space-8);
  --topbar-h: 52px;
  --control-h: 40px; --control-h-sm: 32px;
  --touch-target: 44px;  /* every control on a touch screen */
  --checkbox: 20px; --dot: 6px; --timeline-dot: 8px; --bar-h: 10px; --swatch: 10px; --avatar: 32px;
  --logo-mark: 20px; --logo-mark-lg: 32px;  /* the RoutePakistan mark: in a bar; on a sign-in page */
  --menu-min: 220px;  /* the account panel */
  --dep-seats-w: 280px;  /* a departure row's seat column, from md */
  --count-min: 20px;  /* a waiting count in the top bar: one or two digits, never a squashed pill */
  --textarea-min: 72px; --money-cell-min: 120px;
  --disabled-opacity: .6;
  --autofill-hold: 600000s;  /* keeps the browser's own autofill tint from ever painting (it can't be restyled directly) */

  /* Breakpoints. Media queries can't read custom properties, so these two widths are written out in
     the @media rules below and nowhere else:
       sm 520px: below it, a phone. Rows stack, the manifest drops columns the bus doesn't need.
       md 760px: from it, a tablet or desktop. The case page goes to two columns.
     Above md the page simply stops growing at --content-max. */

  /* Motion: short, and never in the way of the next action. */
  --dur-fast: 120ms; --dur-base: 180ms;
  --ease: cubic-bezier(.2, 0, 0, 1); --ease-out: cubic-bezier(0, 0, .2, 1);
  --toast-life: 4s;

  /* Tones, named by what they mean in the app, mapped onto the semantic hues once. */
  --staff: var(--warning); --customer: var(--info); --done: var(--success);
  --closed: var(--neutral); --blocked: var(--danger);
  /* Interaction states: derived, so every theme gets them for free. Pressing goes further than hovering. */
  --hover-bg: var(--surface-2);
  --primary-hover: color-mix(in srgb, var(--primary) 85%, var(--text));
  --primary-active: color-mix(in srgb, var(--primary) 70%, var(--text));
  --danger-hover: color-mix(in srgb, var(--danger) 85%, var(--text));
  --danger-active: color-mix(in srgb, var(--danger) 70%, var(--text));
  /* ...and their backgrounds, derived from --tint so a theme only ever sets hues */
  --staff-bg: color-mix(in srgb, var(--staff) var(--tint), transparent);
  --customer-bg: color-mix(in srgb, var(--customer) var(--tint), transparent);
  --done-bg: color-mix(in srgb, var(--done) var(--tint), transparent);
  --closed-bg: color-mix(in srgb, var(--closed) var(--tint), transparent);
  --blocked-bg: color-mix(in srgb, var(--blocked) var(--tint), transparent);
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --primary: #1b6f5f; --on-primary: #ffffff;
    --bg: #f7f6f3; --surface: #ffffff; --surface-2: #efede8; --surface-sunken: #f1efea; --line: #e7e4de; --field-line: #868178;
    --text: #1c1b19; --muted: #66625b;
    --success: #1d7140; --warning: #845600; --danger: #b3261e; --on-danger: #ffffff; --info: #2457b3;
    --neutral: #66625b;
    --tint: 10%;
    --shadow-overlay: 0 8px 28px rgb(28 27 25 / .12);
    --shadow-raise: 0 1px 2px rgb(28 27 25 / .06), 0 2px 8px rgb(28 27 25 / .06);
  }
}

/* 2. Base and typography: one style per role --------------------------------------------------- */
* { box-sizing: border-box; }
html, body {
  margin: 0; background: var(--bg); color: var(--text);
  font: var(--weight-regular) var(--text-root)/var(--leading-body) var(--font);  /* body text */
  font-feature-settings: var(--font-features);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
h1, h2 { text-wrap: balance; }
p, .hint { text-wrap: pretty; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Page title: type carries the hierarchy, not boxes or colour */
h1 { font-size: var(--text-xl); font-weight: var(--weight-semibold); line-height: var(--leading-tight);
     letter-spacing: var(--tracking-heading); margin: 0; }
.head h1 { font-size: var(--text-lg); }  /* a case is an object, not a page: its name is one step down */
/* Section heading: a quiet sentence-case label over a section's content */
h2 { font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--muted); margin: 0 0 var(--space-2);
     letter-spacing: var(--tracking-heading); }
/* Subheading: names one item in a list (a departure, a stop) */
h2.title, h3.title { font-size: var(--text-md); color: var(--text); margin: 0; line-height: var(--leading-tight); }
/* Page subtitle: one plain sentence under the title that says where things stand */
.subtitle { margin: var(--space-1) 0 0; color: var(--muted); }
/* Supporting text */
.hint { font-size: var(--text-sm); color: var(--muted); }
/* Label */
label { display: grid; gap: var(--space-1); font-size: var(--text-sm); color: var(--muted); }
/* Metadata: who, when, how much, in passing */
.meta, .when, .legend { font-size: var(--text-sm); color: var(--muted); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
/* Breadcrumb trail on admin detail pages: shows navigation hierarchy (e.g. Operators / OP-9482) */
.breadcrumb { display: flex; flex-wrap: wrap; gap: var(--space-3); margin: 0 0 var(--space-4);
              font-size: var(--text-sm); color: var(--muted); align-items: center; }
.breadcrumb a { color: var(--primary); }
.breadcrumb a:hover { text-decoration: underline; }
/* Interactive: links that do something are the primary colour; buttons are below */
.filters a, a.link { color: var(--primary); }
.filters a.danger, a.link.danger { color: var(--danger); }  /* a link that ends something: same place, its own tone */

:focus-visible { outline: var(--focus-ring) solid var(--primary); outline-offset: var(--focus-offset);
                 border-radius: var(--radius-sm); }
main:focus, h1:focus { outline: none; }  /* focus lands here after skip/save; it is not a control */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
           clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: var(--space-2); top: var(--space-2); z-index: var(--z-overlay);
        transform: translateY(-200%); padding: var(--space-2) var(--space-3); border-radius: var(--radius);
        background: var(--primary); color: var(--on-primary); font-weight: var(--weight-semibold); }
.skip:focus { transform: none; }

/* 3. Components -------------------------------------------------------------------------------- */

/* Top bar: where you are (the operator, then the place) and who you are. One row from sm; on a phone
   the places take their own full-width row under the operator, and only that row scrolls. */
.topbar { background: var(--surface); border-bottom: var(--border) solid var(--line); }
.topbar .wrap { display: flex; align-items: stretch; gap: 0 var(--space-6); min-height: var(--topbar-h); }
/* Brand: our mark, a quiet slash, then whose app this is. The operator's name is what staff read;
   the mark signs it. On /admin the mark carries the wordmark and a muted "Admin". */
.brand { display: flex; align-items: center; gap: var(--space-2); min-width: 0; white-space: nowrap;
         font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); color: var(--text); }
.brand .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.brand .sep, .brand .role, .brand .zone-badge { color: var(--muted); font-weight: var(--weight-regular); }
/* The mark: one drawing, the text colour, never below --logo-mark */
.logo { display: inline-flex; align-items: center; gap: var(--space-2); flex: none; }
.logo svg { width: var(--logo-mark); height: var(--logo-mark); flex: none; }
.wordmark { font-weight: var(--weight-regular); letter-spacing: var(--tracking-tight); }
.wordmark b { font-weight: var(--weight-bold); }
/* A place: the whole bar height is the target; the label inside carries hover and focus, and the
   current place is underlined in the primary along the bar's bottom edge, the way a tab is. */
.nav { display: flex; flex: 1; min-width: 0; }
.nav a { position: relative; display: flex; align-items: center; padding: 0 var(--space-1);
         color: var(--muted); font-weight: var(--weight-medium); }
.nav a > span { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--control-h-sm);
                padding: 0 var(--space-2); border-radius: var(--radius); }
.nav a.on { color: var(--text); }
.nav a.on::after { content: ""; position: absolute; inset: auto var(--space-1) calc(-1 * var(--border));
                   height: var(--border-thick); border-radius: var(--radius-pill); background: var(--primary); }
.nav a:focus-visible { outline: none; }  /* the ring goes on the label, below, not the full-height cell */
.nav a:focus-visible > span { outline: var(--focus-ring) solid var(--primary); outline-offset: var(--focus-offset); }
/* Waiting on you: the "our turn" tone, so it reads as work, never as decoration */
.nav .count { min-width: var(--count-min); padding: 0 var(--space-1); border-radius: var(--radius-pill);
              text-align: center; font-size: var(--text-xs); font-weight: var(--weight-semibold);
              font-variant-numeric: tabular-nums; color: var(--staff); background: var(--staff-bg); }
/* Who is signed in: an initial, then name over role. It opens a small panel with the full identity and
   Sign out, so ending a session is never a permanent button in the bar. */
.account { position: relative; display: flex; align-items: center; color: var(--muted); font-size: var(--text-sm); }
.account > summary { display: flex; align-items: center; gap: var(--space-2); min-height: var(--control-h); padding: 0 var(--space-2);
                     border-radius: var(--radius); cursor: pointer; list-style: none; transition: background-color var(--dur-fast) var(--ease); }
.account > summary::-webkit-details-marker { display: none; }
.account > summary:hover, .account[open] > summary { background: var(--hover-bg); }
.account .avatar { display: grid; place-items: center; width: var(--avatar); height: var(--avatar); flex: none;
                   border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text);
                   font-weight: var(--weight-semibold); }
.account > summary:hover .avatar, .account[open] .avatar { background: var(--surface); }
.account .id { display: grid; line-height: var(--leading-tight); text-align: left; }
.account .id b, .account-menu .who b { color: var(--text); font-weight: var(--weight-medium); }
.account-menu { position: absolute; right: 0; top: calc(100% + var(--space-1)); z-index: var(--z-overlay); min-width: var(--menu-min);
                display: grid; gap: var(--space-2); padding: var(--space-3); background: var(--surface-2);
                border: var(--border) solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-overlay); }
.account-menu .who { display: grid; margin: 0; line-height: var(--leading-tight); padding-bottom: var(--space-2);
                     border-bottom: var(--border) solid var(--line); }
.account-menu button { justify-self: stretch; }

/* Banner, toast */
.banner { padding: var(--space-3) var(--gutter); text-align: center; font-weight: var(--weight-medium); }
.banner.staff { background: var(--staff-bg); color: var(--staff); }
.banner.blocked { background: var(--blocked-bg); color: var(--blocked); }
#toast:not(:empty) {
  position: fixed; left: 50%; bottom: var(--space-5); transform: translateX(-50%); z-index: var(--z-overlay);
  max-width: calc(100% - 2 * var(--gutter)); padding: var(--space-3) var(--space-4); border-radius: var(--radius-lg);
  background: var(--surface-2); border: var(--border) solid var(--line); border-left: var(--border-accent) solid var(--primary);
  box-shadow: var(--shadow-overlay);
  animation: toast-in var(--dur-base) var(--ease-out), toast var(--toast-life) forwards;
}
/* The one movement in the app: the toast rises a step as it arrives, so the eye finds it. */
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, var(--space-2)); } to { transform: translate(-50%, 0); } }
@keyframes toast { 0%, 85% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }
@keyframes toast-still { 0%, 99% { opacity: 1; } 100% { opacity: 0; visibility: hidden; } }

/* Card */
.card { background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-4); }

/* Chip: a tone and a word, never a tone alone */
.chip { font-variant-numeric: tabular-nums; display: inline-flex; align-items: center; gap: var(--space-1); padding: var(--space-0) var(--space-2);
        border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-semibold); white-space: nowrap; }
.chip::before { content: ""; width: var(--dot); height: var(--dot); border-radius: var(--radius-pill); background: currentColor; }
.chip.staff { color: var(--staff); background: var(--staff-bg); }
.chip.customer { color: var(--customer); background: var(--customer-bg); }
.chip.done { color: var(--done); background: var(--done-bg); }
.chip.closed { color: var(--closed); background: var(--closed-bg); }
.chip.blocked { color: var(--blocked); background: var(--blocked-bg); }
.chip.plain::before { display: none; }
.chip.plain { color: var(--muted); background: var(--surface-2); font-weight: var(--weight-medium); }

/* Tabs and filters */
.tabs { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-0); }
.tabs a { padding: var(--space-2) var(--space-3); border-radius: var(--radius); border: var(--border) solid var(--line);
          white-space: nowrap; color: var(--muted); }
.tabs a.on { background: var(--surface-2); color: var(--text); border-color: var(--primary); }
.tabs .count { margin-left: var(--space-2); font-weight: var(--weight-bold); color: var(--text); }
.filters { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: var(--space-3);
           font-size: var(--text-sm); }

/* Case row */
.rows { display: grid; gap: var(--space-2); }
.case-row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-1) var(--space-3); padding: var(--space-3) var(--space-4);
            background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg);
            transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
.case-row:hover { border-color: var(--field-line); box-shadow: var(--shadow-raise); text-decoration: none; }
.case-row .who { font-weight: var(--weight-semibold); }
.ref { color: var(--muted); font-size: var(--text-sm); font-weight: var(--weight-medium); }  /* an identifier: metadata, not a badge */
.case-row .ref { margin-left: var(--space-2); }
.case-row .side { text-align: right; display: grid; gap: var(--space-1); justify-items: end; align-content: start; }
/* Money is what a row is weighed by: body colour, not muted metadata */
.case-row .amount, .row-between .amount { font-size: var(--text-sm); font-weight: var(--weight-medium); font-variant-numeric: tabular-nums; }
.keys-hint { margin: var(--space-3) 0 0; }
kbd { font: inherit; font-size: var(--text-xs); padding: 0 var(--space-1); border: var(--border) solid var(--line);
      border-radius: var(--radius-sm); background: var(--surface); }
.timer { font-size: var(--text-xs); color: var(--customer); font-variant-numeric: tabular-nums; }

/* Departure bar */
.dep-bar { display: grid; gap: var(--space-2); }
.bar { display: flex; height: var(--bar-h); border-radius: var(--radius-pill); overflow: hidden; background: var(--surface-2); }
.bar .c { background: var(--done); }
.bar .h { background: var(--customer); }
.legend { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.legend b { color: var(--text); }
.occupancy { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2); font-size: var(--text-sm);
             font-variant-numeric: tabular-nums; }
/* Each legend key wears the colour of its part of the bar */
.legend .key { display: inline-flex; align-items: center; gap: var(--space-1); }
.legend .key::before { content: ""; width: var(--swatch); height: var(--swatch); border-radius: var(--radius-sm); }
.legend .key.c::before { background: var(--done); }
.legend .key.h::before { background: var(--customer); }
.legend .key.f::before { background: var(--surface-2); border: var(--border) solid var(--field-line); box-sizing: border-box; }

/* Departure row: one departure, an object you act on. What it is beside its seats; prices on demand; links. */
.dep-row { display: grid; gap: var(--space-3); padding: var(--space-4); background: var(--surface);
           border: var(--border) solid var(--line); border-radius: var(--radius-lg); }
.dep-row .title .tour { color: var(--muted); font-weight: var(--weight-medium); margin-left: var(--space-1); }
.dep-row .filters { margin-top: 0; }
/* The empty track is set into the row, so a trip with nothing booked still shows its full length */
.dep-row .bar, .dep-row .legend .key.f::before { background: var(--surface-sunken); }

/* Disclosure: reference figures shown on demand (a departure's prices). Not an action: it holds no form. */
.disclosure > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: baseline; gap: var(--space-2);
                        padding: var(--space-1) var(--space-2); margin-inline: calc(-1 * var(--space-2));
                        border-radius: var(--radius); font-size: var(--text-sm); color: var(--muted);
                        font-variant-numeric: tabular-nums;
                        transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.disclosure > summary::-webkit-details-marker { display: none; }
.disclosure > summary::before { content: "›"; content: "›" / ""; }  /* decoration; <details> announces open/closed */
.disclosure[open] > summary::before { content: "⌄"; content: "⌄" / ""; }
.disclosure > summary:hover { background: var(--hover-bg); color: var(--text); }
.disclosure > summary:active { color: var(--primary); }
.disclosure[open] > summary { color: var(--text); margin-bottom: var(--space-2); }

/* Money strip: the gap between cells is the divider */
.money { display: flex; flex-wrap: wrap; gap: var(--border); margin: 0; background: var(--line);
         border: var(--border) solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.money dd { margin: 0; }
.money > div { flex: 1 1 var(--money-cell-min); background: var(--surface); padding: var(--space-2) var(--space-3); }
.money .k { font-size: var(--text-xs); color: var(--muted); font-weight: var(--weight-medium);
            text-transform: uppercase; letter-spacing: var(--tracking-label); }
.money .v { font-weight: var(--weight-bold); font-variant-numeric: tabular-nums; }
.money .note { font-size: var(--text-xs); color: var(--muted); }
.money .note.staff { color: var(--staff); }  /* waiting on us, as everywhere */

/* Context header */
.head { display: grid; gap: var(--space-2); }
.head .line { display: flex; gap: var(--space-2) var(--space-3); flex-wrap: wrap; align-items: baseline; }
/* A run of facts: space separates them, so nothing dangles at the start of a wrapped line. */
.facts-line { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-4); }

/* Section: a part of one object. A divider and a heading, not a box. */
.section { display: grid; gap: var(--space-3); align-content: start;  /* a short column doesn't spread to match its neighbour */
           padding-top: var(--space-5); border-top: var(--border) solid var(--line); }
.section h2, .section > p { margin: 0; }
/* List: several objects of one kind, split by dividers. */
.list > * { padding-block: var(--space-4); }
.list > * + * { border-top: var(--border) solid var(--line); }
.list > :first-child { padding-top: 0; }
.why { padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--staff-bg); color: var(--staff); }

/* Actions: each one opens one small form */
.actions { display: grid; gap: var(--space-2); }
.action { border: var(--border) solid var(--line); border-radius: var(--radius-lg); background: var(--surface);
          transition: border-color var(--dur-fast) var(--ease); }
.action > summary { cursor: pointer; padding: var(--space-3) var(--space-4); font-weight: var(--weight-semibold); list-style: none; }
.action > summary::-webkit-details-marker { display: none; }
.action > summary::after { content: "›"; content: "›" / ""; float: right; color: var(--muted); }
.action[open] > summary::after { content: "⌄"; content: "⌄" / ""; }  /* the arrow is decoration; <details> announces open/closed */
.action.primary { border-color: var(--primary); }
.action.primary > summary { color: var(--primary); }
.action form { padding: 0 var(--space-4) var(--space-4); display: grid; gap: var(--space-3); }
/* What undoes or ends something comes last, apart from the rest, named in the danger tone */
.action.danger > summary { color: var(--danger); }
.action:not(.danger) + .action.danger { margin-top: var(--space-3); }

/* Form controls */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg); width: 100%; min-height: var(--control-h);
  border: var(--border) solid var(--field-line); border-radius: var(--radius); padding: var(--space-2) var(--space-3);
  line-height: var(--leading-field); transition: border-color var(--dur-fast) var(--ease);
}
/* One ring: the outline sits over the field's own edge, so focus never draws two boxes */
input:focus, select:focus, textarea:focus { outline: var(--focus-ring) solid var(--primary); outline-offset: calc(-1 * var(--border));
                                           border-color: var(--primary); }
/* A saved login filled in by the browser keeps the field's own colours, not the browser's blue-grey. */
input:-webkit-autofill, input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text); caret-color: var(--text);
  transition: background-color var(--autofill-hold) 0s, color var(--autofill-hold) 0s;
}
textarea { min-height: var(--textarea-min); resize: vertical; }
/* Shown for context but fixed (a booked trip's date): looks like a fact, not a field to fill. */
input[readonly] { background: var(--surface-2); color: var(--muted); }
input[type=checkbox] { width: var(--checkbox); height: var(--checkbox); min-height: 0; accent-color: var(--primary); }
label.check { display: flex; gap: var(--space-2); align-items: center; color: var(--text); }
label.check input { width: var(--checkbox); }
.error { color: var(--danger); font-size: var(--text-sm); }
fieldset { border: var(--border) solid var(--line); border-radius: var(--radius-lg); padding: var(--space-3); margin: 0; min-width: 0; }
legend { padding: 0 var(--space-2); font-weight: var(--weight-semibold); }

/* Buttons */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; justify-self: start;
  min-height: var(--control-h); padding: 0 var(--space-4); border-radius: var(--radius); cursor: pointer;
  font: inherit; font-weight: var(--weight-semibold); text-decoration: none;
  border: var(--border) solid var(--primary); background: var(--primary); color: var(--on-primary);
}
.button:hover { text-decoration: none; }
button.quiet { min-height: var(--control-h-sm); padding: 0 var(--space-3); background: transparent; color: var(--muted);
               border-color: var(--field-line); }
button.danger { background: var(--danger); border-color: var(--danger); color: var(--on-danger); }
/* A button that is always on the page but isn't the next step (add a note, save assignment): outlined,
   so each view has one filled button the eye goes to first. */
button.secondary, .button.secondary { background: transparent; color: var(--primary); border-color: var(--field-line); }
/* In flight: htmx disables the form's button (hx-disabled-elt), app.js does the same for plain posts. */
button:disabled { opacity: var(--disabled-opacity); cursor: progress; }

/* States. Colour only, never movement: hover says "this responds", active says "pressed". */
button, .button, .nav a, .tabs a, .action > summary {
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
button:not(:disabled):hover, .button:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:not(:disabled):active, .button:active { background: var(--primary-active); border-color: var(--primary-active); }
button.danger:not(:disabled):hover { background: var(--danger-hover); border-color: var(--danger-hover); }
button.danger:not(:disabled):active { background: var(--danger-active); border-color: var(--danger-active); }
button.quiet:not(:disabled):hover { background: var(--hover-bg); border-color: var(--field-line); color: var(--text); }
button.secondary:not(:disabled):hover, .button.secondary:hover { background: var(--hover-bg); border-color: var(--primary); color: var(--primary); }
button.secondary:not(:disabled):active, .button.secondary:active { background: var(--surface-2); border-color: var(--primary-active); color: var(--primary-active); }
button.quiet:not(:disabled):active { border-color: var(--primary); }
.tabs a:hover { background: var(--hover-bg); color: var(--text); text-decoration: none; }
.tabs a:active { border-color: var(--primary); }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a:hover > span { background: var(--hover-bg); }
.nav a:active > span { color: var(--primary); }
.brand:hover { text-decoration: none; color: var(--primary); }
.action > summary:hover { background: var(--hover-bg); }
.action > summary:active { color: var(--primary); }
.action { overflow: hidden; }  /* the summary's hover fill follows the rounded corners... */
.action > summary:focus-visible { outline-offset: calc(-1 * var(--focus-ring)); border-radius: var(--radius-lg); }  /* ...so its ring sits inside */

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; }
.timeline li { padding: var(--space-3) 0 var(--space-3) var(--space-5); border-left: var(--border-thick) solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; width: var(--timeline-dot); height: var(--timeline-dot);
                       left: calc((var(--timeline-dot) + var(--border-thick)) / -2);
                       top: calc(var(--space-3) + (1em * var(--leading-body) - var(--timeline-dot)) / 2);
                       border-radius: var(--radius-pill); background: var(--line); }
.timeline li.note::before { background: var(--primary); }
.timeline .when { font-size: var(--text-xs); }

/* Payments */
.pay-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-3); }
.pay-list li { display: grid; gap: var(--space-0); padding-bottom: var(--space-3); border-bottom: var(--border) solid var(--line); }
.pay-list li:last-child { border-bottom: 0; padding-bottom: 0; }

/* Empty state */
.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--muted);
         border: var(--border) dashed var(--line); border-radius: var(--radius-lg); }

/* Error recovery card: solid, elevated, with optional badge and action buttons */
.error-card { display: grid; gap: var(--space-4); padding: var(--space-6); margin: var(--space-4) 0;
              background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); }
.error-badge { align-self: start; display: inline-block; padding: var(--space-1) var(--space-3);
               background: var(--info); color: var(--bg); border-radius: var(--radius-pill);
               font-size: var(--text-xs); font-weight: var(--weight-semibold); text-transform: uppercase; letter-spacing: var(--tracking-label); }
.error-message { margin: 0; color: var(--text); line-height: var(--leading-body); }
.error-actions { display: flex; gap: var(--space-3); flex-wrap: wrap; }

/* Printouts (voucher, manifest): the same card on screen, plain black on white on paper */
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.facts.compact { gap: var(--space-1) var(--space-3); font-size: var(--text-sm); }  /* a departure's prices and pickups */
.facts.compact dd { color: var(--muted); }
/* What a destructive step will do, one line each */
.consequences { margin: 0; padding-left: var(--space-5); display: grid; gap: var(--space-1); }
.sheet-scroll { overflow-x: auto; }  /* only the table scrolls; totals stay in view */
.sheet { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.sheet th, .sheet td { text-align: left; padding: var(--space-2); border-bottom: var(--border) solid var(--line);
                       font-variant-numeric: tabular-nums; }
/* Column heads: small, quiet capitals; the figures below carry the weight */
.sheet thead th { font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--muted);
                  text-transform: uppercase; letter-spacing: var(--tracking-label); }
.sheet thead .hint { text-transform: none; letter-spacing: normal; font-weight: var(--weight-regular); }  /* a unit reads as words */
.sheet tbody tr:hover { background: var(--hover-bg); }
.sheet tfoot { background: var(--surface-sunken); }
.sheet .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.sheet th .hint { font-weight: var(--weight-regular); }  /* a header's unit or detail, not its name */
.sheet tfoot td, .sheet tfoot th { border-bottom: 0; }
.search { display: flex; gap: var(--space-2); align-items: center; }  /* the box and its button on one line */
.search input { flex: 1; min-width: 0; }
.secret { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }  /* a long token or URL to copy: wraps, never widens the page */

/* 4. Layout ------------------------------------------------------------------------------------ */
.wrap { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--gutter); }
main { padding: var(--space-5) 0 var(--space-16); display: grid; gap: var(--space-4); }
main > *, .stack-lg > *, .grid-2 > * { min-width: 0; }  /* let wide children (tab strip) scroll instead of widening the page */
.stack { display: grid; gap: var(--space-3); }
.stack-lg { display: grid; gap: var(--space-4); }
.stack > p, .action form > p, .stack > .filters { margin: 0; }  /* the stack's gap is the spacing; no browser margins on top */
.gap-below { margin-bottom: var(--space-3); }
.field-row { display: grid; gap: var(--space-3); align-items: end; }  /* short fields that belong together */
.grid-2 { display: grid; gap: var(--space-4); }
.page-head, .row-between { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-2); }
.card:has(> form.stack:only-child) { max-width: var(--form-max); }  /* a whole-page form reads down one column */

/* The door's task panel: the right half of .auth-shell (sign in, admin sign in, a signed-out 404) */
.login { display: grid; gap: var(--space-4); padding: var(--auth-pad); align-content: center; }
.login p { margin: 0; }
.login-footer { margin: 0; text-align: center; font-size: var(--text-sm); color: var(--muted); }
.login-footer summary { cursor: pointer; list-style: none; color: var(--muted); }
.login-footer summary::-webkit-details-marker { display: none; }
.login-footer summary:hover, .login-footer[open] summary { color: var(--text); text-decoration: underline; }
/* A short note set into the card: what to do when the usual way isn't open */
.callout { margin-top: var(--space-3); padding: var(--space-3); text-align: left; border-radius: var(--radius);
           background: var(--surface-sunken); border: var(--border) solid var(--line); color: var(--muted); }
.callout a, .auth-intro .lede a { color: var(--primary); }  /* a link inside a sentence stays in the line */
.auth-intro .logo { font-size: var(--text-lg); }  /* the door: the lockup at its full size */
.auth-intro .logo svg { width: var(--logo-mark-lg); height: var(--logo-mark-lg); }
/* The door: everything on the page is one object in the window's optical middle. */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
        padding: var(--space-6) var(--gutter) calc(var(--space-6) + var(--auth-lift)); }
/* Staff sign in: one frame, two panels split by a hairline; the brand panel is set into the page. */
.auth-shell { width: 100%; max-width: var(--auth-shell-max); display: grid; overflow: hidden;
              background: var(--surface); border: var(--border) solid var(--line); border-radius: var(--radius-lg); }
.auth-intro .support { font-size: var(--text-sm); }
.auth-intro .support:hover { color: var(--text); }
.auth-intro { display: flex; flex-direction: column; gap: var(--space-8); padding: var(--auth-pad);
               background: var(--surface-sunken); border-bottom: var(--border) solid var(--line); }
.auth-intro .pitch { display: grid; gap: var(--space-3); }
.auth-intro p { margin: 0; }
/* Kicker: a short line of small capitals over a big statement (the sign-in pitch, an error's code) */
.eyebrow { margin: 0; font-size: var(--text-xs); font-weight: var(--weight-semibold); color: var(--muted);
                       text-transform: uppercase; letter-spacing: var(--tracking-kicker); }
.auth-intro .display { font-size: var(--text-display); font-weight: var(--weight-bold); line-height: var(--leading-tight);
                       letter-spacing: var(--tracking-heading); text-wrap: balance; }
.auth-intro .display .line { display: block; }  /* one promise per line */
.auth-intro .lede { color: var(--muted); font-size: var(--text-md); text-wrap: pretty; }
.login form { display: grid; gap: var(--space-3); }
.login button, .login .button { justify-self: stretch; min-height: var(--touch-target); }

/* Phone (below sm) */
@media (max-width: 520px) {
  .case-row { grid-template-columns: 1fr; }
  .case-row .side { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); text-align: left; }
  .sheet .wide { display: none; }  /* the bus needs Collect, not Paid */
  /* Top bar: operator and who on the first row (the name stays, the initial and role go); the
     places on a second row, edge to edge, sharing the width. */
  .topbar .wrap { flex-wrap: wrap; column-gap: var(--space-3); }
  .brand { flex: 1; }
  .account .id { display: none; }  /* the avatar stays; the panel holds the name and role */
  .nav { order: 1; flex-basis: calc(100% + 2 * var(--gutter)); overflow-x: auto; margin-inline: calc(-1 * var(--gutter));
         padding-inline: calc(var(--gutter) - var(--space-1)); border-top: var(--border) solid var(--line); }
  .nav a { flex: 1 0 auto; justify-content: center; min-height: var(--touch-target); }
  .nav a.on::after { bottom: 0; }  /* the strip scrolls, so it clips: keep the underline inside it */
}
/* Tablet and up (from md) */
@media (min-width: 760px) {
  .grid-2, .field-row { grid-template-columns: 1fr 1fr; }
  /* Sign in: brand and promise on the left, the form on the right, one hairline between them */
  .auth-shell { grid-template-columns: 1.1fr 1fr; }
  .auth-intro { justify-content: space-between; border-bottom: 0; border-right: var(--border) solid var(--line); }
  .dep-row { grid-template-columns: 1fr var(--dep-seats-w); column-gap: var(--space-6);
             grid-template-areas: "what seats" "prices seats" "links seats"; align-items: start; }
  .dep-row > .what { grid-area: what; }
  .dep-row > .dep-bar { grid-area: seats; }
  .dep-row > .disclosure { grid-area: prices; }
  .dep-row > .filters { grid-area: links; }
  /* The bar stays in reach on long pages (a case, the manifest); focus and anchors land below it. */
  .topbar { position: sticky; top: 0; z-index: var(--z-bar); }
  html { scroll-padding-top: calc(var(--topbar-h) + var(--space-4)); }
}
/* Touch screens, any width: fingers, not cursors */
@media (pointer: coarse) {
  button, button.quiet, .button, input:not([type=checkbox]), select, .nav a, .tabs a, .action > summary, .disclosure > summary { min-height: var(--touch-target); }
  .tabs a { display: inline-flex; align-items: center; }
  .filters a, a.link, a.back { display: inline-block; padding: var(--space-3) 0; }
  label.check { min-height: var(--touch-target); }
  .keys-hint { display: none; }  /* no keyboard to use it with */
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; scroll-behavior: auto !important; }
  #toast:not(:empty) { animation: toast-still var(--toast-life) forwards; }
}

/* 5. Print: the same components with the tokens remapped to ink on paper ----------------------- */
@media print {
  :root { color-scheme: light; --bg: #fff; --surface: #fff; --text: #000; --muted: #333; --line: #999; }
  .topbar, .banner, #toast, .skip, .no-print { display: none !important; }
  .card { border: 0; padding: 0; }
  .sheet thead th { text-transform: none; letter-spacing: normal; font-size: inherit; color: inherit; }  /* paper keeps plain heads */
  .sheet tfoot { background: none; }
}
