/* AnalyticsHub BI PoC – základní styly a design tokeny
 * Barvy podle firemního manuálu (Colour palette): tmavě zelená #00472e, jasně zelená #41f0aa,
 * CTA zelená #008751, odstíny zelené 10/20/40, šedá škála; doplňkově modrá a růžová v grafech. */

:root {
  color-scheme: light;
  --bg: #f2f2f2;                 /* Grey 20 */
  --surface: #ffffff;
  --surface-2: #f7f8f7;
  --border: #d9d9d9;             /* Grey 40 */
  --border-strong: #a1a1a1;      /* Grey */
  --text: #00472e;               /* Dark green – texty na světlém pozadí */
  --text-muted: #6e6e6e;         /* Dark grey */
  --accent: #008751;             /* CTA green */
  --accent-hover: #00472e;
  --accent-soft: #d9fcee;        /* Green 20 */
  --on-accent: #ffffff;          /* text na akcentu */
  --ok: #008751;
  --ok-soft: #ecfdf6;            /* Green 10 */
  --warn: #a15c00;
  --warn-soft: #fdf2e1;
  --danger: #c4322b;
  --danger-soft: #fbeceb;
  --topbar-bg: #00472e;          /* Dark green blok, bílý text */
  --topbar-text: #ffffff;
  --topbar-muted: #b3f9dd;       /* Green 40 */
  --topbar-hover: rgba(255, 255, 255, .10);
  --topbar-active: #41f0aa;      /* Bright green */
  --brand-mark: #41f0aa;
  --brand-mark-ink: #00472e;
  --shadow: 0 1px 2px rgba(0, 40, 25, .06), 0 1px 3px rgba(0, 40, 25, .08);
  --shadow-lg: 0 12px 32px rgba(0, 40, 25, .18);
  --radius: 8px;
  --radius-sm: 5px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  --topbar-h: 52px;
  /* kategorická paleta grafů – pořadí je pevné; ověřeno na barvoslepost (všechny dvojice) a kontrast.
     Firemní: CTA green, CTA blue, CTA pink, Blue; doplňkové: oranžová, okrová */
  --series-1: #008751; --series-2: #0a76db; --series-3: #e8890c;
  --series-4: #d6248f; --series-5: #6fb5f7; --series-6: #a16207;
  --series-other: #a1a1a1;
  --good: #008751; --bad: #c4322b;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1412;
    --surface: #161b19;
    --surface-2: #1d2421;
    --border: #2a332f;
    --border-strong: #3d4842;
    --text: #f2f2f2;             /* bílý text na tmavém */
    --text-muted: #a1a1a1;
    --accent: #41f0aa;           /* Bright green */
    --accent-hover: #b3f9dd;
    --accent-soft: #123a2b;
    --on-accent: #00472e;
    --ok: #41f0aa;  --ok-soft: #123a2b;
    --warn: #e5a54b; --warn-soft: #342a1a;
    --danger: #f2716b; --danger-soft: #3a1f1f;
    --topbar-bg: #00351f;
    --topbar-hover: rgba(255, 255, 255, .08);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    --series-1: #22a06b; --series-2: #3f8be8; --series-3: #d4781c;
    --series-4: #e0479e; --series-5: #8f7ef0; --series-6: #a97a1a;
    --series-other: #5f6a65;
    --good: #41f0aa; --bad: #f2716b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 17px; font-weight: 600; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); font-size: 13px; }
[hidden] { display: none !important; }

/* --- horní lišta --------------------------------------------------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 24px;
  height: var(--topbar-h); padding: 0 20px;
  background: var(--topbar-bg); color: var(--topbar-text);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--topbar-text); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 5px; background: var(--brand-mark);
  display: grid; place-items: center;
}
.brand-mark svg { width: 14px; height: 14px; fill: var(--brand-mark-ink); }
.nav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.nav a {
  padding: 6px 10px; border-radius: var(--radius-sm); color: var(--topbar-muted); font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--topbar-hover); color: var(--topbar-text); text-decoration: none; }
.nav a.active { color: var(--topbar-text); box-shadow: inset 0 -3px 0 var(--topbar-active); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }

.user-menu { position: relative; }
.user-menu > button {
  display: flex; align-items: center; gap: 8px; border: 0; background: none; color: var(--topbar-text);
  font: inherit; cursor: pointer; padding: 4px 6px; border-radius: var(--radius-sm);
}
.user-menu > button:hover { background: var(--topbar-hover); }
.topbar .badge { background: transparent; color: var(--topbar-muted); border-color: rgba(179, 249, 221, .45); }
.topbar .badge-accent { background: var(--topbar-active); color: #00472e; border-color: transparent; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--brand-mark); color: var(--brand-mark-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 12px; text-transform: uppercase;
}
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 6px;
}
.dropdown button {
  display: block; width: 100%; text-align: left; padding: 7px 10px; border: 0; background: none;
  color: var(--text); font: inherit; border-radius: var(--radius-sm); cursor: pointer;
}
.dropdown button:hover { background: var(--surface-2); }
.dropdown hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* --- obsah --------------------------------------------------------------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.page-center { min-height: 100vh; display: grid; place-items: center; padding: 20px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card-narrow { width: 100%; max-width: 440px; }
.card-title { font-size: 20px; margin-bottom: 16px; }
.card-flush { padding: 0; overflow: hidden; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--text-muted);
}
.empty svg { width: 40px; height: 40px; stroke: var(--border-strong); margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* --- tlačítka ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: 500 14px var(--font); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-ghost { border-color: transparent; background: none; }

/* --- formuláře ----------------------------------------------------------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > span { font-weight: 500; font-size: 13px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  height: 34px; padding: 0 10px; width: 100%;
}
textarea { height: auto; padding: 8px 10px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent);
}
select.inline { width: auto; height: 28px; padding: 0 6px; font-size: 13px; }

.alert { padding: 10px 12px; border-radius: var(--radius-sm); margin: 0 0 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }

/* --- tabulky ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions .btn + .btn { margin-left: 4px; }
.table-compact td { padding: 6px 4px; border-bottom: 1px solid var(--border); }
.table-compact tbody tr:hover td { background: none; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border);
}
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; }
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.bad { background: var(--danger); }

/* --- dialogy ------------------------------------------------------------- */
dialog {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.dialog-head { padding: 16px 20px 0; }
.dialog-body { padding: 16px 20px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }

/* --- toast --------------------------------------------------------------- */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
  background: var(--text); color: var(--surface); max-width: 360px; animation: toast-in .15s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(6px); opacity: 0; } }

/* --- přihlášení ---------------------------------------------------------- */
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.login-brand .brand-mark { width: 32px; height: 32px; border-radius: 7px; }
.login-brand .brand-mark svg { width: 18px; height: 18px; }
.login-brand strong { font-size: 18px; }

@media (max-width: 640px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .brand > span:last-child { display: none; }
  .user-menu .user-name, .user-menu .badge { display: none; }
  .page { padding: 16px 16px 40px; }
}

/* ===== Fáze 2: datasety a import ========================================== */
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-block; margin-bottom: 8px; color: var(--text-muted); font-size: 13px; }
.card-head { font-size: 14px; font-weight: 600; padding: 12px 16px; margin: 0; border-bottom: 1px solid var(--border); }
.card-head .muted { font-weight: 400; margin-left: 6px; }
.meta-row { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--text-muted); margin: -6px 0 18px; }
.meta-row strong { color: var(--text); }
.detail-grid { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.table-link tbody tr { cursor: pointer; }
.empty p { margin: 4px 0 16px; }

.fieldset { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin: 0; display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.fieldset legend { font-weight: 500; font-size: 13px; padding: 0 4px; }
.field-inline { grid-template-columns: 36px 1fr; align-items: center; }

/* typy sloupců */
.badge.type-int, .badge.type-decimal { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.type-date, .badge.type-datetime { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* kroky průvodce */
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 16px; counter-reset: step; flex-wrap: wrap; }
.steps li { counter-increment: step; display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-weight: 500; }
.steps li::before {
  content: counter(step); width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; border: 1px solid var(--border-strong); background: var(--surface);
}
.steps li + li::after { content: none; }
.steps li:not(:last-child)::after { content: ''; width: 28px; height: 1px; background: var(--border-strong); margin-left: 4px; }
.steps li.active { color: var(--text); }
.steps li.active::before { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.steps li.done::before { content: '✓'; background: var(--ok-soft); border-color: transparent; color: var(--ok); }

/* dropzone */
.dropzone {
  display: grid; justify-items: center; gap: 4px; padding: 48px 20px; text-align: center; cursor: pointer;
  border: 2px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.dropzone svg { width: 36px; height: 36px; stroke: var(--accent); margin-bottom: 6px; }
.dropzone strong { font-size: 15px; }
.dropzone .link { color: var(--accent); text-decoration: underline; }
.upload-progress { display: grid; gap: 8px; padding: 36px 20px; }
.progress { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* nastavení importu */
.import-config { display: grid; gap: 16px; margin-bottom: 16px; }
.import-config .alert { margin: 0; }
.file-chip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file-chip .btn { margin-left: auto; }
.settings-row { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: end; }
.settings-row .field { min-width: 180px; }
.check { display: inline-flex; align-items: center; gap: 8px; height: 34px; cursor: pointer; }
.check input, .segmented input { width: auto; height: auto; }
.field-name { max-width: 480px; }
.segmented { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.segmented label { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; }
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.segmented input { margin-top: 3px; }
.segmented span { display: grid; gap: 2px; }
.segmented small { color: var(--text-muted); }

/* náhled dat */
.preview-wrap { overflow: auto; max-height: 520px; }
.preview-tall { max-height: 60vh; }
.preview-wrap.loading { opacity: .45; pointer-events: none; }
.table.preview { font-size: 13px; }
.table.preview th, .table.preview td { padding: 6px 12px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.table.preview thead th { position: sticky; top: 0; z-index: 1; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); vertical-align: top; }
.table.preview td.null { color: var(--border-strong); }
.col-head { display: grid; gap: 4px; min-width: 150px; justify-items: start; white-space: normal; }
.col-head input, .col-head select { height: 30px; font-size: 13px; font-weight: 500; }
.col-head small { font-weight: 400; }
.col-warn { font-size: 12px; font-weight: 500; min-height: 0; }
.col-warn.bad { color: var(--warn); }
.import-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }

/* běh a výsledek importu */
.import-running { display: flex; gap: 16px; align-items: center; padding: 32px 24px; }
.import-running p { margin: 2px 0 0; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.done-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.done-head h2 { margin: 0; }
.done-head p { margin: 2px 0 0; }
.done-icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: var(--ok-soft); color: var(--ok); font-size: 20px; font-weight: 700; flex: none; }
.import-done .table-wrap { max-height: 300px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.import-done .table-compact th, .import-done .table-compact td { padding: 6px 10px; }

/* ===== Fáze 3: míry a průzkum ============================================= */
.section { margin-bottom: 16px; }
.card-pad { padding: 12px 16px; margin: 0; }
.card-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-head-row h2 { font-size: 14px; margin: 0; }
.empty-sm { padding: 24px 20px; }
.empty-sm p { margin: 4px auto 0; max-width: 480px; }
.dialog-wide { width: min(720px, calc(100vw - 32px)); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 560px) { .field-row, .field-row-3 { grid-template-columns: 1fr; } }
.filter-rows { display: grid; gap: 8px; }
.filter-rows:empty { display: none; }
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-row select, .filter-row input { width: auto; flex: 1 1 120px; min-width: 0; height: 30px; font-size: 13px; }
.filter-row [data-f=op] { flex: 0 1 130px; }
.filter-row .btn { flex: none; }
.fieldset .btn-ghost { justify-self: start; }
.measure-preview { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 12px 14px;
  border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.measure-preview strong { font-size: 20px; font-variant-numeric: tabular-nums; text-align: right; }
.measure-preview strong.text-warn, .text-warn { color: var(--warn); font-size: 13px; font-weight: 500; }
.explore-controls { display: flex; gap: 16px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.explore-controls > .field:first-child { min-width: 220px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: 99px; cursor: pointer; font-size: 13px; user-select: none; }
.chip input { width: auto; height: auto; margin: 0; }
.chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.explore-result.loading { opacity: .5; }
.table th.sortable { cursor: pointer; user-select: none; }
.table th.sortable:hover { color: var(--accent); }
.table tfoot td { background: var(--surface-2); border-top: 1px solid var(--border-strong); position: sticky; bottom: 0; }

/* ===== Fáze 4: widgety a návrhář ========================================== */
.page-wide { max-width: 1440px; }
.page-sub { margin: 4px 0 0; }
.builder { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .builder { grid-template-columns: 1fr; } }
.builder-panel { display: grid; gap: 14px; position: sticky; top: calc(var(--topbar-h) + 16px); max-height: calc(100vh - var(--topbar-h) - 32px); overflow: auto; }
@media (max-width: 900px) { .builder-panel { position: static; max-height: none; } }
.builder-panel .alert { margin: 0; }
.builder-preview .widget-card { height: 460px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 2px 0; width: 100%; }
.cfg { display: grid; gap: 14px; }
.cfg-field > small { margin-top: -1px; }
.cfg-list { display: grid; gap: 6px; }
.cfg-row { display: flex; gap: 4px; align-items: center; }
.cfg-row > :first-child { flex: 1; min-width: 0; }
.cfg-dim { display: flex; gap: 6px; }
.cfg-dim select { flex: 1; min-width: 0; }
.cfg-dim .cfg-grain { flex: 0 0 120px; }
.cfg-add { justify-self: start; }
.type-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.type-picker button {
  display: grid; justify-items: center; gap: 4px; padding: 8px 2px; font: 500 11px var(--font); color: var(--text-muted);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer;
}
.type-picker button:hover { color: var(--text); background: var(--surface-2); }
.type-picker button[aria-checked="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.type-picker svg, .widget-actions svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.widget-actions svg { width: 16px; height: 16px; }
.dev-json { margin-top: 16px; color: var(--text-muted); }
.dev-json pre { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; overflow: auto; font: 12px var(--mono); color: var(--text); }

/* karta widgetu */
.widget-card { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-height: 0; height: 100%; }
.widget-head { display: flex; align-items: center; gap: 8px; padding: 10px 8px 4px 14px; min-height: 40px; }
.widget-title { font-size: 14px; font-weight: 600; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.widget-actions { display: flex; gap: 2px; opacity: .6; transition: opacity .15s; }
.widget-card:hover .widget-actions, .widget-actions:focus-within { opacity: 1; }
.widget-actions .btn { width: 28px; padding: 0; }
.widget-body { flex: 1; min-height: 0; position: relative; padding: 4px 12px 10px; }
.widget-body.is-loading::after { content: ''; position: absolute; inset: 0; background: var(--surface); opacity: .5; }
.widget-body.is-loading::before { content: ''; position: absolute; top: 50%; left: 50%; width: 24px; height: 24px; margin: -12px; z-index: 1;
  border-radius: 50%; border: 3px solid var(--accent-soft); border-top-color: var(--accent); animation: spin .8s linear infinite; }
.widget-foot { font-size: 12px; padding: 0 14px 8px; }
.widget-state { height: 100%; display: grid; place-items: center; text-align: center; padding: 16px; color: var(--text-muted); }
.widget-state.error { color: var(--danger); }

/* KPI */
.kpi { height: 100%; display: flex; flex-direction: column; justify-content: center; gap: 4px; padding: 0 4px; container-type: inline-size; }
.kpi-value { font-size: clamp(20px, 10.5cqi, 56px); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-label { color: var(--text-muted); }
.kpi-delta { font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 6px; }
.kpi-delta .muted { font-weight: 400; margin-left: 4px; }
.kpi-delta.good { color: var(--good); }
.kpi-delta.bad { color: var(--bad); }
.kpi-delta.neutral { color: var(--text-muted); font-weight: 400; }

/* tabulka ve widgetu */
.wtable { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.wtable-scroll { flex: 1; overflow: auto; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-dense { font-size: 13px; }
.table-dense th, .table-dense td { padding: 6px 10px; white-space: nowrap; }
.table-dense thead th { position: sticky; top: 0; z-index: 1; text-transform: none; letter-spacing: 0; font-size: 12px; }
.table-dense td.null { color: var(--border-strong); }
.table-dense tbody.selectable tr { cursor: pointer; }
.wtable-foot { display: flex; justify-content: space-between; align-items: center; padding-top: 8px; font-size: 12px; }

/* ===== Fáze 5: dashboardy ================================================= */
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.dash-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 12px; }
.dash-tile { padding: 0; display: flex; flex-direction: column; }
.dash-tile-link { display: flex; gap: 12px; padding: 16px; color: var(--text); flex: 1; }
.dash-tile-link:hover { text-decoration: none; background: var(--surface-2); }
.dash-tile-link:hover strong { color: var(--accent); }
.dash-tile-icon svg { width: 32px; height: 32px; stroke: var(--accent); }
.dash-tile-text { display: grid; gap: 2px; min-width: 0; }
.dash-tile-text strong { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dash-tile-text .muted { font-size: 13px; }
.dash-tile-actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 14px 60px; }

.dash { padding-top: 16px; }
.dash-head { margin-bottom: 10px; }
.dash-titlebar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.dash-titlebar h1 { margin: 0; flex: 1; min-width: 0; }
.dash-name-input { flex: 1; max-width: 520px; height: 38px; font-size: 18px; font-weight: 600; }
.dash-actions { margin-left: auto; align-items: center; }
.dash-body { display: flex; gap: 16px; align-items: flex-start; }
.dash-grid-wrap { flex: 1; min-width: 0; }
.grid-stack { margin: 0 -6px; }
.grid-stack > .grid-stack-item > .grid-stack-item-content { overflow: visible; inset: 6px; }
.grid-stack-item .widget-card { height: 100%; }
.edit-only { display: none; }
.dash-editing .edit-only { display: inline-flex; gap: 2px; }
.dash-editing .widget-actions { opacity: 1; }
.dash-editing .widget-head { cursor: move; }
.dash-editing .grid-stack { background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: calc(100% / 12) 84px; border-radius: var(--radius); min-height: 340px; outline: 1px dashed var(--border-strong); outline-offset: 2px; }
.grid-stack-item.is-selected .widget-card { outline: 2px solid var(--accent); outline-offset: 1px; }
.grid-stack-placeholder > .placeholder-content { background: var(--accent-soft) !important; border: 2px dashed var(--accent); border-radius: var(--radius); }
.ui-resizable-handle { opacity: 0; }
.dash-editing .grid-stack-item:hover .ui-resizable-se { opacity: .7; }

.drawer { width: 360px; flex: none; position: sticky; top: calc(var(--topbar-h) + 12px); max-height: calc(100vh - var(--topbar-h) - 24px);
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: 15px; }
.drawer-body { padding: 14px; overflow: auto; display: grid; gap: 14px; }
.drawer-body .alert { margin: 0; }
@media (max-width: 1100px) {
  .drawer { position: fixed; right: 12px; top: calc(var(--topbar-h) + 8px); bottom: 12px; max-height: none; z-index: 60; width: min(360px, calc(100vw - 24px)); }
}

/* ===== Fáze 6: filtry a výběry ============================================ */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filter-field { display: inline-flex; align-items: center; }
.filter-btn {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px 0 12px; max-width: 320px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: 13px var(--font); color: var(--text); cursor: pointer;
}
.filter-btn:hover { background: var(--surface-2); }
.filter-btn:disabled { opacity: .6; cursor: default; }
.filter-btn.active { border-color: var(--accent); background: var(--accent-soft); }
.filter-name { font-weight: 600; white-space: nowrap; }
.filter-val { color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.filter-btn.active .filter-val { color: var(--accent); }
.filter-btn svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; }
.filter-remove { width: 28px; padding: 0; margin-left: 2px; }
.filter-add { border: 1px dashed var(--border-strong); height: 36px; }

.selection-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); }
.sel-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-right: 4px; }
.sel-chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 10px; max-width: 360px;
  background: var(--accent-soft); color: var(--text); border-radius: 99px; font-size: 13px; }
.sel-chip strong { font-weight: 600; white-space: nowrap; }
.sel-val { color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.sel-chip button { border: 0; background: none; color: var(--text-muted); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; font-size: 12px; }
.sel-chip button:hover { background: var(--surface); color: var(--text); }

.popover { position: absolute; z-index: 80; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 10px; display: grid; gap: 8px; }
.pop-head { font-size: 14px; }
.pop-search { height: 32px; }
.pop-list { max-height: 300px; overflow: auto; display: grid; gap: 1px; margin: 0 -4px; }
.pop-item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px; }
.pop-item:hover { background: var(--surface-2); }
.pop-item input { width: auto; height: auto; margin: 0; flex: none; }
.pop-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-excluded span { color: var(--text-muted); font-style: italic; }
.pop-note { margin: 4px 6px; font-size: 12px; }
.pop-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding-top: 6px; border-top: 1px solid var(--border); font-size: 12px; }
.pop-range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pop-presets { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.pop-presets .chip { height: 26px; font-size: 12px; background: var(--surface); }
.pop-presets .chip:hover { border-color: var(--accent); color: var(--accent); }
.widget-body .table-dense tbody.selectable tr:hover td { background: var(--accent-soft); }

/* ===== Fáze 7: pivot tabulka ============================================== */
.pivot-wrap { height: 100%; display: flex; flex-direction: column; min-height: 0; }
.pivot-tools { display: flex; gap: 4px; justify-content: flex-end; margin: -4px 0 4px; }
.pivot-scroll { flex: 1; overflow: auto; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table.pivot { font-size: 13px; border-collapse: separate; border-spacing: 0; }
.table.pivot th, .table.pivot td { padding: 6px 10px; white-space: nowrap; border-bottom: 1px solid var(--border); }
.table.pivot thead th { position: sticky; z-index: 2; background: var(--surface-2); text-transform: none; letter-spacing: 0; font-size: 12px; color: var(--text); }
.table.pivot thead tr:first-child th { top: 0; }
.table.pivot thead tr:nth-child(2) th { top: 31px; font-weight: 500; color: var(--text-muted); }
.table.pivot .pv-corner { left: 0; z-index: 3; text-align: left; vertical-align: bottom; min-width: 180px; }
.table.pivot .pv-col { text-align: center; border-left: 1px solid var(--border); }
.table.pivot .pv-rowh { position: sticky; left: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 400; min-width: 180px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.table.pivot tbody tr:hover td, .table.pivot tbody tr:hover .pv-rowh { background: var(--surface-2); }
.table.pivot .pv-parent .pv-rowh, .table.pivot .pv-parent td { font-weight: 600; }
.table.pivot .pv-l1.pv-parent td, .table.pivot .pv-l1.pv-parent .pv-rowh { background: var(--surface-2); }
.table.pivot td.pv-total, .table.pivot th.pv-total { border-left: 1px solid var(--border-strong); }
.table.pivot td.null { color: var(--border-strong); }
.table.pivot tfoot th, .table.pivot tfoot td { position: sticky; bottom: 0; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; z-index: 1; }
.table.pivot tfoot .pv-rowh { z-index: 2; background: var(--surface-2); }
.table.pivot tbody th, .table.pivot tfoot th { text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }
.pv-toggle { width: 18px; height: 18px; padding: 0; margin-right: 4px; border: 0; background: none; color: var(--text-muted); cursor: pointer; font-size: 12px; border-radius: 4px; vertical-align: -1px; }
.pv-toggle:hover { background: var(--border); color: var(--text); }
.pv-toggle-sp { display: inline-block; width: 22px; }
.pv-selectable .pv-label, .pv-selectable .pv-col[data-col] { cursor: pointer; }
.pv-selectable .pv-label:hover, .pv-selectable .pv-col[data-col]:hover { color: var(--accent); text-decoration: underline; }
