:root {
  --bg: #0f1117;
  --panel: #191c26;
  --panel-2: #212533;
  --line: #2c3040;
  --text: #e8eaf0;
  --muted: #9aa0b3;
  --accent: #7b3fe4;
  --accent-2: #d1006f;
  --ok: #24c38a;
  --warn: #f0a020;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #241a3a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 22px; border-bottom: 1px solid var(--line);
  background: rgba(15,17,23,.7); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.logo { font-weight: 800; font-size: 22px; letter-spacing: -.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .dot { color: var(--accent-2); -webkit-text-fill-color: var(--accent-2); }
.tagline { color: var(--muted); font-size: 13px; }
.tabs { display: flex; gap: 6px; }
.tab {
  background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 14px; font-weight: 600;
}
.tab:hover { color: var(--text); }
.tab.active { color: #fff; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }

main { max-width: 1000px; margin: 22px auto; padding: 0 18px; }
.view { display: none; }
.view.active { display: block; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; padding: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field.grow { flex: 1 1 220px; min-width: 180px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
input, select, button { font: inherit; }
input, select {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 10px 12px; border-radius: 9px; outline: none; min-width: 120px;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(123,63,228,.25); }

/* accent-insensitive autocomplete dropdown */
.ac-menu {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 40;
  max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 4px;
}
.ac-menu.hidden { display: none; }
.ac-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.ac-item .ac-name { overflow: hidden; text-overflow: ellipsis; }
.ac-item:hover, .ac-item.active { background: var(--panel-2); }
.ac-item.active { box-shadow: inset 0 0 0 1px var(--accent); }
.ac-tag {
  flex: none; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px;
  color: var(--accent); background: rgba(123,63,228,.15); padding: 2px 7px; border-radius: 999px;
}

.seg { display: inline-flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg-btn { background: transparent; color: var(--muted); border: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; }
.seg-btn.active { background: var(--accent); color: #fff; }

button.primary {
  background: linear-gradient(90deg, var(--accent), var(--accent-2)); color: #fff; border: 0;
  padding: 11px 20px; border-radius: 9px; cursor: pointer; font-weight: 700;
}
button.primary:hover { filter: brightness(1.08); }
.swap { align-self: center; background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 18px; margin-bottom: 2px; }
.swap:hover { border-color: var(--accent); }

.filters { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin: 12px 4px 0; color: var(--muted); font-size: 13px; }
.filters .flabel { text-transform: uppercase; font-size: 11px; letter-spacing: .5px; font-weight: 700; }
.filters label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text); }
.filters input { min-width: 0; width: 15px; height: 15px; accent-color: var(--accent); }
.filters .sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }
.sw.ld { background: #b3005a; } .sw.cer { background: #0f9d76; } .sw.bus { background: #e07b1f; }

.result { margin-top: 18px; }

/* Board */
.board-head { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 4px 12px; flex-wrap: wrap; gap: 8px; }
.board-head h2 { margin: 0; font-size: 18px; }
.board-head .sub { color: var(--muted); font-size: 13px; }

table.board { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.board th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel-2); }
table.board td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.board tr:last-child td { border-bottom: 0; }
table.board tr:hover td { background: rgba(123,63,228,.06); }
.t-time { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 16px; white-space: nowrap; }
.t-dest { font-weight: 600; }
.t-stn { font-weight: 600; color: var(--accent); white-space: nowrap; }
.t-buy { text-align: right; white-space: nowrap; }
.buy {
  display: inline-flex; align-items: center; gap: 5px; text-decoration: none; white-space: nowrap;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 12.5px;
  padding: 6px 11px; border-radius: 8px;
}
.buy:hover { filter: brightness(1.12); }
.buy .ext { opacity: .8; font-weight: 400; }
.nobuy { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.t-via { color: var(--muted); font-size: 12.5px; }
.nextday { color: var(--warn); font-size: 11px; margin-left: 4px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11.5px; font-weight: 800; letter-spacing: .3px; color: #fff; white-space: nowrap; }
.badge.AVE, .badge.AVLO, .badge.AVE.INT { background: #b3005a; }
.badge.ALVIA, .badge.AVANT, .badge.AVANT.EXP { background: #6a2fd0; }
.badge.EUROMED { background: #1f7ae0; }
.badge.Intercity, .badge.TRENCELTA { background: #0f9d76; }
.badge.MD, .badge.REGIONAL, .badge.REG.EXP, .badge.PROXIMDAD { background: #4a5064; }
.badge.def { background: #4a5064; }
.badge.cer { background: #0f9d76; }
.badge.bus { background: #e07b1f; }
.modechip { display: inline-block; font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px;
  padding: 2px 6px; border-radius: 5px; margin-left: 6px; color: #fff; vertical-align: middle; }
.modechip.ld { background: #b3005a; } .modechip.cer { background: #0f9d76; } .modechip.bus { background: #e07b1f; }
.tnum { color: var(--muted); font-size: 12px; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* Journey cards */
.jcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; overflow: hidden; }
.jhead { display: flex; align-items: center; gap: 18px; padding: 14px 18px; background: var(--panel-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.jhead .times { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.jhead .arrow { color: var(--muted); margin: 0 8px; }
.jhead .dur { color: var(--text); font-weight: 600; }
.jhead .chg { margin-left: auto; color: var(--muted); font-size: 13px; }
.jhead .chg b { color: var(--text); }
.chg.direct { color: var(--ok) !important; }

.legs { padding: 6px 18px 14px; }
.leg { display: grid; grid-template-columns: 74px 22px 1fr; gap: 12px; align-items: stretch; }
.leg .col-time { display: flex; flex-direction: column; justify-content: space-between; padding: 8px 0; font-variant-numeric: tabular-nums; }
.leg .col-time .a { font-weight: 700; }
.leg .col-time .b { color: var(--muted); }
.leg .col-line { position: relative; display: flex; justify-content: center; }
.leg .col-line::before { content: ""; width: 3px; background: linear-gradient(var(--accent), var(--accent-2)); border-radius: 2px; }
.leg .dotp { position: absolute; width: 11px; height: 11px; border-radius: 50%; background: #fff; border: 3px solid var(--accent); }
.leg .dotp.top { top: 10px; } .leg .dotp.bot { bottom: 10px; }
.leg .col-body { padding: 8px 0; }
.leg .stn { font-weight: 700; }
.leg .mid { color: var(--muted); font-size: 13px; margin: 6px 0; display: flex; align-items: center; gap: 10px; }
.leg .stops-count { font-size: 12px; }
.transfer { display: grid; grid-template-columns: 74px 22px 1fr; gap: 12px; }
.transfer .col-body { color: var(--warn); font-size: 13px; padding: 8px 0; }

.empty, .loading, .error { text-align: center; color: var(--muted); padding: 40px 16px; }
.error { color: #ff6b8a; }
.hint { color: var(--muted); font-size: 13px; text-align: center; padding: 30px; }

.foot { max-width: 1000px; margin: 20px auto 40px; padding: 0 18px; color: var(--muted); font-size: 12px; }
.foot a { color: var(--accent); }

table.board tbody tr { cursor: pointer; }
.rowcaret { color: var(--muted); font-size: 12px; margin-left: 8px; }
.board-hint { color: var(--muted); font-size: 12.5px; margin: 0 4px 10px; }

/* Modal / route detail */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,7,12,.72); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow: auto;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); width: 100%; max-width: 900px; overflow: hidden;
}
.modal-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px; background: var(--panel-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.modal-head .route { font-size: 17px; font-weight: 800; }
.modal-head .close { margin-left: auto; background: transparent; border: 1px solid var(--line); color: var(--text); width: 34px; height: 34px; border-radius: 8px; cursor: pointer; font-size: 18px; }
.modal-head .close:hover { border-color: var(--accent); }
.modal-body { display: grid; grid-template-columns: 300px 1fr; gap: 0; }
.stoplist { border-right: 1px solid var(--line); max-height: 62vh; overflow: auto; }
.stoplist .srow { display: grid; grid-template-columns: 58px 1fr; gap: 10px; padding: 9px 16px; border-bottom: 1px solid var(--line); align-items: baseline; }
.stoplist .srow:last-child { border-bottom: 0; }
.stoplist .srow .tm { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--muted); white-space: nowrap; }
.stoplist .srow .tm .d { color: var(--text); font-weight: 700; display: block; }
.stoplist .srow .nm { font-weight: 600; }
.stoplist .srow.cur { background: rgba(209,0,111,.14); }
.stoplist .srow.cur .nm { color: #ff5ea8; }
.stoplist .srow.end .nm { color: var(--text); }
.stoplist .srow.hl { background: rgba(123,63,228,.22); }
.stoplist .srow.hl .nm { color: #fff; }
.stoplist .srow .tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin-left: 6px; }
.mapwrap { padding: 14px; display: flex; align-items: center; justify-content: center; }
.mapwrap svg { width: 100%; height: auto; }
.mapwrap .nomap { color: var(--muted); font-size: 13px; }
.mapwrap .stn-label { transition: fill .08s ease; }
/* paint-order puts the stroke behind the glyphs, so this reads as a halo rather
   than an outline — it lifts the hovered name off whatever it overlaps */
.mapwrap .stn-label.hl {
  fill: #fff; font-weight: 800;
  paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round;
}
.mapwrap .dot.hl { stroke: #fff; stroke-width: 3; }

@media (max-width: 720px) {
  .modal-body { grid-template-columns: 1fr; }
  .stoplist { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
}
@media (max-width: 620px) {
  .tagline { display: none; }
  table.board .hide-sm { display: none; }
}
