:root {
  --bg: #f2f4f7;
  --bg-card: #ffffff;
  --text: #1a2733;
  --text-muted: #64748b;
  --primary: #1F4E78;
  --primary-dark: #163c5c;
  --accent-green: #2f9e63;
  --accent-green-bg: #e3f6ea;
  --accent-red: #c0392b;
  --accent-red-bg: #fbe6e3;
  --accent-yellow-bg: #fff8dc;
  --border: #e2e6eb;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Tmavý režim má tri možné stavy (viď Nastavenia → Vzhľad appky, js/theme.js):
   - "Podľa systému" (predvolené): nič nenastaví atribút data-theme, riadi to len telefón/prehliadač
     nižšie uvedeným @media dotazom.
   - "Svetlý"/"Tmavý": appka natvrdo nastaví data-theme na <html>, čo prebije systémové nastavenie. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1720;
    --bg-card: #17212c;
    --text: #e7edf3;
    --text-muted: #93a1b0;
    --primary: #3b7ab8;
    --primary-dark: #2c5d8e;
    --accent-green: #3ecb82;
    --accent-green-bg: #123521;
    --accent-red: #ff6b5b;
    --accent-red-bg: #3a1a17;
    --accent-yellow-bg: #3a3316;
    --border: #263241;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1720;
  --bg-card: #17212c;
  --text: #e7edf3;
  --text-muted: #93a1b0;
  --primary: #3b7ab8;
  --primary-dark: #2c5d8e;
  --accent-green: #3ecb82;
  --accent-green-bg: #123521;
  --accent-red: #ff6b5b;
  --accent-red-bg: #3a1a17;
  --accent-yellow-bg: #3a3316;
  --border: #263241;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

.topbar {
  background: var(--primary);
  color: #fff;
  padding: calc(14px + var(--safe-top)) 16px 14px;
  flex: none;
}
.topbar h1 { margin: 0; font-size: 19px; font-weight: 700; }

#screen {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px calc(90px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}

.bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 20;
}
.navbtn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--text-muted);
  font-size: 11px; padding: 8px 2px 6px; cursor: pointer;
}
.navbtn svg { width: 22px; height: 22px; fill: currentColor; }
.navbtn.active { color: var(--primary); }

/* ---- generic components ---- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  border: 1px solid var(--border);
}
.card h2 { margin: 0 0 10px; font-size: 14px; color: var(--primary); text-transform: uppercase; letter-spacing: .02em; }
.card h3 { margin: 0 0 8px; font-size: 14px; }

.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius);
  padding: 12px;
}
.kpi.green { background: var(--accent-green); }
.kpi .label { font-size: 11.5px; opacity: .9; }
.kpi .value { font-size: 20px; font-weight: 700; margin-top: 4px; }

.row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--border); gap: 10px; }
.row:last-child { border-bottom: none; }
.row .label { color: var(--text-muted); font-size: 13.5px; }
.row .value { font-weight: 600; font-size: 13.5px; text-align: right; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge.ok { background: var(--accent-green-bg); color: var(--accent-green); }
.badge.bad { background: var(--accent-red-bg); color: var(--accent-red); }

.alert { border-radius: var(--radius); padding: 12px 14px; font-weight: 600; font-size: 13.5px; margin-bottom: 12px; }
.alert.ok { background: var(--accent-green-bg); color: var(--accent-green); }
.alert.bad { background: var(--accent-red-bg); color: var(--accent-red); }
.hint { background: var(--accent-yellow-bg); border-radius: var(--radius); padding: 10px 12px; font-size: 12.5px; color: var(--text-muted); margin-bottom: 12px; }

select, input, textarea {
  width: 100%;
  font-size: 15px;
  padding: 10px 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-family: inherit;
}
label { display: block; font-size: 12.5px; color: var(--text-muted); margin: 10px 0 4px; }
.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff; border: none;
  padding: 11px 16px; border-radius: 10px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; width: 100%; margin-top: 12px;
}
.btn.secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.danger { background: transparent; color: var(--accent-red); border: 1px solid var(--accent-red); }
.btn.small { width: auto; padding: 7px 12px; font-size: 13px; margin-top: 0; }

.list-item {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px;
  align-items: center;
}
.list-item .meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.list-item .amount { font-weight: 700; white-space: nowrap; }
.list-item .amount.income { color: var(--accent-green); }
.list-item .amount.expense { color: var(--accent-red); }
.list-item .title { font-weight: 600; font-size: 14px; }
.list-item-tap { flex: 1; min-width: 0; }
.list-item-tap .title, .list-item-tap .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.fab {
  position: fixed; right: 18px; bottom: calc(84px + var(--safe-bottom));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 28px; line-height: 54px; text-align: center;
  box-shadow: 0 4px 14px rgba(0,0,0,0.25); border: none; z-index: 15;
}

.chart-wrap { display: flex; flex-direction: column; align-items: center; }
canvas.donut { width: 220px; height: 220px; max-width: 100%; }
.legend { width: 100%; margin-top: 10px; }
.legend-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 12.5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.legend-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-val { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.more-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.more-tile {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 12px; text-align: center; font-weight: 600; font-size: 13.5px;
}
.more-tile svg { width: 26px; height: 26px; fill: var(--primary); margin-bottom: 6px; }

.month-picker { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.month-picker input[type="month"] { flex: 1; }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(10,15,20,0.45); z-index: 30;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--bg-card); width: 100%; max-height: 88vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-bottom));
}
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet-header h2 { margin: 0; font-size: 16px; color: var(--text); text-transform: none; }
.sheet-close { background: none; border: none; font-size: 22px; color: var(--text-muted); padding: 4px 8px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.pill-toggle { display: flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.pill-toggle button { flex: 1; border: none; background: var(--bg-card); color: var(--text); padding: 9px; font-size: 13.5px; }
.pill-toggle button.active { background: var(--primary); color: #fff; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + var(--safe-bottom)); transform: translateX(-50%);
  background: #1a2733; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 13.5px; z-index: 50;
}

.howto-list { margin: 0 0 10px 18px; padding: 0; font-size: 13px; color: var(--text-muted); }
.howto-list li { margin-bottom: 5px; }
.code-block {
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11.5px;
  white-space: pre-wrap; word-break: break-word; overflow-x: auto; color: var(--text); margin: 0 0 10px;
}

.section-gap { height: 4px; }
.muted { color: var(--text-muted); font-size: 12.5px; }
.center { text-align: center; }
.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); }

/* ---- PIN zámok appky ---- */
.pin-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.pin-card { width: 100%; max-width: 320px; text-align: center; }
.pin-title { font-size: 19px; font-weight: 700; color: var(--primary); }
.pin-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.pin-msg { font-size: 13.5px; color: var(--text-muted); margin: 18px 0 14px; min-height: 18px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin-bottom: 26px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid var(--border);
  background: var(--bg-card); display: inline-block;
}
.pin-dot.filled { background: var(--primary); border-color: var(--primary); }
.pin-keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; justify-items: center; }
.pin-key, .pin-key-spacer { width: 62px; height: 62px; }
.pin-key {
  border-radius: 50%; border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text); font-size: 22px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.pin-key:disabled { opacity: 0.4; }
.pin-key:active { background: var(--border); }
.pin-forgot {
  margin-top: 22px; background: none; border: none; color: var(--primary);
  font-size: 13.5px; font-weight: 600; cursor: pointer; padding: 8px;
}
