:root {
  --bg: #0b1220;
  --bg-soft: #111c2f;
  --panel: #0f1a2b;
  --border: #1f2f47;
  --text: #e6edf7;
  --muted: #93a4bd;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --ok: #34d399;
  --error: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  font-size: 14px;
}

body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "top top"
    "map panel"
    "status status";
  height: 100dvh;
}

/* ---------- gorny pasek ---------- */

.topbar {
  grid-area: top;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  padding: 10px 16px;
  background: linear-gradient(180deg, #101d31, #0d1729);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.brand strong { display: block; line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; }

.brand-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent), var(--accent-strong));
  box-shadow: 0 0 14px rgba(56, 189, 248, 0.55);
}

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.field { display: flex; align-items: center; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; }

select, .btn {
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

select { min-width: 120px; }
select:disabled, option:disabled { color: var(--muted); cursor: not-allowed; }
.btn:hover:not(:disabled), select:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border-color: transparent;
  color: #04121e;
  font-weight: 600;
}

.btn-ghost { background: var(--bg-soft); border-color: var(--border); color: var(--text); font-weight: 500; }

.health { display: flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
}

.pill-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.pill--ok { color: var(--text); border-color: rgba(52, 211, 153, 0.5); }
.pill--ok .pill-dot { background: var(--ok); box-shadow: 0 0 8px rgba(52, 211, 153, 0.8); }
.pill--error { color: #ffd7d7; border-color: rgba(248, 113, 113, 0.55); }
.pill--error .pill-dot { background: var(--error); box-shadow: 0 0 8px rgba(248, 113, 113, 0.8); }

/* ---------- mapa ---------- */

#map { grid-area: map; position: relative; min-height: 0; background: #0a1526; }
#map canvas { outline: none; }
.maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib a { color: #cbd5e1; }

.wp-marker {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50% 50% 50% 6px;
  transform: rotate(-45deg);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #04121e;
  font-weight: 700;
  border: 2px solid #08131f;
  box-shadow: var(--shadow);
  cursor: grab;
}

.wp-marker > span { transform: rotate(45deg); }
.wp-marker--start { background: linear-gradient(180deg, #4ade80, #16a34a); }
.wp-marker--end { background: linear-gradient(180deg, #fb7185, #e11d48); }

/* ---------- panel ---------- */

.panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow: hidden;
}

.panel[hidden] { display: none; }
.panel-block { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.panel-block--grow { display: flex; flex-direction: column; flex: 1; min-height: 0; border-bottom: 0; }
.panel h2 { margin: 0 0 8px; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.hint { margin: 0 0 12px; color: var(--muted); line-height: 1.45; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.stat { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.stat-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { display: block; margin-top: 2px; font-size: 17px; font-weight: 700; color: var(--accent); }

.waypoints { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.waypoints:empty { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 6px 4px 10px;
  font-size: 12px;
}

.chip strong { color: var(--accent); }
.chip span { color: var(--muted); font-variant-numeric: tabular-nums; }

.chip-remove {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 50%;
}

.chip-remove:hover { color: var(--error); background: rgba(248, 113, 113, 0.12); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.steps { list-style: none; margin: 0; padding: 0 4px 0 0; overflow-y: auto; flex: 1; }
.steps-empty { color: var(--muted); padding: 6px 0; }

.step {
  display: grid;
  grid-template-columns: 24px 22px 1fr;
  gap: 8px;
  align-items: start;
  padding: 7px 6px;
  border-radius: 9px;
  cursor: pointer;
}

.step:hover, .step:focus-visible { background: rgba(56, 189, 248, 0.09); outline: none; }
.step-index { color: var(--muted); font-size: 11px; text-align: right; padding-top: 2px; font-variant-numeric: tabular-nums; }
.step-icon { text-align: center; color: var(--accent); font-size: 15px; }
.step-text strong { display: block; font-weight: 500; line-height: 1.35; }
.step-text small { color: var(--muted); }

/* ---------- wyszukiwanie adresow ---------- */

.search { position: relative; flex: 1 1 260px; min-width: 190px; max-width: 420px; }
.field--search { width: 100%; }

.search input {
  flex: 1;
  min-width: 0;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 10px;
}

.search input::-webkit-search-cancel-button { filter: invert(0.7); }
.search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.18); }

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 320px;
  max-height: 340px;
  overflow-y: auto;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #0f1a2b;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 20;
}

.search-results[hidden] { display: none; }

.search-result {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}

.search-result:hover, .search-result--active { background: rgba(56, 189, 248, 0.12); }
.search-result .search-pin { color: var(--accent); text-align: center; }
.search-result strong { display: block; font-weight: 500; }
.search-result small { color: var(--muted); }
.search-empty { color: var(--muted); padding: 8px; }
.search-empty--error { color: #ffd7d7; }
.search-note {
  color: var(--accent);
  padding: 6px 8px;
  font-size: 0.78rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.search-attribution {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding: 6px 8px 2px;
  color: var(--muted);
  font-size: 11px;
}

/* ---------- dolny pasek, komunikaty ---------- */

.statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 6px 16px;
  background: #0d1729;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.status-hint { margin-left: auto; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 54px;
  transform: translateX(-50%);
  max-width: min(560px, 90vw);
  background: #14283d;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 30;
}

.toast--error { background: #40161a; border-color: rgba(248, 113, 113, 0.6); }
.toast[hidden] { display: none; }

.busy {
  position: fixed;
  top: 74px;
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(15, 26, 43, 0.94);
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 30;
}

.busy[hidden] { display: none; }

.spinner {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  border: 2px solid rgba(56, 189, 248, 0.35);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- mobile ---------- */

@media (max-width: 860px) {
  body {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(45dvh, 1fr) minmax(0, 40dvh) auto;
    grid-template-areas: "top" "map" "panel" "status";
  }

  .panel { border-left: 0; border-top: 1px solid var(--border); }
  .health { margin-left: 0; width: 100%; }
  .status-hint { display: none; }
  .search { flex: 1 1 100%; max-width: none; }
  .search-results { min-width: 0; max-height: 280px; }
}
