/* Mileage Claim Calculator — dark, premium UI, sibling of Budget Builder.
   Plain CSS, no build. Print styles (bottom) give a clean PDF. */

:root {
  /* Surfaces */
  --bg: #070a10;
  --bg-2: #0b0f17;
  --panel: #10151f;
  --panel-2: #141b27;
  --elevate: #182231;
  --glass: rgba(22, 30, 44, 0.62);
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.14);

  /* Text */
  --ink: #eaf1f8;
  --ink-soft: #b8c4d2;
  --muted: #7c8a9c;

  /* Accent — teal→cyan, matches Budget Builder */
  --accent: #2dd4bf;
  --accent-2: #22d3ee;
  --accent-strong: #14b8a6;
  --accent-ink: #06231f;
  --accent-wash: rgba(45, 212, 191, 0.12);
  --accent-line: rgba(45, 212, 191, 0.30);
  --violet: #7c8cf8;

  /* Status */
  --danger: #f87171;
  --danger-wash: rgba(248, 113, 113, 0.12);
  --warning: #fbbf24;
  --warning-wash: rgba(251, 191, 36, 0.12);
  --good: #34d399;
  --good-wash: rgba(52, 211, 153, 0.12);

  /* Effects */
  --glow: 0 0 40px rgba(45, 212, 191, 0.28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 40px 90px rgba(0, 0, 0, 0.7);
  --r-xl: 22px;
  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 9px;
  --focus: 0 0 0 3px rgba(45, 212, 191, 0.4);

  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(900px 520px at -8% -12%, rgba(45, 212, 191, 0.16) 0, transparent 42%),
    radial-gradient(820px 480px at 108% -6%, rgba(124, 140, 248, 0.16) 0, transparent 42%),
    radial-gradient(1200px 700px at 50% 120%, rgba(34, 211, 238, 0.08) 0, transparent 50%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
::selection { background: rgba(45, 212, 191, 0.3); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
::-webkit-scrollbar { width: 11px; height: 11px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 999px; border: 3px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.2); background-clip: content-box; }

.noscript { margin: 24px; padding: 18px; background: var(--danger-wash); border: 1px solid rgba(248, 113, 113, 0.4); border-radius: var(--r-md); }

/* ---------- Layout ---------- */
.app-shell { max-width: 1320px; margin: 0 auto; padding: 22px; display: flex; flex-direction: column; gap: 22px; min-height: 100vh; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  border: 1px solid var(--line); border-radius: var(--r-xl); padding: 16px 20px; box-shadow: var(--shadow);
}
.brand-block { display: flex; gap: 13px; align-items: center; }
.logo-mark {
  width: 46px; height: 46px; flex: none; display: grid; place-items: center; border-radius: 13px;
  background: linear-gradient(150deg, var(--accent), var(--accent-2)); color: var(--accent-ink);
  box-shadow: 0 8px 22px rgba(45, 212, 191, 0.45);
}
.brand-text h1 { margin: 0; font-size: 1.06rem; letter-spacing: -0.01em; }
.eyebrow { margin: 0 0 3px; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.64rem; font-weight: 700; color: var(--accent); }
.muted { color: var(--muted); font-weight: 400; }

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

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 22px; align-items: start; }
.inputs-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.results-col { position: sticky; top: 22px; display: flex; flex-direction: column; gap: 18px; min-width: 0; }

/* ---------- Buttons ---------- */
.primary-button, .secondary-button, .ghost-button {
  border-radius: var(--r-sm); padding: 10px 16px; font-weight: 600; font-size: 0.9rem;
  border: 1px solid transparent; transition: transform .06s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.primary-button { background: linear-gradient(150deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); box-shadow: 0 10px 26px rgba(45, 212, 191, 0.32); }
.primary-button:hover { transform: translateY(-1px); box-shadow: 0 14px 32px rgba(45, 212, 191, 0.42); }
.secondary-button { background: var(--elevate); color: var(--ink); border-color: var(--line-strong); }
.secondary-button:hover { border-color: var(--accent-line); }
.ghost-button { background: transparent; color: var(--ink-soft); border-color: var(--line-strong); }
.ghost-button:hover { color: var(--ink); border-color: var(--accent-line); background: var(--accent-wash); }
.link-button { background: none; border: none; color: var(--muted); font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; padding: 6px; }
.link-button:hover { color: var(--ink); }

/* ---------- Cards ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 20px; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 14px;
}
.card-head { display: flex; flex-direction: column; gap: 3px; }
.card-head h2 { margin: 0; font-size: 1rem; letter-spacing: -0.01em; }
.card-sub { margin: 0; font-size: 0.84rem; color: var(--muted); line-height: 1.45; }

/* ---------- Journey leg rows ---------- */
.leg-list { display: flex; flex-direction: column; gap: 8px; }
.leg-row { position: relative; display: grid; grid-template-columns: 26px 1fr auto; align-items: center; gap: 10px; }
.leg-dot { width: 26px; display: grid; place-items: center; color: var(--muted); }
.leg-dot .pin { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); }
.leg-row.start .leg-dot .pin { background: var(--accent); }
.leg-row.end .leg-dot .pin { border-color: var(--violet); background: var(--violet); border-radius: 3px; }
.leg-row.stop .leg-dot .pin { border-color: var(--accent-2); width: 9px; height: 9px; }
.leg-connector { position: absolute; left: 12px; top: -8px; height: 8px; width: 2px; background: var(--line-strong); }

.leg-input-wrap { position: relative; min-width: 0; }
.leg-input {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 11px 12px; color: var(--ink); transition: border-color .15s ease, box-shadow .15s ease;
}
.leg-input::placeholder { color: var(--muted); }
.leg-input:focus { border-color: var(--accent-line); box-shadow: var(--focus); }
.leg-input.resolved { border-color: var(--accent-line); background: linear-gradient(0deg, var(--accent-wash), var(--bg-2)); }
.leg-input.error { border-color: rgba(248, 113, 113, 0.6); }
.leg-remove { background: none; border: none; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 6px 8px; border-radius: var(--r-sm); }
.leg-remove:hover { color: var(--danger); background: var(--danger-wash); }
.leg-status { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 0.72rem; color: var(--muted); pointer-events: none; }
.leg-status.ok { color: var(--good); }
.leg-status.loading { color: var(--accent); }

/* Autocomplete dropdown */
.suggest {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--elevate); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  box-shadow: var(--shadow); overflow: hidden; max-height: 260px; overflow-y: auto;
}
.suggest[hidden] { display: none; }
.suggest-item { padding: 10px 12px; font-size: 0.86rem; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 1px; }
.suggest-item:last-child { border-bottom: none; }
.suggest-item:hover, .suggest-item.active { background: var(--accent-wash); }
.suggest-item .s-main { color: var(--ink); }
.suggest-item .s-sub { color: var(--muted); font-size: 0.76rem; }
.suggest-empty { padding: 10px 12px; font-size: 0.82rem; color: var(--muted); }

.leg-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.add-stop { font-size: 0.85rem; padding: 8px 12px; }

/* ---------- Switch ---------- */
.switch-row { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; padding-top: 2px; }
.switch-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { flex: none; width: 42px; height: 24px; border-radius: 999px; background: var(--elevate); border: 1px solid var(--line-strong); position: relative; transition: background .2s ease, border-color .2s ease; margin-top: 1px; }
.switch-thumb { position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: var(--ink-soft); transition: transform .2s ease, background .2s ease; }
.switch-row input:checked + .switch-track { background: var(--accent-wash); border-color: var(--accent-line); }
.switch-row input:checked + .switch-track .switch-thumb { transform: translateX(18px); background: var(--accent); }
.switch-row input:focus-visible + .switch-track { box-shadow: var(--focus); }
.switch-label { display: flex; flex-direction: column; gap: 1px; }
.switch-label strong { font-size: 0.9rem; font-weight: 600; }
.switch-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }

/* ---------- Fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); }
.field input[type="number"], .field select {
  background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  padding: 10px 12px; color: var(--ink);
}
.field input:focus, .field select:focus { border-color: var(--accent-line); box-shadow: var(--focus); outline: none; }
.field-hint { margin: 2px 0 0; font-size: 0.77rem; color: var(--muted); line-height: 1.45; }
.field.inline { gap: 6px; }
input[type="range"] { accent-color: var(--accent); }

/* ---------- Segmented control ---------- */
.seg { display: flex; gap: 6px; background: var(--bg-2); border: 1px solid var(--line-strong); border-radius: var(--r-md); padding: 4px; }
.seg.small { max-width: 100%; }
.seg-btn { flex: 1; background: transparent; border: none; border-radius: var(--r-sm); padding: 9px 10px; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); transition: background .15s ease, color .15s ease; }
.seg-btn:hover { color: var(--ink); }
.seg-btn.is-active { background: linear-gradient(150deg, var(--accent), var(--accent-strong)); color: var(--accent-ink); box-shadow: 0 6px 16px rgba(45, 212, 191, 0.3); }

/* ---------- Details / advanced ---------- */
.manual-details, .advanced { }
.manual-details summary, .advanced summary { cursor: pointer; list-style: none; }
.manual-details summary::-webkit-details-marker, .advanced summary::-webkit-details-marker { display: none; }
.manual-details summary { font-size: 0.84rem; color: var(--accent); font-weight: 600; padding: 4px 0; }
.manual-details summary:hover { text-decoration: underline; }
.manual-body { padding-top: 10px; display: flex; flex-direction: column; gap: 8px; }

.advanced { }
.advanced summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.advanced summary h2 { margin: 0; font-size: 1rem; }
.advanced .chev { transition: transform .2s ease; color: var(--muted); }
.advanced[open] .chev { transform: rotate(180deg); }
.advanced-body { display: flex; flex-direction: column; gap: 14px; padding-top: 16px; }

.vat-details { display: flex; flex-direction: column; gap: 14px; padding-top: 2px; }
.vat-details[hidden] { display: none; }

.disclaimer { font-size: 0.74rem; color: var(--muted); line-height: 1.5; margin: 0; padding: 0 2px; }

/* ---------- Map ---------- */
.map-card { position: relative; border-radius: var(--r-lg); overflow: hidden; border: 1px solid var(--line); box-shadow: var(--shadow); height: 300px; }
#map { position: absolute; inset: 0; background: var(--bg-2); }
.leaflet-container { background: #0d1420; font-family: inherit; }
.leaflet-control-attribution { background: rgba(7, 10, 16, 0.7) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--ink-soft) !important; }
.map-overlay { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; background: rgba(7, 10, 16, 0.55); backdrop-filter: blur(2px); z-index: 500; pointer-events: none; }
.map-overlay p { margin: 0; color: var(--ink-soft); font-size: 0.9rem; max-width: 260px; }
.map-overlay[hidden] { display: none; }

/* ---------- Result card ---------- */
.result-card { background: linear-gradient(160deg, var(--panel-2), var(--panel)); border: 1px solid var(--line-strong); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 16px; }
.result-empty { color: var(--muted); font-size: 0.9rem; text-align: center; padding: 16px 0; }

.headline { display: flex; flex-direction: column; gap: 4px; }
.headline .label { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.headline .amount { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1; background: linear-gradient(120deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.headline .amount.small { font-size: 1.8rem; }
.headline .sub { font-size: 0.86rem; color: var(--ink-soft); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; }
.stat .k { font-size: 0.74rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat .v { font-size: 1.15rem; font-weight: 700; margin-top: 2px; }

.breakdown { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 14px; }
.row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.row:last-child { border-bottom: none; }
.row .rk { font-size: 0.88rem; color: var(--ink-soft); }
.row .rk small { display: block; color: var(--muted); font-size: 0.76rem; }
.row .rv { font-size: 0.95rem; font-weight: 600; white-space: nowrap; }
.row.total { border-top: 2px solid var(--accent-line); border-bottom: none; margin-top: 6px; padding-top: 12px; }
.row.total .rk { color: var(--ink); font-weight: 700; }
.row.total .rv { font-size: 1.2rem; color: var(--accent); font-weight: 800; }
.row.credit .rv { color: var(--good); }
.row.debit .rv { color: var(--warning); }

.callout { display: flex; gap: 10px; align-items: flex-start; background: var(--accent-wash); border: 1px solid var(--accent-line); border-radius: var(--r-md); padding: 12px 14px; font-size: 0.82rem; color: var(--ink-soft); line-height: 1.5; }
.callout.warn { background: var(--warning-wash); border-color: rgba(251, 191, 36, 0.3); }
.callout .ico { flex: none; margin-top: 1px; }
.callout strong { color: var(--ink); }

.plain { font-size: 0.86rem; color: var(--ink-soft); line-height: 1.55; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px 14px; }
.plain strong { color: var(--ink); }

/* ---------- Tour ---------- */
.tour-overlay { position: fixed; inset: 0; z-index: 900; background: rgba(3, 6, 12, 0.72); backdrop-filter: blur(2px); display: none; }
.tour-overlay.on { display: block; }
.tour-tip { position: fixed; max-width: 320px; background: var(--elevate); border: 1px solid var(--accent-line); border-radius: var(--r-md); padding: 16px 18px; box-shadow: var(--shadow-lg); }
.tour-tip h3 { margin: 0 0 6px; font-size: 0.98rem; }
.tour-tip p { margin: 0 0 14px; font-size: 0.86rem; color: var(--ink-soft); line-height: 1.5; }
.tour-tip .tour-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tour-tip .tour-step { font-size: 0.76rem; color: var(--muted); }
.tour-target-glow { position: relative; z-index: 901; box-shadow: 0 0 0 3px var(--accent), var(--glow) !important; border-radius: var(--r-lg); }

/* ---------- Toast ---------- */
.toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: var(--elevate); border: 1px solid var(--line-strong); border-radius: var(--r-sm); padding: 11px 16px; font-size: 0.86rem; box-shadow: var(--shadow); animation: toastIn .2s ease; }
.toast.err { border-color: rgba(248, 113, 113, 0.5); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .results-col { position: static; order: -1; }
  .map-card { height: 240px; }
}
@media (max-width: 560px) {
  .app-shell { padding: 14px; gap: 16px; }
  .topbar { padding: 14px; }
  .brand-text h1 { font-size: 0.98rem; }
  .headline .amount { font-size: 2.1rem; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Embed mode (?embed=1 in an iframe) ----------
   A self-contained dark widget: no giant outer padding, no page-width cap,
   header trimmed. The app keeps its own dark background so it looks
   deliberate on any host page, light or dark. */
body.embed { min-height: 0; }
body.embed .app-shell { padding: 14px; max-width: 100%; gap: 16px; min-height: 0; }
body.embed .topbar { display: none; }
body.embed .results-col { position: static; } /* sticky is pointless when the frame auto-sizes */
@media (max-width: 900px) {
  body.embed .results-col { order: 0; } /* keep inputs first inside a narrow embed */
}

/* ---------- Print (PDF summary) ---------- */
@media print {
  body { background: #fff; color: #0b0f17; }
  .app-shell { max-width: none; padding: 0; }
  .topbar-actions, .leg-actions, .tour-overlay, .toast-root, .manual-details, .advanced summary .chev, .map-overlay { display: none !important; }
  .inputs-col { display: none; }
  .workspace { display: block; }
  .results-col { position: static; }
  .map-card { height: 260px; border: 1px solid #ccc; page-break-inside: avoid; }
  .result-card { background: #fff; border: 1px solid #ccc; box-shadow: none; }
  .headline .amount { color: #0b7f70; -webkit-text-fill-color: #0b7f70; }
  .stat, .plain, .callout, .row.total { border-color: #ccc; }
  .stat .v, .row .rv, .row.total .rv, .row.total .rk { color: #0b0f17; }
}
