/* ==========================================================================
   Waylogia — Design system
   Auteur: Olivier Bourbonnais — 2026
   ========================================================================== */

/* --- Design tokens (dark by default) ------------------------------------- */
:root {
  /* Palette */
  --bg:           #0a0e19;
  --bg-grad-1:    #0b1a15;
  --bg-grad-2:    #0a0e19;
  --surface:      #0f1729;
  --surface-2:    #131c33;
  --surface-3:    #182240;
  --border:       rgba(255, 255, 255, 0.08);
  --border-strong:rgba(255, 255, 255, 0.16);
  --text:         #e6f2ee;
  --text-muted:   #8aa2b8;
  --text-faint:   #5d7286;
  --accent:       #2ecc71;
  --accent-2:     #1faa66;
  --accent-soft:  rgba(46, 204, 113, 0.14);
  --accent-ink:   #08110e;
  --danger:       #ef4444;
  --danger-soft:  rgba(239, 68, 68, 0.12);
  --warn:         #f59e0b;
  --info:         #38bdf8;

  /* Effects */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.25);
  --shadow:     0 4px 12px rgba(0,0,0,0.35);
  --shadow-lg:  0 18px 40px rgba(0,0,0,0.45);

  /* Scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 48px;

  --r-sm:  8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 20px;
  --r-full: 999px;

  /* Typography */
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, monospace;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-30: 30px;

  /* Motion */
  --ease: cubic-bezier(.2, .8, .2, 1);
  --t-fast: 120ms;
  --t-base: 180ms;

  /* Layout */
  --aside-w: 440px;
  --header-h: 64px;
}

/* Light theme overrides */
:root[data-theme="light"] {
  --bg:           #f5f8f7;
  --bg-grad-1:    #f0f5f2;
  --bg-grad-2:    #f5f8f7;
  --surface:      #ffffff;
  --surface-2:    #f4f7f5;
  --surface-3:    #ebf1ed;
  --border:       rgba(0, 0, 0, 0.08);
  --border-strong:rgba(0, 0, 0, 0.16);
  --text:         #0e1a17;
  --text-muted:   #4f6a62;
  --text-faint:   #889b94;
  --accent:       #1faa66;
  --accent-2:     #178f55;
  --accent-soft:  rgba(31, 170, 102, 0.12);
  --accent-ink:   #ffffff;
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.06);
  --shadow:     0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:  0 18px 40px rgba(0,0,0,0.12);
}

/* Auto follow OS unless user pinned a theme */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg:           #f5f8f7;
    --bg-grad-1:    #f0f5f2;
    --bg-grad-2:    #f5f8f7;
    --surface:      #ffffff;
    --surface-2:    #f4f7f5;
    --surface-3:    #ebf1ed;
    --border:       rgba(0, 0, 0, 0.08);
    --border-strong:rgba(0, 0, 0, 0.16);
    --text:         #0e1a17;
    --text-muted:   #4f6a62;
    --text-faint:   #889b94;
    --accent:       #1faa66;
    --accent-2:     #178f55;
    --accent-soft:  rgba(31, 170, 102, 0.12);
    --accent-ink:   #ffffff;
    --shadow-sm:  0 1px 2px rgba(0,0,0,0.06);
    --shadow:     0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg:  0 18px 40px rgba(0,0,0,0.12);
  }
}

/* --- Reset --------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: 1.5;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; }
input, select, textarea, button { font-family: inherit; }

/* Accessible focus ring */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* Scrollbar polish (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* --- App layout ---------------------------------------------------------- */
body {
  display: grid;
  grid-template-columns: var(--aside-w) 1fr;
  grid-template-rows: 100vh;
  /* Explicit named areas so injected DOM (browser extensions etc.) can't break layout */
  grid-template-areas: "panel map";
  min-height: 100vh;
}

aside {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  height: 100vh;
  position: sticky;
  top: 0;
  overflow: hidden; /* inner panel-body scrolls */
}

.panel-head {
  flex: 0 0 auto;
  padding: var(--space-4) var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface), var(--surface-2));
}

.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-4);
  display: grid;
  gap: var(--space-4);
}

#map {
  grid-area: map;
  width: 100%;
  height: 100vh;
  position: relative;
  background: var(--surface-2);
}

/* Any direct child of body that isn't aside / #map should NOT participate in the grid.
   Modals + toast-host already use position:fixed, but extensions inject divs at body level. */
body > :not(aside):not(#map) {
  grid-area: 1 / 1 / 2 / 3; /* same cell as everything else, but they're position:fixed/hidden */
  pointer-events: none;
}
/* Re-enable interactivity on our own UI overlays */
body > #toast-host, body > .modal.open, body > #debug, body > #about-modal, body > #confirm-modal, body > #templates-modal {
  pointer-events: auto;
}

.map-wrap { position: relative; }

/* Map loading state */
#map.is-loading::before {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
  transform: translate(-50%,-50%);
  z-index: 1;
}
@keyframes spin { to { transform: translate(-50%,-50%) rotate(360deg); } }

/* --- Brand --------------------------------------------------------------- */
.brand {
  display: flex; align-items: center; gap: var(--space-3);
}
.brand-logo {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}
.brand-logo svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-name { font-size: var(--fs-18); font-weight: 800; letter-spacing: -0.01em; }
.brand-tagline { font-size: var(--fs-12); color: var(--text-muted); }

/* Header row */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}
.header-actions {
  display: flex; align-items: center; gap: var(--space-2);
}

/* SEO intro (hidden visually, kept for SEO) */
.seo-intro {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

/* --- Tabs ---------------------------------------------------------------- */
.tabs {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 3px;
  margin-top: var(--space-3);
  width: 100%;
}
.tab {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: var(--r-full);
  font-size: var(--fs-13);
  font-weight: 600;
  cursor: pointer;
  transition: color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  box-shadow: var(--shadow-sm);
}

/* --- Inputs / selects ---------------------------------------------------- */
input, select, textarea {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 9px 12px;
  font-size: var(--fs-14);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 28px;
}
input[type="date"] { min-height: 36px; }

/* Field labels */
.field { display: grid; gap: 4px; min-width: 0; }
.field-label {
  font-size: var(--fs-12);
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* --- Buttons ------------------------------------------------------------- */
button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--r-md);
  padding: 9px 14px;
  font-size: var(--fs-14);
  font-weight: 600;
  transition: transform var(--t-fast) var(--ease),
              background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover { border-color: var(--border-strong); background: var(--surface-3); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  color: var(--accent-ink);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--accent-2), var(--accent)); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.btn-danger {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fecaca;
}
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); }

/* Icon-only button */
.btn-icon {
  padding: 0;
  width: 34px; height: 34px;
  border-radius: var(--r-md);
  display: inline-grid; place-items: center;
  font-size: var(--fs-14);
}
.btn-icon.sm { width: 28px; height: 28px; }
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon.sm svg { width: 14px; height: 14px; }

/* Button groups (segmented) */
.btn-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
}
.btn-group > button {
  border-radius: 0; border: 0;
  background: transparent;
  padding: 6px 10px;
  font-size: var(--fs-12);
  color: var(--text-muted);
}
.btn-group > button + button { border-left: 1px solid var(--border); }
.btn-group > button.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* --- Card ---------------------------------------------------------------- */
.card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-lg);
  padding: var(--space-3);
}

.section-title {
  font-size: var(--fs-12);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: var(--space-2) 0 var(--space-1);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
}
.section-title .count {
  font-size: var(--fs-12);
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-muted);
  border-radius: var(--r-full);
  padding: 2px 8px;
  letter-spacing: 0;
  text-transform: none;
}

/* --- Row helper ---------------------------------------------------------- */
.row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.row.nw { flex-wrap: nowrap; }
.grid { display: grid; gap: var(--space-2); }
.split-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2); align-items: center; }
.small { font-size: var(--fs-12); color: var(--text-muted); }

/* --- Summary card -------------------------------------------------------- */
.summary {
  border: 1px solid var(--border);
  background: linear-gradient(135deg, var(--accent-soft), transparent);
  border-radius: var(--r-lg);
  padding: var(--space-3) var(--space-4);
  display: grid;
  gap: 2px;
  text-align: center;
}
.summary-top {
  font-size: var(--fs-18);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.summary-mid, .summary-bot {
  font-size: var(--fs-12);
  color: var(--text-muted);
}

/* --- Stops list ---------------------------------------------------------- */
.stops-list {
  display: grid;
  gap: var(--space-3);
}
.stop {
  position: relative;
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  transition: border-color var(--t-fast) var(--ease), transform var(--t-fast) var(--ease);
}
.stop:hover { border-color: var(--border-strong); }
.stop.dragging { opacity: .6; border-style: dashed; transform: scale(0.99); }

.stop-index {
  position: absolute;
  top: -10px; left: 10px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  font-size: 11px;
  font-weight: 800;
  display: grid; place-items: center;
  box-shadow: var(--shadow-sm);
}

.stop-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-2);
  align-items: center;
}
.stop-handle {
  cursor: grab;
  color: var(--text-faint);
  font-size: var(--fs-18);
  line-height: 1;
  user-select: none;
  padding: 0 4px;
}
.stop-handle:active { cursor: grabbing; }
.stop-label {
  font-weight: 600;
  font-size: var(--fs-15);
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 8px;
  border-radius: var(--r-sm);
}
.stop-label:hover { border-color: var(--border); background: var(--surface-2); }
.stop-label:focus { border-color: var(--accent); background: var(--surface-2); }

.stop-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.stop-actions .btn-icon { width: 28px; height: 28px; }

.stop-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2);
  align-items: center;
}

/* Mini stepper (pause / nights) */
.stepper {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 2px;
  gap: 2px;
}
.stepper input {
  width: 44px;
  text-align: center;
  border: 0;
  background: transparent;
  padding: 2px;
  font-weight: 700;
  font-size: var(--fs-13);
}
.stepper input:focus { box-shadow: none; }
.stepper .stepbtn {
  width: 24px; height: 24px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  padding: 0;
  font-weight: 800;
  line-height: 1;
}
.stepper .stepbtn:hover { background: var(--surface-3); color: var(--text); }
.stepper .label {
  font-size: var(--fs-11, 11px);
  color: var(--text-muted);
  padding: 0 4px;
  font-weight: 600;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

/* Empty state */
.empty {
  text-align: center;
  padding: var(--space-6) var(--space-4);
  color: var(--text-muted);
  border: 1px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
}
.empty-icon { font-size: 28px; margin-bottom: var(--space-2); opacity: .7; }
.empty-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
.empty-hint { font-size: var(--fs-13); }

/* --- Pill bar (categories) ---------------------------------------------- */
.pillbar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.pill {
  font-size: var(--fs-12);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  padding: 6px 12px;
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.pill:hover { color: var(--text); border-color: var(--border-strong); }
.pill.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: 0;
  color: var(--accent-ink);
  font-weight: 700;
}

/* --- Nearby items -------------------------------------------------------- */
.nearby-item {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  display: grid;
  gap: 4px;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.nearby-item:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.nearby-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.nearby-title {
  display: flex; justify-content: space-between; gap: var(--space-2); align-items: center;
}
.nearby-name { font-weight: 600; }
.nearby-meta { font-size: var(--fs-12); color: var(--text-muted); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-12);
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.muted {
  background: var(--surface-3);
  color: var(--text-muted);
}

/* --- Table (segments) ---------------------------------------------------- */
.legs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
}
.legs-table th, .legs-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.legs-table th {
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.legs-table tbody tr:last-child td { border-bottom: 0; }
.legs-table tbody tr:hover { background: var(--surface-2); }

/* --- Share + History toolbar -------------------------------------------- */
.toolbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}
.toolbar .btn-ghost { font-size: var(--fs-12); padding: 8px 6px; }

.history-add {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.history-add .label {
  flex: 1;
  font-size: var(--fs-13);
  color: var(--text-muted);
}
.history-add button { padding: 6px 10px; }

/* --- History list -------------------------------------------------------- */
.histlist { display: grid; gap: var(--space-2); }
.histitem {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-2);
  align-items: center;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--t-fast) var(--ease);
}
.histitem:hover { border-color: var(--border-strong); }
.histitem .dot {
  width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto;
  box-shadow: 0 0 0 2px var(--surface);
}
.histitem .meta { display: grid; gap: 2px; min-width: 0; }
.histitem .name { font-weight: 600; }
.histitem .name[contenteditable="true"] {
  outline: none;
  background: var(--surface-2);
  border-radius: var(--r-sm);
  padding: 2px 6px;
  margin: -2px -6px;
}
.histitem .when { font-size: var(--fs-12); color: var(--text-muted); }
.histitem .actions { display: inline-flex; gap: 4px; }

/* --- History v2: stats / toolbar / years ------------------------------- */
.hist-stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: var(--space-2);
}
.hist-stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-2) var(--space-3);
  text-align: center;
  display: grid;
  gap: 2px;
}
.hist-stat .v { font-size: var(--fs-15); font-weight: 800; color: var(--accent); line-height: 1.1; }
.hist-stat .k { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
@media (max-width: 720px) {
  .hist-stats { grid-template-columns: repeat(2, 1fr); }
  .hist-stat:nth-child(5) { grid-column: span 2; }
}

.hist-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-2);
  align-items: center;
}
.hist-toolbar input { padding: 8px 10px; }
.hist-toolbar select { padding: 8px 10px; width: auto; min-width: 110px; }

.hist-actions-row {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
}
.hist-actions-row button { font-size: var(--fs-12); padding: 6px 10px; }

.year-group {
  display: grid; gap: var(--space-2);
}
.year-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-2) var(--space-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  user-select: none;
}
.year-head:hover { border-color: var(--border-strong); }
.year-head .label { font-weight: 700; font-size: var(--fs-13); }
.year-head .chev { color: var(--text-muted); transition: transform var(--t-fast) var(--ease); }
.year-group.collapsed .year-body { display: none; }
.year-group.collapsed .year-head .chev { transform: rotate(-90deg); }
.year-body { display: grid; gap: var(--space-2); padding-left: var(--space-2); }

/* --- Templates modal ---------------------------------------------------- */
.modal-card.wide { max-width: 780px; }
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-3);
  max-height: 70vh; overflow-y: auto;
  padding-right: 4px;
}
.tpl-card {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--r-lg);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-2);
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.tpl-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.tpl-head { display: flex; align-items: center; gap: var(--space-2); }
.tpl-emoji { font-size: 22px; line-height: 1; }
.tpl-name { font-weight: 700; font-size: var(--fs-14); flex: 1; min-width: 0; }
.tpl-meta {
  display: flex; gap: var(--space-2); flex-wrap: wrap;
  font-size: var(--fs-12); color: var(--text-muted);
}
.tpl-meta span { display: inline-flex; align-items: center; gap: 4px; }
.tpl-desc { font-size: var(--fs-12); color: var(--text-muted); line-height: 1.45; }

/* --- InfoWindow (custom theming applied to .gm-style-iw) --------------- */
.gm-style .gm-style-iw-c {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--r-md) !important;
  padding: 0 !important;
  box-shadow: var(--shadow) !important;
  max-width: 280px !important;
}
.gm-style .gm-style-iw-d { overflow: hidden !important; }
.gm-style .gm-style-iw-tc::after { background: var(--surface) !important; }
.gm-style .gm-ui-hover-effect { filter: invert(var(--invert-icons, 0)) !important; }
:root[data-theme="light"] { --invert-icons: 0; }
:root:not([data-theme]) { --invert-icons: 1; }
@media (prefers-color-scheme: light) { :root:not([data-theme]) { --invert-icons: 0; } }

.iw {
  padding: var(--space-3);
  display: grid;
  gap: 6px;
  font-family: var(--font-sans);
  color: var(--text);
}
.iw .iw-head { display: flex; align-items: center; gap: 8px; }
.iw .iw-idx {
  width: 22px; height: 22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); font-weight: 800; font-size: 11px;
  display: grid; place-items: center; flex: 0 0 auto;
}
.iw .iw-name { font-weight: 700; font-size: var(--fs-14); }
.iw .iw-note { font-size: var(--fs-12); color: var(--text-muted); }
.iw .iw-weather {
  display: flex; align-items: center; gap: 8px;
  font-size: var(--fs-12);
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}
.iw .iw-weather .icon { font-size: 20px; line-height: 1; }
.iw .iw-weather .temp { font-weight: 700; color: var(--accent); }
.iw .iw-links {
  display: flex; gap: var(--space-2);
  font-size: var(--fs-12);
}
.iw .iw-links a {
  color: var(--accent); text-decoration: none;
  border-radius: var(--r-sm); padding: 2px 6px;
  background: var(--accent-soft);
}
.iw .iw-links a:hover { text-decoration: underline; }

/* --- Auto-recalc switch ------------------------------------------------ */
.auto-recalc {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-12); color: var(--text-muted);
  margin-left: auto;
}
.switch {
  position: relative;
  display: inline-block;
  width: 32px; height: 18px;
  flex: 0 0 auto;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background var(--t-fast) var(--ease);
  cursor: pointer;
}
.switch .slider::before {
  content: "";
  position: absolute;
  left: 2px; top: 1px;
  width: 12px; height: 12px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.switch input:checked + .slider {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.switch input:checked + .slider::before {
  transform: translateX(14px);
  background: var(--accent);
}

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 980px) {
  :root { --aside-w: 100%; }
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 60vh;
    grid-template-areas: "panel" "map";
  }
  aside {
    height: auto;
    position: relative;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 60vh;
  }
  #map { height: 60vh; }
  .fabbar { display: flex; }
}
@media (max-width: 480px) {
  .panel-body { padding: var(--space-3); gap: var(--space-3); }
  .panel-head { padding: var(--space-3); }
  .toolbar { grid-template-columns: 1fr 1fr; }
  .toolbar > *:nth-child(3) { grid-column: span 2; }
  .stop-row { grid-template-columns: 1fr; }
  .brand-tagline { display: none; }
  input, select, button { font-size: var(--fs-16); } /* iOS zoom-prevention */
}

body.panel-hidden { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "map"; }
body.panel-hidden aside { display: none; }
body.panel-hidden #map { height: 100vh; }
body.map-hidden { grid-template-columns: 1fr; grid-template-rows: 1fr; grid-template-areas: "panel"; }
body.map-hidden #map { display: none; }
body.map-hidden aside { height: 100vh; max-height: 100vh; }

/* --- Print -------------------------------------------------------------- */
@media print {
  body { grid-template-columns: 1fr; grid-template-areas: "panel"; background: white; color: black; }
  #map, .fabbar, .toolbar, .history-add, .tabs, .header-actions, .empty { display: none !important; }
  aside { border: 0; max-height: none; height: auto; position: static; overflow: visible; }
  .panel-body { overflow: visible; padding: 0; }
  .stop, .card { border: 1px solid #ccc; background: white; }
}
