/* ----- Design tokens ----- */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --ink: #0a2540;
  --ink-2: #475569;
  --muted: #6b7a90;
  --line: #e3e8f0;
  --primary: #0a2540;
  --primary-2: #123a66;
  --accent: #ffd166;
  --danger: #c0392b;
  --success: #1f8f5b;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(10, 37, 64, .06);
  --shadow-md: 0 8px 24px rgba(10, 37, 64, .08);
  --shadow-lg: 0 20px 40px rgba(10, 37, 64, .12);
  --transition: 180ms cubic-bezier(.2, .7, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #121a2c;
    --surface-2: #182338;
    --ink: #e6edf7;
    --ink-2: #b6c2d6;
    --muted: #8b97ad;
    --line: #25304a;
    --primary: #ffd166;
    --primary-2: #ffdf8a;
    --accent: #ffd166;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .35);
    --shadow-lg: 0 20px 40px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ----- Topbar ----- */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(10px);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--primary); color: var(--accent);
  display: grid; place-items: center;
  font-weight: 800; font-size: 18px;
  box-shadow: var(--shadow-sm);
}
.brand-text strong { display: block; font-size: 15px; line-height: 1.1; }
.brand-text small { color: var(--muted); font-size: 11px; }
.topbar-link { font-size: 14px; color: var(--ink-2); }

/* ----- Hero ----- */
.hero { padding: 28px 0 12px; }
.hero h1 {
  margin: 0 0 6px; font-size: clamp(22px, 4.5vw, 32px);
  letter-spacing: -0.02em;
}
.hero p { color: var(--ink-2); margin: 0; font-size: 15px; }

/* ----- Cards ----- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 18px;
  margin-bottom: 18px;
  animation: rise .35s var(--transition) both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ----- Search form ----- */
.search-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr 130px 130px;
  gap: 12px;
  align-items: end;
}
.search-grid .btn-primary { grid-column: 1 / -1; }
.search-grid .field-presets { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600;
}
.select-wrap, select, input[type="search"], input[list], input[type="text"] {
  width: 100%;
}
input, select {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  height: 44px;
  padding: 0 12px;
  border-radius: 10px;
  font: inherit;
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
  background: var(--surface);
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7a90' stroke-width='2'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 16px;
  padding-right: 34px;
}
.swap {
  align-self: end;
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid; place-items: center;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), color var(--transition);
}
.swap:hover { background: var(--primary); color: var(--accent); transform: rotate(180deg); }

/* ----- Combobox ----- */
.combobox { position: relative; }
.combobox input {
  width: 100%;
  padding-right: 64px;            /* room for clear + toggle */
  text-transform: uppercase;
}
.combobox.is-empty .combobox-clear { display: none; }
.combobox-clear,
.combobox-toggle {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  display: grid; place-items: center;
  transition: color var(--transition), background var(--transition);
}
.combobox-clear { right: 34px; font-size: 20px; line-height: 1; width: 24px; height: 24px; }
.combobox-toggle { right: 6px; width: 26px; height: 26px; }
.combobox-clear:hover,
.combobox-toggle:hover { color: var(--ink); background: var(--surface-2); }
.combobox.is-open .combobox-toggle svg { transform: rotate(180deg); transition: transform var(--transition); }

.combobox-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  z-index: 30;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 280px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  -webkit-overflow-scrolling: touch;
  animation: rise .15s var(--transition) both;
}
.combobox-list[hidden] { display: none; }
.combobox-group {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  padding: 8px 10px 4px;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.combobox-item {
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  line-height: 1.2;
  color: var(--ink);
  transition: background var(--transition), color var(--transition);
}
.combobox-item .sta-code {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border-radius: 6px;
  padding: 2px 6px;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
}
.combobox-item mark {
  background: transparent;
  color: var(--primary);
  font-weight: 700;
}
.combobox-item.is-active,
.combobox-item:hover {
  background: var(--surface-2);
}
.combobox-item.is-active .sta-code,
.combobox-item:hover .sta-code {
  background: var(--surface);
}
.combobox-empty {
  padding: 14px 10px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.btn {
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid transparent;
  height: 44px;
  padding: 0 18px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary); color: #fff;
  box-shadow: var(--shadow-sm);
}
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #0a2540; }
}
.btn-primary:hover { background: var(--primary-2); box-shadow: var(--shadow-md); }
.btn[disabled], .btn.is-loading { opacity: .75; cursor: progress; }
.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: none;
  animation: spin .7s linear infinite;
}
.btn.is-loading .btn-spinner { display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- Results ----- */
.results-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 12px;
}
.results-header h2 { margin: 0; font-size: 18px; }
.filter-wrap { width: 100%; max-width: 320px; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 640px;
}
.results-table thead th {
  background: var(--surface-2);
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0;
}
.results-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.results-table tbody tr:last-child td { border-bottom: 0; }
.results-table tbody tr {
  transition: background var(--transition);
  animation: fade .25s ease both;
}
.results-table tbody tr:hover { background: var(--surface-2); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.time { font-variant-numeric: tabular-nums; font-weight: 600; }
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.badge.line {
  color: #fff;
  border: 0;
  background: var(--ink-2);
}

.status {
  padding: 14px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  text-align: center;
  font-size: 14px;
}
.status.error { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.status.empty { font-style: italic; }
.hidden { display: none !important; }

/* ----- Pagination ----- */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 12px;
  font-size: 13px;
  color: var(--muted);
}
.page-btn {
  background: transparent;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
}
.page-btn:hover:not([disabled]) { background: var(--surface-2); }
.page-btn[disabled] { opacity: .4; cursor: not-allowed; }

/* ----- About / footer ----- */
.about-card h2 { margin: 0 0 8px; font-size: 18px; }
.about-card .muted { color: var(--muted); font-size: 13px; }
.footer {
  margin-top: auto;
  padding: 24px 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

/* ----- Responsive ----- */
@media (max-width: 820px) {
  .search-grid {
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
      "from swap to"
      "jamf jamf jamt"
      "presets presets presets"
      "submit submit submit";
  }
  .search-grid .field:nth-of-type(1) { grid-area: from; }
  .search-grid .field:nth-of-type(2) { grid-area: to; }
  .search-grid .field:nth-of-type(3) { grid-area: jamf; }
  .search-grid .field:nth-of-type(4) { grid-area: jamt; }
  .search-grid .field-presets       { grid-area: presets; }
  .search-grid .swap                 { grid-area: swap; }
  .search-grid .btn-primary          { grid-area: submit; width: 100%; }
}
@media (max-width: 520px) {
  .search-grid {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "from from"
      "swap swap"
      "to to"
      "jamf jamt"
      "presets presets"
      "submit submit";
  }
  .search-grid .swap { justify-self: center; }
}
@media (max-width: 480px) {
  .results-header { flex-direction: column; align-items: stretch; }
  .filter-wrap { max-width: none; }
  .hero { padding-top: 18px; }
  .card { padding: 14px; }
}

/* ----- Time pickers & quick presets ----- */
.field-time .time-input { position: relative; }
.field-time input[type="time"] {
  width: 100%;
  font-variant-numeric: tabular-nums;
  letter-spacing: .02em;
  padding-right: 34px;
}
.field-time input[type="time"]::-webkit-calendar-picker-indicator {
  cursor: pointer; opacity: .55; transition: opacity var(--transition);
}
.field-time input[type="time"]::-webkit-calendar-picker-indicator:hover { opacity: 1; }
.time-clear {
  position: absolute;
  right: 6px; top: 50%; transform: translateY(-50%);
  width: 24px; height: 24px;
  border: none; background: transparent;
  color: var(--muted); cursor: pointer;
  font-size: 18px; line-height: 1;
  border-radius: 6px;
  display: none;
  transition: color var(--transition), background var(--transition);
}
.time-clear:hover { color: var(--ink); background: var(--surface); }
.field-time.has-value .time-clear { display: grid; place-items: center; }

.field-presets { gap: 8px; }
.field-label-mini {
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--muted); font-weight: 600;
}
.time-presets {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.chip {
  appearance: none; cursor: pointer;
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--ink-2);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 999px;
  transition: all var(--transition);
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface-2));
}
.chip:active { transform: scale(.96); }
.chip.is-active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chip-ghost {
  color: var(--muted);
  background: transparent;
}
.chip-ghost:hover {
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}
@media (prefers-color-scheme: dark) {
  .chip-ghost:hover { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .4); color: #fca5a5; }
}

/* ----- Detail button + Train detail modal ----- */
.col-detail { width: 1%; white-space: nowrap; text-align: right; }
.muted-inline { color: var(--muted); font-size: 12px; font-weight: 400; }
.btn-detail {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-detail:hover {
  background: var(--primary);
  color: var(--accent);
  border-color: var(--primary);
}

body.modal-open { overflow: hidden; }
.modal {
  position: fixed; inset: 0;
  z-index: 1000;
  display: grid; place-items: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(10, 37, 64, .55);
  backdrop-filter: blur(2px);
  animation: fade-in 160ms ease-out;
}
.modal-dialog {
  position: relative;
  width: min(560px, 100%);
  max-height: 90vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  color: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slide-up 220ms cubic-bezier(.2,.8,.2,1);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes slide-up {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to   { opacity: 1; transform: none; }
}
.modal-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-head-text { flex: 1; min-width: 0; }
.modal-head-text h3 { margin: 6px 0 2px; font-size: 18px; }
.modal-head-text .muted { margin: 0; font-size: 13px; color: var(--muted); }
.modal-head .badge { font-size: 12px; }
.modal-close {
  appearance: none; border: 0; background: transparent;
  font-size: 28px; line-height: 1; cursor: pointer;
  color: var(--muted); padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-line {
  padding: 8px 20px;
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .02em;
}
.modal-body {
  padding: 12px 20px 20px;
  overflow-y: auto;
}

/* Stop list */
.stop-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  position: relative;
}
.stop-list .stop {
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
}
.stop-marker {
  position: relative;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--c, #0084D8);
  box-shadow: 0 0 0 3px var(--surface), 0 0 0 4px var(--c, #0084D8);
  margin-left: 5px;
}
/* connecting vertical line */
.stop:not(.last) .stop-marker::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 14px;
  width: 3px;
  height: calc(100% + 20px);
  background: var(--c, #0084D8);
  transform: translateX(-50%);
}
.stop.transit .stop-marker {
  width: 16px; height: 16px;
  background: var(--surface);
  border: 3px solid var(--c, #0084D8);
  box-shadow: 0 0 0 3px var(--surface);
}
.stop-main {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  min-width: 0;
}
.stop-name { font-weight: 600; color: var(--ink); }
.stop.first .stop-name,
.stop.last  .stop-name { font-weight: 800; }
.stop-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--line);
}
.stop-lines { display: inline-flex; gap: 4px; align-items: center; }
.line-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  vertical-align: middle;
}
.line-dot.sm { width: 9px; height: 9px; }
.stop-time {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: var(--ink-2);
  font-size: 14px;
}
.modal-body .error { color: var(--danger); }

@media (max-width: 540px) {
  .modal { padding: 0; }
  .modal-dialog {
    width: 100%;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
  }
  .btn-detail { padding: 6px 10px; font-size: 12px; }
}

/* ----- Peta Rute ----- */
.map-card { display: flex; flex-direction: column; gap: 14px; }
.map-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
}
.map-head h2 { margin: 0 0 2px; }
.map-head .muted { margin: 0; font-size: 13px; }
.map-tabs {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.map-tab {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink-2);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.map-tab:hover { color: var(--ink); }
.map-tab.active {
  background: var(--primary);
  color: var(--accent);
  border-color: var(--primary);
}
.map-stage {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  display: grid;
  place-items: center;
  min-height: 220px;
  overflow: hidden;
}
.map-stage .muted, .map-stage .error { padding: 24px; text-align: center; }
.map-img-btn {
  appearance: none; border: 0; background: transparent; padding: 0;
  cursor: zoom-in; width: 100%; line-height: 0;
}
.map-img-btn img {
  display: block;
  width: 100%; height: auto;
  max-height: 70vh;
  object-fit: contain;
  border-radius: 8px;
  transition: transform var(--transition);
}
.map-img-btn:hover img { transform: scale(1.01); }
.map-source {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}
.map-source a { color: inherit; text-decoration: underline; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0;
  z-index: 1100;
  display: grid; place-items: center;
}
.lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, .85);
  cursor: zoom-out;
  animation: fade-in 160ms ease-out;
}
.lightbox img {
  position: relative;
  max-width: 96vw;
  max-height: 92vh;
  border-radius: 6px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, .6);
  animation: slide-up 220ms cubic-bezier(.2,.8,.2,1);
}
.lightbox-close {
  position: absolute;
  top: 14px; right: 18px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, .15);
  color: #fff;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255, 255, 255, .28); }

@media (max-width: 540px) {
  .map-head { flex-direction: column; align-items: stretch; }
  .map-tabs { justify-content: flex-start; }
  .lightbox-close { top: 8px; right: 8px; }
}
