/* DeliveryHub — panel operacyjny. System: głęboki granat, cyjan funkcyjny,
   szkło, pigułki nawigacji, dane w monospace. */
:root {
  --bg: #0b0e18;
  --bg-2: #12141f;
  --panel: #171a28e6;
  --panel-2: #1e2233;
  --border: #2b3047;
  --text: #e8eaf2;
  --muted: #9aa0b8;
  --accent: #00aaff;
  --accent-dim: #0088cc;
  --ok: #4caf82;
  --warn: #ffc107;
  --err: #f4574c;
  --glovo: #ffc244;
  --ubereats: #06c167;
  --pyszne: #ff8000;
  --radius: 12px;
  --pill: 100px;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", "Fira Code", Menlo, Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}
* { box-sizing: border-box; margin: 0; }
html { color-scheme: dark; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(0, 170, 255, 0.07), transparent),
    var(--bg);
  color: var(--text);
  min-height: 100dvh;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--err); font-size: 13px; margin-top: 10px; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 13px; margin: 26px 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
h3 { font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; }
.mono { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* paski przewijania */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.24); }

/* ===== brand ===== */
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark { width: 30px; height: 30px; color: var(--accent); flex-shrink: 0; }
.brand-name { font-family: var(--mono); font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }

/* ===== login ===== */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; }
.login-card {
  width: 360px; max-width: calc(100vw - 32px);
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 32px; display: flex; flex-direction: column; gap: 16px;
  backdrop-filter: blur(8px); box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.login-card .brand { justify-content: center; padding-bottom: 0; }
.login-card .muted { text-align: center; margin-top: -8px; }

/* ===== layout ===== */
#appView { display: flex; min-height: 100dvh; }
.sidebar {
  width: 216px; flex-shrink: 0;
  background: var(--bg-2); border-right: 1px solid var(--border);
  padding: 20px 12px; display: flex; flex-direction: column; gap: 6px;
  position: sticky; top: 0; height: 100dvh;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-foot { display: flex; flex-direction: column; gap: 10px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  text-align: left; background: none; border: 0; color: var(--muted);
  padding: 9px 14px; border-radius: var(--pill); cursor: pointer;
  font-size: 13.5px; font-family: var(--mono); font-weight: 500;
  transition: background-color 0.2s var(--ease), color 0.2s var(--ease);
}
.nav-ico { font-size: 13px; opacity: 0.8; width: 16px; text-align: center; }
.nav-btn:hover { background: var(--panel-2); color: var(--text); }
.nav-btn:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, a.btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.nav-btn.active { background: var(--text); color: var(--bg-2); font-weight: 700; }
.nav-badge {
  margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: var(--pill); background: var(--accent); color: var(--bg);
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.nav-badge.warn { background: var(--err); color: #fff; }
.live { display: flex; align-items: center; gap: 8px; padding: 4px 8px; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background-color 0.3s; }
.live.on .live-dot { background: var(--ok); box-shadow: 0 0 8px rgba(76, 175, 130, 0.8); animation: pulse 2.4s infinite; }
.live.off .live-dot { background: var(--err); }
@keyframes pulse { 50% { opacity: 0.5; } }

main { flex: 1; padding: 24px 30px 60px; max-width: 1280px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.topbar-actions { display: flex; gap: 10px; }
.tab { display: none; }
.tab.active { display: block; animation: tabin 0.25s var(--ease); }
@keyframes tabin { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { .tab.active { animation: none; } .live-dot { animation: none !important; } }

/* ===== KPI cards ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; backdrop-filter: blur(8px);
  transition: border-color 0.2s var(--ease);
}
.card:hover { border-color: #3a4160; }
.card .num { font-family: var(--mono); font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card .num.accent { color: var(--accent); }
.card .num.ok { color: var(--ok); }
.card .num.err { color: var(--err); }
.card .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.card .sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; font-family: var(--mono); }

/* ===== wykresy ===== */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.chart-panel { padding: 16px 18px; }
.chart-panel h3 { margin-bottom: 12px; }
.chart-panel canvas { width: 100%; display: block; }
.top-items { display: flex; flex-direction: column; gap: 8px; }
.top-item { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 13px; }
.top-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-item .qty { font-family: var(--mono); color: var(--muted); font-variant-numeric: tabular-nums; }
.top-item .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--panel-2); overflow: hidden; }
.top-item .bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.5s var(--ease); }

/* ===== tabele ===== */
.table-wrap {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; backdrop-filter: blur(8px);
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; padding: 10px 14px; color: var(--muted); font-weight: 600;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-2); z-index: 1;
}
td { padding: 10px 14px; border-bottom: 1px solid rgba(43, 48, 71, 0.55); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; transition: background-color 0.15s var(--ease); }
tbody tr.clickable:hover { background: var(--panel-2); }
.empty { padding: 34px; text-align: center; color: var(--muted); }

/* ===== badge i statusy (pigułki) ===== */
.badge {
  display: inline-block; padding: 3px 11px; border-radius: var(--pill);
  font-family: var(--mono); font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.badge.GLOVO { background: rgba(255, 194, 68, 0.14); color: var(--glovo); }
.badge.UBER_EATS { background: rgba(6, 193, 103, 0.14); color: var(--ubereats); }
.badge.PYSZNE { background: rgba(255, 128, 0, 0.14); color: var(--pyszne); }
.status {
  display: inline-block; padding: 3px 11px; border-radius: var(--pill);
  font-family: var(--mono); font-size: 11px; font-weight: 600; background: var(--panel-2);
}
.status.RECEIVED { color: var(--muted); }
.status.ACCEPTED, .status.PREPARING { color: var(--warn); }
.status.READY { color: var(--accent); }
.status.DELIVERED { color: var(--ok); }
.status.CANCELLED, .status.REJECTED { color: var(--err); }
.status.done { color: var(--ok); }
.status.pending, .status.failed { color: var(--warn); }
.status.active { color: var(--accent); }
.status.dead { color: var(--err); }

/* ===== formularze ===== */
.filters { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.filters .spacer { flex: 1; }
input, select {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  padding: 9px 12px; border-radius: 10px; font-size: 13.5px; outline: none;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0, 170, 255, 0.15); }
input[type="checkbox"] {
  appearance: none; width: 17px; height: 17px; border-radius: 5px; flex-shrink: 0;
  border: 1.5px solid var(--muted); background: transparent; cursor: pointer; padding: 0;
  display: inline-grid; place-items: center; transition: all 0.15s var(--ease);
}
input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
input[type="checkbox"]:checked::after {
  content: ""; width: 9px; height: 5px;
  border-left: 2px solid var(--bg); border-bottom: 2px solid var(--bg);
  transform: rotate(-45deg) translateY(-1px);
}
input[type="range"] { accent-color: var(--accent); }
.btn {
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 16px; border-radius: var(--pill); cursor: pointer; font-size: 13.5px;
  font-family: var(--mono); font-weight: 500;
  transition: background-color 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease), transform 0.1s var(--ease);
}
.btn:hover { border-color: #3a4160; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--bg); font-weight: 700; }
.btn.primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn.danger { background: rgba(244, 87, 76, 0.12); border-color: rgba(244, 87, 76, 0.4); color: var(--err); }
.btn.ghost { background: none; }
.btn.block { width: 100%; justify-content: center; }
.btn.small { padding: 5px 12px; font-size: 11.5px; }
label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
label.row { flex-direction: row; align-items: center; }

/* ===== settings ===== */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; backdrop-filter: blur(8px);
}
.panel h3 { margin-bottom: 14px; }
.panel form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.copy-url {
  display: flex; gap: 8px; align-items: center; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  font-family: var(--mono); font-size: 12px;
}
.copy-url code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }
.mapping-row { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; align-items: center; }
.mapping-row input { width: 100%; }
.arrow-mono { font-family: var(--mono); color: var(--muted); }

/* ===== drawer ===== */
.overlay { position: fixed; inset: 0; background: rgba(5, 7, 13, 0.6); backdrop-filter: blur(3px); animation: fadein 0.2s var(--ease); }
.drawer {
  position: fixed; top: 0; right: 0; height: 100dvh; width: 540px; max-width: 94vw;
  background: var(--bg-2); border-left: 1px solid var(--border);
  box-shadow: -24px 0 60px rgba(0, 0, 0, 0.5); display: flex; flex-direction: column; z-index: 10;
  animation: drawerin 0.28s var(--ease);
}
@keyframes fadein { from { opacity: 0; } }
@keyframes drawerin { from { transform: translateX(40px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .overlay, .drawer { animation: none; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 15px; color: var(--text); text-transform: none; letter-spacing: 0; }
.drawer-body { padding: 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 18px; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { font-variant-numeric: tabular-nums; }
.timeline { border-left: 2px solid var(--border); margin-left: 6px; padding-left: 16px; display: flex; flex-direction: column; gap: 12px; }
.tl-item { position: relative; font-size: 13px; }
.tl-item::before {
  content: ""; position: absolute; left: -22px; top: 4px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--accent);
}
.tl-item .t { color: var(--muted); font-family: var(--mono); font-size: 11.5px; margin-top: 1px; }

/* ===== toasty ===== */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 20; }
.toast {
  background: var(--bg-2); border: 1px solid var(--border);
  padding: 12px 18px; border-radius: var(--pill); font-size: 13px;
  font-family: var(--mono);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
  animation: slidein 0.22s var(--ease);
}
.toast.ok { border-color: rgba(76, 175, 130, 0.5); color: var(--ok); }
.toast.err { border-color: rgba(244, 87, 76, 0.5); color: var(--err); }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

pre.raw {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-family: var(--mono); font-size: 12px; overflow-x: auto; max-height: 280px;
}

/* ===== mobile ===== */
@media (max-width: 860px) {
  .sidebar { width: 60px; padding: 20px 8px; }
  .sidebar .brand-name, .nav-btn { font-size: 0; gap: 0; justify-content: center; }
  .nav-btn .nav-ico { font-size: 15px; width: auto; }
  .nav-badge { position: absolute; }
  .live { justify-content: center; }
  .live span:last-child { display: none; }
  .sidebar .btn.ghost { font-size: 0; padding: 9px; justify-content: center; }
  .sidebar .btn.ghost::before { content: "⏻"; font-size: 15px; }
  main { padding: 18px 14px 60px; }
  .topbar-actions .btn { font-size: 0; }
  .topbar-actions .btn::first-letter { font-size: 15px; }
}

/* ===== mapa dostaw (Leaflet) ===== */
.map-panel { padding: 10px; }
#mapCanvas {
  height: 560px; border-radius: 10px; background: var(--bg);
  border: 1px solid var(--border); z-index: 0;
}
.map-toggle { flex-direction: row; align-items: center; gap: 7px; }
.map-toggle span { font-size: 12.5px; }
.chip-warn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--pill);
  background: rgba(255, 193, 7, 0.1); border: 1px solid rgba(255, 193, 7, 0.35);
  color: var(--warn); font-family: var(--mono); font-size: 11.5px; font-weight: 600;
}
.chip-err {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--pill);
  background: rgba(244, 87, 76, 0.12); border: 1px solid rgba(244, 87, 76, 0.4);
  color: #f4574c; font-family: var(--mono); font-size: 11.5px; font-weight: 600;
}
tr.sla-warn td { background: rgba(255, 193, 7, 0.055); }

/* autocomplete adresow (formularz lokalu) */
.suggest-list {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--panel, #171a28); border: 1px solid var(--border, #2b3047);
  border-radius: 10px; overflow: hidden; box-shadow: 0 12px 30px rgba(0,0,0,.45);
  max-height: 240px; overflow-y: auto;
}
.suggest-list.hidden { display: none; }
.suggest-item {
  padding: 9px 12px; font-size: 13px; cursor: pointer; line-height: 1.35;
}
.suggest-item:hover, .suggest-item.active { background: rgba(0, 170, 255, 0.12); }

/* kafelki jasne (OSM) przyciemniamy filtrem; ciemne (Esri/Google) sa natywne */
.leaflet-container { font-family: var(--sans); }
.tiles-light .leaflet-tile-pane { filter: grayscale(0.55) brightness(0.82) contrast(1.05); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-2); color: var(--text); box-shadow: 0 12px 30px rgba(0,0,0,0.5);
}
.leaflet-popup-content { font-size: 13px; line-height: 1.45; margin: 12px 14px; }
.leaflet-popup-content .mono { color: var(--muted); }
.leaflet-popup-content a { color: var(--accent); }
.leaflet-bar a { background: var(--bg-2); color: var(--text); border-color: var(--border); }
.leaflet-control-attribution { background: rgba(18,20,31,0.8) !important; color: var(--muted); font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted); }

.map-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }

/* ===== karty lokali / kurierow ===== */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.entity-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; backdrop-filter: blur(8px); display: flex; flex-direction: column; gap: 10px;
  border-top: 3px solid var(--border);
}
.entity-card.off { opacity: 0.55; }
.entity-card .entity-head { display: flex; align-items: center; gap: 10px; }
.entity-card .entity-name { font-weight: 700; font-size: 15px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entity-card .entity-kpis { display: flex; gap: 16px; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.entity-card .courier-state { font-size: 12.5px; color: var(--purple, #b48cff); font-weight: 600; }
.entity-card .entity-kpis b { color: var(--text); font-size: 15px; display: block; }
.entity-card .entity-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.loc-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }

/* formularze lokali/kurierow */
.loc-form { display: flex; flex-direction: column; gap: 12px; }
.loc-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.loc-form-grid input, .loc-form-grid select { width: 100%; }
input[type="color"] { padding: 4px; height: 38px; width: 100%; cursor: pointer; }
.zone-picker {
  height: 240px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); z-index: 0;
}

/* status w drodze */
.status.OUT_FOR_DELIVERY { color: #b48cff; }

/* link kuriera */
.courier-link {
  display: flex; gap: 8px; align-items: center; background: var(--bg-2);
  border: 1px dashed var(--border); border-radius: 10px; padding: 7px 10px;
  font-family: var(--mono); font-size: 11px;
}
.courier-link code { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--accent); }

@media (max-width: 860px) {
  #mapCanvas { height: 420px; }
}

/* szuflada zamowienia: czasy reakcji + mapa sladu GPS kuriera */
.timing-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.timing-seg {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 12px;
}
.timing-seg strong { font-size: 15px; }
.trail-map {
  height: 220px; border-radius: var(--radius); border: 1px solid var(--border);
  overflow: hidden; margin-top: 4px;
}

/* kolejka "Do przydzialu" */
.dispatch-queue {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 12px;
}
.dispatch-queue .dq-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.dispatch-queue .dq-head h2 { margin: 0; font-size: 15px; }
#dqList { display: flex; flex-direction: column; gap: 6px; }
.dq-item {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.02); font-size: 13px;
}
.dq-item .dq-sug { flex: 1; min-width: 120px; }
