/* ============================================================
   Design plan (written before any UI markup, per the brief's §8)

   Palette (dark-first; true-black is a settings toggle, not the default):
     --canvas       #0b0d10   deep neutral background, not pure black
     --surface      #15181c   card chrome / raised panels
     --surface-2    #1d2126   further-raised panels (sheets, modals)
     --ink          #e8eaed   primary text
     --ink-dim      #8b9198   secondary text / labels
     --line         #262a30   dividers and borders that mean something
     --accent-fallback #6b8afd  UI focus rings & icons only when a card has
                                 no brand color of its own to borrow

   Type: one family, the platform's own UI font. Phase 0 runs from a
   double-clicked file with no network, so a vendored webfont can't be
   fetched — this deliberately falls back to the OS system-UI stack
   (San Francisco / Roboto / Segoe UI) rather than pretending otherwise.
   Phase 1 vendors "Inter" as local .woff2 files once there's a proper
   build step. Scale: 13 / 15 / 17 / 22 / 28 / 40, weights 400/500/650.
   Numbers (card numbers, times, seats) get tabular-nums — they're data
   and should line up in a column.

   Layout concept: bottom-weighted, one-thumb home screen. Search and tag
   filters sit in a header that scrolls away; favourites render as a large
   2-column grid right under it; everything else is a dense list further
   down. A fixed bottom tab bar (Wallet / Travel / Settings) keeps the most
   reachable zone of the screen for navigation, and the add button lives
   inside that same thumb zone.

   Three principles:
     1. Brand colour is the only colour — the chrome around a card stays
        quiet and near-monochrome so each card's own hue can do the work.
     2. The barcode is furniture, not content — the full-screen scan view
        has no header chrome, no card-on-a-card framing, just the white
        stage, the code, and the number underneath.
     3. A divider means something — a hairline appears only where it marks
        a real boundary (favourites vs. the rest, one trip vs. the next),
        never as decoration.
   ============================================================ */

:root {
  color-scheme: dark;
  --canvas: #0b0d10;
  --surface: #15181c;
  --surface-2: #1d2126;
  --ink: #e8eaed;
  --ink-dim: #8b9198;
  --line: #262a30;
  --accent-fallback: #6b8afd;
  --danger: #f2665a;
  --good: #4ade80;
  --font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
  --radius-sm: 9px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
:root[data-trueblack="1"] {
  --canvas: #000000;
  --surface: #0a0a0a;
  --surface-2: #131313;
  --line: #1e1e1e;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
button { cursor: pointer; }
.tabular { font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

a, button, input, select, [tabindex] {
  outline-offset: 2px;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent-fallback);
}

/* ---------- App shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; min-height: 0; flex-direction: column; }
.screen.active { display: flex; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--canvas) 88%, transparent);
  backdrop-filter: blur(10px);
  padding: 14px 16px 10px;
  border-bottom: 1px solid transparent;
}
.topbar.scrolled { border-bottom-color: var(--line); }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--ink);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  min-height: 44px;
}
.search-input::placeholder { color: var(--ink-dim); }
.icon-btn {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--ink);
  font-size: 18px;
}

.chip-row { display: flex; gap: 8px; overflow-x: auto; padding: 10px 2px 2px; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 13px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-dim);
  font-size: 13px; white-space: nowrap; min-height: 36px; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { color: var(--canvas); border-color: transparent; font-weight: 600; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.content { flex: 1; overflow-y: auto; padding: 4px 16px calc(96px + var(--safe-bottom)); }

.section-label {
  font-size: 13px; color: var(--ink-dim); font-weight: 500;
  margin: 18px 2px 10px; display: flex; align-items: center; justify-content: space-between;
}

.fav-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-tile {
  position: relative; border-radius: var(--radius); padding: 14px;
  min-height: 108px; display: flex; flex-direction: column; justify-content: space-between;
  border: 1px solid var(--line); background: var(--surface);
  text-align: left; overflow: hidden;
}
.card-tile.wide { grid-column: 1 / -1; flex-direction: row; align-items: center; min-height: 64px; }
.card-tile::before {
  content: ""; position: absolute; inset: 0; opacity: 0.16;
  background: var(--tile-color, var(--accent-fallback));
}
.card-tile > * { position: relative; }
.card-tile .logo {
  width: 34px; height: 34px; border-radius: 9px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-weight: 650; font-size: 14px;
  color: var(--tile-color, var(--ink)); flex: none; overflow: hidden;
}
.card-tile .logo img { width: 100%; height: 100%; object-fit: cover; }
.card-tile .name { font-weight: 600; font-size: 14.5px; margin-top: 8px; }
.card-tile .sub { color: var(--ink-dim); font-size: 12.5px; margin-top: 2px; }
.card-tile .fav-star { position: absolute; top: 10px; right: 10px; font-size: 14px; }

.list-row {
  display: flex; align-items: center; gap: 12px; padding: 11px 4px;
  border-bottom: 1px solid var(--line); text-align: left; width: 100%; background: none; border-left: none; border-right: none; border-top: none;
}
.list-row:last-child { border-bottom: none; }
.list-row .logo { width: 38px; height: 38px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-weight: 650; font-size: 14px; color: var(--row-color, var(--ink)); flex: none; overflow: hidden; }
.list-row .logo img { width: 100%; height: 100%; object-fit: cover; }
.list-row .meta { flex: 1; min-width: 0; }
.list-row .meta .name { font-weight: 550; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .meta .sub { color: var(--ink-dim); font-size: 12.5px; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-row .star { color: var(--ink-dim); font-size: 15px; flex: none; }
.list-row .star.on { color: #f6c945; }

.empty-state { text-align: center; padding: 48px 20px; color: var(--ink-dim); }
.empty-state .big { font-size: 34px; margin-bottom: 10px; }
.empty-state .title { color: var(--ink); font-weight: 600; font-size: 16px; margin-bottom: 6px; }
.empty-state button { margin-top: 14px; }

.btn {
  min-height: 44px; padding: 0 18px; border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 550; font-size: 14.5px;
}
.btn.primary { background: var(--ink); color: var(--canvas); border-color: var(--ink); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; }

.fab {
  position: fixed; right: 16px; bottom: calc(78px + var(--safe-bottom)); z-index: 6;
  width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: var(--canvas);
  font-size: 26px; display: flex; align-items: center; justify-content: center;
  border: none; box-shadow: 0 6px 20px rgba(0,0,0,0.4);
}

.tabbar {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--canvas) 92%, transparent);
  backdrop-filter: blur(10px);
  padding-bottom: var(--safe-bottom);
}
.tabbar button {
  flex: 1; background: none; border: none; padding: 10px 4px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-dim); font-size: 11px; min-height: 56px;
}
.tabbar button .ico { font-size: 20px; }
.tabbar button.active { color: var(--ink); }

/* ---------- Full-screen card / ticket view ---------- */
.card-view { position: fixed; inset: 0; z-index: 20; background: var(--canvas); display: flex; flex-direction: column; }
.card-view-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px; }
.card-view-header .title { font-weight: 600; font-size: 15px; }
.card-view-body { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 8px 20px 28px; gap: 16px; overflow-y: auto; }
.stage {
  background: #ffffff; border-radius: 16px; padding: 20px 16px 16px;
  width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.stage canvas { max-width: 100%; height: auto; image-rendering: pixelated; }
.stage .code-number {
  color: #111; font-size: 20px; font-weight: 650; letter-spacing: 0.02em; text-align: center; word-break: break-all;
}
.stage.rotated { transform: rotate(90deg); transform-origin: center; margin: 60px 0; width: 80vh; max-width: none; }
.card-facts { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 0; }
.fact-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.fact-row:last-child { border-bottom: none; }
.fact-row .k { color: var(--ink-dim); }
.fact-row .v { font-weight: 550; text-align: right; }
.secure-toggle { background: none; border: none; color: var(--accent-fallback); font-size: 13px; padding: 4px; }
.stale-note { font-size: 12px; color: var(--ink-dim); text-align: center; }
.no-barcode-plate { background: var(--surface-2); border-radius: 16px; padding: 40px 20px; text-align: center; width: 100%; max-width: 420px; }
.warn-banner { background: color-mix(in srgb, #f2b445 22%, var(--surface)); border: 1px solid color-mix(in srgb, #f2b445 45%, var(--line)); color: #f2c96b; border-radius: 11px; padding: 10px 12px; font-size: 12.5px; width: 100%; max-width: 420px; }

/* ---------- Sheets & modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 30; display: flex; align-items: flex-end; }
.overlay.center { align-items: center; justify-content: center; padding: 20px; }
.sheet {
  background: var(--surface-2); width: 100%; max-height: 90vh; overflow-y: auto;
  border-radius: 20px 20px 0 0; padding: 8px 18px calc(24px + var(--safe-bottom));
}
.overlay.center .sheet { border-radius: 18px; max-width: 480px; padding: 20px; }
.sheet-handle { width: 36px; height: 4px; background: var(--line); border-radius: 2px; margin: 8px auto 14px; }
.sheet h2 { font-size: 18px; margin: 4px 0 16px; }
.sheet-actions { display: grid; gap: 10px; margin-top: 6px; }
.method-btn { display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); text-align: left; }
.method-btn .ico { font-size: 22px; }
.method-btn .lbl { font-weight: 600; font-size: 14.5px; }
.method-btn .sub { color: var(--ink-dim); font-size: 12.5px; margin-top: 1px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--ink-dim); margin-bottom: 6px; }
.field input[type=text], .field input[type=number], .field input[type=tel], .field input[type=url],
.field input[type=date], .field select, .field textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 12px; font-size: 16px; min-height: 44px; color: var(--ink);
}
.field textarea { min-height: 72px; resize: vertical; }
.field.invalid input, .field.invalid select { border-color: var(--danger); }
.field .hint { font-size: 12px; color: var(--ink-dim); margin-top: 5px; }
.field .hint.error { color: var(--danger); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.toggle-row:last-child { border-bottom: none; }
.switch { position: relative; width: 46px; height: 27px; border-radius: 14px; background: var(--line); border: none; flex: none; }
.switch.on { background: var(--good); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform 0.15s ease; }
.switch.on::after { transform: translateX(19px); }
.tag-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.color-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; }
.color-swatch.active { border-color: var(--ink); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; position: sticky; bottom: 0; background: var(--surface-2); padding-top: 10px; }

/* ---------- Travel ---------- */
.trip-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; background: var(--surface); }
.trip-card .trip-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.trip-card .trip-head .name { font-weight: 650; font-size: 16px; }
.trip-card .trip-head .dates { color: var(--ink-dim); font-size: 12.5px; }
.ticket-row { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); text-align: left; width: 100%; background: none; border-left: none; border-right: none; border-bottom: none; }
.ticket-row:first-of-type { border-top: none; }
.ticket-row .ico { font-size: 20px; flex: none; width: 30px; text-align: center; }
.ticket-row .body { flex: 1; min-width: 0; }
.ticket-row .title { font-weight: 600; font-size: 14px; }
.ticket-row .sub { color: var(--ink-dim); font-size: 12.5px; margin-top: 2px; }
.ticket-row .countdown { font-size: 12px; color: var(--good); margin-top: 2px; font-weight: 600; }
.watched-flight { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; }
.watched-flight .leaveby { font-size: 15px; font-weight: 650; margin-top: 6px; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 50; }

.settings-group { margin-bottom: 22px; }
.settings-group h3 { font-size: 13px; color: var(--ink-dim); font-weight: 500; margin: 0 0 8px 2px; }
.settings-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; border-bottom: 1px solid var(--line); }
.settings-row:last-child { border-bottom: none; }
.settings-row .lbl { font-size: 14.5px; }
.settings-row .sub { color: var(--ink-dim); font-size: 12px; margin-top: 2px; }
.settings-row select { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; min-height: 36px; }

@media (min-width: 720px) {
  .content { max-width: 640px; margin: 0 auto; width: 100%; }
  .topbar > * { max-width: 640px; margin: 0 auto; }
}
