/* ============================================================
   Pluto — identita
   Inkoust a papír, tmavý režim výchozí. Barvy kategorií jsou
   colorways — jediný pigment v seznamu. Archivo s osou šířky nese nadpisy a čísla, Inter zbytek.
   Pilulky, měkké rohy, jediná hlavní animace = odkliknutí platby.
   Dva režimy: světlý (výchozí) a tmavý, data-theme na <html>.
   ============================================================ */

/* Tmavý režim je výchozí; světlý přes data-theme="light" na <html>. */
:root {
  --ink:         #0a0a0a;
  --paper:       #ffffff;

  --bg:          #141414;
  --bg-raised:   #1d1d1c;
  --bg-hover:    rgba(255, 255, 255, 0.06);

  --text:        #f2f2ee;
  --text-muted:  #8f8f8a;
  --text-faint:  #4a4a47;

  --line:        #2e2e2c;
  --line-soft:   #232322;

  --positive:    #7ed957;
  --warning:     #e0a03a;
  --negative:    #ff6b52;
  --negative-soft: rgba(255, 107, 82, 0.5);

  --check-ink:   #0a0a0a;

  /* hlavní tlačítko a zvýraznění: v tmavém bílá na černé, ve světlém obráceně */
  --accent:      var(--paper);
  --accent-ink:  var(--ink);

  --canvas:      #0a0a0a;
  --frame-gap:   20px;
  --frame-pad:   24px;
  --frame-radius: 28px;

  --r-pill:      999px;
  --r-input:     12px;
  --r-square:    14px;
  --r-sq:        4px;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  --font-display: 'Archivo', 'Inter', -apple-system, sans-serif;

  --page-max: 640px;
  --square: 52px;
  --cat: #8e8e8e; /* přepisuje se inline per položka */

  --ease-pop: cubic-bezier(0.34, 1.56, 0.64, 1);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg:          var(--paper);
  --bg-raised:   #f4f4f1;
  --bg-hover:    rgba(10, 10, 10, 0.05);

  --text:        var(--ink);
  --text-muted:  #6f6f6a;
  --text-faint:  #c4c4bf;

  --line:        #d6d6d1;
  --line-soft:   #ebebe7;

  --positive:    #2f8f3a;
  --warning:     #b8740f;
  --negative:    #ff4d2e;
  --negative-soft: rgba(255, 77, 46, 0.45);

  --check-ink:   #ffffff;

  --accent:      var(--ink);
  --accent-ink:  var(--paper);

  /* světlá deska na tmavě šedém plátně (stejná šedá jako deska v tmavém režimu) */
  --canvas:      #141414;
  color-scheme: light;
}

/* ---------- Základ ---------- */
* { box-sizing: border-box; }
html { background: var(--canvas); height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  height: 100%;
  overflow: hidden; /* scroluje se uvnitř .frame, ne okno */
  padding: var(--frame-gap) 16px;
  background: var(--canvas);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'ss01', 'cv11';
}
@media (max-width: 480px) { body { padding: 10px; } }

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums lining-nums; white-space: nowrap; }

:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

/* Rám = deska plovoucí na plátně, úzká i na desktopu. Pevná výška okna,
   scroluje se uvnitř; hlavička drží nahoře (sticky). */
.frame {
  position: relative; z-index: 1;
  max-width: var(--page-max);
  height: 100%;
  margin: 0 auto;
  padding: 0 var(--frame-pad) 48px;
  background: var(--bg);
  border-radius: var(--frame-radius);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08), 0 30px 60px -30px rgba(0, 0, 0, 0.35);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
@media (max-width: 480px) {
  .frame { padding: 0 16px 40px; --frame-pad: 16px; --frame-radius: 22px; }
}

/* ---------- Hlavička: segmentový přepínač + ikony ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  padding: 14px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.tabs {
  display: inline-flex; gap: 2px;
  padding: 3px; border-radius: var(--r-pill);
  background: var(--bg-raised);
}
/* ikony (režim, odhlášení) vpravo */
.topbar .theme-toggle { margin-left: auto; }
.tab {
  padding: 7px 14px;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  border-radius: var(--r-pill);
  transition: color 120ms ease, background 160ms ease;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--bg); background: var(--text); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; color: var(--text-muted);
  background: none; border: 0; padding: 0; border-radius: var(--r-pill);
  transition: color 120ms ease, background 120ms ease, transform 200ms var(--ease-pop);
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn:active { transform: scale(0.9); }
.theme-toggle .icon-sun, .theme-toggle .icon-moon { display: none; }
:root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
:root[data-theme="light"] .theme-toggle .icon-moon { display: block; }
.theme-toggle .icon { transition: transform 400ms var(--ease-pop); }
.theme-toggle:hover .icon { transform: rotate(25deg); }
.auth-toggle { position: absolute; top: 14px; right: 14px; }

/* ---------- Stránka ---------- */
.page { padding-top: 22px; }
.page-head h1, .month-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-stretch: 112%;
  font-size: clamp(20px, 8.2cqw, 30px); /* podle šířky desky (container query) — „červenec 2026" se nesmí zalomit */
  line-height: 1;
  letter-spacing: -0.02em;
  margin: 0;
  white-space: nowrap;
}
/* stejná výška a zarovnání jako .month-nav, ať nadpis mezi taby nelítá */
.page-head { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 44px; margin-bottom: 24px; container-type: inline-size; }
.section { margin-top: 40px; padding-top: 22px; border-top: 1px solid var(--line-soft); }
.section-title {
  font-family: var(--font-display); font-weight: 700; font-stretch: 105%;
  font-size: 15px; letter-spacing: -0.01em;
  margin: 0 0 16px;
}
.empty { color: var(--text-muted); padding: 30px 0; text-align: center; }
.empty a { color: var(--text); font-weight: 600; border-bottom: 2px solid var(--text); }
.hint { color: var(--text-faint); font-size: 12px; margin: 10px 0 0; }
.link-muted { color: var(--text-muted); font-size: 13px; border-bottom: 1px solid var(--line); transition: color 120ms ease; }
.link-muted:hover { color: var(--text); border-color: var(--text); }
.page-actions { margin-top: 34px; display: flex; gap: 8px; }

.flash {
  padding: 11px 16px; margin-bottom: 18px; font-size: 13px; font-weight: 500;
  border-radius: var(--r-input); background: var(--bg-raised); color: var(--text);
  animation: flash-in 320ms var(--ease-pop);
}
.flash-ok   { background: color-mix(in srgb, var(--positive) 22%, var(--bg)); }
.flash-warn { background: color-mix(in srgb, var(--warning) 18%, var(--bg)); }
.flash-error, .flash-err { background: color-mix(in srgb, var(--negative) 16%, var(--bg)); }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---------- Navigace měsíc / rok ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 6px; container-type: inline-size; }
.month-nav .month-title { min-width: 0; }
.month-title { text-transform: capitalize; text-align: center; flex: 1; }
.nav-arrow {
  flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; color: var(--text-muted);
  border-radius: var(--r-pill);
  transition: color 120ms ease, background 120ms ease, transform 200ms var(--ease-pop);
}
.nav-arrow:hover { color: var(--text); background: var(--bg-hover); }
.nav-arrow:active { transform: scale(0.9); }

/* ---------- Souhrn: tři čísla vlevo / střed / vpravo ---------- */
.stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  container-type: inline-size;
  margin: 26px 0 22px; padding: 16px 0;
  border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft);
}
.stat { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.stat:nth-child(1) { text-align: left; }
.stat:nth-child(2) { text-align: center; }
.stat:nth-child(3) { text-align: right; align-items: flex-end; }
.stat-label { font-size: 12px; color: var(--text-muted); }
.stat-value {
  font-family: var(--font-display); font-weight: 800; font-stretch: 112%; letter-spacing: -0.02em;
  line-height: 1; font-size: clamp(16px, 7.2cqw, 28px); /* podle šířky desky, ať se šestimístné částky vejdou do třetiny */
  overflow: hidden; text-overflow: ellipsis;
}
/* hotovo = zbývá 0 → pilulka místo čísla */
.stat-done .stat-value {
  display: inline-block;
  font-size: 13px; font-family: var(--font-sans); font-weight: 700; letter-spacing: 0;
  padding: 6px 12px; border-radius: var(--r-pill);
  background: var(--accent); color: var(--accent-ink);
  animation: pop 360ms var(--ease-pop);
}
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Seznam položek (měsíc) ---------- */
.expense-list { list-style: none; margin: 0; padding: 0; }
.expense {
  display: flex; align-items: center; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid var(--line-soft);
}
.expense-main { flex: 1; min-width: 0; }
.expense-name {
  display: block; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color 160ms ease;
}
.expense-name:hover { text-decoration: underline; text-decoration-thickness: 2px; text-decoration-color: var(--text); text-underline-offset: 3px; }
.expense-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.expense-side { text-align: right; }
.expense-amount {
  font-family: var(--font-display); font-weight: 700; font-stretch: 108%; letter-spacing: -0.02em;
  font-size: 19px; line-height: 1.1; transition: color 160ms ease;
}
.expense-due { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.expense.is-overdue .expense-due, .expense.is-missed .expense-due { color: var(--negative); font-weight: 600; }
.expense.is-paid .expense-name, .expense.is-paid .expense-amount { color: var(--text-muted); }
.expense.is-paid .expense-due { color: var(--text-faint); }

/* Velký čtverec — hlavní ovládací prvek a jediná velká animace v appce.
   Nezaplaceno = šrafování v barvě kategorie s rámečkem tenkým jako čára
   šrafování, zaplaceno = plná barva + fajfka dokreslená tahem. */
.square {
  flex: none;
  width: var(--square); height: var(--square);
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid color-mix(in srgb, var(--cat) 60%, transparent);
  border-radius: var(--r-square);
  /* šrafování nahoře, pod ním podklad (--wash), který se na hover zalije barvou */
  --wash: transparent;
  background:
    repeating-linear-gradient(135deg, transparent 0 3px, color-mix(in srgb, var(--cat) 28%, transparent) 3px 4.5px),
    linear-gradient(var(--wash), var(--wash));
  color: transparent;
  transition: --wash 140ms ease, border-color 140ms ease, transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
  -webkit-tap-highlight-color: transparent;
}
.square:hover { --wash: color-mix(in srgb, var(--cat) 18%, transparent); border-color: var(--cat); }
.square:active { transform: scale(0.94); transition-duration: 140ms, 140ms, 60ms; }
.square[aria-checked="true"] { background: var(--cat); border-color: var(--cat); color: var(--check-ink); }
.square .icon polyline { stroke-width: 2.4; }
/* právě odkliknuto (třídu dává app.js po výměně snippetu) */
/* krátké, tvrdé — jako fyzické tlačítko: stlačit a vrátit, bez přestřelení */
.square.just-paid { animation: square-pop 240ms cubic-bezier(0.22, 1, 0.36, 1); }
.square.just-paid .icon polyline {
  stroke-dasharray: 24; stroke-dashoffset: 24;
  animation: draw-check 180ms ease-out 40ms forwards;
}
@keyframes square-pop { 0% { transform: scale(0.9); } 100% { transform: none; } }
@keyframes draw-check { to { stroke-dashoffset: 0; } }

.cat-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--cat); flex: none; }
.cat-dot-lg { width: 16px; height: 16px; border-radius: 5px; }

.cat-summary { margin-top: 18px; display: flex; flex-direction: column; gap: 7px; }
.cat-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-muted); }
.cat-name { flex: 1; }
.cat-nums { color: var(--text-faint); }

/* ---------- Roční matice ---------- */
.matrix-tools { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 12px; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend .sq { --cat: var(--text-muted); width: 12px; height: 12px; }

/* Tabulka jde až ke krajům desky a scrolluje se vodorovně uvnitř. Odstup od
   krajů dělá vnitřní inline-block s paddingem (padding samotného scroll
   kontejneru Safari na konci zahodí). overscroll-behavior brání přenosu na desku. */
.matrix-wrap {
  overflow-x: auto; overflow-y: hidden;
  margin: 0 calc(-1 * var(--frame-pad));
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}
.matrix-inner { display: inline-block; min-width: 100%; padding: 0 var(--frame-pad); vertical-align: top; }
.matrix { border-collapse: collapse; width: 100%; min-width: 590px; }
.matrix th {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
  text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--line);
}
.matrix td { padding: 9px 4px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.matrix .col-name { width: 100%; min-width: 150px; }
.matrix .col-amount, .matrix .col-sum { text-align: right; padding-right: 10px; }
.matrix th:first-child, .matrix td:first-child { padding-left: 4px; }
.matrix th:last-child, .matrix td:last-child { padding-right: 4px; }
.matrix .col-m { text-align: center; width: 28px; padding-left: 2px; padding-right: 2px; }
.matrix tfoot td { border-bottom: 0; border-top: 1px solid var(--line); color: var(--text-muted); font-size: 12px; padding-top: 10px; }
.matrix tfoot .col-sum { color: var(--text); font-size: 14px; font-weight: 700; }
.month-total { font-size: 11px; }
.row-name { font-weight: 600; letter-spacing: -0.01em; }
.row-name:hover { text-decoration: underline; text-decoration-thickness: 2px; text-decoration-color: var(--text); text-underline-offset: 3px; }
.row-meta { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
tr.is-archived { opacity: 0.4; }

/* malé čtverce ve 4 stavech */
.sq {
  display: inline-block; width: 18px; height: 18px; vertical-align: middle;
  border: 1.5px solid var(--cat); border-radius: var(--r-sq);
  -webkit-tap-highlight-color: transparent;
  transition: transform 160ms var(--ease-pop);
}
a.sq:hover { transform: scale(1.18); }
.sq-paid { background: var(--cat); }
.sq-due, .sq-upcoming { border-color: color-mix(in srgb, var(--cat) 55%, transparent); }
.sq-upcoming { border-style: dashed; }
.sq-overdue, .sq-missed {
  border-color: var(--negative);
  background: repeating-linear-gradient(135deg, transparent 0 3px, var(--negative-soft) 3px 4.5px);
}
.sq-none { width: 4px; height: 4px; border: 0; border-radius: 1px; background: var(--text-faint); }

/* ---------- Kategorie v nastavení ---------- */
.cat-list { list-style: none; margin: 0; padding: 0; }
.cat-item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.cat-item .cat-name { font-size: 15px; font-weight: 600; }
.cat-order { color: var(--text-faint); font-size: 12px; margin-right: 8px; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { position: relative; width: 40px; height: 40px; cursor: pointer; }
.swatch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.swatch span {
  display: block; width: 100%; height: 100%; background: var(--cat);
  border-radius: 12px; border: 3px solid transparent;
  transition: transform 180ms var(--ease-pop);
}
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { border-color: var(--text); box-shadow: inset 0 0 0 3px var(--bg); transform: scale(1.08); }
.swatch input:focus-visible + span { outline: 3px solid var(--text); outline-offset: 2px; }

/* ---------- Formuláře ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label, .field > label { font-size: 12.5px; color: var(--text-muted); font-weight: 500; }
.field input[type=text], .field input[type=email], .field input[type=password], .field input[type=number], .field select {
  font: inherit; font-size: 15px; color: var(--text);
  background: var(--bg-raised); border: 2px solid transparent; padding: 11px 14px; width: 100%;
  border-radius: var(--r-input); appearance: none; -webkit-appearance: none;
  transition: border-color 120ms ease, background 120ms ease;
}
.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 15px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--text); background: var(--bg); }
.field input:disabled { opacity: 0.4; }
.field-hint { font-size: 12px; color: var(--text-muted); }
.field-check { justify-content: flex-end; gap: 2px; }
.check { display: inline-flex; align-items: center; gap: 9px; font-size: 14px; color: var(--text); padding: 10px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 480px) { .grid-2 { grid-template-columns: 1fr; } }

/* frekvence = segmentový přepínač jako záložky */
.radio-row { display: inline-flex; align-self: flex-start; gap: 2px; padding: 3px; border-radius: var(--r-pill); background: var(--bg-raised); }
.radio-pill { position: relative; cursor: pointer; }
.radio-pill input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.radio-pill span {
  display: inline-block; padding: 8px 16px; border-radius: var(--r-pill);
  color: var(--text-muted); font-size: 13.5px; font-weight: 600;
  transition: color 120ms ease, background 160ms ease;
}
.radio-pill:hover span { color: var(--text); }
.radio-pill input:checked + span { background: var(--text); color: var(--bg); }
.radio-pill input:focus-visible + span { outline: 3px solid var(--text); outline-offset: 2px; }

.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.form-actions .spacer { flex: 1; }
.form-errors {
  list-style: none; margin: 0 0 16px; padding: 11px 16px; font-size: 13px; font-weight: 500;
  color: var(--text); background: color-mix(in srgb, var(--negative) 16%, var(--bg)); border-radius: var(--r-input);
}
.form-errors li + li { margin-top: 4px; }

/* tlačítka: pilulky; primární = inkoust na papíře (v tmavém bílá na černé) */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px; font-size: 13.5px; font-weight: 600;
  color: var(--text); background: transparent; border: 2px solid var(--line); border-radius: var(--r-pill);
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, transform 200ms var(--ease-pop);
}
.btn:hover { border-color: var(--text); }
.btn:active { transform: scale(0.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { background: transparent; color: var(--text); border-color: var(--text); }
.btn.danger { color: var(--negative); border-color: color-mix(in srgb, var(--negative) 40%, transparent); }
.btn.danger:hover { background: var(--negative); color: #fff; border-color: var(--negative); }
.row-action { display: inline-flex; padding: 6px; color: var(--text-muted); border-radius: var(--r-pill); transition: color 120ms ease, background 120ms ease; }
.row-action:hover { color: var(--text); background: var(--bg-hover); }
.row-action.danger:hover { color: var(--negative); }

/* ---------- Přihlášení ---------- */
.auth-box { max-width: 320px; margin: 24px auto 0; }
.auth-hero { display: block; width: 70%; max-width: 224px; height: auto; margin: 10px auto 22px; }
.auth-box .btn.primary { width: 100%; justify-content: center; padding: 13px 18px; font-size: 14.5px; }

/* ---------- Bez animací, když si to člověk nepřeje ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
