:root {
  --bg: #0f1720;
  --panel: #17212b;
  --card: #1e2a38;
  --card-2: #24374a;
  --line: #2c3e50;
  --text: #e8eef4;
  --muted: #9db0c2;
  --accent: #38bdf8;
  --accent-2: #0ea5e9;
  --good: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #17212b, #131b24);
  border-bottom: 1px solid var(--line);
  z-index: 700; flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { font-size: 26px; }
.app-header h1 { font-size: 18px; margin: 0; letter-spacing: .3px; }
.tagline { margin: 1px 0 0; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.role-switch { display: flex; background: var(--card); border-radius: 999px; padding: 3px; border: 1px solid var(--line); flex-shrink: 0; }
.role-btn { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 999px; cursor: pointer; font-size: 12.5px; font-weight: 600; }
.role-btn.active { background: var(--accent-2); color: #04202e; }

/* Layout */
.layout { flex: 1; display: flex; min-height: 0; position: relative; }

/* Map */
.map-wrap { position: relative; flex: 1; min-width: 0; order: 2; }
#map { position: absolute; inset: 0; background: #0b1118; }
.map-overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px; pointer-events: none; z-index: 500; text-align: center; padding: 20px;
}
.map-overlay.hidden { display: none; }
.add-hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--accent-2); color: #04202e; font-weight: 700; font-size: 12.5px;
  padding: 8px 14px; border-radius: 999px; z-index: 600; box-shadow: var(--shadow); text-align: center;
  max-width: 92%;
}
.add-hint.hidden { display: none; }

/* Panel (desktop: left column) */
.panel {
  width: 380px; max-width: 42vw; flex-shrink: 0; order: 1;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.sheet-handle { display: none; }
.panel-scroll { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 13.5px; text-transform: uppercase; letter-spacing: .6px; color: var(--accent); }
.hidden { display: none !important; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field span { font-size: 12.5px; color: var(--muted); }
input[type=text], select {
  background: var(--card-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px; border-radius: 10px; font-size: 16px; outline: none; width: 100%;
}
input[type=text]:focus, select:focus { border-color: var(--accent); }

.primary { width: 100%; border: 0; background: var(--accent-2); color: #04202e; padding: 13px; border-radius: 10px; font-weight: 700; font-size: 15px; cursor: pointer; }
.primary:hover { background: var(--accent); }
.primary:disabled { opacity: .55; cursor: default; }
.ghost {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  padding: 11px 12px; border-radius: 10px; cursor: pointer; font-size: 13.5px; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.ghost:hover { border-color: var(--accent); }
.ghost.full { width: 100%; margin-top: 8px; }
.ghost.add-stop.active { background: var(--accent-2); color: #04202e; border-color: var(--accent-2); font-weight: 700; }

.hint { font-size: 11.5px; color: var(--muted); margin: 8px 0 0; line-height: 1.5; }
.muted { color: var(--muted); font-size: 13px; }

/* Stops */
.radius-default { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.radius-default label { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.radius-default select { width: auto; padding: 8px; }

.city-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.city-item { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; transition: border-color .2s, background .2s; }
.city-item.reached { border-color: var(--good); background: rgba(52,211,153,.10); }
.city-item.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.city-top { display: flex; align-items: center; gap: 8px; }
.city-num { width: 22px; height: 22px; flex-shrink: 0; border-radius: 50%; background: var(--accent-2); color: #04202e; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.city-item.reached .city-num { background: var(--good); }
.city-name-input { flex: 1; background: transparent; border: 0; border-bottom: 1px solid transparent; color: var(--text); font-weight: 700; font-size: 14.5px; padding: 3px 2px; outline: none; min-width: 0; }
.city-name-input:focus { border-bottom-color: var(--accent); }
.del-btn { flex-shrink: 0; border: 0; background: transparent; color: var(--muted); font-size: 15px; cursor: pointer; padding: 3px 5px; border-radius: 6px; }
.del-btn:hover { color: var(--danger); background: rgba(248,113,113,.1); }

.city-row { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.city-row input[type=range] { flex: 1; accent-color: var(--accent); height: 22px; }
.radius-val { font-size: 12.5px; color: var(--text); min-width: 48px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.pills { display: flex; gap: 6px; margin-top: 8px; }
.pill-btn { border: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11.5px; padding: 5px 11px; border-radius: 999px; cursor: pointer; }
.pill-btn:hover { border-color: var(--accent); color: var(--text); }
.badge-row { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.city-badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: var(--line); color: var(--muted); }
.city-badge.reached { background: var(--good); color: #043a2a; }
.dist-note { font-size: 11.5px; color: var(--muted); }

/* Track */
.track-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.track-controls .primary, .track-controls .ghost { width: auto; flex: 1; }
.speed { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); flex-basis: 100%; }
.speed input { flex: 1; accent-color: var(--accent); height: 22px; }

.status { background: var(--card-2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 13px; min-height: 20px; }
.status.active { border-color: var(--accent); }
.status b { color: var(--accent); }
.log { margin-top: 10px; max-height: 150px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.log-entry { font-size: 12px; color: var(--muted); padding: 5px 8px; border-left: 2px solid var(--line); background: rgba(255,255,255,.02); }
.log-entry.hit { color: var(--good); border-left-color: var(--good); }

/* Map pins */
.pin { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #04202e; color: #04202e; font-size: 12px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.car-pin { font-size: 24px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.5)); }
.city-marker-label { background: var(--card); border: 1px solid var(--line); color: var(--text); padding: 2px 6px; border-radius: 6px; font-size: 11px; font-weight: 600; white-space: nowrap; }

/* Toast */
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: var(--card-2); border: 1px solid var(--accent); color: var(--text);
  padding: 10px 16px; border-radius: 10px; font-size: 13px; box-shadow: var(--shadow);
  opacity: 0; transition: opacity .25s, transform .25s; pointer-events: none; z-index: 1000; text-align: center; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

/* ================= MOBILE: map full-screen + bottom sheet ================= */
@media (max-width: 760px) {
  .app-header { padding: 8px 12px; }
  .tagline { display: none; }

  .layout { display: block; }
  .map-wrap { position: absolute; inset: 0; order: 0; }

  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; max-width: none;
    max-height: 80vh;
    background: var(--panel);
    border: 0; border-top: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 28px rgba(0,0,0,.45);
    z-index: 650;
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    transform: translateY(0);
  }
  .panel.collapsed { transform: translateY(calc(100% - 92px)); }

  .sheet-handle {
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 34px; border: 0; background: transparent; cursor: pointer; flex-shrink: 0;
    position: relative;
  }
  .sheet-handle span { width: 42px; height: 5px; border-radius: 999px; background: var(--line); }
  .sheet-handle::after { content: "⌄ tap to close"; position: absolute; font-size: 10.5px; color: var(--muted); bottom: 1px; }
  .panel.collapsed .sheet-handle::after { content: "⌃ tap to open"; }

  .panel-scroll { padding: 4px 14px 22px; max-height: calc(80vh - 34px); }
  .add-hint { top: 8px; font-size: 12px; }
  .toast { bottom: 110px; }
}
