/* Kasa — mobile first. Palety: jeden hue (niebieski) + kolory statusów. */

:root {
  color-scheme: light;
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f2f1ed;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --muted:        #898781;
  --line:         #e1e0d9;
  --axis:         #c3c2b7;
  --border:       rgba(11, 11, 11, .10);

  --accent:       #2a78d6;
  --accent-soft:  #cde2fb;
  --accent-ink:   #ffffff;

  --good:         #0ca30c;
  --good-ink:     #006300;
  --warning:      #fab219;
  --critical:     #d03b3b;

  --radius:       14px;
  --tap:          44px;
  --safe-b:       env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane:       #0d0d0d;
    --surface:     #1a1a19;
    --surface-2:   #242422;
    --ink:         #ffffff;
    --ink-2:       #c3c2b7;
    --muted:       #898781;
    --line:        #2c2c2a;
    --axis:        #383835;
    --border:      rgba(255, 255, 255, .10);
    --accent:      #3987e5;
    --accent-soft: #184f95;
    --good-ink:    #0ca30c;
  }
}

* { box-sizing: border-box; }

/* Musi wygrać z regułami .screen/.sheet-wrap, które ustawiają display. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 650; }
ul { list-style: none; margin: 0; padding: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1 1 auto; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---------------- ekran blokady ---------------- */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lock-box { width: min(320px, 100%); text-align: center; }
.lock-logo { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.lock-hint { color: var(--muted); margin: 6px 0 22px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin-bottom: 10px; }
.pin-dots i {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--axis); background: transparent;
  transition: background .12s ease, border-color .12s ease;
}
.pin-dots i.on { background: var(--accent); border-color: var(--accent); }
.pin-err { color: var(--critical); font-size: 14px; min-height: 20px; }
.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px;
}
.keypad button {
  height: 64px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); font-size: 24px; cursor: pointer;
}
.keypad button:active { background: var(--surface-2); }

/* ---------------- układ ---------------- */

.app { padding-bottom: calc(122px + var(--safe-b)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  padding: 10px 12px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  min-width: var(--tap); height: var(--tap);
  border: 0; background: transparent; color: var(--ink-2);
  font-size: 22px; border-radius: 10px; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.settings { margin-left: auto; font-size: 19px; }
.period-btn {
  border: 0; background: transparent; font-size: 16px; font-weight: 600;
  min-width: 130px; height: var(--tap); border-radius: 10px; cursor: pointer;
}

.screen { padding: 14px 12px 4px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 14px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.link-btn { border: 0; background: transparent; color: var(--accent); font-size: 13px; cursor: pointer; padding: 4px; }

/* ---------------- hero ---------------- */

.hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px 14px;
}
.hero-label { font-size: 13px; color: var(--muted); }
.hero-value {
  font-size: clamp(38px, 12vw, 52px);
  font-weight: 700; letter-spacing: -.03em; line-height: 1.05; margin: 2px 0 4px;
}
.hero-value.neg { color: var(--critical); }
.hero-sub { font-size: 13px; color: var(--ink-2); min-height: 18px; }

.meter {
  position: relative; height: 8px; border-radius: 999px;
  background: var(--surface-2); margin-top: 14px; overflow: hidden;
}
.meter-fill { height: 100%; background: var(--accent); border-radius: 999px; width: 0; transition: width .3s ease; }
.meter-fill.over { background: var(--critical); }
.meter-today { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .55; }
.meter-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }

.kpi-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px;
}
.kpi-k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi b { font-size: 15px; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 650; }

/* ---------------- listy ---------------- */

.bill-list li, .exp-list li, .def-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 0; border-top: 1px solid var(--line);
}
.bill-list li:first-child, .exp-list li:first-child, .def-list li:first-child { border-top: 0; }

.b-main { flex: 1 1 auto; min-width: 0; }
.b-name { font-size: 15px; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.b-meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.b-amt { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }
.b-amt.done { color: var(--muted); font-weight: 500; text-decoration: line-through; }

.pill {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap;
}
.pill.late { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); border-color: transparent; font-weight: 600; }
.pill.soon { background: color-mix(in srgb, var(--warning) 22%, transparent); color: var(--ink); border-color: transparent; }
.pill.paid { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); border-color: transparent; }
.pill.auto { color: var(--muted); }

.tap-row { cursor: pointer; }
.tap-row:active { background: var(--surface-2); }

.exp-cat { font-size: 20px; width: 28px; text-align: center; }
.empty { color: var(--muted); font-size: 14px; padding: 8px 0; }

.calibrate-row { display: flex; align-items: center; gap: 10px; padding: 0 2px 8px; }
.calibrate-row .btn-ghost { white-space: nowrap; flex: 0 0 auto; }
.calibrate-row .small { flex: 1 1 auto; min-width: 0; }

/* ---------------- przyciski ---------------- */

.btn-primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 12px; min-height: var(--tap);
  padding: 0 18px; font-weight: 650; cursor: pointer; flex: 1 1 auto;
}
.btn-primary:disabled { opacity: .4; }
.btn-ghost {
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--border); border-radius: 12px;
  min-height: var(--tap); padding: 0 16px; cursor: pointer;
}
.btn-ghost.danger { color: var(--critical); }
.btn-ghost.wide { width: 100%; margin-top: 10px; }

.fab {
  position: fixed; right: 16px; bottom: calc(84px + var(--safe-b));
  width: 58px; height: 58px; border-radius: 50%;
  background: var(--accent); color: var(--accent-ink);
  border: 0; font-size: 30px; line-height: 1; cursor: pointer; z-index: 30;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .22);
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--plane) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  border: 0; background: transparent; color: var(--muted);
  display: grid; gap: 2px; justify-items: center;
  padding: 9px 0 8px; font-size: 11px; cursor: pointer;
}
.tab span { font-size: 19px; line-height: 1; }
.tab.is-active { color: var(--accent); }

/* ---------------- arkusze ---------------- */

.sheet-wrap { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); }
.sheet {
  position: relative; width: 100%; max-height: 92dvh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px;
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-grip { width: 38px; height: 4px; border-radius: 3px; background: var(--axis); margin: 4px auto 8px; }
.sheet-title { font-size: 18px; }
.sheet-row { display: flex; gap: 10px; align-items: flex-end; }
.field-label { font-size: 12px; color: var(--muted); }

.cat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cat {
  display: grid; gap: 4px; justify-items: center;
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: 12px; padding: 10px 4px; cursor: pointer;
}
.cat.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--surface-2)); }
.cat-ico { font-size: 22px; line-height: 1; }
.cat-lbl { font-size: 10.5px; color: var(--ink-2); text-align: center; line-height: 1.2; }

.amount-box {
  display: flex; align-items: baseline; gap: 8px;
  background: var(--surface-2); border-radius: 12px; padding: 10px 14px;
}
.amount {
  flex: 1 1 auto; min-width: 0; border: 0; background: transparent;
  font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em; outline: none;
}
.cur { color: var(--muted); font-size: 16px; }

.text-in {
  width: 100%; min-height: var(--tap);
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: 12px; padding: 8px 12px; outline: none;
}
.text-in:focus { border-color: var(--accent); }

.cal-diff { border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.cal-diff.minus { background: color-mix(in srgb, var(--critical) 12%, transparent); color: var(--critical); }
.cal-diff.plus  { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good-ink); }
.cal-diff.zero  { background: var(--surface-2); color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-b)); transform: translateX(-50%);
  background: var(--ink); color: var(--plane);
  padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 90;
  max-width: 88vw; text-align: center;
}

/* ---------------- wykresy ---------------- */

.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; max-width: 100%; }
.bar { fill: var(--accent); }
.bar.dim { fill: var(--accent-soft); }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-label { fill: var(--muted); font-size: 11px; }
.val-label { fill: var(--ink); font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; }

.data-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 13px; }
.data-table th, .data-table td { padding: 6px 4px; border-top: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }

.hbar-row { display: grid; grid-template-columns: 1fr; gap: 3px; padding: 7px 0; border-top: 1px solid var(--line); }
.hbar-row:first-child { border-top: 0; }
.hbar-head { display: flex; justify-content: space-between; font-size: 13px; }
.hbar-head b { font-variant-numeric: tabular-nums; font-weight: 650; }
.hbar-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.hbar-fill { height: 100%; background: var(--accent); border-radius: 999px; }

@media (min-width: 700px) {
  .app { max-width: 620px; margin: 0 auto; }
  .tabbar { max-width: 620px; left: 50%; transform: translateX(-50%); }
  .fab { right: calc(50% - 310px + 16px); }
  .sheet { max-width: 620px; margin: 0 auto; border-radius: 20px; }
  .sheet-wrap { align-items: center; padding: 20px; }
}
