/* ═══════════════════════════════════════════════════════════════
   TripAlgo Operations — design system

   Hand-written rather than Tailwind/Pico, deliberately:
     • No build step and no CDN dependency — one file, served by us.
     • Tailwind's play CDN compiles in the browser at runtime, which the
       Tailwind team advise against in production; it also fills the
       templates with utility soup, and these templates are read and
       edited constantly over the phases ahead.
     • Named component classes (.btn, .card, .pill) mean a Phase 3 QC
       table and a Phase 2 billing form inherit the same look without
       anyone re-deciding padding.

   Brand: navy #1D2436, orange #F16726.
   Structure: tokens -> reset -> layout -> components -> responsive.
   ═══════════════════════════════════════════════════════════════ */

/* ── Tokens ───────────────────────────────────────────────────── */
:root {
  /* Brand */
  --navy-900: #141a28;
  --navy-800: #1d2436;   /* primary */
  --navy-700: #29324a;
  --navy-600: #3b4760;
  --orange-600: #d4551a; /* pressed / hover */
  --orange-500: #f16726; /* accent */
  --orange-200: #fbcdb5;
  --orange-50:  #fef2ec;

  /* Neutrals */
  --ink:    #1d2436;
  --ink-2:  #5a6577;
  --ink-3:  #8b94a3;
  --line:   #e3e7ee;
  --line-2: #eef1f5;
  --bg:     #f6f7f9;
  --surface: #ffffff;

  /* Status */
  --ok:        #14724a;  --ok-bg:     #e6f4ed;  --ok-line:     #bfe2d1;
  --warn:      #97600a;  --warn-bg:   #fdf4e3;  --warn-line:   #f0dcb4;
  --danger:    #b3261e;  --danger-bg: #fcecea;  --danger-line: #f3cdc9;
  --neutral:   #56617a;  --neutral-bg:#eef1f5;  --neutral-line:#dde3ec;

  /* Shape & depth */
  --r-sm: 5px;
  --r:    8px;
  --r-lg: 12px;
  --shadow-1: 0 1px 2px rgba(20, 26, 40, 0.05);
  --shadow-2: 0 2px 8px rgba(20, 26, 40, 0.07);
  --shadow-3: 0 8px 24px rgba(20, 26, 40, 0.10);

  /* Spacing scale */
  --s-1: 4px;  --s-2: 8px;   --s-3: 12px;  --s-4: 16px;
  --s-5: 24px; --s-6: 32px;  --s-7: 48px;  --s-8: 64px;

  --nav-h: 56px;
  --page-max: 1180px;

  --font: "Segoe UI Variable Text", "Segoe UI", -apple-system,
          BlinkMacSystemFont, Inter, Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.015em; color: var(--ink); }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p  { margin: 0; }
a  { color: var(--navy-700); }

:focus-visible {
  outline: 2px solid var(--orange-500);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ── Top navigation ───────────────────────────────────────────── */
.nav {
  height: var(--nav-h);
  background: var(--navy-800);
  color: #fff;
  display: flex;
  align-items: center;
  gap: var(--s-5);
  padding: 0 var(--s-5);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-brand {
  display: flex; align-items: center; gap: 9px;
  font-size: 15px; font-weight: 680; letter-spacing: -0.02em;
  color: #fff; text-decoration: none; white-space: nowrap;
}
.nav-brand .mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: var(--orange-500);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff;
}
.nav-brand .sub { font-weight: 400; color: #9aa4b8; }

.nav-links { display: flex; align-items: center; gap: 2px; flex: 1; min-width: 0; overflow: hidden; }

.nav-link {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 7px 11px; border-radius: var(--r-sm);
  color: #c3cad8; text-decoration: none;
  font-size: 13.5px; font-weight: 500; white-space: nowrap;
}
.nav-link:hover { background: var(--navy-700); color: #fff; }
.nav-link.active { background: var(--navy-900); color: #fff; }
.nav-link.active::before {
  content: ""; width: 5px; height: 5px; border-radius: 50%;
  background: var(--orange-500);
}
.nav-link.locked {
  color: #707b90; cursor: default; pointer-events: none;
}
.nav-link.locked .phase-dot {
  font-size: 10px; font-weight: 700; color: #8b94a3;
  background: rgba(255,255,255,0.07);
  padding: 1px 5px; border-radius: 3px;
}

.nav-user { display: flex; align-items: center; gap: var(--s-3); margin-left: auto; white-space: nowrap; }
.nav-user .who { text-align: right; line-height: 1.25; }
.nav-user .name { display: block; font-size: 13px; font-weight: 600; color: #fff; }
.nav-user .mail { display: block; font-size: 11.5px; color: #97a0b3; }
.nav-user .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--navy-600); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
}
.nav-signout {
  color: #c3cad8; text-decoration: none; font-size: 13px;
  padding: 6px 10px; border-radius: var(--r-sm);
  border: 1px solid rgba(255,255,255,0.14);
}
.nav-signout:hover { background: var(--navy-700); color: #fff; }

/* ── Page shell ───────────────────────────────────────────────── */
main { flex: 1; }
.page { max-width: var(--page-max); margin: 0 auto; padding: var(--s-6) var(--s-5) var(--s-7); }
.page.narrow { max-width: 760px; }
.centred { flex: 1; display: grid; place-items: center; padding: var(--s-5); }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--s-5); margin-bottom: var(--s-5);
  padding-bottom: var(--s-4); border-bottom: 1px solid var(--line);
}
.page-head .lede { color: var(--ink-2); margin-top: 3px; max-width: 68ch; }
.page-head .actions { display: flex; gap: var(--s-2); flex-shrink: 0; }

.section-title {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--ink-3);
  margin: var(--s-6) 0 var(--s-3);
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-4) var(--s-5);
  border-bottom: 1px solid var(--line-2);
}
.card-body { padding: var(--s-5); }
.card-foot {
  padding: var(--s-3) var(--s-5);
  border-top: 1px solid var(--line-2);
  background: #fafbfc;
  border-radius: 0 0 var(--r) var(--r);
}

/* ── Grid ─────────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--s-4); }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.auto   { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ── Module cards (dashboard) ─────────────────────────────────── */
.module {
  display: flex; flex-direction: column; gap: var(--s-3);
  padding: var(--s-5);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-1);
  text-decoration: none; color: inherit;
  position: relative; overflow: hidden;
}
.module::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--line);
}
.module.is-live::before { background: var(--orange-500); }
.module.is-live:hover { box-shadow: var(--shadow-2); border-color: var(--orange-200); }
.module.is-pending { background: #fcfdfe; }
.module.is-pending .module-name { color: var(--ink-2); }

.module-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-3); }
.module-name { font-size: 15px; font-weight: 640; letter-spacing: -0.01em; }
.module-desc { color: var(--ink-2); font-size: 13px; }
.module-foot { margin-top: auto; padding-top: var(--s-2); font-size: 12px; color: var(--ink-3); }

.module-icon {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  display: grid; place-items: center; flex-shrink: 0;
  background: var(--neutral-bg); color: var(--neutral);
  font-size: 15px;
}
.module.is-live .module-icon { background: var(--orange-50); color: var(--orange-600); }

/* ── Status pills ─────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  white-space: nowrap;
  background: var(--neutral-bg); color: var(--neutral);
  border: 1px solid var(--neutral-line);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.ok     { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-line); }
.pill.warn   { background: var(--warn-bg);   color: var(--warn);   border-color: var(--warn-line); }
.pill.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.pill.plain::before { display: none; }

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; border-radius: var(--r-sm);
  font-family: inherit; font-size: 13.5px; font-weight: 600; line-height: 1.3;
  text-decoration: none; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--ink);
  transition: background-color .12s ease, border-color .12s ease;
}
.btn-primary { background: var(--orange-500); color: #fff; border-color: var(--orange-500); }
.btn-primary:hover { background: var(--orange-600); border-color: var(--orange-600); }

.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: #f8fafc; border-color: #cbd3de; }

.btn-navy { background: var(--navy-800); color: #fff; border-color: var(--navy-800); }
.btn-navy:hover { background: var(--navy-700); border-color: var(--navy-700); }

.btn-ghost { color: var(--ink-2); }
.btn-ghost:hover { background: var(--line-2); color: var(--ink); }

.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r); }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table thead th {
  text-align: left; font-size: 11.5px; font-weight: 700;
  letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-3);
  padding: 10px var(--s-4); background: #fafbfc;
  border-bottom: 1px solid var(--line);
}
/* Sticky headers are opt-in, not the default. Inside an overflow-x
   container they stick to the wrapper rather than the viewport, and row
   content bled above the header. Phase 1 can add .sticky-head to the long
   passenger and QC lists where it earns its keep; short tables don't need
   it and shouldn't carry the risk. */
.table.sticky-head thead th {
  position: sticky; top: var(--nav-h); z-index: 3;
  background-clip: padding-box;
}
.table tbody td { padding: 11px var(--s-4); border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .mono { font-family: var(--mono); font-size: 12.5px; }

/* ── Forms ────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: var(--s-4); }
.label { font-size: 12.5px; font-weight: 620; color: var(--ink); }
.label .req { color: var(--orange-600); }

.input, .select, .textarea {
  width: 100%; padding: 8px 11px;
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--surface);
  border: 1px solid #cfd6e0; border-radius: var(--r-sm);
  box-shadow: var(--shadow-1);
}
.input:hover, .select:hover, .textarea:hover { border-color: #b6c0ce; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--orange-500);
  box-shadow: 0 0 0 3px rgba(241, 103, 38, 0.15);
}
.input::placeholder { color: var(--ink-3); }
.textarea { min-height: 88px; resize: vertical; }
.help  { font-size: 12px; color: var(--ink-2); }
.error { font-size: 12px; color: var(--danger); font-weight: 550; }
.field.has-error .input { border-color: var(--danger); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-4); }
.form-actions { display: flex; gap: var(--s-2); padding-top: var(--s-2); }

/* ── Misc ─────────────────────────────────────────────────────── */
.empty {
  padding: var(--s-7) var(--s-5); text-align: center;
  color: var(--ink-2); border: 1px dashed var(--line);
  border-radius: var(--r); background: #fcfdfe;
}
.mono-chip {
  display: inline-block; padding: 3px 9px; border-radius: var(--r-sm);
  background: var(--line-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px;
}
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }

.foot {
  padding: var(--s-4) var(--s-5);
  border-top: 1px solid var(--line);
  color: var(--ink-3); font-size: 12px; text-align: center;
  background: var(--surface);
}

/* ── Auth screens ─────────────────────────────────────────────── */
.auth-card { width: min(420px, 100%); text-align: center; padding: var(--s-7) var(--s-6); }
.auth-brand {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 19px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink);
  margin-bottom: var(--s-2);
}
.auth-brand .mark {
  width: 28px; height: 28px; border-radius: 7px; background: var(--orange-500);
  display: grid; place-items: center; color: #fff; font-size: 14px; font-weight: 800;
}
.auth-brand .sub { font-weight: 400; color: var(--ink-2); }

.btn-ms {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; margin-top: var(--s-5); padding: 11px 16px;
  border: 1px solid var(--line); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 600; text-decoration: none;
  box-shadow: var(--shadow-1);
}
.btn-ms:hover { background: #f8fafc; border-color: #cbd3de; }

.denied-mark { margin: var(--s-4) 0 var(--s-2); font-size: 16px; font-weight: 700; color: var(--danger); }
.account {
  display: inline-block; margin-top: 5px; padding: 5px 11px;
  border-radius: var(--r-sm); background: var(--line-2); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 12.5px; color: var(--ink);
  max-width: 100%; overflow-wrap: anywhere;
}
.big-code { font-size: 34px; font-weight: 700; color: var(--ink-3); letter-spacing: -0.02em; }

/* ── Responsive — laptop first, must not break when narrowed ──── */
@media (max-width: 1080px) {
  .nav-user .who { display: none; }
}
@media (max-width: 920px) {
  .grid.cols-3 { grid-template-columns: repeat(2, 1fr); }
  .nav { gap: var(--s-4); padding: 0 var(--s-4); }
  .nav-brand .sub { display: none; }
}
@media (max-width: 760px) {
  .nav { height: auto; flex-wrap: wrap; padding: var(--s-3) var(--s-4); row-gap: var(--s-2); }
  .nav-links { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
  .table thead th { position: static; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .page { padding: var(--s-5) var(--s-4) var(--s-6); }
  .page-head { flex-direction: column; }
}
