:root {
  color-scheme: light;
  --bg: #f4f4f2; --surface: #fcfcfb; --surface-2: #efeeeb; --border: #dddcd7;
  --text: #0b0b0b; --text-2: #52514e; --muted: #7a7974;
  --accent: #1f5fae; --accent-ink: #ffffff; --accent-soft: #e3edf9;
  --series-1: #2a78d6; --series-2: #eb6834;
  --good: #1d7a3a; --good-soft: #e3f3e7; --warn: #9a6200; --warn-soft: #fbf0d9;
  --bad: #b42323; --bad-soft: #fbe5e3; --info-soft: #e8eef8;
  --market: #6250d6; --market-soft: #efedfb;
  --side: #14263f; --side-ink: #c9d4e4; --side-active: #ffffff; --side-hover: #1f3656;
  --radius: 8px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #353532;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #918f87;
    --accent: #5b9be8; --accent-ink: #0b0b0b; --accent-soft: #1d2b3e;
    --series-1: #3987e5; --series-2: #d95926;
    --good: #5cc27a; --good-soft: #1b2e21; --warn: #e3a73a; --warn-soft: #33281a;
    --bad: #f07a76; --bad-soft: #3a1f1d; --info-soft: #1d2533;
    --market: #9085e9; --market-soft: #24213a;
    --side: #0d1828; --side-ink: #aab6c8; --side-hover: #18273d;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #353532;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #918f87;
  --accent: #5b9be8; --accent-ink: #0b0b0b; --accent-soft: #1d2b3e;
  --series-1: #3987e5; --series-2: #d95926;
  --good: #5cc27a; --good-soft: #1b2e21; --warn: #e3a73a; --warn-soft: #33281a;
  --bad: #f07a76; --bad-soft: #3a1f1d; --info-soft: #1d2533;
  --market: #9085e9; --market-soft: #24213a;
  --side: #0d1828; --side-ink: #aab6c8; --side-hover: #18273d;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); }
.pos { color: var(--good); }

/* Layout */
.layout { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 14px 10px 24px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 14px; display: flex; gap: 10px; align-items: center; }
.brand .logo { width: 30px; height: 30px; border-radius: 6px; background: #1f5fae; display: grid; place-items: center; font-size: 13px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--side-ink); }
.side .sec { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #7f93ad; padding: 14px 10px 4px; }
.side a { display: block; color: var(--side-ink); text-decoration: none; padding: 6px 10px; border-radius: 6px; }
.side a:hover { background: var(--side-hover); }
.side a.active { background: var(--side-hover); color: var(--side-active); box-shadow: inset 3px 0 0 #5b9be8; }
.side a { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.side .count:empty { display: none; }
.vehicle-tabs { align-items: center; }
.vehicle-tabs .own-tab { font-weight: 600; }
.vehicle-tabs .market-tab { color: var(--market); }
.vehicle-tabs .market-tab.active { border-bottom-color: var(--market); color: var(--market); }
.tab-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--market); margin: 0 4px 0 14px; padding-left: 12px; border-left: 1px solid var(--border); }
.count-inline { background: #c0392b; color: #fff; border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 6px; }
.side .count { background: #c0392b; color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11px; font-weight: 600; line-height: 18px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 20px 24px 60px; max-width: 1500px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Controls */
button, .btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 6px; cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px; align-items: center; }
button:hover, .btn:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.link { border: none; background: none; color: var(--accent); padding: 0 2px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; width: 100%; min-width: 0; }
input[type=checkbox] { width: auto; }
textarea { min-height: 64px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-2); }
label.f.req > span::after { content: " *"; color: var(--bad); }
label.chk { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.grid { display: grid; gap: 10px 12px; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.grid .wide { grid-column: 1 / -1; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 12px; }
.filters > * { width: auto; }
.filters label.f { min-width: 140px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; display: flex; gap: 5px; align-items: center; font-size: 12px; cursor: pointer; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 16px; }
.cols-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); margin-bottom: 16px; }
.kpi .label { color: var(--text-2); font-size: 13px; }
.kpi .value { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 4px; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile { display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; }
.tile .value { font-size: 19px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile.alert-bad { border-color: var(--bad); }
.dl { display: grid; grid-template-columns: 170px 1fr; gap: 4px 12px; font-size: 13px; }
.dl dt { color: var(--text-2); }
.dl dd { margin: 0; overflow-wrap: anywhere; }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; margin: 1px 2px 1px 0; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.market { background: var(--market-soft); color: var(--market); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-2); font-weight: 600; color: var(--text-2); position: sticky; top: 0; cursor: pointer; user-select: none; white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr.click { cursor: pointer; }
tfoot td { font-weight: 650; background: var(--surface-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.tools-left { display: inline-flex; align-items: center; gap: 8px; }
.info-btn { width: 20px; height: 20px; padding: 0; border-radius: 50%; justify-content: center; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--muted); font: italic 700 12px/1 Georgia, 'Times New Roman', serif; }
.info-btn:hover, .info-btn.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.help-panel { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin: 0 0 8px; }
.help-panel dl { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 5px 14px; margin: 0; font-size: 13px; }
.help-panel dt { font-weight: 600; } .help-panel dd { margin: 0; color: var(--text-2); }
@media (max-width: 900px) { .help-panel dl { grid-template-columns: 1fr; } }
.table-tools { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; font-size: 12px; color: var(--muted); }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--text-2); }
.tabs button.active { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 20, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 12px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 10px; width: min(760px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal.wide { width: min(1100px, 100%); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px 18px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.line-box { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; background: var(--bg); }
.line-box .line-head { display: flex; justify-content: space-between; margin-bottom: 8px; font-weight: 600; }
.alloc-row { display: grid; grid-template-columns: 1.2fr 1.2fr 1fr .6fr .8fr auto; gap: 6px; margin-top: 6px; }
.sum-row { display: flex; gap: 18px; justify-content: flex-end; font-variant-numeric: tabular-nums; padding: 6px 0; }
.note { background: var(--info-soft); border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 12px; }
.note.warn { background: var(--warn-soft); color: var(--warn); }

/* Strefa danych porównawczych (konkurencja) – wyraźnie oddzielona */
.market-zone { border: 2px dashed var(--market); background: var(--market-soft); border-radius: var(--radius); padding: 16px; margin-top: 8px; }
.market-zone > .zone-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.zone-label { font-weight: 700; color: var(--market); letter-spacing: .04em; text-transform: uppercase; font-size: 12px; }
.own-zone-label { font-weight: 700; color: var(--accent); letter-spacing: .04em; text-transform: uppercase; font-size: 12px; margin-bottom: 8px; }

/* Chart */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .bar-1 { fill: var(--series-1); }
.chart .bar-2 { fill: var(--series-2); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--surface-2); opacity: .6; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.tooltip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); white-space: nowrap; z-index: 3; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; gap: 8px; align-items: center; font-size: 13px; margin: 5px 0; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.login h1 { margin-bottom: 4px; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--good); padding: 10px 14px; border-radius: 6px; box-shadow: var(--shadow); max-width: 420px; }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 14px 16px 60px; }
  .topbar { padding: 10px 16px; }
  .cols-2 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
  .alloc-row { grid-template-columns: 1fr 1fr; }
}
@media print { .side, .topbar, .page-head .actions, .filters { display: none !important; } .layout { display: block; } }
