:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-2: #eef0ec;
  --text: #1b1d1a;
  --muted: #646a62;
  --border: #dde1d9;
  --primary: #1f7a4d;
  --primary-text: #ffffff;
  --primary-soft: #e3f1e9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --info-soft: #e6eefb;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  --nav-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  /* grafy (referenčná paleta, slot 1) */
  --chart-series: #2a78d6;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --chart-wash: rgb(42 120 214 / 10%);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2025;
    --surface-2: #262a30;
    --text: #e8eae6;
    --muted: #a0a69e;
    --border: #33373e;
    --primary: #4cc38a;
    --primary-text: #0d1f16;
    --primary-soft: #1d3328;
    --danger: #ff8a80;
    --danger-soft: #3a1f1d;
    --warn: #ffcf66;
    --warn-soft: #3a3020;
    --info-soft: #1f2a3a;
    --shadow: none;
    --chart-series: #3987e5;
    --chart-grid: #2c2c2a;
    --chart-axis: #383835;
    --chart-wash: rgb(57 135 229 / 14%);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
p { margin: 8px 0; }
[hidden] { display: none !important; }

/* rozloženie */
.app { min-height: 100dvh; }
.content { padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 16px); }
.main { max-width: 760px; margin: 0 auto; padding: 16px; padding-top: max(16px, env(safe-area-inset-top)); outline: none; }
.app.public .content { padding-bottom: 16px; }
.app.public .main { max-width: 440px; padding-top: max(40px, env(safe-area-inset-top)); }

.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--nav-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.nav a {
  position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .72rem;
}
.nav a.active { color: var(--primary); font-weight: 600; }
.nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-brand { display: none; }
.nav .badge { position: absolute; top: 6px; left: calc(50% + 6px); }
.nav a.desktop-only { display: none; }
.mobile-only { display: block; }

@media (min-width: 900px) {
  .app:not(.public) { display: grid; grid-template-columns: 230px 1fr; }
  .nav {
    position: sticky; inset: auto; top: 0; height: 100dvh; padding: 20px 12px; /* top až po inset, inak ho inset zruší */
    flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--border);
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; padding: 0 12px 20px; }
  .nav a { flex: 0 0 auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; border-radius: 10px; font-size: .95rem; }
  .nav a.active { background: var(--primary-soft); }
  .nav .badge { position: static; margin-left: auto; }
  .nav a.desktop-only { display: flex; }
  .nav a.mobile-badge .badge { display: none; }
  .mobile-only { display: none; }
  .content { padding-bottom: 24px; }
  .main { padding: 28px 32px; max-width: 980px; }
}

/* komponenty */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card > h2:first-child { margin-top: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row-gap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.loading { color: var(--muted); padding: 24px 0; text-align: center; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--primary); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .9rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

.form { display: grid; gap: 12px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: .9rem; font-weight: 600; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 90px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
input[type="color"] { padding: 4px; width: 64px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.check { display: flex; align-items: center; gap: 10px; }
.check input { width: 22px; min-height: 22px; height: 22px; }
.links { text-align: center; }

.alert { padding: 12px 14px; border-radius: 12px; margin: 10px 0; font-size: .95rem; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.info { background: var(--info-soft); }
.alert.ok { background: var(--primary-soft); color: var(--primary); }

.banner { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; text-align: center; font-size: .9rem; }
.banner button { margin-left: 8px; }

.badge { display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; }
.status { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.status.pending { background: var(--warn-soft); color: var(--warn); }
.status.fetched { background: var(--primary-soft); color: var(--primary); }
.status.failed { background: var(--danger-soft); color: var(--danger); }
.status.queued { background: var(--info-soft); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); font-size: .85rem; }
.list-picker-wrap { display: inline-flex; align-items: center; gap: 2px; padding-left: 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.list-picker { width: auto; min-height: 34px; padding: 4px 10px 4px 6px; border: 0; background: transparent; font-size: .9rem; font-weight: 600; border-radius: 999px; cursor: pointer; }
.list-picker:focus { outline-offset: 0; }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); z-index: 50; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (min-width: 900px) { .toasts { bottom: 24px; } }

/* skener */
.scanner-top { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.scanner-top select { flex: 1; font-weight: 600; }
.counter { display: grid; place-items: center; min-width: 56px; height: 46px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 1.1rem; }
.reader-wrap { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 1 / 1; max-height: 58vh; margin: 0 auto 12px; width: 100%; }
.reader { width: 100%; height: 100%; }
.reader video { width: 100% !important; height: 100% !important; object-fit: cover; }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 20px; color: #fff; background: rgb(0 0 0 / 65%); }
.cam-msg[hidden] { display: none; }
.scan-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(72px, 1fr)); gap: 8px; margin-bottom: 12px; }
.scan-actions .btn { padding: 0 8px; }
.camera-select { margin-bottom: 8px; font-size: .9rem; }
.diag { margin-bottom: 12px; }
.diag summary { cursor: pointer; padding: 4px 0; }
.diag .code { margin-top: 6px; padding: 8px; border-radius: 8px; background: var(--surface-2); user-select: all; }
.scan-result { margin-bottom: 12px; }
.scan-result .card { margin: 0; }
.result-title { font-weight: 700; font-size: 1.05rem; }
.result-sum { font-size: 1.4rem; font-weight: 800; }
.flash { animation: flash .6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 4px var(--primary); } }

/* zoznam bločkov */
.month { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; box-shadow: var(--shadow); }
.month > summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; }
.month > summary::-webkit-details-marker { display: none; }
.month > summary::before { content: "›"; font-size: 1.3rem; color: var(--muted); transition: transform .15s; }
.month[open] > summary::before { transform: rotate(90deg); }
.month-name { font-weight: 700; text-transform: capitalize; white-space: nowrap; }
.month-sum { margin-left: auto; font-weight: 800; }
.rows { border-top: 1px solid var(--border); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); border-left: 4px solid transparent; }
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; display: grid; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { color: var(--muted); font-size: .85rem; }
.row-end { display: grid; justify-items: end; gap: 3px; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border-radius: 50%; background: var(--surface-2); font-size: .8rem; font-weight: 700; color: var(--muted); }

/* detail bločku */
.detail-head { display: grid; gap: 4px; }
.detail-total { font-size: 1.8rem; font-weight: 800; }
.items { width: 100%; border-collapse: collapse; font-size: .95rem; }
.items td { padding: 9px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.items tr:last-child td { border-bottom: 0; }
.items .num { text-align: right; white-space: nowrap; padding-left: 12px; }
.items .sub { color: var(--muted); font-size: .82rem; }
.items tr.special td { color: var(--warn); }
.items tr.special .type { display: inline-block; margin-right: 6px; padding: 0 6px; border-radius: 6px; background: var(--warn-soft); font-size: .72rem; font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* zoznamy a priatelia */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); color: inherit; text-decoration: none; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.member-row:last-child { border-bottom: 0; }
.member-row select { width: auto; min-height: 38px; }
.code { font-family: ui-monospace, Consolas, monospace; font-size: .8rem; word-break: break-all; }

/* filtre a karty štatistík */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input { width: auto; min-height: 42px; }
.filters .grow { flex: 1 1 160px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--muted); font-size: .85rem; }
.tile-value { font-size: 1.5rem; font-weight: 700; }
.tile.hero .tile-value { font-size: 2.2rem; }
.card-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-head h2 { margin: 0 0 8px; }
.card-head .spacer { flex: 1; }
.card-head select { width: auto; min-height: 38px; margin-bottom: 8px; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs a.active { background: var(--primary-soft); color: var(--primary); }

/* grafy */
.chart { position: relative; width: 100%; outline: none; }
.chart:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 8px; }
.chart-svg { display: block; overflow: visible; }
.chart-grid { stroke: var(--chart-grid); stroke-width: 1; }
.chart-axis { stroke: var(--chart-axis); stroke-width: 1; }
.chart-tick { fill: var(--chart-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-value { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart-bar { fill: var(--chart-series); transition: opacity .1s; }
.chart-bar.active { opacity: .75; }
.chart-hit { fill: transparent; cursor: default; outline: none; }
.chart-line { fill: none; stroke: var(--chart-series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart-dot { fill: var(--chart-series); stroke: var(--surface); stroke-width: 2; }
.chart-dot.active { r: 6; }
.chart-cross { stroke: var(--chart-axis); stroke-width: 1; }
.chart-tip {
  position: absolute; z-index: 2; pointer-events: none; display: grid; gap: 1px;
  padding: 6px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgb(0 0 0 / 12%); font-size: .82rem; white-space: nowrap;
}
.chart-tip strong { font-size: .95rem; }
.chart-tip span { color: var(--muted); }
.bar-list { display: grid; gap: 4px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 8px; }
.bar-row:hover { background: var(--surface-2); }
.bar-label { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-sub { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.bar-track { height: 12px; }
.bar-fill { display: block; height: 100%; min-width: 2px; background: var(--chart-series); border-radius: 0 4px 4px 0; }
.bar-value { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-toggle { margin-top: 6px; }
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; margin-top: 6px; }
.data-table th, .data-table td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--border); }
.data-table th { color: var(--muted); font-weight: 600; font-size: .8rem; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* produkty a priradenie položiek */
.assign { display: grid; gap: 10px; padding: 12px; margin: 6px 0 10px; border-radius: 12px; background: var(--surface-2); }
.assign .row-gap { align-items: end; }
.assign .row-gap > * { flex: 1 1 120px; }
.assign .field > span { font-size: .8rem; font-weight: 600; color: var(--muted); }
.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.suggestion { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--primary); background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; cursor: pointer; }
.suggestion small { color: var(--muted); }
.unassigned-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.unassigned-row:last-child { border-bottom: 0; }
.unassigned-head { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.unassigned-head .grow { flex: 1; min-width: 0; }
.items tr.item-row { cursor: pointer; }
.items tr.item-row:hover td { background: var(--surface-2); }
.items .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.items .tag { display: inline-flex; align-items: center; gap: 4px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); font-size: .72rem; color: var(--muted); }
.items tr.moved td { opacity: .8; }
.tag.guess { background: transparent; border: 1px dashed var(--border); }
.items td.panel { padding: 0; }

/* prihlásenie cez Google/Microsoft */
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .85rem; margin: 6px 0 2px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn.provider { gap: 10px; }
.provider-icon { flex: 0 0 auto; }

/* nová verzia aplikácie */
.update-bar {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-bottom) + 12px); width: min(92vw, 440px);
  display: flex; align-items: center; gap: 12px; padding: 10px 10px 10px 16px;
  background: var(--surface); border: 1px solid var(--primary); border-radius: 14px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 18%); animation: toast-in .2s ease-out;
}
.update-bar span { flex: 1; font-size: .92rem; }
.app.public ~ .update-bar { bottom: calc(var(--safe-bottom) + 16px); }
@media (min-width: 900px) { .update-bar { bottom: 24px; } }

/* ručný bloček */
.manual-items { display: grid; gap: 6px; margin: 6px 0 8px; }
.manual-item { display: grid; grid-template-columns: minmax(0, 1fr) 64px 84px 72px 36px; gap: 6px; align-items: center; }
.manual-item input, .manual-item select { min-height: 40px; padding: 6px 8px; }
@media (max-width: 480px) {
  /* názov na celý riadok, pod ním množstvo, cena, DPH a ✕ */
  .manual-item { grid-template-columns: 1fr 1fr 1fr 36px; }
  .manual-item input[name=name] { grid-column: 1 / -1; }
  .manual-item + .manual-item { padding-top: 6px; border-top: 1px solid var(--border); }
}

/* administrácia */
.log-output {
  margin: 0; padding: 12px; max-height: 70vh; overflow: auto; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border);
  font: 12px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-word;
}
.unassigned-row > .actions { margin-top: 10px; }

@media (min-width: 900px) {
  .scanner-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
}
