/* Design systém aplikace. Popis komponent: DESIGN.md. Bez externích závislostí. */
:root {
  --bg: #f4f2ee;
  --surface: #ffffff;
  --surface-2: #faf8f5;
  --ink: #1c2229;
  --ink-2: #3b4450;
  --muted: #636b78;
  --line: #e4e0d9;
  --line-2: #efece7;
  --brand: #a8482a;
  --brand-2: #8d3a20;
  --brand-ink: #ffffff;
  --brand-soft: #f7e8e1;
  --side: #1f252c;
  --side-ink: #c9ced6;
  --side-active: #2c343d;
  --ok: #2c7a4b;
  --ok-soft: #e2f1e7;
  --warn: #946100;
  --warn-soft: #fbf0d6;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --info: #2c4a73;
  --info-soft: #e6ecf4;
  --ai: #5b3fa0;
  --ai-soft: #f1edfa;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(28, 34, 41, .05), 0 2px 8px rgba(28, 34, 41, .04);
  --side-w: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14.5px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-2); text-decoration: underline; }
h1 { font-size: 1.45rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.02rem; margin: 0 0 .8rem; }
h3 { font-size: .92rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.strong { font-weight: 650; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ico.lg { width: 22px; height: 22px; }
.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; }
.skip-link { position: absolute; left: .75rem; top: -3rem; z-index: 70; background: var(--surface); color: var(--ink); padding: .5rem .8rem; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-weight: 600; }
.skip-link:focus { top: .75rem; }
.main:focus { outline: none; }

/* ---------- Rozvržení ---------- */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--side-w); background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; z-index: 30; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.1rem 1.1rem 1rem; color: #fff; }
.brand:hover { text-decoration: none; color: #fff; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; font-weight: 800; color: #fff; }
.brand strong { display: block; font-size: 1rem; letter-spacing: .04em; }
.brand small { display: block; color: var(--side-ink); font-size: .75rem; }
.bell { position: absolute; top: 1.15rem; right: .9rem; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; color: var(--side-ink); }
.bell:hover, .bell.active { background: var(--side-active); color: #fff; text-decoration: none; }
.bell .count { position: absolute; top: -3px; right: -3px; background: var(--brand); color: #fff; font-size: .66rem; font-weight: 700; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 999px; display: grid; place-items: center; }
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: .25rem .6rem; flex: 1; overflow-y: auto; }
.side-nav a { display: flex; align-items: center; gap: .65rem; padding: .5rem .65rem; border-radius: var(--radius-sm); color: var(--side-ink); font-weight: 500; }
.side-nav a:hover { background: var(--side-active); color: #fff; text-decoration: none; }
.side-nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--brand); }
.side-nav .count { margin-left: auto; background: var(--brand); color: #fff; font-size: .72rem; font-weight: 700; padding: 0 .45rem; border-radius: 999px; }
.side-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: #8a929d; padding: .9rem .65rem .3rem; display: block; }
.side-foot { padding: .9rem; border-top: 1px solid #2f363f; display: grid; gap: .6rem; }
.side-foot select { width: 100%; background: var(--side-active); color: #fff; border: 1px solid #3a434d; }
.side-foot .side-label { padding: 0 0 .25rem; }
.side-foot .btn.ghost { color: var(--side-ink); width: 100%; justify-content: flex-start; }
.side-foot .btn.ghost:hover { background: var(--side-active); color: #fff; }
.who strong { display: block; color: #fff; } .who small { color: var(--side-ink); }
.demo-tag { background: rgba(232, 175, 60, .15); color: #e8b04a; font-size: .72rem; padding: .2rem .55rem; border-radius: 999px; justify-self: start; }

.main { min-height: 100vh; min-width: 0; }
body.with-sidebar .main { margin-left: var(--side-w); }
.page { max-width: 1320px; margin: 0 auto; padding: 1.6rem 2rem 3rem; }
.menu-toggle, .menu-backdrop { display: none; }

@media (max-width: 960px) {
  body.with-sidebar .main { margin-left: 0; }
  /* Zavřené menu je mimo obrazovku i mimo pořadí tabulátoru a čtečky (visibility se přepne až po animaci). */
  .sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .2s, visibility 0s .2s; box-shadow: 0 0 30px rgba(0, 0, 0, .3); z-index: 50; }
  body.menu-open .sidebar { transform: none; visibility: visible; transition: transform .2s; }
  .menu-backdrop { position: fixed; inset: 0; z-index: 45; background: rgba(28, 34, 41, .45); }
  body.menu-open .menu-backdrop { display: block; }
  body.menu-open .menu-toggle { z-index: 55; left: calc(min(var(--side-w), 100vw - 3.5rem) + .7rem); }
  .menu-toggle { display: grid; place-items: center; position: fixed; top: .7rem; left: .7rem; z-index: 40; width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
  .page { padding: 4rem 1rem 2rem; }
}

/* ---------- Hlavička stránky ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.4rem; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: .3rem; display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.crumbs { font-size: .82rem; color: var(--muted); margin-bottom: .35rem; display: flex; gap: .35rem; align-items: center; }
.crumbs a { color: var(--muted); }
.head-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- Karty a mřížky ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.3rem; margin-bottom: 1.25rem; box-shadow: var(--shadow); }
.card.flush { padding: 0; }
.card.flush > .card-head { padding: 1rem 1.3rem .2rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.split { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.sticky { position: sticky; top: 1.2rem; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 900px) { .grid-2, .grid-3, .split { grid-template-columns: minmax(0, 1fr); } }
/* Položky mřížky se nesmí roztáhnout podle nejširšího obsahu (tabulka, dlouhé slovo); tabulky mají vlastní posuv v .table-wrap. */
.grid > *, .split > * { min-width: 0; }

/* ---------- Ukazatele (KPI) ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .78rem; display: flex; align-items: center; gap: .35rem; }
.kpi .value { font-size: 1.3rem; font-weight: 680; font-variant-numeric: tabular-nums; margin-top: .15rem; letter-spacing: -.01em; }
.kpi .hint { color: var(--muted); font-size: .78rem; }
.kpi.good .value { color: var(--ok); }
.kpi.bad .value { color: var(--danger); }
.kpi.accent { border-color: var(--brand); box-shadow: inset 0 3px 0 var(--brand), var(--shadow); }

/* ---------- Tabulky ---------- */
/* position: relative – i absolutně umístěné prvky v buňkách (např. .sr-only popisky) zůstanou uvnitř posuvné oblasti. */
.table-wrap { overflow-x: auto; position: relative; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .7rem; border-bottom: 1px solid var(--line-2); text-align: left; vertical-align: middle; }
thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; background: var(--surface-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; }
.card.flush table th:first-child, .card.flush table td:first-child { padding-left: 1.3rem; }
.card.flush table th:last-child, .card.flush table td:last-child { padding-right: 1.3rem; }
tbody tr:hover { background: #fbf9f6; }
tbody tr.clickable { cursor: pointer; }
tr.total td { font-weight: 680; border-top: 2px solid var(--ink-2); background: var(--surface-2); }
td .sub, .cell-sub { display: block; color: var(--muted); font-size: .8rem; }
.over { color: var(--danger); font-weight: 600; }
.under { color: var(--ok); font-weight: 600; }
th a.sort { color: inherit; } th a.sort:hover { color: var(--ink); text-decoration: none; }

/* ---------- Čerpání ---------- */
.bar { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; min-width: 70px; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 3px; max-width: 100%; }
.bar.ok > span { background: var(--ok); }
.bar.over > span { background: var(--danger); }
.meter { display: flex; align-items: center; gap: .5rem; } .meter .bar { flex: 1; } .meter small { color: var(--muted); min-width: 2.6rem; text-align: right; }

/* ---------- Štítky ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 650; white-space: nowrap; background: var(--line-2); color: var(--ink-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.badge.neutral, .badge.draft, .badge.received { background: var(--info-soft); color: var(--info); }
.badge.warn, .badge.pending, .badge.site_approval, .badge.pm_approval, .badge.owner_approval, .badge.open { background: var(--warn-soft); color: var(--warn); }
.badge.ok, .badge.approved, .badge.paid, .badge.exported, .badge.awarded, .badge.closed { background: var(--ok-soft); color: var(--ok); }
.badge.danger, .badge.rejected, .badge.cancelled { background: var(--danger-soft); color: var(--danger); }
.badge.ai { background: var(--ai-soft); color: var(--ai); }

/* ---------- Upozornění ---------- */
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .95rem; border-radius: var(--radius-sm); margin-bottom: .6rem; border: 1px solid transparent; }
.alert.danger, .alert.error { background: var(--danger-soft); color: var(--danger); border-color: #f0c3bf; }
.alert.warning { background: var(--warn-soft); color: var(--warn); border-color: #f0dcab; }
.alert.success { background: var(--ok-soft); color: var(--ok); border-color: #c2e1cd; }
.alert.info { background: var(--info-soft); color: var(--info); border-color: #ccd8e8; }
.toasts { margin-bottom: 1rem; }
.ai-box { background: var(--ai-soft); border: 1px solid #ddd3f3; color: #3f2b78; border-radius: var(--radius-sm); padding: .75rem .95rem; margin-bottom: 1rem; display: flex; gap: .6rem; }
.ai-box .ico { color: var(--ai); }

/* ---------- Tlačítka ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; font: inherit; font-weight: 600; font-size: .9rem; padding: .5rem .95rem; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { text-decoration: none; border-color: #cfc9c0; background: var(--surface-2); color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover { filter: brightness(.95); color: #fff; }
.btn.danger { color: var(--danger); border-color: #efc3bf; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: .3rem .6rem; font-size: .82rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .9rem; }
.actions.end { justify-content: flex-end; }

/* ---------- Filtry a záložky ---------- */
.toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 360px; }
.toolbar .search input { padding-left: 2rem; }
.toolbar .search .ico { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar select, .toolbar input { width: auto; max-width: 100%; }
.chips { display: flex; gap: .35rem; flex-wrap: wrap; }
.chip { padding: .3rem .7rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .82rem; font-weight: 550; }
.chip:hover { text-decoration: none; border-color: #cfc9c0; color: var(--ink); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.chip .n { opacity: .65; margin-left: .25rem; }
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.2rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Formuláře ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid .wide, .form-grid .full { grid-column: 1 / -1; }
.form-grid > * { min-width: 0; }
@media (max-width: 700px) { .form-grid, .form-grid.cols-3 { grid-template-columns: minmax(0, 1fr); } }
.field label, label { display: block; font-size: .78rem; font-weight: 600; color: var(--ink-2); margin-bottom: .25rem; }
.field .help { font-size: .76rem; color: var(--muted); margin-top: .2rem; }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); padding: .5rem .6rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(168, 72, 42, .25); border-color: var(--brand); }
input[type="checkbox"], input[type="radio"] { width: auto; }
label.check { display: inline-flex; align-items: center; gap: .5rem; font-size: .9rem; font-weight: 600; color: var(--ink); cursor: pointer; }
label.check input { margin: 0; width: 16px; height: 16px; }
.form-section { color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; margin: 1rem 0 .55rem; }
textarea { resize: vertical; min-height: 4.5rem; }
.errorlist { color: var(--danger); font-size: .78rem; margin: .25rem 0 0; padding-left: 1rem; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 2rem; text-align: center; background: var(--surface-2); color: var(--muted); }
.dropzone.drag { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.formset-table td { padding: .35rem .4rem; }
.formset-table input { padding: .35rem .45rem; }

/* ---------- Údaje ---------- */
dl.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem 1.4rem; margin: 0; }
dl.facts.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
dl.facts dt { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
dl.facts dd { margin: .05rem 0 .3rem; font-weight: 550; overflow-wrap: anywhere; }
.pdf-frame { width: 100%; height: calc(100vh - 2.4rem); border: 1px solid var(--line); border-radius: var(--radius); background: #525659; }
.empty { color: var(--muted); padding: 1.6rem 0; text-align: center; }
.empty .ico { width: 28px; height: 28px; display: block; margin: 0 auto .4rem; opacity: .6; }
.divider { border: 0; border-top: 1px solid var(--line-2); margin: 1rem 0; }

/* ---------- Historie ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .15rem 0 .85rem 1.2rem; border-left: 2px solid var(--line); position: relative; margin-left: .3rem; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand); }
.timeline .when { color: var(--muted); font-size: .78rem; }
.timeline .note { background: var(--surface-2); border-radius: 6px; padding: .35rem .55rem; margin-top: .3rem; font-size: .86rem; }

/* ---------- Seznam úkolů ---------- */
.task-list { list-style: none; margin: 0; padding: 0; }
.task-list li { display: flex; align-items: center; gap: .8rem; padding: .7rem 0; border-bottom: 1px solid var(--line-2); }
.task-list li:last-child { border-bottom: 0; }
.task-list .main-col { flex: 1; min-width: 0; }
.task-list .title { font-weight: 600; color: var(--ink); }
.task-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); flex: none; }
.task-icon.warn { background: var(--warn-soft); color: var(--warn); }
.task-icon.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Přihlášení ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 460px; }
.login .brand { color: var(--ink); padding: 0 0 1rem; }
.login .brand small { color: var(--muted); }
.user-pick { display: grid; gap: .5rem; }
.user-pick-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .9rem 0 .35rem; }
.user-pick button { width: 100%; justify-content: space-between; padding: .75rem 1rem; }

/* ---------- Graf ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* ---------- Hlášení chyb (static/js/app.js) ---------- */
.toasts-float { position: fixed; top: 1rem; right: 1rem; z-index: 60; display: grid; gap: .5rem; width: min(420px, calc(100vw - 2rem)); }
.toasts-float .toast { margin: 0; box-shadow: 0 8px 24px rgba(28, 34, 41, .16); align-items: flex-start; }
.toasts-float .toast span { flex: 1; min-width: 0; }
.toast-close { background: none; border: 0; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; padding: 0 .15rem; }

/* ---------- Úzké obrazovky (telefon) ---------- */
@media (max-width: 600px) {
  .card { padding: 1rem; }
  .card.flush > .card-head { padding: .9rem 1rem .2rem; }
  .card.flush table th:first-child, .card.flush table td:first-child { padding-left: 1rem; }
  .card.flush table th:last-child, .card.flush table td:last-child { padding-right: 1rem; }
  .card-head { flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi { padding: .7rem .8rem; }
  .kpi .value { font-size: 1.08rem; overflow-wrap: anywhere; }
  .task-list li { flex-wrap: wrap; row-gap: .3rem; }
  .task-list .main-col { flex-basis: calc(100% - 34px - .8rem); }
  .task-list .task-side { flex-direction: row; align-items: center; flex-wrap: wrap; margin-left: calc(34px + .8rem); }
  dl.facts.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .toolbar .search { min-width: 0; flex-basis: 100%; max-width: none; }
  .btn { white-space: normal; }
  .pdf-frame { height: 70vh; }
}
