/* Mobile-first. Desktop adjustments are in the media query at the bottom. */

:root {
  --color-bg: #f6f7f9;
  --color-surface: #ffffff;
  --color-text: #1c1f24;
  --color-muted: #6b7280;
  --color-border: #e2e5ea;
  --color-accent: #2563eb;
  --color-income: #15803d;
  --color-transfer: #7c3aed;
  --color-expense: #b91c1c;
  --color-important: #dc2626;

  --tap-size: 44px;
  --nav-height: 60px;
  --gap: 16px;
  --radius: 10px;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #121418;
    --color-surface: #1c1f24;
    --color-text: #e8eaed;
    --color-muted: #9aa0a8;
    --color-border: #2d3138;
    --color-accent: #60a5fa;
    --color-income: #4ade80;
    --color-transfer: #a78bfa;
    --color-expense: #fca5a5;
    --color-important: #f87171;
  }
}

* { box-sizing: border-box; }

/* The hidden attribute must win over display rules like .field { display: flex }. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
}

.app-header {
  padding: var(--gap);
  padding-top: max(var(--gap), env(safe-area-inset-top));
}

.app-title {
  margin: 0;
  font-size: 1.25rem;
}

/* Mobile: tab bar fixed at the bottom (thumb reach on iPhone). */
.app-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}

.app-nav a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--nav-height);
  color: var(--color-muted);
  text-decoration: none;
  font-weight: 500;
}

.app-nav a[aria-current="page"] {
  color: var(--color-accent);
  font-weight: 700;
}

.app-main {
  padding: 0 var(--gap);
  /* Space so the content is not hidden behind the bottom tab bar. */
  padding-bottom: calc(var(--nav-height) + env(safe-area-inset-bottom) + var(--gap));
  max-width: 960px;
}

h2 { font-size: 1.125rem; margin: 0 0 var(--gap); }

.muted { color: var(--color-muted); }

.error { color: var(--color-important); }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
}

.list {
  list-style: none;
  margin: 0 0 var(--gap);
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  min-height: var(--tap-size);
  padding: 8px var(--gap);
  border-bottom: 1px solid var(--color-border);
}

.list li:last-child { border-bottom: none; }

.list .amount { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* Planned items: day | name | amount */
.items .item-main { gap: 8px; }
.items .day { width: 2em; flex: none; color: var(--color-muted); font-variant-numeric: tabular-nums; }
.items .name { flex: 1; }
.items .amount { text-align: right; }
.items small { display: block; font-size: 0.8rem; color: var(--color-muted); }

/* Kind colour only on group totals: income green, expense red, transfer violet. Item amounts stay text colour. */
.kind-income > .group-header .amount { color: var(--color-income); }
.kind-expense > .group-header .amount { color: var(--color-expense); }
.kind-transfer > .group-header .amount { color: var(--color-transfer); }
/* Group paid in full: the paid line takes the kind colour too, less prominent than the total. */
.kind-income.all-paid > .group-paid { color: var(--color-income); }
.kind-expense.all-paid > .group-paid { color: var(--color-expense); }
.kind-transfer.all-paid > .group-paid { color: var(--color-transfer); }

/* Tick circle at the start of the row: empty = unpaid, filled with a tick = paid. */
.tick {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-accent);
  border-radius: 50%;
  color: var(--color-surface);
  font-size: 0.875rem;
  font-weight: 800;
  line-height: 1;
}
.status-paid .tick { background: var(--color-accent); }
.status-skipped .tick { border-style: dashed; border-color: var(--color-muted); }

/* Item states (US-05). Each state has a mark, not only a colour. Paid rows are slightly dimmed, still readable. */
.status-paid .day,
.status-paid .name,
.status-paid .amount { opacity: 0.7; }
.status-skipped .name,
.status-skipped .amount { text-decoration: line-through; color: var(--color-muted); }
.status-estimate .mark { color: var(--color-muted); font-weight: 700; }
.important { box-shadow: inset 4px 0 0 var(--color-important); }
.important .flag {
  display: inline-block;
  margin-right: 6px;
  color: var(--color-important);
  font-weight: 800;
}

/* Summary at the top of the month: 1 column on phone, 2 on desktop. */
.summary { display: grid; gap: 6px 24px; }
.summary-row { display: flex; justify-content: space-between; gap: 12px; }
.summary-row .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.summary-row.strong { font-weight: 700; }

.group-header {
  display: flex;
  justify-content: space-between;
  font-size: 1rem;
  margin: 0 0 8px;
}

.group-paid { margin: -4px 0 8px; font-size: 0.875rem; text-align: right; }

/* Item row (US-06): the whole row is a button (tap = paid), "›" opens the detail. */
.items li { padding: 0; gap: 0; }

.item-main {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--tap-size);
  padding: 8px 0 8px var(--gap);
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.item-detail {
  flex: none;
  width: var(--tap-size);
  min-height: var(--tap-size);
  align-self: stretch;
  background: none;
  border: none;
  border-left: 1px solid var(--color-border);
  color: var(--color-muted);
  font-size: 1.5rem;
  cursor: pointer;
}

/* Item detail: bottom sheet on phone, centered dialog on desktop. */
.sheet {
  width: 100%;
  max-width: 480px;
  margin: auto auto 0;
  padding: var(--gap);
  padding-bottom: max(var(--gap), env(safe-area-inset-bottom));
  border: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--color-surface);
  color: var(--color-text);
}

.sheet::backdrop { background: rgb(0 0 0 / 0.4); }
.sheet h3 { margin: 0; }
.sheet .muted { margin: 4px 0 var(--gap); }
.sheet .hint { margin: -8px 0 var(--gap); font-size: 0.875rem; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--gap); }

.field input {
  min-height: var(--tap-size);
  padding: 0 12px;
  font: inherit;
  font-size: 1rem; /* 16px+ prevents zoom on iPhone */
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.field select {
  min-height: var(--tap-size);
  padding: 0 8px;
  font: inherit;
  font-size: 1rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.field input:disabled { opacity: 0.5; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; border: none; padding: 0; margin: 0 0 var(--gap); }
.choices legend { padding: 0; margin-bottom: 4px; }

.choice, .check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap-size);
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}

.check { margin-bottom: var(--gap); }
.choice:has(input:disabled) { opacity: 0.4; cursor: default; }

.actions { display: flex; justify-content: flex-end; gap: 8px; }

.actions button {
  min-height: var(--tap-size);
  padding: 0 20px;
  font: inherit;
  font-weight: 600;
  border-radius: var(--radius);
  border: 1px solid var(--color-accent);
  background: var(--color-accent);
  color: #fff;
  cursor: pointer;
}

.actions button.secondary { background: none; color: var(--color-accent); }
.actions button.danger { background: none; color: var(--color-important); border-color: var(--color-important); }
.actions .spacer { flex: 1; }

/* Origin of a manual item (BR-16): "ad-hoc" / "nepravidelná". */
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  font-size: 0.75rem;
  color: var(--color-muted);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  vertical-align: middle;
}

/* Budgets (US-08): progress bar, overspent in red (with "+" and "prekročenie" text, not only colour). */
.budget-main { padding-right: var(--gap); }
.progress {
  display: block;
  height: 6px;
  margin-top: 6px;
  background: var(--color-border);
  border-radius: 3px;
  overflow: hidden;
}
.progress .bar { display: block; height: 100%; background: var(--color-accent); }
.progress.over .bar { background: var(--color-important); }
.amount.over { color: var(--color-important); font-weight: 600; }

.sheet h4 { margin: var(--gap) 0 8px; padding-top: var(--gap); border-top: 1px solid var(--color-border); }
.quick-add .actions { margin-top: -8px; }
.link {
  min-height: var(--tap-size);
  padding: 0 4px;
  font: inherit;
  color: var(--color-accent);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}

.inactive { opacity: 0.6; }

/* Rules (US-03): cost center filter, month toggles, amount versions, reset of mock data. */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: var(--gap); }
.chip {
  min-height: var(--tap-size);
  padding: 0 14px;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  cursor: pointer;
}
.chip[aria-pressed="true"] { color: #fff; background: var(--color-accent); border-color: var(--color-accent); }

.month-choice { min-width: 64px; justify-content: center; padding: 0 8px; }

.version-list { margin: 0 0 var(--gap); padding-left: 20px; }

.reset { margin-top: calc(var(--gap) * 2); text-align: center; }
.danger-link { color: var(--color-important); }

.add-item {
  width: 100%;
  min-height: var(--tap-size);
  margin-bottom: var(--gap);
  font: inherit;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-surface);
  border: 1px dashed var(--color-accent);
  border-radius: var(--radius);
  cursor: pointer;
}

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: var(--gap);
}

.month-nav h2 { margin: 0; text-align: center; }

.month-nav button {
  min-width: var(--tap-size);
  min-height: var(--tap-size);
  font-size: 1.25rem;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}

.month-nav button:disabled { opacity: 0.35; cursor: default; }

/* Month name opens the month picker: looks like a title, not like a button. */
.month-nav .month-title {
  padding: 0 8px;
  font: inherit;
  font-weight: 700;
  background: none;
  border: none;
}
.sheet .month-nav h3 { margin: 0; }

/* Month picker: 4 × 3 grid, selected month filled, current month outlined. */
.month-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: var(--gap);
}
.month-grid button {
  min-height: var(--tap-size);
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
}
.month-grid button.today { border: 2px solid var(--color-accent); }
.month-grid button[aria-current] { color: #fff; background: var(--color-accent); border-color: var(--color-accent); }
.month-grid button:disabled { opacity: 0.35; cursor: default; }

/* Desktop: navigation moves to the top next to the title. */
@media (min-width: 768px) {
  .app-header {
    display: flex;
    align-items: center;
    gap: calc(var(--gap) * 2);
    max-width: 960px;
  }

  .app-nav {
    position: static;
    background: none;
    border: none;
    padding: 0;
    gap: 8px;
  }

  .app-nav a {
    flex: none;
    min-height: var(--tap-size);
    padding: 0 var(--gap);
    border-radius: var(--radius);
  }

  .app-nav a[aria-current="page"] { background: var(--color-surface); }

  .app-main { padding-bottom: var(--gap); }

  .summary { grid-template-columns: 1fr 1fr; }

  .sheet { margin: auto; border-radius: var(--radius); }
}

/* Settings (US-02): subcategories indented under their main category, deactivation warning. */
.list li.sub { padding-left: calc(var(--gap) * 2); }
.sheet .warning { margin: -8px 0 var(--gap); font-size: 0.875rem; color: var(--color-important); }
.sheet .warning[hidden] { display: none; }

/* A row with a single button (budgets, settings) keeps the amount off the right edge. */
.items li > .item-main:only-child { padding-right: var(--gap); }

/* Sign in (US-11): no navigation before sign in, form centred on desktop. */
.signed-out .app-nav { display: none; }
.login { max-width: 420px; margin: calc(var(--gap) * 2) auto; }
.login .actions button { width: 100%; }

/* Data in Settings (US-13): import / wipe messages, warning in the sheets. */
.data-message:empty { display: none; }
.sheet p.warning { margin: 0 0 var(--gap); }

/* Sub-menu and view switch (US-15): Limity výdavkov | Pravidlá, Mesiac | Rok. */
.segmented {
  display: flex;
  margin-bottom: var(--gap);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  overflow: hidden;
}
.segmented button {
  flex: 1;
  min-height: var(--tap-size);
  font: inherit;
  font-weight: 600;
  color: var(--color-accent);
  background: var(--color-surface);
  border: none;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--color-accent); }
.segmented button[aria-pressed="true"] { color: #fff; background: var(--color-accent); }

/* Account of an item or rule (US-15), under the name. */
.items small.account, .year-table small.account { display: block; font-size: 0.8rem; color: var(--color-muted); }

/* Year of a cost center (BR-19): wide table scrolls sideways on a phone, the name column stays. */
.table-scroll {
  overflow-x: auto;
  margin-bottom: var(--gap);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.year-table { border-collapse: collapse; min-width: 100%; font-size: 0.875rem; }
.year-table th, .year-table td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.year-table thead th { color: var(--color-muted); font-weight: 600; }
.year-table tbody th { font-weight: 500; white-space: normal; min-width: 120px; }
.year-table th:first-child {
  position: sticky;
  left: 0;
  background: var(--color-surface);
  box-shadow: 1px 0 0 var(--color-border);
}
.year-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.year-table tr.total th, .year-table tr.total td { font-weight: 700; border-bottom: none; }

/* Expenses by month: 3 × 4 grid on a phone (amounts need the width), 6 × 2 on desktop. */
.month-totals {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: var(--gap);
}
.month-totals div {
  display: flex;
  flex-direction: column;
  padding: 6px 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.8rem;
}
.month-totals .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (min-width: 768px) { .month-totals { grid-template-columns: repeat(6, 1fr); } }

/* Four menu items on a narrow phone: slightly smaller text, so "Nastavenia" fits. */
@media (max-width: 400px) { .app-nav a { font-size: 0.9375rem; } }
