:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --text: #1b2430;
    --muted: #5d6b7c;
    --border: #d9e0e8;
    --primary: #1f4e79;
    --primary-text: #ffffff;
    --accent: #2b7bd1;
    --ok: #2e8b57;
    --ok-bg: #e3f4e8;
    --ok-text: #1d6b34;
    --head-1: #d6e0ec;
    --head-2: #e4ebf3;
    --head-3: #eef2f7;
    --head-4: #f5f8fb;
    --danger: #c0392b;
    --danger-bg: #fdecea;
    --warn-bg: #fff4d6;
    --warn-text: #6b4e00;
    --bar-bg: #e3e9f0;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --radius: 10px;
    --tap: 44px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0f141a;
        --surface: #171e26;
        --surface-2: #1f2832;
        --text: #e6ebf1;
        --muted: #9aa8b8;
        --border: #2c3744;
        --primary: #5b9bd5;
        --primary-text: #0b1620;
        --accent: #6fb1f0;
        --ok: #4cbb7f;
        --ok-bg: #173a27;
        --ok-text: #8fe0b2;
        --head-1: #2b3846;
        --head-2: #25303c;
        --head-3: #202a34;
        --head-4: #1b232c;
        --danger: #ff6b5e;
        --danger-bg: #3a1d1a;
        --warn-bg: #3a3014;
        --warn-text: #f3d98b;
        --bar-bg: #2a3440;
        --shadow: none;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1f2832;
    --text: #e6ebf1;
    --muted: #9aa8b8;
    --border: #2c3744;
    --primary: #5b9bd5;
    --primary-text: #0b1620;
    --accent: #6fb1f0;
    --ok: #4cbb7f;
    --ok-bg: #173a27;
    --ok-text: #8fe0b2;
    --head-1: #2b3846;
    --head-2: #25303c;
    --head-3: #202a34;
    --head-4: #1b232c;
    --danger: #ff6b5e;
    --danger-bg: #3a1d1a;
    --warn-bg: #3a3014;
    --warn-text: #f3d98b;
    --bar-bg: #2a3440;
    --shadow: none;
    color-scheme: dark;
}


* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    padding-bottom: env(safe-area-inset-bottom);
}

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.pad { padding: 12px 16px; margin: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--danger) !important; }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- horní lišta */

.topbar {
    position: sticky; top: 0; z-index: 10;
    background: var(--primary); color: var(--primary-text);
    padding-top: env(safe-area-inset-top);
    box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}

.topbar-row {
    display: flex; align-items: center; gap: 8px;
    max-width: var(--frame-w, 1200px); margin: 0 auto; padding: 8px 16px;
}

.brand { font-size: 18px; margin: 0; flex: 1; font-weight: 650; letter-spacing: .2px; white-space: nowrap; }
.brand span { opacity: .75; font-weight: 500; }

.year-picker select {
    min-height: 38px; padding: 4px 8px; border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .12); color: inherit; font: inherit; font-weight: 600;
}
.year-picker select option { color: #1b2430; }

.icon-btn {
    min-width: var(--tap); min-height: var(--tap); border: 0; border-radius: 8px;
    background: transparent; color: inherit; font-size: 20px; cursor: pointer; line-height: 1;
}
.icon-btn:hover:not(:disabled) { background: rgba(127, 127, 127, .15); }
.icon-btn:disabled { opacity: .4; cursor: default; }

.tabs {
    display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none;
    max-width: var(--frame-w, 1200px); margin: 0 auto; padding: 0 12px;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-start;
    min-height: var(--tap); padding: 6px 14px 8px; border: 0; border-bottom: 3px solid transparent;
    background: transparent; color: inherit; font: inherit; cursor: pointer; opacity: .8;
}
.tab.active { opacity: 1; border-bottom-color: currentColor; }
.tab[draggable="true"] { cursor: grab; }
.tab.dragging { opacity: .4; }
.tab.drop-before { box-shadow: inset 3px 0 0 currentColor; }
.tab.drop-after { box-shadow: inset -3px 0 0 currentColor; }
.tab-code { font-weight: 700; font-size: 14px; }
.tab-name { font-size: 12px; opacity: .85; }
.tab-add { font-size: 22px; justify-content: center; align-items: center; }

/* ---------------------------------------------------------------- obsah */

main { max-width: var(--frame-w, 1200px); margin: 0 auto; padding: 16px; }

.banner { max-width: var(--frame-w, 1200px); margin: 12px auto 0; padding: 10px 16px; border-radius: var(--radius); }
.banner-warn { background: var(--warn-bg); color: var(--warn-text); margin: 12px 16px 0; }
@media (min-width: 1232px) { .banner-warn { margin: 12px auto 0; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

.summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat { padding: 12px 14px; min-width: 0; display: flex; flex-direction: column; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.stat-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; overflow-wrap: anywhere; }
.stat-sub { font-size: 13px; color: var(--muted); }
.stat > .bar { margin-top: auto; flex: none; } /* ukazatele ve všech kartách na stejné výšce */
.stat > :nth-last-child(2) { margin-bottom: 8px; }

/* Při scrollování dolů se přehled přilepí pod horní lištu a karty se animovaně zploští: zůstane
   v nich jen popis a částka. Výška přehledu v toku stránky (--sum-h) se nemění, takže obsah
   neposkakuje; průhledná část pod zploštělými kartami propouští kliky na obsah pod ní. */
.summary {
    position: sticky; top: calc(var(--topbar-h, 0px) + 8px); z-index: 5;
    height: var(--sum-h, auto); align-content: start; pointer-events: none;
    --stat-c: 58px; --cmp-h: var(--stat-c);
}
.summary > .stat { pointer-events: auto; position: relative; height: var(--stat-h, auto); overflow: hidden; }
.summary > .stat > * { flex-shrink: 0; } /* při zploštění se nic nemačká, přebytek se jen ořízne dole */
.summary.animated > .stat { transition: height .25s ease, padding .25s ease; }
.summary.animated .stat-value { transition: font-size .25s ease; }
.summary.animated .stat-sub, .summary.animated .stat > .bar { transition: opacity .15s ease; }
.summary::before {
    content: ""; position: absolute; left: -16px; right: -16px; top: -8px; height: calc(var(--cmp-h) + 16px);
    background: var(--bg); opacity: 0; transition: opacity .2s ease; pointer-events: none;
}
.summary.compact::before { opacity: 1; pointer-events: auto; }
.summary.compact > .stat { height: var(--stat-c); padding-top: 8px; padding-bottom: 8px; }
.summary.compact .stat-value { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; overflow-wrap: normal; }
.summary.compact .stat-sub, .summary.compact .stat > .bar { opacity: 0; }

.bar { height: 6px; border-radius: 3px; background: var(--bar-bg); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.full span { background: var(--ok); }
.bar.over span { background: var(--danger); }
.c-amt .bar { height: 4px; margin-top: 3px; }
.bar.inv span { margin-left: auto; }
.c-amt.done { color: var(--ok-text); }
.c-amt.done .bar span { background: var(--ok); }

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] {
    flex: 1 1 220px; min-height: var(--tap); padding: 8px 12px; font: inherit; font-size: 16px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}

.btn {
    min-height: var(--tap); padding: 8px 14px; border-radius: 8px; border: 1px solid transparent;
    font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn-sm { min-height: 36px; padding: 4px 10px; font-size: 14px; }
.btn-primary { background: var(--primary); color: var(--primary-text); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }

.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; text-align: left; }
.link:hover { text-decoration: underline; }

.kind-section { margin-bottom: 24px; }
.kind-head { display: flex; align-items: center; justify-content: space-between; margin: 0 0 8px; }
.kind-head h2 { font-size: 18px; margin: 0; }

/* Řádky: číslo | název | [vlastní sloupce] | oddělovač (+) | naplánováno | vyčerpáno | zbývá | akce
   Odsazení: podkapitola je na stejné úrovni jako položky nadřazené kapitoly (3.2 a 3.3),
   odsazují se až její položky (3.3.1). --lvl = hloubka kapitoly − 1, --ind = krok odsazení. */
#main { --ind: 22px; --amt: 130px; --sep: 28px; --numw: 64px; }
.col-head, .row {
    display: grid;
    grid-template-columns: var(--numw) minmax(0, 1fr) var(--xcols,) var(--sep) var(--amt) var(--amt) var(--amt) var(--tap);
    gap: 8px; align-items: center;
}
.col-head { padding: 0 12px 4px 12px; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.col-head > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chapter > .col-head { padding-top: 10px; align-items: center; }
/* Úzký oddělovač mezi volitelnými sloupci a částkami; v záhlaví je v něm uprostřed „+“ (přidat sloupec). */
.col-head > .h-sep { display: flex; align-items: center; justify-content: center; overflow: visible; }
.chapter + .chapter > .col-head { padding-top: 14px; }
.col-head .h-col { font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; background: none; border: 0; padding: 2px 4px; margin: -2px -4px; border-radius: 6px; text-align: left; }
.col-head .h-col.num { text-align: right; }
.col-head.can-manage .h-col { cursor: grab; }
.col-head.can-manage .h-col:hover { background: var(--surface-2); color: var(--text); }
.col-head .h-col.dragging { opacity: .4; }
.col-head .drop-before { box-shadow: inset 3px 0 0 var(--accent); }
.col-head .drop-after { box-shadow: inset -3px 0 0 var(--accent); }
.col-add { position: relative; flex: none; width: 20px; height: 20px; line-height: 18px; padding: 0; border-radius: 4px; border: 1px solid var(--border); background: var(--surface); color: var(--accent); font-size: 14px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
/* bublina s popisem až po 1 s držení kurzoru (nebo při fokusu z klávesnice) */
.col-add::after {
    content: attr(data-tip); position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 20;
    padding: 4px 8px; border-radius: 6px; background: var(--text); color: var(--surface); font-size: 12px; font-weight: 500;
    text-transform: none; letter-spacing: normal; white-space: nowrap; pointer-events: none;
    opacity: 0; visibility: hidden; transition: opacity .15s, visibility .15s;
}
.col-add:hover::after, .col-add:focus-visible::after { opacity: 1; visibility: visible; transition-delay: 1s; }
.col-add:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

.tree { display: flex; flex-direction: column; gap: 10px; }

.chapter { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.chapter .chapter { border: 0; border-radius: 0; box-shadow: none; border-top: 1px solid var(--border); }
.row { padding: 6px 12px; min-height: 48px; }
.chapter-row {
    background: var(--head-4); font-weight: 650;
    grid-template-columns: 28px 36px minmax(0, 1fr) var(--xcols,) var(--sep) var(--amt) var(--amt) var(--amt) var(--tap);
    padding-left: calc(12px + max(0, var(--lvl, 0) - 1) * var(--ind));
}
/* záhlaví podkapitoly je vždy světlejší než úroveň nad ní */
.depth-1 > .chapter-row { background: var(--head-1); }
.depth-2 > .chapter-row { background: var(--head-2); font-weight: 600; }
.depth-3 > .chapter-row { background: var(--head-3); font-weight: 600; }
.depth-4 > .chapter-row { background: var(--head-4); font-weight: 600; }
.item-row { border-top: 1px solid var(--border); padding-left: calc(40px + var(--lvl, 0) * var(--ind)); }
.c-x { min-width: 0; overflow-wrap: anywhere; font-size: 14px; }
.chapter-row .c-x { color: var(--muted); }
.field-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
body.read-only .edit-only { display: none; }
.item-row.is-over { background: var(--danger-bg); }
.add-row { display: flex; gap: 8px; border-top: 1px solid var(--border); padding-left: calc(40px + var(--lvl, 0) * var(--ind)); min-height: 52px; }

.toggle { width: 28px; height: 36px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 0; }
.c-num { color: var(--muted); font-variant-numeric: tabular-nums; }
.chapter-row .c-num { color: var(--text); }
.c-name { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.c-name .name { overflow-wrap: anywhere; }
.note { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.more { color: var(--muted); }

.empty { text-align: center; padding: 48px 16px; }
.small { font-size: 13px; }

/* přihlášení */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: min(400px, 100%); padding: 24px; display: flex; flex-direction: column; }
.auth-card img { align-self: center; }
.auth-card h1 { text-align: center; font-size: 22px; margin: 8px 0 4px; }
.auth-card > p { text-align: center; margin: 0 0 16px; }
.auth-card .small { margin: 12px 0 0; }
.btn-block { width: 100%; }

/* probíhající komunikace se serverem */
.busy-bar { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 100; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity .2s; }
.busy-bar::after { content: ""; position: absolute; inset: 0; width: 40%; background: var(--accent); animation: busy 1s ease-in-out infinite; }
body.busy .busy-bar { opacity: 1; }
@keyframes busy { from { transform: translateX(-100%); } to { transform: translateX(250%); } }

/* jen čtení */
body.read-only .kind-head .btn { display: none; }

/* konflikt souběžné úpravy */
.diff { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0; }
.diff th, .diff td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; overflow-wrap: anywhere; }
.diff thead th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.diff td:last-child { font-weight: 600; }
.form-notice { color: var(--warn-text); background: var(--warn-bg); padding: 8px 10px; border-radius: 8px; margin: 4px 0 0; }

/* nastavení: účet a přístupy */
.settings-card + .settings-card { margin-top: 12px; }
.legend { font-weight: 650; margin-bottom: 8px; }
.settings-line { margin: 0 0 8px; }
.settings-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.role-list { margin: 0 0 8px; padding-left: 20px; }
.settings code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }

.settings { max-width: 640px; }
.settings h2 { font-size: 18px; margin: 4px 0 12px; }
.settings-card { padding: 8px 16px; }
.settings-group { border: 0; margin: 0; padding: 8px 0; }
.settings-group legend { font-weight: 650; padding: 0; margin-bottom: 8px; }
.radio { display: flex; gap: 12px; align-items: flex-start; min-height: var(--tap); padding: 8px 0; cursor: pointer; border-top: 1px solid var(--border); }
.radio:first-of-type { border-top: 0; }
.radio input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.radio small { display: block; color: var(--muted); font-size: 13px; }
.tab-admin { margin-left: auto; }
.tab-settings { margin-left: auto; }
.tab-admin + .tab-settings { margin-left: 0; }

/* administrace: role a práva */
.admin { max-width: 1100px; }
.admin h2 { font-size: 18px; margin: 4px 0 4px; }
.admin-intro { margin: 0 0 12px; }
.admin-card { padding: 12px 16px; min-width: 0; }
.admin-card + .admin-card { margin-top: 12px; }
.admin-card h3 { font-size: 16px; margin: 0 0 8px; }
.role-rows { list-style: none; margin: 0; padding: 0; }
.role-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.role-row:first-child { border-top: 0; }
.role-name { flex: 1 1 180px; min-width: 0; min-height: 40px; font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.role-row .check { display: flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.role-row .check input { width: 18px; height: 18px; accent-color: var(--primary); }
.role-count { min-width: 90px; }
.role-add { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.role-add input { flex: 1 1 200px; min-width: 0; min-height: 40px; font: inherit; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.matrix { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.matrix th, .matrix td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.matrix thead th { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.matrix tbody th { font-weight: 600; white-space: nowrap; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.matrix .user-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.matrix .center { text-align: center; }
.matrix .eff { min-width: 160px; }
.big-check { width: 22px; height: 22px; accent-color: var(--primary); cursor: pointer; }
select.acc { min-height: 36px; font: inherit; font-size: 14px; padding: 4px 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.acc-edit, .acc-manage { background: var(--ok-bg) !important; color: var(--ok-text) !important; border-color: transparent; }
.acc-manage { box-shadow: inset 0 0 0 2px var(--ok-text); }
.acc-read { background: var(--surface-2) !important; color: var(--text) !important; border-color: transparent; }
select.acc-none { color: var(--muted); }
.chip-admin { background: var(--primary); color: var(--primary-text); }

.foot { max-width: var(--frame-w, 1200px); margin: 0 auto; padding: 8px 16px 32px; font-size: 13px; color: var(--muted); }
.foot p { margin: 4px 0; }

/* ---------------------------------------------------------------- dialog */

dialog {
    width: min(520px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto;
    border: 1px solid var(--border); border-radius: 14px; padding: 0;
    background: var(--surface); color: var(--text); box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 15, 25, .45); }
dialog form { padding: 18px; }
dialog h3 { margin: 0 0 12px; font-size: 18px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; flex: 1; min-width: 0; }
.field span { font-size: 13px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea {
    font: inherit; font-size: 16px; /* 16px brání přiblížení na iPhonu */
    min-height: var(--tap); padding: 8px 10px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%;
}
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-pair { display: flex; gap: 12px; }
.check { display: flex; gap: 8px; align-items: center; min-height: var(--tap); }
.check input { width: 20px; height: 20px; }
.hint { font-size: 13px; color: var(--muted); margin: 0 0 8px; }
.form-error { color: var(--danger); background: var(--danger-bg); padding: 8px 10px; border-radius: 8px; margin: 4px 0 0; }

.sheet-list { display: flex; flex-direction: column; }
.sheet-list hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; width: 100%; }
.sheet-btn {
    min-height: var(--tap); text-align: left; padding: 10px 12px; border: 0; border-radius: 8px;
    background: transparent; color: var(--text); font: inherit; font-size: 16px; cursor: pointer;
}
.sheet-btn:hover:not(:disabled) { background: var(--surface-2); }
.sheet-btn:disabled { opacity: .4; cursor: default; }
.sheet-btn.danger { color: var(--danger); }

/* ---------------------------------------------------------------- toast */

.toast {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 50;
    display: flex; gap: 16px; align-items: center;
    max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 10px;
    background: #1b2430; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
}
.toast .link { color: #8cc4ff; font-weight: 700; min-height: 32px; }

/* ---------------------------------------------------------------- tablet */

@media (max-width: 900px) {
    #main { --numw: 52px; }
    .summary { grid-template-columns: repeat(2, 1fr); }
    #main { --amt: 110px; --ind: 16px; }
    .col-head, .row { grid-template-columns: var(--numw) minmax(0, 1fr) var(--xcols,) var(--sep) var(--amt) var(--amt) var(--amt) var(--tap); }
    .chapter-row { grid-template-columns: 28px 24px minmax(0, 1fr) var(--xcols,) var(--sep) var(--amt) var(--amt) var(--amt) var(--tap); }
}

/* ---------------------------------------------------------------- telefon: karty místo tabulky */

@media (max-width: 640px) {
    main { padding: 12px; }
    .brand { font-size: 16px; }
    .summary { gap: 8px; }
    .stat { padding: 10px 12px; }
    .stat-value { font-size: 18px; }
    .summary { --stat-c: 54px; --cmp-h: calc(2 * var(--stat-c) + 8px); }
    .summary::before { left: -12px; right: -12px; }
    .summary.compact > .stat { padding-top: 7px; padding-bottom: 7px; }
    .summary.compact .stat-value { font-size: 15px; }
    .col-head { display: none; }
    .toolbar .btn-ghost { flex: 1; }

    /* 6 stejných sloupců: 1. řádek číslo | název | akce, 2. řádek volitelné sloupce (po třech),
       dole tři částky po dvou sloupcích */
    #main { --ind: 10px; }
    .row, .chapter-row { grid-template-columns: repeat(6, minmax(0, 1fr)); row-gap: 2px; column-gap: 6px; }
    .item-row { padding-left: calc(12px + var(--lvl, 0) * var(--ind)); }
    .chapter-row { padding-left: calc(12px + max(0, var(--lvl, 0) - 1) * var(--ind)); }
    .row > .c-x { grid-row: 2; grid-column: span 3; font-size: 13px; }
    .row > .c-x.x-empty { display: none; }
    .x-pad, .c-sep { display: none; }
    .row > .c-x::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .3px; }
    .row > .c-num { grid-column: 1; grid-row: 1; }
    .row > .c-name { grid-column: 2 / span 4; grid-row: 1; }
    .row > .more { grid-column: 6; grid-row: 1; justify-self: end; }
    .chapter-row > .toggle { grid-column: 1; grid-row: 1; justify-self: start; }
    .chapter-row > .c-num { grid-column: 1; grid-row: 1; padding-left: 26px; }
    .chapter-row > .c-name { grid-column: 2 / span 4; }
    .row > .c-amt { grid-row: 3; grid-column: span 2; text-align: left; font-size: 14px; }
    .row > .c-amt::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .3px; }
    .add-row { padding-left: calc(12px + var(--lvl, 0) * var(--ind)); }
    .tab-settings-label, .tab-settings .tab-name, .tab-admin .tab-name { display: none; }
    .role-row .role-name { flex-basis: 100%; }
    .role-row .icon-btn { margin-left: auto; }
    .tab-settings, .tab-admin { justify-content: center; align-items: center; font-size: 20px; }
}

/* ---------------------------------------------------------------- tabulka (počítač, tablet, telefon na šířku)
   Rámec stránky (--frame-w) se rozšíří tak, aby se tabulka vešla; na užší obrazovce se vlastní sloupce
   úměrně zúží (nejvýš na polovinu) a Název až na 140 px (--name-min, jinak 240 px), viz layoutColumns().
   Vodorovné posouvání zůstává jen jako záchrana tam, kde se tabulka nevejde ani tak (telefon na šířku).
   Název se láme jen po slovech, nejvýš na dva řádky (celý je v bublině); vlastní sloupce jsou na jednom řádku. */

@media (min-width: 641px) {
    .tree { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* stejná minimální šířka pro všechny kapitoly, aby sloupce zůstaly pod sebou */
    .tree > .chapter { min-width: calc(var(--numw) + var(--name-min, 240px) + var(--xarea, 0px) + var(--sep) + 3 * var(--amt) + var(--tap) + 72px); }
    .c-name .name {
        overflow-wrap: break-word; word-break: normal;
        display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
    }
    .c-name .note { overflow-wrap: break-word; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .row > .c-x { overflow-wrap: normal; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}

/* ---------------------------------------------------------------- tisk */

@media print {
    .topbar, .toolbar, .more, .toggle, .add-row, .foot, .kind-head .btn, .toast, .banner { display: none !important; }
    body { background: #fff; color: #000; font-size: 11px; }
    main { max-width: none; padding: 0; }
    .card, .chapter { box-shadow: none; break-inside: avoid; }
    .item-row.is-over { background: #fde2df; }
    .summary { position: static; height: auto !important; }
    .summary::before { display: none; }
    .summary > .stat { height: auto !important; }
    .summary .stat-sub, .summary .stat > .bar { opacity: 1 !important; }
}
