/* =========================================================================
   STYLES — InterRail Planner mock-up
   Responsive split-screen (laptop) & stacked/toggleable map (mobile).
   ========================================================================= */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f2a44;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --bad: #b91c1c;
  --bad-soft: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  --topbar-h: 56px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h2 { margin: 0 0 0.65rem; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; }
h3 { margin: 0 0 0.5rem; font-size: 0.98rem; font-weight: 700; }
h4 { margin: 1rem 0 0.35rem; font-size: 0.88rem; font-weight: 700; color: var(--brand); }
p { margin: 0.35rem 0; }
.small { font-size: 0.83rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }

/* ---------------- Top bar & stepper ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0 1rem;
  background: var(--brand); color: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.16);
}
.brand {
  display: flex; align-items: center; gap: 0.45rem;
  font-size: 1rem; cursor: pointer; white-space: nowrap;
}
.brand .tag {
  font-style: normal; font-size: 0.68rem; font-weight: 600;
  padding: 0.1rem 0.4rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.15); color: #e2e8f0;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.stepper {
  display: flex; align-items: center; gap: 0.25rem;
  margin-left: auto; overflow-x: auto; scrollbar-width: none;
}
.stepper::-webkit-scrollbar { display: none; }
.st {
  display: inline-flex; align-items: center; gap: 0.35rem;
  border: 0; background: transparent; color: rgba(255, 255, 255, 0.55);
  padding: 0.32rem 0.55rem; border-radius: 999px;
  font: inherit; font-size: 0.82rem; cursor: pointer; white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.st span {
  width: 20px; height: 20px; border-radius: 50%;
  display: inline-grid; place-items: center;
  font-size: 0.74rem; font-weight: 700;
  background: rgba(255, 255, 255, 0.14);
}
.st em { font-style: normal; }
.st.done { color: #cbd5e1; }
.st.done:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.st.on { background: rgba(255, 255, 255, 0.18); color: #fff; font-weight: 600; }
.st.on span { background: #38bdf8; color: var(--brand); }
.st:disabled { cursor: default; opacity: 0.45; }

.map-toggle {
  display: none;
  border: 1px solid rgba(255, 255, 255, 0.25); background: rgba(255, 255, 255, 0.1);
  color: #fff; border-radius: 8px; padding: 0.3rem 0.55rem;
  font-size: 1rem; cursor: pointer;
}

/* ---------------- Main responsive layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(380px, 480px) 1fr;
  height: calc(100vh - var(--topbar-h));
  height: calc(100dvh - var(--topbar-h));
}
.panel {
  order: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex; flex-direction: column; gap: 0.85rem;
  background: var(--bg);
}
.map-wrap {
  order: 2;
  position: relative;
  min-height: 260px;
  background: #dbeafe;
  border-left: 1px solid var(--line);
}
#map { width: 100%; height: 100%; }
.legend {
  position: absolute; bottom: 12px; left: 12px; z-index: 500;
  display: flex; flex-wrap: wrap; gap: 0.65rem;
  padding: 0.35rem 0.65rem; border-radius: 999px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: blur(6px);
  font-size: 0.74rem; font-weight: 600; color: var(--ink);
  box-shadow: var(--shadow);
}
.legend span { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }
.legend i.dash { height: 0; border-top: 2px dashed; background: none !important; }

/* ---------------- Cards & controls ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}
.card.tight { padding: 0.85rem 1rem; }
.card.subtle { background: var(--surface-alt); box-shadow: none; }
.card.warn-card { background: var(--warn-soft); border-color: #fcd34d; color: #78350f; font-size: 0.88rem; }
.card.ok-card { background: var(--ok-soft); border-color: #86efac; color: #14532d; font-size: 0.88rem; }

.lbl {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.82rem; font-weight: 600; color: var(--muted);
  margin: 0.75rem 0 0.35rem;
}
.lbl:first-of-type { margin-top: 0.25rem; }

select {
  width: 100%; min-width: 0;
  padding: 0.55rem 0.65rem;
  border: 1px solid #cbd5e1; border-radius: 8px;
  background: #fff; color: var(--ink);
  font: inherit; font-size: 0.9rem;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: flex; align-items: center; gap: 0.5rem; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 0.5rem; }
.grow { flex: 1; min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  padding: 0.55rem 0.9rem; border-radius: 8px;
  border: 1px solid transparent; font: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: all 0.12s ease;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1d4ed8; }
.btn.ghost { background: #fff; border-color: #cbd5e1; color: var(--ink); }
.btn.ghost:hover:not(:disabled) { background: var(--surface-alt); border-color: #94a3b8; }
.btn.icon { width: 32px; height: 32px; padding: 0; background: var(--surface-alt); border-color: var(--line); color: var(--ink); }
.btn.icon:hover { background: var(--line); }
.btn.sm { padding: 0.32rem 0.6rem; font-size: 0.8rem; border-radius: 6px; }
.btn.icon.sm { width: 26px; height: 26px; font-size: 0.95rem; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.link {
  border: 0; background: none; padding: 0.2rem 0;
  color: var(--accent); font: inherit; font-weight: 600; cursor: pointer;
}
.link:hover { text-decoration: underline; }

.pill {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  font-size: 0.78rem; font-weight: 700;
}
.badge {
  display: inline-block; padding: 0.12rem 0.5rem; border-radius: 999px;
  font-size: 0.73rem; font-weight: 700;
}
.badge.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #fcd34d; }

.range { width: 100%; accent-color: var(--accent); margin: 0.25rem 0; cursor: pointer; }
.range-scale { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); }
.hint { margin-top: 0.5rem; font-size: 0.85rem; color: var(--ink); }

.plain { list-style: none; margin: 0.25rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.86rem; }
.actions {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  margin-top: auto; padding-top: 0.25rem;
}

/* ---------------- Calendar (Step 2) ---------------- */
.cal { user-select: none; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.6rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid.dow { margin-bottom: 0.25rem; text-align: center; font-size: 0.74rem; font-weight: 600; color: var(--muted); }
.day {
  aspect-ratio: 1 / 0.86; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink);
  font: inherit; font-size: 0.86rem; font-weight: 500;
  cursor: pointer; transition: background 0.1s;
}
.day:hover:not(:disabled) { background: var(--accent-soft); }
.day.today { box-shadow: inset 0 0 0 1.5px var(--accent); font-weight: 700; }
.day.past { color: #cbd5e1; cursor: default; }
.day.in { background: var(--accent-soft); color: var(--accent); border-radius: 4px; }
.day.start, .day.end { background: var(--accent); color: #fff; font-weight: 700; }

.trip-summary {
  margin-top: 0.75rem; padding: 0.6rem 0.75rem; border-radius: 8px;
  background: var(--surface-alt); border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.35rem;
  font-size: 0.88rem;
}

.choice { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
.choice-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.2rem;
  text-align: left; padding: 0.75rem; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; cursor: pointer; transition: all 0.15s;
}
.choice-card:hover { border-color: #93c5fd; }
.choice-card.on { border-color: var(--accent); background: var(--accent-soft); }
.choice-card .big { font-size: 1.15rem; }

/* ---------------- Destinations (Step 3) ---------------- */
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.chip {
  border: 1px solid var(--line); background: var(--surface-alt); color: var(--ink);
  padding: 0.3rem 0.65rem; border-radius: 999px; font: inherit; font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
}
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }

.dest-list { display: flex; flex-direction: column; gap: 0.6rem; }
.dest {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem 0.95rem; cursor: pointer; transition: border-color 0.15s, transform 0.1s;
  box-shadow: var(--shadow);
}
.dest:hover { border-color: var(--accent); }
.dest.on { border-color: var(--accent); background: var(--accent-soft); }
.dest-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.35rem; }
.flag { font-size: 1.25rem; line-height: 1; }
.price { font-weight: 800; font-size: 1rem; color: var(--brand); text-align: right; }
.price small { display: block; font-size: 0.68rem; font-weight: 500; color: var(--muted); line-height: 1; }
.dest-row { font-size: 0.84rem; margin-top: 0.22rem; }

/* ---------------- Routes (Step 4) ---------------- */
.section { margin: 0.2rem 0 -0.25rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.opt {
  background: var(--surface); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 0.85rem 0.95rem; cursor: pointer; box-shadow: var(--shadow);
}
.opt:hover { border-color: #93c5fd; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.opt-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.chain { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem; margin: 0.5rem 0; }
.stop-chip {
  display: inline-flex; align-items: center; gap: 0.2rem;
  padding: 0.16rem 0.5rem; border-radius: 999px;
  background: #fff; border: 1px solid var(--line);
  font-size: 0.78rem; font-weight: 600;
}
.stop-chip em { font-style: normal; color: var(--ok); font-weight: 700; }
.arrow { color: var(--muted); font-size: 0.85rem; }

.stats {
  display: flex; flex-wrap: wrap; gap: 0.65rem;
  font-size: 0.8rem; font-weight: 600; color: var(--ink);
  padding-top: 0.4rem; border-top: 1px dashed var(--line);
}

/* ---------------- Builder & Totals (Step 5) ---------------- */
.totals {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem;
}
.totals > div {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 0.55rem 0.45rem; text-align: center; box-shadow: var(--shadow);
}
.totals > div[role="button"] { cursor: pointer; }
.totals > div[role="button"]:hover { border-color: var(--accent); }
.totals b { display: block; font-size: 0.98rem; color: var(--brand); }
.totals span { font-size: 0.72rem; color: var(--muted); }
.totals .bad { background: var(--bad-soft); border-color: #fca5a5; }
.totals .bad b { color: var(--bad); }

.cost-break { background: var(--surface-alt); }

.label-rec, .label-alt {
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  margin: 0.65rem 0 0.35rem;
}
.label-rec { color: var(--ok); }
.label-alt { color: var(--muted); }

.cand {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0.65rem 0.75rem; margin-bottom: 0.45rem; background: var(--surface);
}
.cand.rec { border-color: #86efac; background: var(--ok-soft); }
.cand.nv { opacity: 0.72; background: var(--surface-alt); }
.cand-head { display: flex; align-items: center; gap: 0.45rem; margin-bottom: 0.2rem; }
.wx { font-size: 0.78rem; font-weight: 600; color: var(--muted); white-space: nowrap; margin-left: 0.35rem; }

details summary { cursor: pointer; color: var(--muted); margin: 0.4rem 0; font-weight: 600; }

/* ---------------- Timeline ---------------- */
.timeline {
  list-style: none; margin: 0.6rem 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 0.55rem;
}
.tl {
  display: grid; grid-template-columns: 52px 26px 1fr; gap: 0.5rem; align-items: start;
  position: relative;
}
.tl:not(:last-child)::after {
  content: ""; position: absolute; left: 69px; top: 26px; bottom: -10px;
  width: 2px; background: var(--line);
}
.tl-date { text-align: right; line-height: 1.2; padding-top: 2px; }
.tl-date b { display: block; font-size: 0.75rem; color: var(--brand); }
.tl-date span { font-size: 0.72rem; color: var(--muted); }
.tl-dot {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.82rem;
  background: var(--surface-alt); border: 1.5px solid var(--line); z-index: 1;
}
.tl.flight .tl-dot { background: #f3e8ff; border-color: #c084fc; }
.tl.travel .tl-dot { background: var(--accent-soft); border-color: #93c5fd; }
.tl.free .tl-dot { background: var(--ok-soft); border-color: #86efac; }
.tl.spare .tl-dot { border-style: dashed; }
.tl.over .tl-body { border-color: #fca5a5; background: var(--bad-soft); }

.tl-body {
  padding: 0.45rem 0.65rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface-alt);
}
.tl-body[data-action="sheet"] { cursor: pointer; }
.tl-body[data-action="sheet"]:hover { border-color: var(--accent); background: #fff; }
.tl-title { display: flex; align-items: baseline; justify-content: space-between; gap: 0.4rem; font-size: 0.87rem; font-weight: 600; }
.legs {
  display: flex; flex-direction: column; gap: 0.25rem;
  margin-top: 0.35rem; padding-top: 0.35rem;
  border-top: 1px dashed var(--line);
}
.leg-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  font-size: 0.79rem; line-height: 1.35;
}
.leg-row em { font-style: normal; }
.leg-row > span:last-child { white-space: nowrap; font-weight: 600; }
.ctl { display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.45rem; }
.btn.ghost.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.via-box {
  margin-top: 0.55rem; padding: 0.6rem 0.65rem; border-radius: 8px;
  background: #fff; border: 1px solid #bfdbfe; cursor: default;
}
.via-list { display: flex; flex-direction: column; gap: 0.4rem; margin-top: 0.45rem; }
.via-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0.5rem; border-radius: 7px;
  background: var(--surface-alt); border: 1px solid var(--line);
}
.via-item.nv { opacity: 0.7; }

.timeline.compact .tl-body { padding: 0.35rem 0.55rem; }

/* ---------------- City Guide Sheet ---------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 23, 42, 0.45);
  display: flex; justify-content: flex-end; align-items: stretch;
}
.sheet {
  width: min(440px, 100%); max-height: 100%;
  background: var(--surface); display: flex; flex-direction: column;
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.25);
}
.sheet-head {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.9rem 1rem; border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; flex: 1; }
.sheet-body { padding: 1rem; overflow-y: auto; }
.wx-card {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.85rem; border-radius: 10px;
  background: var(--accent-soft); font-size: 1.5rem;
}
.wx-card b { display: block; font-size: 0.95rem; }

/* ---------------- Map pins & toast ---------------- */
.pin {
  display: grid !important; place-items: center;
  border-radius: 50%; font-size: 0.78rem; font-weight: 800;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.35);
  border: 2px solid #fff;
}
.pin.home { background: var(--brand); color: #fff; }
.pin.air { background: #9333ea; color: #fff; }
.pin.num { background: var(--accent); color: #fff; }

.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 1100;
  background: var(--brand); color: #fff; padding: 0.6rem 1rem; border-radius: 999px;
  font-size: 0.85rem; font-weight: 500; box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  max-width: calc(100% - 2rem); text-align: center;
}

/* ---------------- Mobile layout ---------------- */
@media (max-width: 860px) {
  .topbar { padding: 0 0.65rem; gap: 0.45rem; }
  .brand { font-size: 0.92rem; gap: 0.3rem; flex-shrink: 0; }
  .brand .tag { display: none; }
  .stepper { flex: 1; min-width: 0; justify-content: flex-end; gap: 0.15rem; }
  .st { padding: 0.25rem 0.35rem; font-size: 0.78rem; gap: 0.25rem; }
  .st.on { padding: 0.25rem 0.5rem; }
  .st em { display: none; }
  .st.on em { display: inline; }
  .map-toggle { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }

  .layout {
    display: flex; flex-direction: column;
    height: auto; min-height: calc(100dvh - var(--topbar-h));
  }
  .map-wrap {
    order: 1; height: 34vh; min-height: 220px; max-height: 320px;
    border-left: 0; border-bottom: 1px solid var(--line);
  }
  body.map-hidden .map-wrap { display: none; }
  .panel { order: 2; overflow: visible; padding: 0.85rem; }

  .choice { grid-template-columns: 1fr; }
  .totals { grid-template-columns: repeat(2, 1fr); }

  .sheet-backdrop { align-items: flex-end; justify-content: center; }
  .sheet { width: 100%; max-height: 85dvh; border-radius: 16px 16px 0 0; }
}
@media (max-width: 460px) {
  .brand span { display: none; }
}
