:root {
    --plane: #f9f9f7; --surface: #fcfcfb; --ink: #0b0b0b; --ink2: #52514e;
    --muted: #898781; --hair: #e1e0d9; --axis: #c3c2b7;
    --accent: #2a78d6; --accent-strong: #256abf;
    --good: #006300; --bad: #d03b3b; --warn-bg: #fdf3dc; --warn-ink: #7a5300;
    --ring: rgba(11,11,11,0.10);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--plane); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.45; }
a { color: var(--accent-strong); text-decoration: none; }
.card { background: var(--surface); border: 1px solid var(--ring); border-radius: 12px; padding: 18px 20px; }
.btn { display: inline-block; background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--accent-strong); }
input[type=text], input[type=password], select { width: 100%; padding: 10px 12px; border: 1px solid var(--axis); border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink); }
input[type=file] { display: block; padding: 8px; border: 1px dashed var(--axis); border-radius: 8px; background: var(--plane); font-size: 13px; max-width: 480px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.card form label { display: block; font-size: 12px; font-weight: 600; color: var(--ink2); margin: 12px 0 6px; }
.alert { background: #fdecec; color: var(--bad); border: 1px solid rgba(208,59,59,.25); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

/* Přihlášení */
body.login-page { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login { width: 360px; max-width: calc(100vw - 32px); }
.login .brand { text-align: center; margin-bottom: 18px; }
.login .brand p { color: var(--muted); margin: 4px 0 0; }
.login label { display: block; font-size: 12px; font-weight: 600; color: var(--ink2); margin: 14px 0 6px; }
.login .btn { width: 100%; margin-top: 18px; }
.login code { background: var(--plane); border: 1px solid var(--hair); border-radius: 6px; padding: 2px 6px; font-size: 12px; display: inline-block; }
.login pre { background: var(--plane); border: 1px solid var(--hair); border-radius: 8px; padding: 12px; font-size: 12px; overflow-x: auto; }

/* Postranní panel a obsah */
.logo { font-size: 18px; font-weight: 800; letter-spacing: -0.02em; }
.logo span { color: var(--accent); }
.login .logo { font-size: 22px; }
body.app { display: flex; min-height: 100vh; }
.side { width: 220px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--hair); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { padding: 18px 20px 10px; }
.side-search { padding: 4px 12px 2px; }
.side-search input { width: 100%; padding: 8px 10px; border: 1px solid var(--hair); border-radius: 8px; font-size: 13px; background: var(--plane); color: var(--ink); }
.side-search input::placeholder { color: var(--muted); }
.side-nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.navgroup h4 { margin: 14px 8px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.side-nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink2); font-weight: 600; margin-bottom: 2px; }
.side-nav a:hover { background: var(--plane); color: var(--ink); }
.side-nav a.active { background: #eaf2fc; color: var(--accent-strong); }
.navsub { margin: 2px 0 7px 13px; padding-left: 9px; border-left: 1px solid var(--hair); }
.side-nav .navsub a { position: relative; padding: 5px 8px; margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; }
.side-nav .navsub a:hover { color: var(--accent-strong); background: #f2f6fb; }
.side-user { border-top: 1px solid var(--hair); padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink2); font-size: 13px; }
.side-user form { margin: 0; }
.linkbtn { background: none; border: 0; color: var(--accent-strong); cursor: pointer; font-size: 13px; padding: 0; }
main { flex: 1; min-width: 0; max-width: 1200px; padding: 20px 24px 48px; }

/* Nástrojová lišta a přepínač období — drží se u horního okraje při scrollu */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; position: sticky; top: 0; z-index: 40; background: var(--plane); margin: 0 -24px 18px; padding: 12px 24px; border-bottom: 1px solid var(--hair); }
main > .toolbar:first-child { margin-top: -20px; }
.toolbar h1 { font-size: 20px; margin: 0; }
.toolbar .sub { color: var(--muted); font-size: 13px; }
/* Cíle kotev z navigace nesmí zajet pod fixovanou lištu */
[id] { scroll-margin-top: 96px; }
.segmented { display: inline-flex; background: var(--surface); border: 1px solid var(--ring); border-radius: 10px; padding: 3px; }
.seg { padding: 6px 12px; border-radius: 7px; color: var(--ink2); font-size: 13px; font-weight: 600; }
.seg.active { background: var(--accent); color: #fff; }
.seg:not(.active):hover { background: var(--plane); }

/* KPI dlaždice */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi h3 { margin: 0 0 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.kpi .caption { color: var(--muted); font-size: 12px; margin-top: 4px; }
.owner-kpis { grid-template-columns: repeat(3, minmax(210px, 1fr)); }
.kpi-featured { border-color: rgba(42,120,214,.32); box-shadow: inset 0 3px 0 var(--accent); }
.delta { font-size: 12px; font-weight: 700; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.delta-none { color: var(--muted); font-weight: 500; }

/* Karty a tabulky */
.cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-items: start; }
.cards > .card + .card { margin-top: 0; }
.card + .card, .cards + .card, .card + .cards, .kpis + .card { margin-top: 14px; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
.card .hint { color: var(--muted); font-size: 12px; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--hair); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tbody tr:hover td { background: var(--plane); }
.code { color: var(--muted); font-size: 12px; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }
.banner { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid rgba(122,83,0,.2); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; font-size: 13px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; }
.badge-ok { background: #e7f4e7; color: var(--good); }
.badge-err { background: #fdecec; color: var(--bad); }
.cash { font-weight: 700; }
.table-tools { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 6px; }
.table-search { flex: 1; max-width: 360px; }
.table-search input { width: 100%; padding: 7px 10px; border: 1px solid var(--hair); border-radius: 8px; background: #fff; color: var(--ink); font-size: 13px; }
.table-search input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.table-count { color: var(--muted); font-size: 11px; white-space: nowrap; }
.table-scroll { overflow-x: auto; }
th.sortable { cursor: pointer; user-select: none; padding-right: 22px; position: relative; }
th.sortable::after { content: '⇅'; position: absolute; right: 7px; color: var(--axis); font-size: 12px; }
th.sortable[aria-sort="ascending"]::after { content: '↑'; color: var(--accent); }
th.sortable[aria-sort="descending"]::after { content: '↓'; color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.card-link { font-size: 12px; font-weight: 600; white-space: nowrap; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
[id] { scroll-margin-top: 18px; }
.listing-filter { display: flex; align-items: center; gap: 9px; margin: 12px 0; }
.listing-filter label { flex: 1; max-width: 430px; }
.listing-filter input { width: 100%; padding: 8px 10px; border: 1px solid var(--hair); border-radius: 8px; font: inherit; }
.listing-filter button { padding: 8px 13px; border: 1px solid var(--accent); border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
.listing-filter > a { font-size: 12px; }
.listing-count { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.server-sort a { display: block; color: inherit; }
.server-sort[aria-sort="ascending"] a::after { content: ' ↑'; color: var(--accent); }
.server-sort[aria-sort="descending"] a::after { content: ' ↓'; color: var(--accent); }
.pagination { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 5px; margin-top: 18px; }
.pagination a, .pagination span { min-width: 34px; padding: 7px 9px; text-align: center; border-radius: 7px; font-size: 12px; }
.pagination a { border: 1px solid var(--hair); color: var(--ink2); }
.pagination a:hover { border-color: var(--accent); color: var(--accent-strong); }
.pagination a.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
.btn-danger { background: var(--bad); }
.btn-danger:hover { background: #b72f2f; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.rebuild-card { border-color: rgba(208,59,59,.25); }
.rebuild-progress { height: 9px; overflow: hidden; margin: 14px 0 8px; border-radius: 999px; background: var(--hair); }
.rebuild-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .25s ease; }
.file-queue { max-height: 180px; overflow: auto; margin: 8px 0 14px; padding-left: 28px; }
.file-queue li { padding: 2px 0; }

/* Majitelský panel upozornění */
.attention-card { padding-bottom: 20px; }
.attention-grid { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 10px; margin-top: 12px; }
.attention { display: flex; align-items: center; gap: 11px; min-width: 0; padding: 13px; border: 1px solid var(--hair); border-radius: 10px; color: var(--ink); background: var(--plane); }
.attention:hover { border-color: var(--axis); background: #fff; }
.attention-icon { width: 30px; height: 30px; flex: 0 0 30px; display: grid; place-items: center; border-radius: 50%; font-weight: 800; background: #e9e8e3; color: var(--ink2); }
.attention span:last-child { min-width: 0; }
.attention strong, .attention small { display: block; }
.attention strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attention small { color: var(--muted); font-size: 11px; line-height: 1.35; margin-top: 2px; }
.attention-critical .attention-icon { background: #fde4e4; color: var(--bad); }
.attention-warning .attention-icon { background: var(--warn-bg); color: var(--warn-ink); }
.attention-ok .attention-icon { background: #e7f4e7; color: var(--good); }

/* Srovnávací graf */
.chart-legend { display: flex; justify-content: flex-end; gap: 18px; color: var(--muted); font-size: 11px; margin: 0 4px 4px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i { width: 22px; height: 0; border-top: 3px solid var(--accent); }
.chart-legend .legend-previous { border-top: 2px dashed var(--muted); }
.line-chart { display: block; width: 100%; height: auto; }

/* Stránka vyhledávání */
.search-form { display: flex; gap: 10px; align-items: center; }
.search-form input[type=search] { flex: 1; padding: 10px 12px; border: 1px solid var(--axis); border-radius: 8px; font-size: 14px; background: #fff; color: var(--ink); }

/* Roční součty pod měsíčním grafem */
.year-summary { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.year-summary .year { flex: 1 1 170px; max-width: 260px; border: 1px solid var(--hair); border-radius: 10px; padding: 10px 12px; }
.year-summary .year h4 { margin: 0 0 4px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.year-summary .yr-value { font-size: 18px; font-weight: 700; letter-spacing: -0.01em; }
.year-summary .yr-caption { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* ABC klasifikace skladu */
.abc { display: inline-grid; width: 25px; height: 25px; place-items: center; border-radius: 7px; font-size: 12px; font-weight: 800; }
.abc-a { background: #e4f3e6; color: var(--good); }
.abc-b { background: var(--warn-bg); color: var(--warn-ink); }
.abc-c { background: #efefec; color: var(--ink2); }

/* Graf */
.bar:hover path { fill: var(--accent-strong); }
.bar:hover rect:not([fill="transparent"]) { fill: var(--accent-strong); }
svg a { cursor: pointer; }

/* Mini-grafy kanálů (small multiples) */
.multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.multiple { border: 1px solid var(--hair); border-radius: 10px; padding: 12px 14px; }
.multiple-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; font-weight: 600; }
.multiple-head .cash { font-size: 13px; }

/* Drobečková navigace na detailových stránkách */
.crumb { font-size: 13px; margin-bottom: 2px; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--accent-strong); }

@media (max-width: 800px) {
    body.app { flex-direction: column; }
    .side { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
    .side-search { flex: 1 1 160px; padding: 8px; }
    .side-nav { display: flex; padding: 4px 8px; overflow-x: auto; }
    .navgroup { display: flex; align-items: center; flex-wrap: wrap; }
    .navitem-active { flex-basis: 100%; }
    .navsub { display: flex; gap: 2px; margin: 0 8px 5px; padding: 3px 0 0; border-left: 0; overflow-x: auto; }
    .side-nav .navsub a { white-space: nowrap; }
    .navgroup h4 { display: none; }
    .side-nav a { white-space: nowrap; margin: 0 2px; }
    .side-user { border-top: 0; margin-left: auto; }
    main { padding: 16px 14px 40px; }
    .owner-kpis { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
    .attention-grid { grid-template-columns: 1fr 1fr; }
    .card { overflow-x: auto; }
}

@media (max-width: 520px) {
    .attention-grid { grid-template-columns: 1fr; }
    .section-head, .table-tools { align-items: stretch; flex-direction: column; }
    .table-search { max-width: none; }
    .listing-filter { align-items: stretch; flex-wrap: wrap; }
    .listing-filter label { flex-basis: 100%; max-width: none; }
    .listing-count { margin-left: 0; align-self: center; }
}
