:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --line: #dcdcd6;
  --accent: #ff5a00;
  --accent-ink: #ffffff;
  --ok: #1e7f4f;
  --bad: #c62828;
  --bad-bg: #fdecea;
  --warn-bg: #fff4e5;
  --focus: #2563eb;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { color: var(--bad); }
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
input:disabled { background: transparent; border-style: dashed; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.topbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.brand strong { font-size: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner { background: var(--warn-bg); padding: 10px 16px; border-bottom: 1px solid var(--line); }

.settings { margin: 12px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.settings summary { padding: 10px 14px; cursor: pointer; font-weight: 600; }
.settings-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; padding: 4px 14px 14px;
}
.settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.settings-grid label small { font-size: 11px; }
.settings-grid label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 13px; }
.settings-grid label.check input { width: auto; }
.pill { font-size: 12px; font-weight: 500; margin-left: 8px; padding: 2px 8px; border-radius: 99px; border: 1px solid currentColor; }
.err, td.err { border-color: var(--bad) !important; }
input.err, select.err { background: var(--bad-bg); }

.tabs { display: flex; gap: 4px; align-items: flex-end; padding: 0 16px; }
.tab { border: 1px solid var(--line); border-bottom: none; border-radius: 8px 8px 0 0; background: var(--bg); padding: 8px 16px; }
.tab.active { background: var(--surface); font-weight: 600; }
.tab .bad { font-weight: 500; }

main { padding: 0 16px 32px; }
.empty { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 40px 16px; text-align: center; }
#sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius); }
.toolbar { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding: 10px; border-bottom: 1px solid var(--line); }
.toolbar-left { display: flex; gap: 6px; flex-wrap: wrap; }
.summary { align-self: center; }
.hint { padding: 0 10px 10px; font-size: 12px; }

.sel { display: flex; align-items: center; gap: 6px; padding-left: 4px; }
.sel input { width: auto; }
.status { border: none; background: transparent; padding: 4px; font-weight: 600; width: 44px; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.cellwrap { position: relative; }
.cellwrap .counter { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); font-size: 11px; color: var(--muted); pointer-events: none; }
.cellwrap input { padding-right: 48px; }
.cellbtn { width: 100%; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }

dialog { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 32px)); }
dialog.wide { width: min(1000px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { margin: 0; font-size: 17px; }
.dlg p { margin: 0; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.spacer { flex: 1; }

.cat-list { list-style: none; margin: 0; padding: 0; max-height: 50vh; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.cat-list li button { width: 100%; display: flex; justify-content: space-between; gap: 12px; text-align: left; border: none; border-bottom: 1px solid var(--line); border-radius: 0; }
.cat-list li button:hover { background: var(--bg); }

.img-preview { display: flex; flex-wrap: wrap; gap: 6px; }
.img-preview img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.img-preview img.broken { outline: 2px solid var(--bad); }

.desc-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 760px) { .desc-layout { grid-template-columns: 1fr; } }
.desc-blocks { display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow: auto; }
.desc-block { border: 1px solid var(--line); border-radius: 6px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.desc-head { display: flex; justify-content: space-between; align-items: center; }
.desc-head button { padding: 2px 8px; margin-left: 2px; }
.desc-add { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.desc-preview { border: 1px solid var(--line); border-radius: 6px; padding: 12px; max-height: 55vh; overflow: auto; margin-top: 4px; }
.desc-preview img { max-width: 100%; }
.checks-list { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.checks-list input { width: auto; }
.boolcell { display: flex; justify-content: center; }
.boolcell input { width: auto; }

.slot-label { font-size: 11px; color: var(--muted); padding: 2px 8px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.readonly { padding: 5px 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
#viewHint { padding: 8px 10px 0; margin: 0; }

/* ---------- Tabulator ---------- */
#sheet { background: var(--surface); border: 1px solid var(--line); border-radius: 0 var(--radius) var(--radius) var(--radius); margin: 0 16px 24px; padding: 0; }
main#sheet { padding: 0; }
#grid { border: none; border-top: 1px solid var(--line); font-size: 13px; background: var(--surface); }
#grid.tabulator { background-color: var(--surface); }
#grid .tabulator-header { background: var(--bg); color: var(--text); border-bottom: 1px solid var(--line); }
#grid .tabulator-header .tabulator-col { background: var(--bg); border-right: 1px solid var(--line); }
#grid .tabulator-col-title { font-weight: 600; font-size: 12px; }
#grid .tabulator-tableholder { background: var(--surface); }
#grid .tabulator-row { background: var(--surface); color: var(--text); border-bottom: 1px solid var(--line); }
#grid .tabulator-row.tabulator-row-even { background: var(--surface); }
#grid .tabulator-row .tabulator-cell { border-right: 1px solid var(--line); padding: 6px 8px; }
#grid .tabulator-row .tabulator-cell.tabulator-frozen { background: inherit; }
#grid .tabulator-cell.cell-err { background: var(--bad-bg) !important; box-shadow: inset 0 0 0 1px var(--bad); }
#grid .tabulator-cell.cell-na { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--bg) 6px 12px) !important; }
#grid .tabulator-cell.col-attrname { color: var(--muted); background: var(--bg); }
#grid .tabulator-cell.col-status { cursor: pointer; font-weight: 600; }
#grid .tabulator-cell.tabulator-range-selected:not(.tabulator-range-only-cell-selected) { background-color: rgb(37 99 235 / .12); }
#grid .tabulator-cell.tabulator-range-only-cell-selected, #grid .tabulator-cell.tabulator-range-selected { outline: none; }
#grid .tabulator-range-overlay .tabulator-range.tabulator-range-active { border-color: var(--focus); }
#grid .tabulator-cell.tabulator-editing { box-shadow: inset 0 0 0 2px var(--focus); }
#grid .tabulator-cell.tabulator-editing textarea { min-height: 120px; position: relative; z-index: 3; background: var(--surface); }
.tabulator-edit-list { font-size: 13px; }
.hint { padding: 8px 12px 12px; margin: 0; font-size: 12px; }
.tick { color: var(--ok); font-weight: 700; }
.lang { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.lang select { width: auto; }
.cb { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border: 1.5px solid #b9b9b2; border-radius: 4px; background: #fff; color: #fff; font-size: 13px; font-weight: 700; line-height: 1; vertical-align: middle; }
.cb.on { background: var(--ok); border-color: var(--ok); }
#grid .tabulator-col .tabulator-col-title { overflow: visible; text-overflow: clip; white-space: normal; }

/* ---------- Editor popisu ---------- */
.desc-top { display: flex; align-items: baseline; gap: 12px; }
.desc-toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.desc-toolbar button { padding: 4px 10px; }
.desc-editor { min-height: 340px; max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 16px 20px; background: #fff; outline: none; line-height: 1.5; }
.desc-editor:focus { border-color: var(--focus); box-shadow: 0 0 0 2px rgb(37 99 235 / .15); }
.aukro-preview h2 { font-size: 20px; margin: 16px 0 8px; }
.aukro-preview p { margin: 0 0 8px; }
.aukro-preview ul, .aukro-preview ol { margin: 0 0 8px; padding-left: 24px; }
.desc-foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* tabulka se vejde do stránky a posouvá se uvnitř (šipky drží označenou buňku v zobrazení) */
#grid { width: 100%; max-width: 100%; }
#sheet { overflow: hidden; min-width: 0; }
/* stránka vyplní okno, posouvá se jen tabulka */
html, body { height: 100%; }
#sheet { margin-bottom: 0; }
.hint { margin: 0; }
.desc-tabs { display: flex; gap: 4px; align-items: center; border-bottom: 1px solid var(--line); }
.desc-tabs .tab { border-bottom: none; padding: 6px 14px; }
.desc-tabs .tab.active { background: var(--surface); font-weight: 600; border-color: var(--line); }
.desc-html { min-height: 340px; max-height: 60vh; width: 100%; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; border-radius: 8px; padding: 12px; resize: vertical; }
.desc-note { background: var(--warn-bg); border-radius: 6px; padding: 8px 12px; font-size: 13px; }
.html-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: #4a4a45; }
