/*
 * Design tokens and base styles. Shared by the operator console, the driver display,
 * the demo landing page and (by copy of the token block) the pitch.
 *
 * Rules (docs/DECISIONS.md D13, D17):
 *  - No CDN, no web fonts: the console must work in a guard booth with no internet.
 *  - Green, amber, red and blue mean bay and gate states, exactly as the lights on the
 *    hardware do. They are never decoration, and every state also carries a word.
 *  - The one accent is sand. Depth is a step up the ink ramp, never a shadow.
 */
:root {
  /* "Mist at dawn" (DESIGN.md): khareef fog ground, escarpment-green ink, sea-teal for the
     smart-city layer, frankincense amber as the one accent. Variable names are kept from the
     first version so every rule below follows the new palette. */
  color-scheme: light;
  --ink-0: #f1f4f0; /* page ground: morning fog */
  --ink-1: #e6ece7; /* raised band */
  --ink-2: #d8e1da; /* lifted: hover, selected */
  --ink-3: #c9d6cd; /* strong lift */
  --line: #c3d0c7;
  --line-soft: #d6e0d9;
  --mute: #3f5a51; /* secondary text, 7.0:1 on the ground */
  --text: #10302a; /* escarpment green, 13.9:1 */
  --sand: #0b6e78; /* sea teal: links, focus, the active tab */
  --sand-ink: #ffffff;
  --resin: #e3a23b; /* frankincense: the primary action */
  --resin-ink: #8a5a12;

  --ok: #17874d; --warn: #b86e00; --stop: #c23b2b; --info: #2563c9; --fault: #7a3fb0;
  --ok-bg: rgb(23 135 77 / 0.12); --warn-bg: rgb(184 110 0 / 0.13); --stop-bg: rgb(194 59 43 / 0.12);
  --info-bg: rgb(37 99 201 / 0.12); --fault-bg: rgb(122 63 176 / 0.12);

  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --arabic: 'SF Arabic', 'Geeza Pro', 'Noto Kufi Arabic', 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, Consolas, monospace;

  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem; --s7: 3rem; --s8: 4.5rem;
  --gutter: clamp(1rem, 0.4rem + 3vw, 3rem);
  --radius: 6px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
}
:root[lang='en'] .ar, :root[lang='ar'] .en { display: none !important; }
:root[lang='ar'] body, :root[lang='ar'] .btn, :root[lang='ar'] input, :root[lang='ar'] select, :root[lang='ar'] .tab,
:root[lang='ar'] .state, :root[lang='ar'] .verdict-word, :root[lang='ar'] .view-title { font-family: var(--arabic); letter-spacing: 0; }
:root[lang='ar'] body { line-height: 1.7; }
:root[lang='ar'] .state { text-transform: none; }
.lang-btn { font: 700 0.875rem/1 var(--font); padding: 0.45rem 0.8rem; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); cursor: pointer; }
.lang-btn .en { font-family: var(--arabic); }
.lang-btn:hover { border-color: var(--sand); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ink-0);
  color: var(--text);
  font: 400 1rem/1.55 var(--font);
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
img, svg { max-width: 100%; }
a { color: var(--sand); text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
::selection { background: var(--sand); color: var(--sand-ink); }
:focus-visible { outline: 2px solid var(--sand); outline-offset: 3px; border-radius: 2px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.mute { color: var(--mute); }

/* --- controls --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 2.5rem; padding: 0.5rem 0.95rem;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: transparent; color: var(--text);
  font: 600 0.9375rem/1.1 var(--font); cursor: pointer; text-decoration: none;
  transition: background-color 140ms var(--ease), border-color 140ms var(--ease);
}
.btn:hover { background: var(--ink-2); border-color: var(--mute); }
.btn:active { transform: translateY(1px); }
.btn:disabled { color: var(--mute); border-color: var(--line-soft); cursor: not-allowed; background: transparent; }
.btn-primary { background: var(--resin); border-color: var(--resin); color: var(--text); }
.btn-primary:hover { background: #ecb455; border-color: #ecb455; }
.btn-small { min-height: 2rem; padding: 0.3rem 0.65rem; font-size: 0.8125rem; }
.btn[aria-pressed='true'] { background: var(--ink-3); border-color: var(--sand); }

input[type='text'], input[type='password'], input[type='number'], select {
  min-height: 2.5rem; padding: 0.4rem 0.7rem; width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--ink-1); color: var(--text); font: inherit;
}
label { font-weight: 600; font-size: 0.875rem; }

/* --- state words: a shape and a word, never colour alone --- */
.state {
  display: inline-flex; align-items: center; gap: 0.45em;
  padding: 0.2rem 0.6rem; border-radius: 999px;
  font: 700 0.75rem/1.4 var(--font); letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
  background: var(--ink-2); color: var(--mute);
}
.state::before { content: ''; width: 0.6em; height: 0.6em; border-radius: 50%; background: currentColor; flex: none; }
.state.ok { background: var(--ok-bg); color: var(--ok); }
.state.warn { background: var(--warn-bg); color: var(--warn); }
.state.warn::before { border-radius: 1px; transform: rotate(45deg); }
.state.stop { background: var(--stop-bg); color: var(--stop); }
.state.stop::before { border-radius: 1px; }
.state.info { background: var(--info-bg); color: var(--info); }
.state.info::before { background: transparent; box-shadow: inset 0 0 0 2px currentColor; }
.state.fault { background: var(--fault-bg); color: var(--fault); }
.state.fault::before { width: 0; height: 0; border-radius: 0; background: none; border: 0.35em solid transparent; border-bottom: 0.6em solid currentColor; margin-top: -0.25em; }

/* --- console shell --- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.shell > main { flex: 1; min-width: 0; }
.bar {
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
  padding: var(--s3) var(--gutter); border-bottom: 1px solid var(--line); background: var(--ink-1);
}
.brand { display: flex; align-items: baseline; gap: var(--s2); font-weight: 800; letter-spacing: 0.02em; }
.brand-ar { font-family: var(--arabic); font-weight: 700; letter-spacing: 0; color: var(--sand); font-size: 1.05rem; }
.bar-site { color: var(--mute); font-size: 0.9375rem; }
.bar-end { margin-inline-start: auto; display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.clock { font-family: var(--mono); color: var(--mute); font-size: 0.875rem; }

.tabs { display: flex; gap: 0; overflow-x: auto; padding: 0 var(--gutter); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: var(--s3) var(--s4); border: 0; border-bottom: 3px solid transparent; background: none;
  color: var(--mute); font: 600 0.9375rem/1.2 var(--font); cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab[aria-selected='true'] { color: var(--text); border-bottom-color: var(--sand); }

.view { padding: var(--s5) var(--gutter) var(--s8); min-width: 0; }
.view-title { font: 700 1.375rem/1.2 var(--font); }
.view-lede { color: var(--mute); max-width: 68ch; margin-top: var(--s1); }
.region { border-top: 1px solid var(--line); padding-top: var(--s4); margin-top: var(--s5); }
.region > h2, .region-head h2 { font: 700 0.8125rem/1.3 var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--mute); }
.region-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); flex-wrap: wrap; }

/* --- gate view --- */
.gate-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: var(--s6); margin-top: var(--s4); align-items: start; }
.scene { background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.scene svg, .scene img { display: block; width: 100%; height: auto; }
.scene-foot { display: flex; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; padding: var(--s2) var(--s3); border-top: 1px solid var(--line); font-size: 0.8125rem; color: var(--mute); }

.verdict { border-inline-start: 4px solid var(--line); padding: var(--s3) var(--s4); background: var(--ink-1); min-height: 5.2rem; }
.verdict-word { font: 800 1.5rem/1.15 var(--font); letter-spacing: 0.01em; }
.verdict-text { color: var(--mute); margin-top: var(--s1); }
.verdict.ok { border-color: var(--ok); } .verdict.ok .verdict-word { color: var(--ok); }
.verdict.stop { border-color: var(--stop); } .verdict.stop .verdict-word { color: var(--stop); }
.verdict.warn { border-color: var(--warn); } .verdict.warn .verdict-word { color: var(--warn); }
.verdict.info { border-color: var(--info); } .verdict.info .verdict-word { color: var(--info); }
.verdict.fault { border-color: var(--fault); } .verdict.fault .verdict-word { color: var(--fault); }

.who { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s4); min-height: 3.5rem; }
.avatar { width: 3.25rem; height: 3.25rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; flex: none; background: var(--ink-3); color: var(--text); }
.who-name { font-weight: 700; font-size: 1.125rem; }

.checks { margin-top: var(--s4); border-top: 1px solid var(--line); }
.check { display: grid; grid-template-columns: 2rem minmax(0, 1fr) auto; gap: var(--s3); align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--line-soft); }
.check svg { width: 1.5rem; height: 1.5rem; stroke: var(--mute); fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.check.done svg { stroke: var(--ok); }
.check-name { font-weight: 600; }
.check-value { font-family: var(--mono); font-size: 0.8125rem; color: var(--mute); overflow-wrap: anywhere; }
.check.off { opacity: 0.5; }

.timer { height: 4px; background: var(--ink-2); margin-top: var(--s3); }
.timer > i { display: block; height: 100%; background: var(--warn); width: 0; transition: width 200ms linear; }
.timer-text { font-size: 0.8125rem; color: var(--mute); margin-top: var(--s1); min-height: 1.3em; }

.manual { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: var(--s2); margin-top: var(--s3); align-items: end; }

/* --- lot --- */
.counts { display: flex; gap: var(--s6); flex-wrap: wrap; margin-top: var(--s4); }
.count b { display: block; font: 800 2rem/1 var(--font); }
.count span { color: var(--mute); font-size: 0.875rem; }
.bays { display: grid; grid-template-columns: repeat(auto-fill, minmax(11.5rem, 1fr)); gap: var(--s3); margin-top: var(--s4); }
.bay { border: 1px solid var(--line); border-top: 4px solid var(--mute); background: var(--ink-1); padding: var(--s3); display: grid; gap: var(--s2); border-radius: 0 0 var(--radius) var(--radius); }
.bay.vacant { border-top-color: var(--ok); }
.bay.vacant.accessible { border-top-color: var(--info); }
.bay.partial { border-top-color: var(--warn); }
.bay.occupied { border-top-color: var(--stop); }
.bay.reserved { animation: pulse 1.1s steps(2, jump-none) infinite; }
@keyframes pulse { 50% { border-top-color: var(--ink-3); } }
.bay-head { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s2); }
.bay-id { font: 800 1.5rem/1 var(--font); }
.bay-type { font-size: 0.8125rem; color: var(--mute); }
.bay-note { font-size: 0.8125rem; color: var(--mute); min-height: 1.3em; overflow-wrap: anywhere; }
.sensors { display: flex; gap: var(--s2); }
.sensor { flex: 1; min-height: 2rem; border: 1px dashed var(--line); background: none; color: var(--mute); font: 600 0.75rem/1 var(--font); border-radius: 4px; cursor: pointer; }
.sensor[aria-pressed='true'] { border-style: solid; border-color: var(--text); color: var(--text); background: var(--ink-3); }
.sensor:disabled { cursor: default; }
.legend { display: flex; gap: var(--s3); flex-wrap: wrap; margin-top: var(--s4); }

/* --- tables --- */
.table-wrap { overflow-x: auto; margin-top: var(--s3); }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th { text-align: start; font: 700 0.75rem/1.3 var(--font); letter-spacing: 0.08em; text-transform: uppercase; color: var(--mute); padding: var(--s2) var(--s3) var(--s2) 0; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
td.nowrap { white-space: nowrap; }
.note { margin-top: var(--s3); padding: var(--s3) var(--s4); background: var(--ink-1); border-inline-start: 4px solid var(--line); max-width: 78ch; }
.note.ok { border-color: var(--ok); } .note.stop { border-color: var(--stop); }

/* --- insights --- */
.split { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: var(--s6); }
.bars { display: grid; gap: var(--s2); margin-top: var(--s3); }
.bar-row { display: grid; grid-template-columns: minmax(7rem, 12rem) minmax(0, 1fr) 2.5rem; gap: var(--s3); align-items: center; font-size: 0.875rem; }
.bar-track { height: 0.8rem; background: var(--ink-2); }
.bar-fill { display: block; height: 100%; background: var(--sand); min-width: 2px; }
.hours { display: block; width: 100%; height: auto; margin-top: var(--s3); }
.hours text { fill: var(--mute); font: 400 11px var(--font); }
.calc { display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: var(--s3) var(--s4); margin-top: var(--s3); }
.calc-out { margin-top: var(--s4); display: flex; gap: var(--s6); flex-wrap: wrap; }
.footnote { font-size: 0.8125rem; color: var(--mute); max-width: 80ch; margin-top: var(--s3); line-height: 1.6; }

/* --- health --- */
.health { display: grid; grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr)); gap: 0 var(--s6); margin-top: var(--s3); }
.health > div { display: flex; justify-content: space-between; gap: var(--s3); align-items: center; padding: var(--s3) 0; border-bottom: 1px solid var(--line-soft); }
.health small { display: block; color: var(--mute); font-size: 0.8125rem; }

/* --- simulator dock: sits above the page so the narration stays beside the picture --- */
.sim { border-bottom: 1px solid var(--line); background: var(--ink-1); padding: var(--s3) var(--gutter); }
.sim-top { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s3); align-items: start; }
.sim-caption { padding-inline-start: var(--s3); border-inline-start: 3px solid var(--sand); min-height: 3.1em; max-width: 96ch; }
.sim-row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; margin-top: var(--s3); }
.sim-label { font: 700 0.75rem/1.3 var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--mute); margin-right: var(--s1); }
.sim details { margin-top: var(--s3); }
.sim summary { cursor: pointer; font-weight: 600; font-size: 0.875rem; color: var(--sand); width: fit-content; }
.sim-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: var(--s5); margin-top: var(--s3); }
.sim-grid h3 { font: 700 0.75rem/1.3 var(--font); letter-spacing: 0.1em; text-transform: uppercase; color: var(--mute); margin-bottom: var(--s2); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.field { display: grid; gap: var(--s1); margin-bottom: var(--s2); }

/* --- sheet (login) --- */
.sheet { position: fixed; inset: 0; background: rgb(16 48 42 / 0.45); display: grid; place-items: center; padding: var(--s4); z-index: 20; }
.sheet-box { background: var(--ink-1); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s5); width: min(24rem, 100%); display: grid; gap: var(--s3); }
.error { color: var(--stop); font-size: 0.875rem; min-height: 1.3em; }

@media (max-width: 62em) {
  .gate-grid { grid-template-columns: minmax(0, 1fr); gap: var(--s5); }
}
@media (max-width: 34em) {
  .sim-top { grid-template-columns: minmax(0, 1fr); }
  .manual { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .manual .field { grid-column: 1 / -1; }
  .bar-row { grid-template-columns: minmax(0, 1fr) 2.5rem; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .count b { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
  .bay.reserved { animation: none; border-top-style: dashed; }
}
