:root {
  --bg: #f3f5f7;
  --card: #ffffff;
  --glass: rgba(255, 255, 255, .86);
  --ink: #171a1f;
  --ink-2: #3b424b;
  --muted: #737c87;
  --line: #e2e6eb;
  --accent: #1f8a70;
  --accent-ink: #136a55;
  --accent-soft: #e4f3ee;
  --warn: #b9742a;
  --warn-soft: #f8eedf;
  --danger: #b8463c;
  --r: 4px;
  --shadow: 0 1px 2px rgba(20, 28, 38, .05), 0 6px 20px rgba(20, 28, 38, .06);
  --ease: cubic-bezier(.2, .7, .2, 1);
  --t: 160ms;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased; font-feature-settings: "tnum" 1;
}
button, input, select { font: inherit; color: inherit; }
button:focus, input:focus, select:focus, a:focus { outline: none; }
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }

/* ---------- przyciski ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 18px; border-radius: var(--r); border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-weight: 600; font-size: 15px; cursor: pointer;
  transition: background var(--t) var(--ease), border-color var(--t) var(--ease), transform var(--t) var(--ease);
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:hover { border-color: #cfd5dc; background: #fafbfc; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); border-color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

.field { display: grid; gap: 6px; }
.field label { font-size: 13px; color: var(--muted); font-weight: 500; }
.input {
  height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: var(--r); background: #fff;
  transition: border-color var(--t) var(--ease), box-shadow var(--t) var(--ease); width: 100%;
}

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px; border-radius: var(--r);
  font-size: 13px; font-weight: 600; background: #eef1f4; color: var(--ink-2); white-space: nowrap;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #aab2bc; }
.pill.ok { background: var(--accent-soft); color: var(--accent-ink); }
.pill.ok i { background: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.warn i { background: var(--warn); }

.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 12px); opacity: 0; z-index: 50;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r); font-size: 14px; max-width: calc(100% - 32px);
  transition: opacity var(--t) var(--ease), transform var(--t) var(--ease); pointer-events: none;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ================= TELEFON ================= */
body.phone { min-height: 100%; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
.ph-top {
  position: sticky; top: 0; z-index: 20; background: rgba(243, 245, 247, .92); backdrop-filter: blur(10px);
  padding: 14px 16px 10px; border-bottom: 1px solid var(--line);
}
.ph-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; }
.brand b { width: 10px; height: 10px; border-radius: 2px; background: var(--accent); display: inline-block; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.step {
  height: 38px; border: 1px solid var(--line); border-radius: var(--r); background: var(--card); cursor: pointer;
  font-size: 14px; font-weight: 600; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all var(--t) var(--ease);
}
.step span { width: 20px; height: 20px; border-radius: 3px; background: #eef1f4; font-size: 12px; display: grid; place-items: center; }
.step.on { color: var(--accent-ink); border-color: var(--accent); background: var(--accent-soft); }
.step.on span { background: var(--accent); color: #fff; }

.ph-main { padding: 16px; max-width: 640px; margin: 0 auto; }
.pane { display: none; animation: fadein 180ms var(--ease); }
.pane.on { display: grid; gap: 14px; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); display: grid; gap: 14px; }
.card h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card p { margin: 0; font-size: 14px; color: var(--muted); line-height: 1.5; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1 1 0; }

.readouts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.ro { border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; background: #fafbfc; }
.ro small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.ro strong { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.ro em { font-style: normal; font-size: 12px; color: var(--muted); margin-left: 3px; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch input { display: none; }
.switch .tg { width: 44px; height: 26px; border-radius: 13px; background: #d9dee4; position: relative; transition: background var(--t) var(--ease); flex: none; }
.switch .tg::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform var(--t) var(--ease); }
.switch input:checked + .tg { background: var(--accent); }
.switch input:checked + .tg::after { transform: translateX(18px); }
input[type=range] { width: 100%; accent-color: var(--accent); }

.log { margin: 0; max-height: 240px; overflow: auto; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; background: #f6f7f9; border: 1px solid var(--line); border-radius: var(--r); padding: 10px; white-space: pre-wrap; word-break: break-all; }
details.card summary { list-style: none; cursor: pointer; font-weight: 700; font-size: 15px; display: flex; justify-content: space-between; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::after { content: "+"; color: var(--muted); font-weight: 500; }
details.card[open] summary::after { content: "–"; }

.routes { display: grid; gap: 8px; }
.route {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--r); background: #fff; cursor: pointer; transition: border-color var(--t) var(--ease), background var(--t) var(--ease);
}
.route:hover { border-color: #cfd5dc; }
.route.on { border-color: var(--accent); background: var(--accent-soft); }
.route b { display: block; font-size: 15px; }
.route small { color: var(--muted); font-size: 13px; }
.route .x { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); border-radius: var(--r); cursor: pointer; font-size: 18px; }
.route .x:hover { background: #f1f3f5; color: var(--danger); }
.empty { padding: 18px; text-align: center; color: var(--muted); font-size: 14px; border: 1px dashed var(--line); border-radius: var(--r); }

.mapbox { height: 52vh; min-height: 320px; border-radius: var(--r); overflow: hidden; border: 1px solid var(--line); background: #e9edf1; position: relative; }
.mapbox .hint { position: absolute; left: 10px; top: 10px; z-index: 2; background: var(--glass); padding: 6px 10px; border-radius: var(--r); font-size: 13px; color: var(--ink-2); pointer-events: none; }
.route-meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }
.route-meta b { color: var(--ink); }

.big { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.big .ro { padding: 14px; }
.big .ro strong { font-size: 32px; }
.big .ro.hero { grid-column: 1 / -1; background: var(--accent-soft); border-color: transparent; }
.big .ro.hero strong { font-size: 56px; color: var(--accent-ink); }
.progress { height: 8px; border-radius: 4px; background: #e6eaee; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--accent); transition: width 600ms linear; }

.ph-foot {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: rgba(243, 245, 247, .94); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
}
.ph-foot .inner { max-width: 640px; margin: 0 auto; display: flex; gap: 10px; }
.ph-foot .btn { flex: 1; height: 50px; }

.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(23, 26, 31, .35); display: grid; place-items: center; padding: 16px; animation: fadein 160ms var(--ease); }
.overlay .card { width: 100%; max-width: 380px; }

/* ================= TV ================= */
body.tv { overflow: hidden; background: #dde3e8; cursor: none; }
body.tv.pointer { cursor: default; }
#pano { position: fixed; inset: 0; }
.tv-top { position: fixed; top: 2.2vh; left: 2vw; right: 2vw; display: flex; justify-content: space-between; align-items: flex-start; gap: 2vw; z-index: 5; pointer-events: none; }
.chip { background: var(--glass); backdrop-filter: blur(12px); border-radius: var(--r); padding: 1.1vh 1.2vw; box-shadow: var(--shadow); font-size: clamp(14px, 1.15vw, 26px); font-weight: 600; display: flex; align-items: center; gap: .8vw; }
.chip small { color: var(--muted); font-weight: 500; }
.chip .dot { width: .7vw; height: .7vw; min-width: 9px; min-height: 9px; border-radius: 50%; background: #aab2bc; }
.chip .dot.ok { background: var(--accent); }
.chip .dot.warn { background: var(--warn); }
#minimap { position: fixed; right: 2vw; top: 9vh; width: 22vw; height: 26vh; min-width: 280px; min-height: 190px; border-radius: var(--r); overflow: hidden; box-shadow: var(--shadow); z-index: 5; border: 3px solid rgba(255,255,255,.9); }

.tv-bottom { position: fixed; left: 2vw; right: 2vw; bottom: 2.4vh; z-index: 5; display: grid; gap: 1.2vh; }
.tv-progress { background: var(--glass); backdrop-filter: blur(12px); border-radius: var(--r); padding: 1vh 1.2vw; box-shadow: var(--shadow); display: grid; grid-template-columns: auto 1fr auto; gap: 1.2vw; align-items: center; font-size: clamp(13px, 1vw, 22px); font-weight: 600; }
.tv-progress .bar { height: 1vh; min-height: 6px; background: rgba(23,26,31,.08); border-radius: 4px; overflow: hidden; }
.tv-progress .bar i { display: block; height: 100%; width: 0; background: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: 1vw; }
.tile { background: var(--glass); backdrop-filter: blur(12px); border-radius: var(--r); box-shadow: var(--shadow); padding: 1.6vh 1.2vw; display: grid; gap: .4vh; }
.tile small { font-size: clamp(12px, .95vw, 22px); color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.tile strong { font-size: clamp(26px, 3.2vw, 74px); font-weight: 700; letter-spacing: -.03em; line-height: 1; }
.tile strong em { font-style: normal; font-size: .38em; color: var(--muted); font-weight: 600; margin-left: .3em; letter-spacing: 0; }
.tile.hero { background: rgba(31, 138, 112, .92); }
.tile.hero small, .tile.hero strong, .tile.hero strong em { color: #fff; }

.tv-center { position: fixed; inset: 0; z-index: 8; display: grid; place-items: center; pointer-events: none; }
.tv-msg { background: var(--glass); backdrop-filter: blur(14px); border-radius: var(--r); box-shadow: var(--shadow); padding: 4vh 3vw; text-align: center; max-width: 60vw; }
.tv-msg h1 { margin: 0 0 1vh; font-size: clamp(22px, 2.4vw, 56px); letter-spacing: -.02em; }
.tv-msg p { margin: 0; font-size: clamp(14px, 1.2vw, 28px); color: var(--ink-2); line-height: 1.5; }
.tv-note { position: fixed; left: 50%; top: 9vh; transform: translateX(-50%); z-index: 6; }
.tv-btn { position: fixed; right: 2vw; bottom: 22vh; z-index: 9; opacity: 0; transition: opacity var(--t) var(--ease); }
body.tv.pointer .tv-btn { opacity: 1; }
#tvIdleMap { position: fixed; inset: 0; z-index: 1; }

/* ---------- planer: punkty trasy ---------- */
.stops { display: grid; gap: 8px; }
.stop { display: grid; grid-template-columns: 26px 1fr 36px; gap: 8px; align-items: center; }
.stop .mk { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff; background: #8a939d; justify-self: center; }
.stop .mk.a { background: var(--accent); }
.stop .mk.b { background: var(--ink); }
.stop .del { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); border-radius: var(--r); cursor: pointer; font-size: 18px; }
.stop .del:hover { background: #f1f3f5; color: var(--danger); }
.stop .del:focus, .route button:focus, .ac-item:focus { outline: none; }
.ac { position: relative; }
.ac .input { width: 100%; }
.ac .input.set { border-color: #cfe7df; background: #f7fbfa; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 30; background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 8px 28px rgba(20, 28, 38, .12); max-height: 280px; overflow: auto; animation: fadein 120ms var(--ease); }
.ac-item { padding: 10px 12px; cursor: pointer; display: grid; gap: 2px; border-bottom: 1px solid #f0f2f4; }
.ac-item:last-of-type { border-bottom: 0; }
.ac-item b { font-size: 15px; font-weight: 600; }
.ac-item small { color: var(--muted); font-size: 12px; }
.ac-item.on, .ac-item:hover { background: var(--accent-soft); }
.ac-empty { padding: 12px; font-size: 14px; color: var(--muted); }
.ac-foot { padding: 6px 12px; font-size: 11px; color: var(--muted); text-align: right; border-top: 1px solid #f0f2f4; }
.route .acts { display: flex; gap: 2px; }
.route .rv { height: 32px; padding: 0 8px; border: 0; background: transparent; color: var(--muted); border-radius: var(--r); cursor: pointer; font-size: 13px; font-weight: 600; white-space: nowrap; }
.route .rv:hover { background: #f1f3f5; color: var(--accent-ink); }
.pill.busy { background: var(--warn-soft); color: var(--warn); }
.mapwrap { position: relative; }
.mapwrap .hint { position: absolute; left: 10px; top: 10px; z-index: 2; background: var(--glass); padding: 6px 10px; border-radius: var(--r); font-size: 13px; color: var(--ink-2); pointer-events: none; }

/* ---------- planer v3: układ, podsumowanie, pinezki ---------- */
.plan.on { grid-template-areas: "new" "map" "saved"; }
.plan-new { grid-area: new; }
.plan-map { grid-area: map; padding: 0; overflow: hidden; }
.plan-saved { grid-area: saved; }
.plan-map .mapwrap, .plan-map .mapbox { height: 100%; }
.plan-map .mapbox { border: 0; border-radius: 0; height: 58vh; min-height: 340px; }
.legend { position: absolute; left: 10px; bottom: 10px; z-index: 2; display: flex; gap: 12px; background: var(--glass); backdrop-filter: blur(8px); padding: 6px 10px; border-radius: var(--r); font-size: 12px; color: var(--ink-2); pointer-events: none; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 10px; height: 10px; border-radius: 50%; background: #8a939d; }
.legend i.a { background: var(--accent); } .legend i.b { background: var(--ink); }

.stop { grid-template-columns: 20px 26px 1fr 36px; transition: transform 120ms var(--ease), box-shadow 120ms var(--ease); border-radius: var(--r); background: var(--card); }
.stop .handle { width: 20px; height: 36px; display: grid; place-items: center; color: #aab2bc; cursor: grab; touch-action: none; user-select: none; font-size: 14px; letter-spacing: -2px; }
.stop .handle:hover { color: var(--ink-2); }
.stop.dragging { position: relative; z-index: 6; box-shadow: 0 8px 24px rgba(20, 28, 38, .16); }
.stop.dragging .handle { cursor: grabbing; }
.stops.sorting { user-select: none; }

.sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sum-i { border: 1px solid var(--line); border-radius: var(--r); background: #fafbfc; padding: 10px 12px; display: grid; gap: 2px; min-width: 0; }
.sum-i small { font-size: 12px; color: var(--muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum-i strong { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.sum.ok .sum-i { background: var(--accent-soft); border-color: transparent; }
.sum.ok .sum-i strong { color: var(--accent-ink); }
.sum.busy { opacity: .55; }
.card .sum-note { font-size: 12px; margin-top: -6px; }

.pin { position: absolute; transform: translate(-50%, -50%); width: 28px; height: 28px; border-radius: 50%; border: 3px solid #fff; background: #8a939d; color: #fff; font: 700 12px/1 Inter, system-ui, sans-serif; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(20, 28, 38, .35); cursor: grab; touch-action: none; user-select: none; transition: transform 100ms var(--ease); }
.pin.a { background: var(--accent); }
.pin.b { background: var(--ink); }
.pin.add { background: var(--accent); opacity: .8; width: 22px; height: 22px; }
.pin.ro { cursor: default; width: 22px; height: 22px; font-size: 10px; border-width: 2px; }
.pin:hover:not(.ro) { transform: translate(-50%, -50%) scale(1.1); }
.pin.drag { cursor: grabbing; transform: translate(-50%, -50%) scale(1.18); }

.route small .tm { color: var(--ink-2); }

@media (min-width: 1100px) {
  .ph-main.wide { max-width: 1760px; }
  .plan.on {
    grid-template-columns: 440px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "new map" "saved map"; height: calc(100vh - 222px); min-height: 560px;
  }
  .plan-map .mapbox { height: 100%; min-height: 0; }
  .plan-saved { grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; }
  .plan-saved .routes { overflow: auto; min-height: 0; align-content: start; }
}
#pano { position: fixed !important; inset: 0; width: 100vw; height: 100vh; }
