/* Kokpit Finansowy - styles. Mobile first, light/dark via tokens; html[data-theme] overrides the system choice. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #15201e;
  --muted: #62716e;
  --border: #dfe6e4;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #d7f0ec;
  --in: #15803d;
  --in-soft: #dcfce7;
  --out: #c2410c;
  --out-soft: #ffedd5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --grid: #e7ecea;
  --shadow: 0 8px 30px rgba(10, 40, 35, .10);
  --radius: 16px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1413;
    --surface: #161e1c;
    --surface-2: #1f2a28;
    --text: #e9f1ef;
    --muted: #93a39f;
    --border: #2a3634;
    --accent: #2dd4bf;
    --accent-ink: #042f2a;
    --accent-soft: #123a35;
    --in: #4ade80;
    --in-soft: #12301f;
    --out: #fb923c;
    --out-soft: #3a220f;
    --warn: #fbbf24;
    --warn-soft: #3a2c0c;
    --danger: #f87171;
    --danger-soft: #3b1515;
    --grid: #22302d;
    --shadow: 0 8px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1413;
  --surface: #161e1c;
  --surface-2: #1f2a28;
  --text: #e9f1ef;
  --muted: #93a39f;
  --border: #2a3634;
  --accent: #2dd4bf;
  --accent-ink: #042f2a;
  --accent-soft: #123a35;
  --in: #4ade80;
  --in-soft: #12301f;
  --out: #fb923c;
  --out-soft: #3a220f;
  --warn: #fbbf24;
  --warn-soft: #3a2c0c;
  --danger: #f87171;
  --danger-soft: #3b1515;
  --grid: #22302d;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.in { color: var(--in); }
.out { color: var(--out); }
.danger-text { color: var(--danger); }

/* ---------- layout ---------- */
.shell { min-height: 100%; }
.side { display: none; }
.top {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.top h1 { flex: 1; font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.main { padding: 14px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px); max-width: 1180px; margin: 0 auto; }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; height: var(--nav-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.bottom-nav a svg { width: 23px; height: 23px; }
.bottom-nav a.on { color: var(--accent); }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 236px 1fr; }
  .side {
    display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
    padding: 18px 12px; border-right: 1px solid var(--border); background: var(--surface);
  }
  .side .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 16px; padding: 4px 10px 18px; }
  .side .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .side a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px;
    color: var(--text); text-decoration: none; font-weight: 600;
  }
  .side a svg { width: 20px; height: 20px; color: var(--muted); }
  .side a:hover { background: var(--surface-2); }
  .side a.on { background: var(--accent-soft); color: var(--accent); }
  .side a.on svg { color: var(--accent); }
  .side .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; }
  .bottom-nav { display: none; }
  .main { padding: 22px 28px 110px; }
  .top { padding: 14px 28px; }
}

/* ---------- basics ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.grid > .card + .card { margin-top: 0; }
.grid > * { min-width: 0; }
.card h2 { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 12px; }
@media (min-width: 700px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1100px) { .grid.wide-left { grid-template-columns: 1.4fr 1fr; } }
.stack > * + * { margin-top: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); font-weight: 600; cursor: pointer; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.icon { width: 42px; padding: 0; }
.btn.icon.sm { width: 34px; }
.btn svg { width: 20px; height: 20px; }
.btn.block { width: 100%; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }

.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 14px; }
label.field > span, .field-label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

.banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 12px;
}
.banner.info { background: var(--accent-soft); color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 36px 16px; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--muted); padding: 30px; }
.spin { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.code { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; }

/* segmented + chips */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; color: var(--muted); min-height: 38px; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.seg.big { display: flex; }
.seg.big button { flex: 1; min-height: 44px; }
.seg.big button.on.out { color: var(--out); }
.seg.big button.on.in { color: var(--in); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* month switcher */
.monthbar { display: flex; align-items: center; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.monthbar .label { font-weight: 800; font-size: 17px; min-width: 150px; text-align: center; text-transform: capitalize; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 700px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.kpi .t { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 22px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (min-width: 1100px) { .kpi .v { font-size: 26px; } }
.kpi .d { font-size: 12px; margin-top: 4px; color: var(--muted); }
.kpi.hero { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.kpi.hero .t, .kpi.hero .d { color: inherit; opacity: .85; }
.delta-up { color: var(--danger); font-weight: 700; }
.delta-down { color: var(--in); font-weight: 700; }
.kpi.hero .delta-up, .kpi.hero .delta-down { color: inherit; }

.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut { width: 170px; height: 170px; flex: none; margin: 0 auto; }
.donut text { fill: var(--text); }
.legend { flex: 1; min-width: min(200px, 100%); }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--grid); font-size: 14px; }
.legend-row:last-child { border-bottom: 0; }
.legend-row .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .p { color: var(--muted); font-size: 12px; width: 40px; text-align: right; }
.legend-row .a { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; min-width: 90px; }

.hbar { margin: 10px 0; }
.hbar .lbl { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; gap: 8px; }
.hbar .lbl b { font-variant-numeric: tabular-nums; }
.hbar .track { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); overflow: visible; }
.hbar .fill { height: 100%; border-radius: 6px; }
.hbar .ghost { position: absolute; top: -3px; bottom: -3px; width: 3px; border-radius: 2px; background: var(--text); opacity: .45; }

.chart svg { width: 100%; height: auto; display: block; }
.chart .axis { fill: var(--muted); font-size: 12px; }
@media (max-width: 600px) { .chart .axis { font-size: 18px; } }
.chart .gl { stroke: var(--grid); stroke-width: 1; }
.chart-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 16px; height: 3px; border-radius: 2px; display: inline-block; }

.progress { height: 10px; border-radius: 5px; background: var(--surface-2); overflow: hidden; margin: 8px 0 4px; }
.progress > div { height: 100%; background: var(--in); border-radius: 5px; }

/* ---------- lists ---------- */
.day-head { display: flex; justify-content: space-between; padding: 14px 4px 6px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: capitalize; }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--grid); cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:hover { background: var(--surface-2); }
.item .ic { width: 38px; height: 38px; border-radius: 11px; display: flex; align-items: center; justify-content: center; flex: none; font-weight: 800; font-size: 14px; color: #fff; }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.item.static { cursor: default; }
.item.static:hover { background: transparent; }

.tick {
  width: 30px; height: 30px; border-radius: 9px; border: 2px solid var(--border); background: var(--surface);
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex: none; padding: 0; color: transparent;
}
.tick svg { width: 18px; height: 18px; }
.tick.on { background: var(--in); border-color: var(--in); color: #fff; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.badge.late { background: var(--danger-soft); color: var(--danger); }
.badge.soon { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--in-soft); color: var(--in); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters .input { min-height: 40px; width: auto; flex: 1; min-width: 160px; }
.sumbar { display: flex; gap: 16px; flex-wrap: wrap; font-size: 14px; padding: 4px 4px 0; }
.sumbar b { font-variant-numeric: tabular-nums; }

/* ---------- FAB, sheets, toast ---------- */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 35;
  display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 22px 0 18px; border-radius: 18px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 15px; box-shadow: var(--shadow); cursor: pointer;
}
.fab svg { width: 22px; height: 22px; }
@media (min-width: 900px) { .fab { bottom: 28px; right: 28px; } }

.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  border-radius: 22px 22px 0 0; padding: 8px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 4px auto 10px; }
.sheet-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.sheet-head h2 { flex: 1; font-size: 19px; }
.sheet-foot { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.sheet-foot .btn { flex: 1; }
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 22px; padding: 12px 22px 22px; }
  .sheet .grab { display: none; }
}
.amount-box { display: flex; align-items: baseline; gap: 8px; border-bottom: 2px solid var(--border); margin: 6px 0 16px; padding-bottom: 4px; }
.amount-box:focus-within { border-color: var(--accent); }
.amount-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font-size: 38px; font-weight: 800; font-variant-numeric: tabular-nums; padding: 0; }
.amount-box span { font-size: 22px; font-weight: 700; color: var(--muted); }
.help h3 { margin: 16px 0 6px; }
.help p, .help li { font-size: 14px; }
.help ul { padding-left: 20px; margin: 6px 0; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 84px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); display: flex; align-items: center; gap: 14px;
}
.toast.err { background: var(--danger); color: #fff; }
.toast button { background: transparent; border: 1px solid currentColor; color: inherit; border-radius: 8px; padding: 4px 10px; font-weight: 700; cursor: pointer; }
@media (min-width: 900px) { .toast { bottom: 100px; } }

/* settings */
.set-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.set-row:last-child { border-bottom: 0; }
.set-row .n { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.colors { display: flex; gap: 8px; flex-wrap: wrap; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.colors button.on { border-color: var(--text); }

/* start screen */
.start { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.start .box { width: 100%; max-width: 440px; text-align: center; }
.start .box .btn { width: 100%; margin-bottom: 10px; }
.start .logo { width: 76px; height: 76px; border-radius: 20px; margin-bottom: 14px; }
.start h1 { font-size: 26px; margin-bottom: 8px; }
.start .lead { color: var(--muted); margin: 0 0 22px; }
.start .card { text-align: left; }
