:root {
  --accent: #7B1E3A;
  --accent-strong: #5E1229;
  --accent-text: #7B1E3A;
  --accent-soft: #F6E7EC;
  --bg: #F4F1F2;
  --card: #FFFFFF;
  --text: #1C1A1B;
  --muted: #6E6568;
  --line: rgba(60, 20, 35, 0.1);
  --input-bg: #F4F1F2;
  --danger: #C62828;
  --warn-bg: #FFF3E0;
  --warn-text: #8A4B00;
  --shadow: 0 1px 2px rgba(60, 20, 35, 0.06), 0 4px 16px rgba(60, 20, 35, 0.05);
  --radius: 14px;
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #8E2546;
    --accent-strong: #6B1732;
    --accent-text: #F08CA8;
    --accent-soft: #3A1822;
    --bg: #121011;
    --card: #1E1B1D;
    --text: #F2EEF0;
    --muted: #A79DA1;
    --line: rgba(255, 255, 255, 0.1);
    --input-bg: #2A2628;
    --danger: #FF6B6B;
    --warn-bg: #3A2A10;
    --warn-text: #FFC266;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }

[hidden] { display: none !important; }

/* ---------- Horná lišta ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: calc(52px + var(--safe-top));
  padding: var(--safe-top) 8px 0;
  background: var(--accent);
  color: #fff;
}
.bar h1 {
  grid-column: 2;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar .bar-left { grid-column: 1; justify-self: start; }
.bar .bar-right { grid-column: 3; justify-self: end; }
.bar-btn {
  border: 0;
  background: none;
  color: #fff;
  padding: 10px 8px;
  font-size: 17px;
  text-decoration: none;
}
.bar-btn.strong { font-weight: 600; }
.bar-btn:disabled { opacity: 0.5; }

/* ---------- Obsah ---------- */

.view {
  min-height: 100vh;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}
body.no-tabbar .view { padding-bottom: calc(var(--safe-bottom) + 32px); }

.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

.section-title {
  margin: 24px 4px 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.section-title:first-child { margin-top: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card + .card { margin-top: 12px; }
.card-pad { padding: 16px; }

.hint {
  margin: 8px 4px 0;
  font-size: 13px;
  color: var(--muted);
}

/* ---------- Mesačný súhrn ---------- */

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.month-nav h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: var(--card);
  color: var(--accent-text);
  box-shadow: var(--shadow);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:disabled { opacity: 0.35; }

.hero {
  padding: 20px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  color: #fff;
}
.hero-label { font-size: 14px; opacity: 0.85; }
.hero-value {
  margin-top: 2px;
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-sub { margin-top: 4px; font-size: 14px; opacity: 0.85; }

/* ---------- Zoznamy ---------- */

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  color: inherit;
  text-decoration: none;
}
a.row:active { background: var(--line); }
.row-main { flex: 1; min-width: 0; }
.row-title {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-sub { font-size: 13px; color: var(--muted); }
.row-end {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.row-end .row-sub { margin-top: 1px; }
.chevron { color: var(--muted); opacity: 0.6; flex: none; }
.chevron svg { width: 16px; height: 16px; display: block; }

.empty {
  padding: 32px 16px;
  text-align: center;
  color: var(--muted);
}
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--warn-bg);
  color: var(--warn-text);
  white-space: nowrap;
}
.badge.muted { background: var(--line); color: var(--muted); }

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 14px;
}
.notice a { color: inherit; font-weight: 600; }
.notice.info { background: var(--accent-soft); color: var(--accent-text); }

details.archived { margin-top: 20px; }
details.archived summary {
  padding: 8px 4px;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
}

/* ---------- Formuláre ---------- */

.field { display: block; padding: 12px 16px; }
.field + .field { border-top: 1px solid var(--line); }
.field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.input, select.input, textarea.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--input-bg);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
select.input {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
textarea.input { min-height: 72px; resize: vertical; }
input[type="date"].input { display: block; text-align: left; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; }
.input:focus { outline: none; border-color: var(--accent-text); }
.input.invalid { border-color: var(--danger); }
.input-suffix { position: relative; }
.input-suffix .input { padding-right: 36px; }
.input-suffix span {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.field-error { margin-top: 6px; font-size: 13px; color: var(--danger); }

.btn {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
}
.btn:active { background: var(--accent-strong); }
.btn.secondary { background: var(--card); color: var(--accent-text); box-shadow: var(--shadow); }
.btn.danger { background: var(--card); color: var(--danger); box-shadow: var(--shadow); }
.btn + .btn { margin-top: 12px; }
.btn-stack { margin-top: 24px; }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent-text);
  font-size: 15px;
  font-weight: 600;
}

/* ---------- Stepper a položky ---------- */

.stepper {
  display: inline-flex;
  align-items: center;
  border-radius: 10px;
  background: var(--input-bg);
  flex: none;
}
.stepper button {
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: 22px;
  line-height: 1;
}
.stepper input {
  width: 48px;
  height: 40px;
  border: 0;
  background: none;
  text-align: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.stepper input:focus { outline: none; }
.stepper.large button { width: 52px; height: 52px; font-size: 26px; }
.stepper.large input { width: 72px; height: 52px; font-size: 22px; font-weight: 600; }

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 10px 16px;
}
.item-row + .item-row { border-top: 1px solid var(--line); }
.item-row .row-main .row-sub { font-variant-numeric: tabular-nums; }
.item-row .row-sub b { font-weight: 600; color: var(--text); }
.item-row .stepper button { width: 36px; }
.item-row .stepper input { width: 40px; }
.remove-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--muted);
  flex: none;
}
.remove-btn svg { width: 16px; height: 16px; }

.add-row { padding: 12px 16px; border-top: 1px solid var(--line); }

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 14px 16px;
  border-top: 1px solid var(--line);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.total-row .value { font-size: 20px; }

.qty-block {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* ---------- Spodná lišta ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
body.no-tabbar .tabbar { display: none; }
.tabbar a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  text-decoration: none;
}
.tabbar a svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tabbar a.active { color: var(--accent-text); }
.tabbar a.tab-add {
  justify-self: center;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 12px rgba(123, 30, 58, 0.35);
}
.tabbar a.tab-add svg { width: 26px; height: 26px; stroke-width: 2.4; }

/* ---------- Aktualizácia ---------- */

.update-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
}
.update-banner button {
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 64px);
  z-index: 40;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  animation: toast 2.4s ease forwards;
}
@keyframes toast {
  0% { opacity: 0; transform: translate(-50%, -8px); }
  10%, 85% { opacity: 1; transform: translate(-50%, 0); }
  100% { opacity: 0; transform: translate(-50%, -8px); }
}
