:root {
  --bg: #f4f5f7; --panel: #fff; --ink: #1d2330; --muted: #6b7280; --line: #e3e6eb; --line2: #d3d8df;
  --side: #17202e; --side-ink: #c9d1dd; --accent: #1f6feb; --accent-ink: #fff; --accent-soft: #e8f0fe;
  --ok: #1a7f37; --ok-soft: #e6f4ea; --warn: #9a6700; --warn-soft: #fff4d6; --err: #c0262d; --err-soft: #fde8e8;
  --radius: 6px; --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 var(--font); color: var(--ink); background: var(--bg); }
.hidden { display: none !important; }
h1 { font-size: 20px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0; font-weight: 600; }
h3 { font-size: 14px; margin: 16px 0 8px; font-weight: 600; color: #374151; }
a { color: var(--accent); }
kbd { font: 11px var(--font); opacity: .55; margin-left: auto; }

/* rozvržení */
#app { display: flex; height: 100vh; }
#side { width: 220px; flex: none; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 12px; }
.brand b { color: #fff; display: block; font-size: 15px; }
.brand small { color: #8a96a8; font-size: 12px; }
.logo { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
#nav { flex: 1; overflow: auto; padding: 4px 8px; }
#nav a { display: flex; align-items: center; padding: 7px 10px; border-radius: 6px; color: var(--side-ink); text-decoration: none; cursor: pointer; margin: 1px 0; }
#nav a:hover { background: #222d3e; color: #fff; }
#nav a.active { background: var(--accent); color: #fff; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #6c798c; padding: 12px 10px 4px; }
.side-foot { padding: 10px 16px; font-size: 12px; color: #8a96a8; border-top: 1px solid #253043; display: flex; flex-direction: column; gap: 2px; }
#save-status.err { color: #ff8a8a; font-weight: 600; }
#data-place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#main { flex: 1; overflow: auto; padding: 18px 24px 40px; min-width: 0; }

/* hlavička stránky */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin-right: auto; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .grow { flex: 1; }
.toolbar input[type=search], .toolbar input.search { min-width: 260px; }
.sum-line { color: var(--muted); font-size: 13px; }

/* tlačítka a pole */
.btn { font: inherit; border: 1px solid var(--line2); background: #fff; color: var(--ink); padding: 6px 12px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5fd0; }
.btn.danger { color: var(--err); border-color: #f0b4b4; }
.btn.danger:hover { background: var(--err-soft); }
.btn.small { padding: 3px 8px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 16px; color: var(--muted); padding: 4px 8px; border-radius: 4px; }
.icon-btn:hover { background: #eef0f3; color: var(--ink); }
input, select, textarea { font: inherit; border: 1px solid var(--line2); border-radius: var(--radius); padding: 6px 8px; background: #fff; color: var(--ink); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ff; outline-offset: -1px; border-color: var(--accent); }
input[readonly] { background: #f6f7f9; color: #4b5563; }
textarea { resize: vertical; width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 14px; }
.fld { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.fld > span { color: var(--muted); font-size: 12px; }
.fld.chk { flex-direction: row-reverse; align-items: center; justify-content: flex-end; gap: 8px; padding-top: 18px; }
.fld.chk > span { font-size: 13px; color: var(--ink); }
.form-sep { grid-column: 1 / -1; font-weight: 600; font-size: 13px; padding-top: 6px; border-bottom: 1px solid var(--line); padding-bottom: 4px; color: #374151; }

/* karty a panely */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; cursor: default; }
.card.link { cursor: pointer; }
.card.link:hover { border-color: var(--accent); }
.card .lbl { font-size: 12px; color: var(--muted); }
.card .val { font-size: 22px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.card .sub { font-size: 12px; color: var(--muted); }
.card.warn .val { color: var(--warn); }
.card.err .val { color: var(--err); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* tabulky */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; overflow: auto; max-height: calc(100vh - 210px); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.grid th { position: sticky; top: 0; background: #f8f9fb; text-align: left; font-weight: 600; color: #4b5563; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; z-index: 1; }
table.grid td { padding: 5px 8px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
table.grid tbody tr:hover td { background: #f5f8ff; }
table.grid tr[data-id], table.grid tr[data-c] { cursor: pointer; }
table.grid tfoot td { position: sticky; bottom: 0; background: #f8f9fb; font-weight: 600; border-top: 1px solid var(--line); }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.c, th.c { text-align: center; }
td.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
td.empty { text-align: center; color: var(--muted); padding: 24px; }
td.neg { color: var(--err); }
tr.storno td { color: #9ca3af; text-decoration: line-through; }
tr.grp td { background: #f3f5f8; font-weight: 600; }
.more-note { font-size: 12px; color: var(--muted); padding: 6px 2px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.badge { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 10px; background: #eef0f3; color: #4b5563; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.blue { background: var(--accent-soft); color: var(--accent); }

/* okna */
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 4vh 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 10px; width: 560px; max-width: 100%; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: flex; flex-direction: column; max-height: 92vh; }
.modal.wide { width: 900px; }
.modal.xwide { width: 1200px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 14px 16px; overflow: auto; }
.modal-foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.confirm-text { margin: 4px 0; line-height: 1.55; }

/* našeptávač */
.ac-list { position: fixed; z-index: 100; background: #fff; border: 1px solid var(--line2); border-radius: 6px; box-shadow: 0 8px 24px rgba(0,0,0,.15); max-height: 320px; overflow: auto; font-size: 13px; }
.ac-item { padding: 5px 10px; cursor: pointer; display: flex; gap: 8px; align-items: baseline; }
.ac-item b { font-family: Consolas, monospace; font-weight: 600; min-width: 64px; }
.ac-item em { margin-left: auto; font-style: normal; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ac-item.sel, .ac-item:hover { background: var(--accent-soft); }
.ac-empty { padding: 8px 10px; color: var(--muted); }

/* oznámení */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.2); max-width: 420px; transition: opacity .3s; }
.toast.err { background: var(--err); }
.toast.warn { background: #b7791f; }
.toast.hide { opacity: 0; }

/* doklad – editor */
.doc-head { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px 12px; }
.doc-lines { margin-top: 12px; }
.doc-lines table.grid td { vertical-align: middle; }
.doc-lines input { width: 100%; padding: 4px 6px; }
.doc-lines input.r { text-align: right; }
.doc-add { display: grid; grid-template-columns: 2.6fr .8fr 1fr .7fr .6fr auto; gap: 8px; align-items: end; margin-top: 10px; background: #f8f9fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.doc-add .fld { min-width: 0; }
.doc-add input { width: 100%; }
.doc-add .info { grid-column: 1 / -1; font-size: 12px; color: var(--muted); min-height: 16px; }
.doc-sum { display: flex; gap: 24px; justify-content: flex-end; margin-top: 10px; font-size: 14px; flex-wrap: wrap; }
.doc-sum b { font-variant-numeric: tabular-nums; }
.doc-sum .big { font-size: 18px; }

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.tabs button { font: inherit; border: 0; background: none; padding: 8px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.kv { display: grid; grid-template-columns: 160px 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* úvodní obrazovka */
#start { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.start-box { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px 32px; width: 640px; max-width: 100%; box-shadow: 0 10px 30px rgba(0,0,0,.06); }
.start-box h1 { font-size: 24px; margin-bottom: 4px; }
.start-box p { color: #4b5563; line-height: 1.55; }
.start-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.start-actions .btn { text-align: left; padding: 12px 14px; }
.start-actions .btn small { display: block; color: inherit; opacity: .75; font-size: 12px; margin-top: 2px; white-space: normal; }
.progress { margin-top: 14px; font-size: 13px; color: var(--muted); }
.import-log { font-size: 13px; background: #f8f9fb; border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; margin-top: 10px; white-space: pre-line; }
.set-list label { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; margin-bottom: 6px; cursor: pointer; }
.set-list label:hover { background: #f8f9fb; }

/* tisk */
#print-area { display: none; }
@media print {
  @page { size: A4; margin: 12mm 12mm 14mm; }
  body { background: #fff; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
}
.pr { font: 10pt/1.35 "Segoe UI", Arial, sans-serif; color: #000; }
.pr h1 { font-size: 16pt; margin: 0 0 2mm; }
.pr h2 { font-size: 11pt; margin: 4mm 0 2mm; }
.pr .row { display: flex; gap: 6mm; }
.pr .box { border: 1px solid #000; padding: 2.5mm 3mm; flex: 1; }
.pr .box .t { font-size: 8pt; text-transform: uppercase; color: #444; margin-bottom: 1mm; }
.pr table { width: 100%; border-collapse: collapse; margin-top: 3mm; }
.pr th { border-bottom: 1.2px solid #000; text-align: left; font-size: 8.5pt; padding: 1.2mm 1.5mm; }
.pr td { border-bottom: .5px solid #bbb; padding: 1mm 1.5mm; font-size: 9pt; vertical-align: top; }
.pr td.r, .pr th.r { text-align: right; white-space: nowrap; }
.pr .tot { margin-top: 3mm; display: flex; }
.pr .tot table { width: auto; min-width: 85mm; }
.pr .tot td { border: 0; padding: .6mm 1.5mm; }
.pr .tot .grand td { font-size: 12pt; font-weight: 700; border-top: 1.2px solid #000; padding-top: 1.5mm; }
.pr .meta { display: grid; grid-template-columns: auto 1fr; gap: .5mm 4mm; font-size: 9.5pt; }
.pr .foot { margin-top: 8mm; font-size: 8.5pt; color: #333; display: flex; justify-content: space-between; }
.pr .sign { margin-top: 14mm; display: flex; justify-content: space-between; font-size: 9pt; }
.pr .sign div { border-top: .5px solid #000; width: 60mm; text-align: center; padding-top: 1mm; }
.pr .page-break { break-after: page; }
.pr .small { font-size: 8.5pt; }

/* ---------- hledání, klávesy ---------- */
.btn kbd, .tabs kbd { margin-left: 6px; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; font-size: 10.5px; opacity: .6; }
kbd { font-family: var(--font); }
table.keys kbd, .cmdk-foot kbd, .choose kbd, .side-foot kbd { margin: 0; border: 1px solid var(--line2); border-bottom-width: 2px; border-radius: 4px; padding: 1px 6px; font-size: 12px; opacity: 1; background: #f8f9fb; color: var(--ink); }
.side-foot a { color: #8a96a8; text-decoration: none; margin-top: 4px; }
.side-foot a:hover { color: #fff; }
.side-foot kbd { background: none; color: inherit; border-color: #3a475c; font-size: 10.5px; padding: 0 4px; }
.side-search { margin: 0 8px 6px; padding: 7px 10px; display: flex; align-items: center; font: inherit; color: #8a96a8; background: #222d3e; border: 1px solid #2f3b50; border-radius: 6px; cursor: pointer; text-align: left; }
.side-search:hover { color: #fff; border-color: #48566e; }
.choose { display: flex; flex-direction: column; gap: 6px; }
.choose .btn { text-align: left; padding: 9px 12px; display: flex; gap: 10px; align-items: center; }
.cmdk-wrap { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 150; display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px; }
.cmdk { width: 680px; max-width: 100%; background: #fff; border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.3); overflow: hidden; display: flex; flex-direction: column; max-height: 70vh; }
.cmdk > input { border: 0; border-bottom: 1px solid var(--line); border-radius: 0; padding: 14px 18px; font-size: 16px; outline: none !important; }
.cmdk-list { overflow: auto; padding: 4px 0; }
.cmdk-group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 18px 3px; }
.cmdk-item { display: flex; gap: 10px; align-items: baseline; padding: 6px 18px; cursor: pointer; }
.cmdk-item b { font-family: Consolas, "Cascadia Mono", monospace; font-weight: 600; font-size: 12.5px; min-width: 62px; }
.cmdk-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item em { margin-left: auto; font-style: normal; font-size: 12px; color: var(--muted); white-space: nowrap; padding-left: 12px; }
.cmdk-item.sel { background: var(--accent-soft); }
.cmdk-empty { padding: 18px; color: var(--muted); }
.cmdk-foot { display: flex; gap: 18px; padding: 8px 18px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); background: #fafbfc; }

/* ---------- seznamy: řazení, výběr, stránkování ---------- */
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--ink); background: #eef1f5; }
table.grid th.sorted { color: var(--accent); }
.sort-ind { display: inline-block; width: 12px; margin-left: 3px; font-size: 9px; }
table.grid tbody tr.sel td { background: var(--accent-soft); }
table.grid tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.lt { max-height: calc(100vh - 250px); }
.pager { display: flex; align-items: center; gap: 8px; padding: 8px 2px 0; font-size: 13px; color: var(--muted); }
.pager .grow { flex: 1; }

/* ---------- přehled: panely a grafy ---------- */
.panel.note { border-color: #f0d58a; background: var(--warn-soft); }
.dash { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: 14px; }
.dash .panel { margin: 0; min-width: 0; }
.dash .table-wrap { border: 0; border-radius: 0; max-height: none; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
.stat.err { color: var(--err); font-weight: 600; }
@media (max-width: 1100px) { .dash { grid-template-columns: 1fr; } }
.graf { --series-1: #2a78d6; --gline: #e8eaee; position: relative; padding: 14px 4px 0 52px; }
.gplot { position: relative; height: var(--gh); }
.ggrid { position: absolute; inset: 0 0 22px 0; }
.gline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--gline); }
.gline:first-child { border-top-color: #c9ced6; }
.gline span { position: absolute; right: 100%; margin-right: 8px; transform: translateY(-50%); font-size: 11px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.gcols { position: absolute; inset: 0; display: flex; }
.gcol { flex: 1; min-width: 0; display: flex; flex-direction: column; outline: none; }
.gbar-area { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.gbar { width: min(24px, 62%); background: var(--series-1); border-radius: 4px 4px 0 0; position: relative; min-height: 0; }
.gcol.hl .gbar-area { background: rgba(31, 111, 235, .06); }
.gcol:focus-visible .gbar-area { box-shadow: inset 0 0 0 2px #9cc0ff; border-radius: 4px; }
.bval { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); margin-bottom: 3px; font-size: 11px; color: var(--ink); white-space: nowrap; font-variant-numeric: tabular-nums; }
.glab { height: 22px; line-height: 22px; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.gtip { position: absolute; transform: translateX(-50%); background: #1f2937; color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 6px; white-space: nowrap; pointer-events: none; z-index: 2; }
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hrow { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; cursor: pointer; border-radius: 4px; }
.hrow:hover .hname { color: var(--accent); }
.hname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.htrack { height: 10px; }
.hbar { height: 100%; background: #2a78d6; border-radius: 0 4px 4px 0; }
.hval { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ink); min-width: 92px; text-align: right; }

/* ---------- nastavení: logo ---------- */
.logo-row { display: flex; gap: 16px; align-items: center; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.logo-prev { width: 180px; height: 70px; border: 1px dashed var(--line2); border-radius: 6px; display: grid; place-items: center; background: #fff; flex: none; }
.logo-prev img { max-width: 170px; max-height: 60px; }

/* ---------- tisk: záhlaví s logem, QR platba ---------- */
.pr .phead { align-items: flex-end; margin-bottom: 3mm; gap: 5mm; }
.pr .phead h1 { flex: 1; margin: 0; }
.pr .pnum { font-size: 14pt; font-weight: 700; white-space: nowrap; }
.pr .plogo { max-height: 18mm; max-width: 55mm; }
.pr .tot { justify-content: space-between; align-items: flex-start; gap: 6mm; }
.pr .tot table { margin-left: auto; margin-top: 0; }
.pr .pqr { display: flex; gap: 3mm; align-items: center; font-size: 8.5pt; line-height: 1.45; break-inside: avoid; }
.pr .pqr svg { flex: none; border: .5px solid #999; }
body.skladnik .only-sef { display: none !important; }

/* ---------- nastavení: oprávnění ---------- */
.prava-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; margin: 4px 0 10px; }
.chk-row { display: flex; gap: 8px; align-items: center; padding: 4px 0; font-size: 13.5px; cursor: pointer; }
