:root {
  --bg: #f3f4f1;
  --card: #ffffff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1b5e3f;
  --accent-soft: #e3f1ea;
  --plus: #15803d;
  --minus: #b91c1c;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --card: #1e221f;
    --text: #f1f1f1;
    --muted: #9ca3af;
    --line: #2e332f;
    --accent: #3fa072;
    --accent-soft: #1d3a2c;
    --plus: #4ade80;
    --minus: #f87171;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--accent);
  color: #fff;
  padding: calc(var(--safe-top) + 12px) 16px 12px;
}
.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

main {
  flex: 1;
  padding: 12px 12px calc(var(--safe-bottom) + 150px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Saldo */
.cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 14px;
}
.cards.single { grid-template-columns: 1fr; }
.howto {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
  font-size: 15px;
  line-height: 1.45;
}
.howto ol {
  margin: 0;
  padding-left: 1.2em;
}
.howto li { margin: 4px 0; }
.howto .muted { font-size: 13px; }
.field-hint {
  margin: 4px 2px 0;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.35;
}
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.card .label {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}
.card .value {
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.card .sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}
.value.neg { color: var(--minus); }
.value.pos { color: var(--plus); }
.card-btn {
  border: 0;
  text-align: left;
  font: inherit;
  color: inherit;
  width: 100%;
  cursor: pointer;
}
.card-btn:active { background: var(--accent-soft); }
.muted { color: var(--muted); font-weight: 400; }

.item.setting { cursor: default; }
.item.setting:active { background: none; }
.item.setting input.wide {
  width: 100%;
  max-width: 220px;
  text-align: left;
}
.item.setting input {
  width: 90px;
  font: inherit;
  font-size: 17px;
  text-align: right;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
}

/* Lista */
.section-title {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 16px 4px 8px;
  display: flex;
  justify-content: space-between;
}
.list {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  width: 100%;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  color: inherit;
  text-align: left;
  font: inherit;
}
.item:last-child { border-bottom: 0; }
.item:active { background: var(--accent-soft); }
.item .date {
  width: 58px;
  flex: none;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.2;
}
.item .date b { display: block; color: var(--text); font-size: 15px; }
.item .note {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.item .note small { display: block; color: var(--muted); font-size: 12px; }
.item .amt {
  flex: none;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  text-align: right;
}
.item .amt small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--muted);
}
.amt.plus { color: var(--plus); }
.amt.minus { color: var(--minus); }
.amt.neutral { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(128,128,128,.5); }

/* Karta podziału kasy */
.breakdown { padding: 6px 14px; }
.brow {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.brow:last-child { border-bottom: 0; }
.brow.total { font-weight: 700; border-top: 2px solid var(--line); }
.brow .plus { color: var(--plus); }
.brow .minus { color: var(--minus); }
.brow.muted { color: var(--muted); font-size: 13px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  line-height: 1.5;
}

/* Filtry miesięcy */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 8px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  font: inherit;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* FAB */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--safe-bottom) + 76px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 32px;
  line-height: 56px;
  box-shadow: 0 6px 16px rgba(0,0,0,.25);
  z-index: 6;
  padding: 0;
}
.fab:active { transform: scale(.95); }
.fab[hidden] { display: none; }

/* Tabbar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
  z-index: 5;
}
.tab {
  flex: 1;
  background: none;
  border: 0;
  color: var(--muted);
  padding: 8px 0 6px;
  font: inherit;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.tab-icon { font-size: 22px; }
.tab.active { color: var(--accent); font-weight: 600; }

/* Dialogi */
dialog {
  border: 0;
  border-radius: 18px 18px 0 0;
  padding: 0;
  width: 100%;
  max-width: 560px;
  margin: auto auto 0;
  background: var(--card);
  color: var(--text);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form {
  padding: 18px 18px calc(var(--safe-bottom) + 18px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
dialog h2 { margin: 0 0 4px; font-size: 18px; }

.seg {
  display: flex;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
}
.seg label { flex: 1; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 8px;
  border-radius: 8px;
  font-size: 15px;
}
.seg input:checked + span {
  background: var(--card);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}

.seg.cats span { font-size: 14px; padding: 8px 4px; }
form.is-in .only-out { display: none; }
form.is-out .only-in { display: none; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 15px;
  line-height: 1.3;
}
.check input { width: 22px; height: 22px; margin: 0; flex: none; accent-color: var(--accent); }
.check small { display: block; color: var(--muted); font-size: 12px; }

.menu-form { gap: 10px; }
.menu-form h2 { margin-bottom: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
.field input, .field select {
  font: inherit;
  font-size: 17px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  width: 100%;
  min-height: 44px;
}
.row { display: flex; gap: 10px; }
.grow { flex: 1; }

.actions { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.btn {
  font: inherit;
  font-size: 16px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  min-height: 44px;
}
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.danger { color: var(--minus); border-color: var(--minus); background: none; }
.btn.block { width: 100%; text-align: left; display: flex; justify-content: space-between; }

/* Więcej */
.menu { display: flex; flex-direction: column; gap: 10px; }
.menu .btn { background: var(--card); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 6px 4px 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 90px);
  transform: translateX(-50%);
  background: #222;
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 20;
  max-width: 90vw;
}
.toast[hidden] { display: none; }

pre.summary {
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  margin: 0 0 10px;
}
