/* ═══════════════════════════════════════════════════════════════
   RailTracker web — shared styles
   Tokens mirror RTTheme + JGShape in the Flutter app. Change a value
   here and every page follows.
   ═══════════════════════════════════════════════════════════════ */

:root {
  /* Brand + status (RTTheme) */
  --accent: #E8410A;
  --good: #34C759;
  --warn: #FF9500;
  --bad: #FF3B30;
  --special: #AF52DE;

  /* Light surfaces */
  --canvas-top: #F6F9FF;
  --canvas-bottom: #BBDFFA;
  --surface: #FFFFFF;
  --surface-h: #F5F4F0;
  --t1: #1A1917;
  --t2: #6B6860;
  --t3: #A3A09A;
  --border: #E2E0DA;
  --border-s: #D4D2CC;
  --tint: 8%;
  --tint-icon: 11%;
  --topbar: rgba(246, 249, 255, 0.82);

  /* Page line colour (set per page/line by JS) */
  --lc: #E8410A;
  --lfg: #fff;

  /* Shape (JGShape) */
  --r-card: 6px;
  --r-icon: 4px;
  --r-action: 10px;
  --rail-status: 5px;
  --rail-line: 4px;
  --page: 20px;

  /* Type + motion */
  --fd: 'Syne', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fm: 'DM Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(0.33, 1, 0.68, 1);      /* Curves.easeOutCubic */
  --ease-in: cubic-bezier(0.32, 0, 0.67, 0);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --canvas-top: #1F2C3C; --canvas-bottom: #000000;
    --surface: #161616; --surface-h: #1E1E1E;
    --t1: #F0EDE8; --t2: #9A9590; --t3: #5A5650;
    --border: #2A2A2A; --border-s: #333333;
    --tint: 10%; --tint-icon: 16%;
    --topbar: rgba(31, 44, 60, 0.82);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --canvas-top: #1F2C3C; --canvas-bottom: #000000;
  --surface: #161616; --surface-h: #1E1E1E;
  --t1: #F0EDE8; --t2: #9A9590; --t3: #5A5650;
  --border: #2A2A2A; --border-s: #333333;
  --tint: 10%; --tint-icon: 16%;
  --topbar: rgba(31, 44, 60, 0.82);
  color-scheme: dark;
}

/* ── Base ── */
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--canvas-bottom); }
body {
  margin: 0; min-height: 100vh; font-family: var(--fd); color: var(--t1);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
body::before {  /* RTTheme.backgroundGradient */
  content: ''; position: fixed; inset: 0; z-index: -1;
  background: linear-gradient(180deg, var(--canvas-top), var(--canvas-bottom));
}
button { font: inherit; color: inherit; }
svg { display: block; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Type (JGType) ── */
.eyebrow { font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase; color: var(--t3); }
.subtitle { font-size: 12px; color: var(--t3); letter-spacing: 0.2px; line-height: 1.4; }
.card-title { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; }
.card-sub { font-size: 11.5px; color: var(--t2); line-height: 1.4; }

/* ── Top bar ── */
.topbar {
  position: sticky; top: 0; z-index: 1000;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--topbar);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { max-width: 1120px; margin: 0 auto; padding: 12px var(--page); display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--t1); font-size: 15px; font-weight: 700; letter-spacing: -0.2px; }
.brand img { width: 30px; height: 30px; border-radius: 7px; }
.nav { display: flex; gap: 4px; margin: 0 auto; list-style: none; padding: 0; }
.nav a {
  display: block; padding: 9px 12px; border-radius: var(--r-card);
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  color: var(--t2); text-decoration: none; transition: color .15s, background-color .15s;
}
.nav a:hover { color: var(--t1); }
.nav a[aria-current="page"] { color: var(--t1); background: var(--surface); box-shadow: inset 0 0 0 1px var(--border); }
.actions { display: flex; gap: 8px; margin-left: auto; }

/* JGHeaderAction */
.action {
  width: 36px; height: 36px; border-radius: var(--r-action); flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border); color: var(--t2);
  display: grid; place-items: center; cursor: pointer; padding: 0;
  transition: background-color .15s, color .15s;
}
.action:hover { background: var(--surface-h); color: var(--t1); }
.action.spinning svg { animation: rt-spin .8s linear infinite; }
@keyframes rt-spin { to { transform: rotate(360deg); } }

.theme-dark-icon { display: none; }
:root[data-theme="dark"] .theme-dark-icon { display: block; }
:root[data-theme="dark"] .theme-light-icon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-dark-icon { display: block; }
  :root:not([data-theme="light"]) .theme-light-icon { display: none; }
}

/* ── Page layout ── */
.page-head { max-width: 1120px; margin: 0 auto; padding: 32px var(--page) 4px; text-align: center; }
.page-title { font-size: clamp(28px, 4vw, 40px); font-weight: 700; letter-spacing: -0.2px; line-height: 1.05; margin: 4px 0 6px; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--page) 56px; }
.back {
  display: inline-flex; align-items: center; gap: 10px; margin: 24px 0 16px;
  background: none; border: 0; padding: 0; cursor: pointer; text-decoration: none;
  color: var(--t2); font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
}
.back:hover { color: var(--t1); }

/* ── Cards (JGCardStyle) ── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); position: relative; overflow: hidden; }
.card.strong { border-color: var(--border-s); }
.rail { position: absolute; left: 0; top: 0; bottom: 0; width: var(--rail-status); background: var(--rc, var(--lc)); transition: background-color .3s; }
.icon-solid {
  width: 48px; height: 48px; border-radius: var(--r-icon); flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--ic, var(--lc)); color: var(--ifg, var(--lfg));
  transition: background-color .3s, color .3s;
}
.icon-tint {
  width: 36px; height: 36px; border-radius: var(--r-icon); flex-shrink: 0;
  display: grid; place-items: center; color: var(--ic);
  background: color-mix(in srgb, var(--ic) var(--tint-icon), transparent);
}
.sec-head { display: flex; align-items: center; gap: 11px; padding: 16px; }
.sec-head > div:nth-child(2) { flex: 1; min-width: 0; }
.sec-body { padding: 0 16px 16px; }

.section-label {
  display: flex; align-items: center; gap: 10px; margin: 28px 0 14px;
  font-size: 9px; font-weight: 500; letter-spacing: 1.5px; text-transform: uppercase; color: var(--t3);
}
.section-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ── Line rows (LineStatusRow) ──
   --c: line colour, --cfg: badge text colour, --st: status colour */
.row {
  all: unset; box-sizing: border-box; position: relative; overflow: hidden; cursor: pointer;
  display: flex; align-items: center; gap: 12px; padding: 12px 14px 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  transition: background-color .15s, border-color .3s, transform .18s var(--ease);
}
.row::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: var(--rail-line); background: var(--c); }
.row:hover { background: var(--surface-h); }
.row:active { transform: scale(0.985); }
.row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.row.issue { border-color: color-mix(in srgb, var(--st) 30%, transparent); }
.row[aria-pressed="true"] { border-color: var(--c); background: color-mix(in srgb, var(--c) var(--tint), var(--surface)); }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font-size: 14px; font-weight: 700; letter-spacing: -0.2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-status { font-size: 11.5px; color: var(--st, var(--t2)); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-icon { color: var(--st); flex-shrink: 0; }
.chev { color: var(--t3); flex-shrink: 0; }

.badge {
  width: 36px; height: 36px; border-radius: var(--r-icon); flex-shrink: 0;
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  background: var(--c); color: var(--cfg);
}
.badge.sm { width: 28px; height: 28px; font-size: 10px; }
.badge.lg { width: 48px; height: 48px; font-size: 14px; }
.badge.outline { box-shadow: inset 0 0 0 1px var(--border-s); }

/* ── Buttons ── */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 16px; border-radius: var(--r-card); text-decoration: none; cursor: pointer;
  font-size: 10px; font-weight: 700; letter-spacing: 1.2px; text-transform: uppercase;
  transition: filter .15s, background-color .15s, transform .18s var(--ease);
}
.btn:active { transform: scale(0.985); }
.btn-primary { background: var(--accent); color: #fff; border: 0; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface-h); color: var(--t1); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* ── Feedback ── */
.empty { padding: 14px 2px 2px; font-size: 13px; color: var(--t2); line-height: 1.5; display: flex; align-items: center; gap: 8px; }
.notice {
  margin-top: 12px; padding: 14px; border-radius: var(--r-card); display: flex; align-items: center; gap: 10px; color: var(--warn);
  background: color-mix(in srgb, var(--warn) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warn) 28%, transparent);
}
.notice-t { font-size: 13px; font-weight: 700; }
.notice-s { font-size: 10.5px; line-height: 1.4; margin-top: 2px; }
.notice button { margin-left: auto; background: none; border: 0; cursor: pointer; color: inherit; font-size: 10px; font-weight: 700; letter-spacing: 0.8px; padding: 6px; }
.skel {
  display: block; border-radius: 3px;
  background: linear-gradient(90deg, var(--surface-h) 25%, var(--border) 50%, var(--surface-h) 75%);
  background-size: 200% 100%; animation: rt-shimmer 1.4s infinite;
}
@keyframes rt-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.time-badge { font-family: var(--fm); font-size: 0.92em; padding: 0 5px; border-radius: var(--r-icon); color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); white-space: nowrap; }

/* ── Footer ── */
.footer { border-top: 1px solid var(--border); }
.footer-in { max-width: 1120px; margin: 0 auto; padding: 20px var(--page) calc(20px + env(safe-area-inset-bottom, 0px)); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; }
.footer-brand { font-size: 14px; font-weight: 700; }
.footer-note { font-size: 11px; color: var(--t3); margin-top: 3px; }
.footer-links { display: flex; gap: 18px; }
.footer-links a { font-size: 12px; color: var(--t2); text-decoration: none; }
.footer-links a:hover { color: var(--t1); }

/* ═════════════ Motion ═════════════ */

/* Load-in (JGReveal) */
.reveal { animation: rt-reveal .42s var(--ease) backwards; animation-delay: var(--d, 0ms); }
@keyframes rt-reveal { from { opacity: 0; transform: translateY(12px) scale(0.985); } }

/* Staggered entrances: set --i on each item */
.rise { animation: rt-rise .42s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 28ms); }
@keyframes rt-rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }

/* Slides: forward = deeper, back = up a level */
@keyframes rt-out-fwd  { to { opacity: 0; transform: translateX(-28px); } }
@keyframes rt-out-back { to { opacity: 0; transform: translateX(28px); } }
@keyframes rt-in-fwd   { from { opacity: 0; transform: translateX(28px); } }
@keyframes rt-in-back  { from { opacity: 0; transform: translateX(-28px); } }
.out-fwd  { animation: rt-out-fwd .2s var(--ease-in) forwards; }
.out-back { animation: rt-out-back .2s var(--ease-in) forwards; }
.in-fwd   { animation: rt-in-fwd .4s var(--ease) backwards; }
.in-back  { animation: rt-in-back .4s var(--ease) backwards; }

/* Page-to-page (View Transitions API). Top bar stays put, content slides. */
@view-transition { navigation: auto; }
.topbar { view-transition-name: topbar; }
.vt-page { view-transition-name: page; }
::view-transition-group(page) { animation: none; }
::view-transition-old(page) { animation: rt-out-fwd .2s var(--ease-in) both; }
::view-transition-new(page) { animation: rt-in-fwd .4s var(--ease) both; }
html:active-view-transition-type(back)::view-transition-old(page) { animation-name: rt-out-back; }
html:active-view-transition-type(back)::view-transition-new(page) { animation-name: rt-in-back; }

@media (prefers-reduced-motion: reduce) {
  .reveal, .rise, .skel, .action.spinning svg,
  .out-fwd, .out-back, .in-fwd, .in-back { animation: none; }
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  *, *::before, *::after { transition: none !important; }
}

/* ── Responsive ── */
@media (max-width: 720px) {
  .nav { display: none; }
}