/* ==========================================================================
   KnowYourBus — mobile-first arrival board.

   DESIGN TARGET: 360–430px viewport (R2.0). Every user is on a phone.
   Nothing here depends on hover; everything is tap-sized.

   VISUAL CONTRACT (owner's spec):
     - Every tile shares the SAME background, and the background IS the
       arrival state:  RED = not here yet  ->  GREEN = arrived.
     - The bus CATEGORY is shown by the accent colour only — the tile border
       and the label badge. Category colours come from data/categories.json
       and are applied as --accent at runtime.
   So the background answers "is it here?" and the accent answers
   "what kind of bus is it?".
   ========================================================================== */

:root {
  color-scheme: dark;

  /* Page + chrome */
  --bg: #0b1015;
  --surface: #141b23;
  --surface-2: #1c2530;
  --line: #27333f;
  --text: #f3f7fb;
  --muted: #9aabb9;

  /* ARRIVAL STATE — identical for every category. */
  --absent: #b91c1c;
  --present: #15803d;

  /* Fallback category accents (overridden per element from categories.json) */
  --accent-regular: #3b82f6;
  --accent-private: #a855f7;
  --accent-sped: #f97316;
  --accent: var(--accent-regular);
  --accent-ink: #08121d;

  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  --tap: 48px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
  overscroll-behavior-y: contain;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3, p, ul, ol {
  margin: 0;
}

ul, ol {
  padding: 0;
  list-style: none;
}

/* ------------------------------------------------------------- app bar --- */

.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  background: rgba(11, 16, 21, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.app-bar__title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}

.app-bar__date {
  margin: 1px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* Tap-mode toggle — thumb-sized, tap-only, no hover dependency. */

.tap-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 6px 12px;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  touch-action: manipulation;
  flex: none;
}

.tap-toggle__dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #55636f;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
  flex: none;
}

.tap-toggle__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
}

.tap-toggle__state {
  font-weight: 700;
  font-size: 0.88rem;
}

.tap-toggle__hint {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}

.tap-toggle[aria-pressed="true"] {
  border-color: var(--accent-sped);
  background: rgba(249, 115, 22, 0.14);
}

.tap-toggle[aria-pressed="true"] .tap-toggle__dot {
  background: var(--accent-sped);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.22);
}

.mode-banner {
  margin: 0;
  padding: 9px 12px;
  background: rgba(249, 115, 22, 0.16);
  border-bottom: 1px solid rgba(249, 115, 22, 0.4);
  color: #ffd9b3;
  font-size: 0.85rem;
}

/* ---------------------------------------------------------------- layout - */

.layout {
  max-width: 620px;
  margin: 0 auto;
  padding: 12px 12px 56px;
  display: grid;
  gap: 12px;
}

@media (min-width: 700px) {
  .layout {
    max-width: 980px;
    padding: 16px 16px 64px;
    gap: 16px;
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 14px;
}

.panel--arrivals {
  border-color: #35455a;
  background: linear-gradient(180deg, #18212c 0%, var(--surface) 100%);
}

.panel__heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.panel__heading--hero {
  font-size: 1.05rem;
  margin-bottom: 12px;
}

.panel__meta {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: none;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.panel__empty {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.panel__disclosure {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 2px 0;
  background: none;
  border: 0;
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

.panel__disclosure-title {
  flex: none;
}

.panel__disclosure-meta {
  flex: 1;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: none;
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.panel__disclosure-icon {
  flex: none;
  font-size: 1.05rem;
  color: var(--muted);
  transition: transform 0.15s ease;
}

.panel__disclosure[aria-expanded="true"] .panel__disclosure-icon {
  transform: rotate(180deg);
}

.panel__body {
  margin-top: 10px;
}

/* --------------------------------------------------------- arrival list -- */
/* The dismissal order — the boldest text on the page. */

.arrival-list {
  display: grid;
  gap: 8px;
}

.arrival-row {
  --accent: var(--accent-regular);
  --accent-ink: #08121d;

  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  grid-template-areas:
    "order label time"
    "order meta  meta";
  align-items: center;
  column-gap: 11px;
  row-gap: 3px;

  padding: 11px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  background: var(--surface-2);
}

.arrival-row__order {
  grid-area: order;
  align-self: center;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.arrival-row__label {
  grid-area: label;
  min-width: 0;
  font-size: clamp(1.3rem, 5.4vw, 1.65rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.015em;
  overflow-wrap: anywhere;
}

.arrival-row__time {
  grid-area: time;
  align-self: center;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.arrival-row__meta {
  grid-area: meta;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
}

.arrival-row__badge,
.bus-tile__badge {
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.66rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.arrival-row__lane,
.bus-tile__lane {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-list--compact .arrival-row__label {
  font-size: 1.05rem;
}

/* ------------------------------------------------------------ bus tiles -- */

.bus-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

@media (min-width: 560px) {
  .bus-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  .bus-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.bus-tile {
  --accent: var(--accent-regular);
  --accent-ink: #08121d;

  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;

  min-height: 108px;
  padding: 10px 11px 11px;

  /* ARRIVAL STATE — the shared background for every category. */
  background: var(--absent);
  border: 5px solid var(--accent);
  border-radius: var(--radius);

  color: #fff;
  font: inherit;
  text-align: left;
  cursor: default;
  box-shadow: var(--shadow);
  touch-action: manipulation;
  transition: background-color 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
}

.bus-tile__top {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 100%;
}

.bus-tile__label {
  font-size: clamp(1.05rem, 4.2vw, 1.3rem);
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
  overflow-wrap: anywhere;
}

.bus-tile__status {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 1.15em;
  font-size: 0.82rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
}

.bus-tile__glyph {
  font-size: 0.9rem;
  line-height: 1;
}

body.tap-mode .bus-tile {
  cursor: pointer;
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 255, 255, 0.28);
}

body.tap-mode .bus-tile:active {
  transform: scale(0.97);
}

/* ----------------------------------------------------------------- form -- */

.field {
  display: block;
  margin-bottom: 14px;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.field__control {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
}

/* ------------------------------------------------------------ manage link */

.manage-link {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 12px;
  border-radius: var(--radius-lg);
  border: 1px dashed #3d4c5e;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  text-decoration: none;
  touch-action: manipulation;
}

/* -------------------------------------------------------------- feedback - */

.offline-note {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  margin: 0;
  padding: 10px 16px;
  border-radius: 999px;
  background: #7f1d1d;
  color: #fff;
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 30;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(92vw, 460px);
  margin: 0;
  padding: 12px 18px;
  border-radius: 999px;
  background: #f3f7fb;
  color: #08121d;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  z-index: 40;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* ==========================================================================
   Manage screen (R2.4) — thumb-first, one-handed, no hover dependencies.
   ========================================================================== */

.manage-body .layout {
  max-width: 560px;
}

.app-bar__title--center {
  flex: 1;
  text-align: center;
  font-size: 1.1rem;
}

.app-bar__spacer {
  width: 62px;
  flex: none;
}

.back-link {
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 0 10px 0 4px;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.9rem;
  text-decoration: none;
  flex: none;
}

.panel__hint {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.panel__hint--foot {
  margin: 4px 2px 0;
  font-size: 0.78rem;
  text-align: center;
}

.panel__hint code {
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.85em;
}

/* ------------------------------------------------------------------ CSV */

.csv-input {
  width: 100%;
  min-height: 180px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.55;
  resize: vertical;
}

.csv-input:focus,
.field__control:focus {
  outline: 2px solid #60a5fa;
  outline-offset: 1px;
}

/* --------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  background: #2563eb;
  border-color: #3b82f6;
  color: #fff;
}

.btn--ghost {
  background: transparent;
  color: var(--muted);
}

.btn--danger {
  background: rgba(185, 28, 28, 0.16);
  border-color: rgba(185, 28, 28, 0.6);
  color: #fca5a5;
}

.btn--block {
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.btn-row .btn {
  flex: 1 1 140px;
}

/* ---------------------------------------------------------- manage lists */

.manage-list {
  display: grid;
  gap: 8px;
}

.manage-row {
  --accent: var(--accent-regular);
  --accent-ink: #08121d;

  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 58px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  border-left: 6px solid var(--accent);
  background: var(--surface-2);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.manage-row:active {
  background: #232d3a;
}

.manage-row__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.manage-row__label {
  font-size: 1.02rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.manage-row__sub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.74rem;
  color: var(--muted);
}

.manage-row__badge {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 0.64rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.manage-row__lane {
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: var(--text);
  font-size: 0.66rem;
  font-weight: 700;
  white-space: nowrap;
}

.manage-row__action {
  flex: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.manage-row__swatch {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 2px solid rgba(255, 255, 255, 0.25);
}

/* ------------------------------------------------------------- swatches */

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.swatch {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  border: 3px solid transparent;
  cursor: pointer;
  touch-action: manipulation;
  padding: 0;
}

.swatch[aria-checked="true"] {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

/* --------------------------------------------------------- bottom sheet */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 12, 0.66);
  z-index: 50;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 51;
  max-height: 88vh;
  overflow-y: auto;
  padding: 8px 14px calc(18px + env(safe-area-inset-bottom));
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.5);
  animation: sheet-in 0.18s ease-out;
}

@keyframes sheet-in {
  from {
    transform: translateY(12px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sheet__grip {
  width: 42px;
  height: 4px;
  margin: 4px auto 10px;
  border-radius: 999px;
  background: #3a4757;
}

.sheet__title {
  margin: 0 0 14px;
  font-size: 1.15rem;
  font-weight: 800;
}

.sheet__body {
  margin-bottom: 16px;
}

.sheet__actions {
  display: flex;
  gap: 8px;
}

.sheet__actions .btn {
  flex: 1;
}

/* --------------------------------------------------------------- result */

.result {
  margin-top: 12px;
  padding: 11px 13px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.result--ok {
  background: rgba(21, 128, 61, 0.18);
  border: 1px solid rgba(21, 128, 61, 0.55);
  color: #bbf7d0;
}

.result--error {
  background: rgba(185, 28, 28, 0.18);
  border: 1px solid rgba(185, 28, 28, 0.55);
  color: #fecaca;
}
