:root {
  color-scheme: light;
  --page: #f6f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --gain: #006300;
  --loss: #c62f2f;
  --gain-mark: #1f9a3a;
  --loss-mark: #e34948;
  --warn: #9a6400;
  --warn-bg: #fdf3dc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e; --surface: #1a1a19; --surface-2: #232321; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #8f8d86;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --accent: #3987e5; --accent-wash: rgba(57,135,229,.16);
    --gain: #3ec45a; --loss: #ff7b7b; --gain-mark: #2fb04c; --loss-mark: #e66767; --warn: #f0b545; --warn-bg: #2d2413;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e; --surface: #1a1a19; --surface-2: #232321; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #8f8d86;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10); --accent: #3987e5; --accent-wash: rgba(57,135,229,.16);
  --gain: #3ec45a; --loss: #ff7b7b; --gain-mark: #2fb04c; --loss-mark: #e66767; --warn: #f0b545; --warn-bg: #2d2413;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font-size: 14px; line-height: 1.45; display: flex; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
h3 { font-size: 13px; color: var(--ink-2); font-weight: 600; }

/* --- sidebar */
.side { width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 17px; padding: 18px 18px 14px; display: flex; align-items: center; gap: 10px; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 22l6-7 5 4 7-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100% no-repeat; }
nav { display: flex; flex-direction: column; padding: 4px 10px; gap: 2px; overflow-y: auto; }
nav a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-weight: 500; }
nav a:hover { background: var(--surface-2); color: var(--ink); }
nav a.active { background: var(--accent-wash); color: var(--accent); }
.side-foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }

/* --- main */
main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px); display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toggles { display: flex; align-items: center; gap: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent); border-color: transparent; font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 5px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.custom-range input { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 4px 6px; }
.switch { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; color: var(--ink-2); user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch span { width: 30px; height: 18px; border-radius: 99px; background: var(--axis); position: relative; transition: .15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 14px; }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 16px; }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

#view { padding: 20px 24px 60px; display: flex; flex-direction: column; gap: 16px; max-width: 1500px; width: 100%; }
#banner:empty { display: none; }
#banner { padding: 0 24px; margin-top: 12px; }
.loading { color: var(--muted); padding: 40px 0; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.view-head h1 { font-size: 22px; }
.view-head .sub { color: var(--muted); font-size: 13px; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head .hint { color: var(--muted); font-size: 12px; }
.chart { width: 100%; height: 320px; }
.chart.tall { height: 400px; }
.chart.short { height: 240px; }

/* --- KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .value { font-size: 22px; font-weight: 650; margin-top: 4px; letter-spacing: -0.02em; white-space: nowrap; }
.kpi .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.pos { color: var(--gain); }
.neg { color: var(--loss); }

/* --- tabele */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th.sorted::after { content: " ▾"; }
th.sorted.asc::after { content: " ▴"; }
td.l, th.l { text-align: left; }
td { font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.total td { font-weight: 650; border-top: 1px solid var(--axis); }
tr.sub td { color: var(--ink-2); font-size: 12px; }
.name-cell { display: flex; flex-direction: column; }
.name-cell small { color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.bar-inline { display: inline-block; height: 6px; border-radius: 3px; background: var(--accent); vertical-align: middle; margin-left: 6px; opacity: .8; }
.heat td.cell { min-width: 58px; font-size: 12px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: rgba(31,154,58,.14); color: var(--gain); }
.badge.bad { background: rgba(227,73,72,.14); color: var(--loss); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }

.notice { border-radius: 10px; padding: 10px 14px; background: var(--warn-bg); color: var(--warn); font-size: 13px; }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.notice details summary { cursor: pointer; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn { border: 1px solid var(--border); background: var(--surface); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; }
select, input[type="text"], input[type="number"], input[type="search"] { border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 5px 8px; }
input.num { width: 80px; text-align: right; }
.legend-list { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; font-size: 13px; }
.meter { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 3px; }

.dropzone { border: 2px dashed var(--axis); border-radius: var(--radius); padding: 34px; text-align: center; color: var(--ink-2); cursor: pointer; transition: .15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-wash); }
.dropzone strong { color: var(--ink); }
pre.report { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer-panel .view-head { padding-right: 36px; }
.drawer-panel { width: min(1100px, 96vw); height: 100%; background: var(--page); overflow-y: auto; padding: 20px 24px 60px; position: relative; display: flex; flex-direction: column; gap: 16px; }
.drawer-close { position: absolute; right: 16px; top: 12px; border: 0; background: transparent; font-size: 28px; cursor: pointer; color: var(--ink-2); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 10px 16px; border-radius: 10px; z-index: 30; font-size: 13px; max-width: 90vw; }

body.privacy .money { filter: blur(7px); user-select: none; }

@media (max-width: 1100px) {
  .g3, .g-2-1 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  nav { flex-direction: row; padding: 6px; }
  nav a { white-space: nowrap; }
  .side-foot { display: none; }
  .g2 { grid-template-columns: 1fr; }
  .top, #view { padding-left: 16px; padding-right: 16px; }
  #banner { padding: 0 16px; }
}

/* prognoza: formularz założeń */
.proj-form { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; font-size: 13px; margin-bottom: 6px; }
.proj-form label { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card + .notice, .notice + .card { margin-top: 14px; }

/* nawigacja w grupach */
.nav-group { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 12px 10px 4px; }
.nav-group:first-child { padding-top: 4px; }
@media (max-width: 860px) { .nav-group { display: none; } }

/* ekran powitalny (tryb przeglądarkowy) */
body.welcome header.top, body.welcome #nav, body.welcome #banner { display: none; }
.welcome-box { max-width: 760px; margin: 5vh auto 0; display: flex; flex-direction: column; gap: 16px; }
.welcome-head { display: flex; gap: 16px; align-items: center; }
.welcome-head h1 { margin: 0; font-size: 30px; }
.welcome-head .lead { margin: 4px 0 0; color: var(--ink-2); font-size: 15px; }
.logo.big { width: 52px; height: 52px; border-radius: 12px; flex: none; }
.welcome-list { margin: 8px 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--ink-2); line-height: 1.5; }
.welcome-actions { margin-bottom: 10px; }
.welcome-actions .btn { padding: 9px 16px; font-size: 14px; }
label.btn { cursor: pointer; }
.folder-link { color: var(--accent); text-decoration: none; }
.folder-link:hover { text-decoration: underline; }
