:root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #e1e6ec;
    --primary: #1f6feb;
    --primary-dark: #1859c2;
    --danger: #c9372c;
    --success-bg: #e6f6ec;
    --success-text: #1d6b3a;
    --error-bg: #fdecea;
    --error-text: #9b2c22;
    --sidebar: #1c2533;
    --sidebar-text: #c3ccd8;
    --radius: 8px;
    font-size: 15px;
}

* { box-sizing: border-box; }

/* Atribút hidden má vždy prednosť (inak ho prebije napr. display: flex) */
[hidden] { display: none !important; }

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.45;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
.negative { color: var(--danger); }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { padding: .2rem 0; }

/* --- rozloženie --- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1rem 0;
}
.sidebar .brand {
    display: block;
    color: #fff;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0 1.25rem 1rem;
    text-decoration: none;
}
.sidebar nav a {
    display: block;
    color: var(--sidebar-text);
    padding: .45rem 1.25rem;
    text-decoration: none;
    border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.sidebar nav a.active { background: rgba(255, 255, 255, .08); color: #fff; border-left-color: var(--primary); }
.nav-section {
    text-transform: uppercase;
    font-size: .72rem;
    letter-spacing: .06em;
    color: #7f8ca0;
    padding: 1rem 1.25rem .3rem;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .6rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.user-menu { display: flex; gap: 1rem; align-items: center; font-size: .9rem; }
.user-menu form { margin: 0; }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1rem;
}
.actions { display: flex; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

/* --- karty --- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}
.card-head h2 { margin: 0; }
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 0; }

/* --- tabuľky --- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: .55rem .75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}
.table th { font-size: .8rem; font-weight: 600; color: var(--muted); background: #fafbfc; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }
.table .empty { text-align: center; color: var(--muted); padding: 2rem; }
.table tr.inactive td { color: var(--muted); }
.table.small td { font-size: .85rem; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline; margin-left: .5rem; }

/* --- badge --- */
.badge {
    display: inline-block;
    font-size: .72rem;
    padding: .1rem .45rem;
    border-radius: 99px;
    background: #eceff3;
    color: #4a5562;
    margin-left: .25rem;
    vertical-align: middle;
}
.badge-blue { background: #e3edfd; color: #1650b4; }
.badge-green { background: #e3f5e9; color: #1d6b3a; }
.badge-warn { background: #fdf3dc; color: #8a5a00; }
.badge-red { background: var(--error-bg); color: var(--error-text); }

.inline-check { display: flex; gap: .35rem; align-items: center; font-size: .9rem; cursor: pointer; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.serial-panel { margin: 1rem 0; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.stock-levels tr.has-serials td { border-bottom: none; }
.stock-levels tr.serial-row:hover { background: transparent; }
.stock-levels tr.serial-row > td { padding-top: 0; }
.stock-levels .serial-panel { margin: 0 0 .25rem; }
.stock-levels .serial-panel > summary { font-size: .88rem; padding: .4rem .75rem; }
.serial-panel > summary { cursor: pointer; padding: .6rem .9rem; display: flex; gap: .5rem; align-items: center; }
.serial-panel > summary:hover { background: #f8fafc; }
.serial-panel[open] > summary { border-bottom: 1px solid var(--border); }
.serial-panel[open] > summary .muted { display: none; }
.serial-panel > p { padding: 0 .9rem; }
.serial-toolbar { display: flex; gap: 1rem; align-items: center; justify-content: space-between; padding: .6rem .9rem; }
.serial-toolbar input { max-width: 280px; }
.serial-scroll { max-height: 320px; overflow-y: auto; border-top: 1px solid var(--border); }
.serial-scroll thead th { position: sticky; top: 0; z-index: 1; }
.serials { margin-top: .35rem; }
.serials .link { text-align: left; }
.serials .link.negative { color: var(--danger); }

/* --- okno (dialóg) --- */
dialog.serial-dialog { width: min(640px, calc(100vw - 2rem)); max-height: calc(100vh - 3rem); border: none; border-radius: 10px;
    padding: 1.25rem 1.5rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .25); color: var(--text); }
dialog.serial-dialog::backdrop { background: rgba(20, 28, 40, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: .5rem; }
.dialog-head h3 { margin: 0; font-size: 1.15rem; }
.dialog-close { background: none; border: none; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 .25rem; }
.dialog-close:hover { color: var(--text); }
.dialog-section { display: flex; flex-direction: column; gap: .75rem; }
.dialog-section h4 { margin: .25rem 0 0; font-size: .95rem; }
.dialog-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.dialog-row select { width: auto; flex: 1; min-width: 200px; }
.dialog-or { display: flex; align-items: center; gap: .75rem; margin: 1rem 0 .75rem; color: var(--muted); font-size: .85rem; }
.dialog-or::before, .dialog-or::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.serial-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .15rem 1rem; margin-top: .4rem;
    max-height: 240px; overflow-y: auto; padding: .5rem .75rem; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; }
.serials details > summary { cursor: pointer; color: var(--primary); }
.serials details > summary.negative { color: var(--danger); }
.serial-form { margin-top: .5rem; padding: .75rem; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; }
.serial-chips { display: flex; flex-wrap: wrap; gap: .25rem; align-items: center; margin: .25rem 0; }
.chip-serial { font-family: ui-monospace, Consolas, monospace; font-size: .78rem; padding: .05rem .4rem; border: 1px solid var(--border); border-radius: 4px; background: #fff; color: var(--text); }
a.chip-serial:hover { border-color: var(--primary); text-decoration: none; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: .2rem .75rem; max-height: 220px; overflow-y: auto; padding: .5rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.pick-list label { display: flex; gap: .35rem; align-items: center; font-family: ui-monospace, Consolas, monospace; font-size: .85rem; cursor: pointer; }
.totals { display: flex; justify-content: flex-end; margin-top: 1rem; }
.totals table { border-collapse: collapse; min-width: 320px; }
.totals td { padding: .25rem .75rem; }
.totals td.num { text-align: right; white-space: nowrap; padding-right: 0; }
.totals tr.grand td { font-weight: 700; font-size: 1.1rem; border-top: 2px solid var(--text); padding-top: .5rem; }
.print-totals { margin-bottom: 1.5rem; }
.sales-items input[name^="name"] { min-width: 220px; }
.qty-input.input-sm { width: 90px; }
.qty-input.input-xs { width: 60px; }
.qty-input { width: 110px; text-align: right; }
.cancel-box { padding: .75rem 1.25rem; }
.cancel-box summary { cursor: pointer; }
.add-line { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--border); }
details.card > summary { cursor: pointer; }
.table tfoot td { border-top: 2px solid var(--border); border-bottom: none; }
.table tr.row-error td { background: #fff7f6; }
.table tr.row-new td { background: #f5fbf7; }
.summary-chips { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.summary-chips .chip { padding: .35rem .75rem; border-radius: 99px; background: #eef1f5; font-size: .88rem; }
.summary-chips .chip strong { font-size: 1rem; }

/* --- tlačidlá --- */
.btn {
    display: inline-block;
    padding: .45rem .9rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: .9rem;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.3;
}
.btn:hover { background: #f1f4f7; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: #f0c4c0; }
.btn-danger:hover { background: var(--error-bg); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-block { width: 100%; }
button.link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
}
button.link:hover { text-decoration: underline; }
button.link.danger { color: var(--danger); }

/* --- formuláre --- */
.form h2 { margin-top: .5rem; padding-top: .75rem; }
.form h2:first-of-type { padding-top: 0; margin-top: 0; }
.form.narrow { max-width: 560px; }
.grid-2, .grid-4 { display: grid; gap: .75rem 1rem; margin-bottom: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2.tight { margin-bottom: 0; }
.span-2 { grid-column: span 2; }
.span-4 { grid-column: span 4; }

.field { display: flex; flex-direction: column; gap: .25rem; }
.field > span { font-size: .82rem; font-weight: 600; color: #4a5562; }
.field.checks { flex-direction: row; gap: 1.25rem; align-items: center; padding-top: 1.2rem; }
.field.checks label { display: flex; gap: .35rem; align-items: center; cursor: pointer; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
    width: 100%;
    padding: .45rem .6rem;
    border: 1px solid #cfd6de;
    border-radius: 6px;
    font: inherit;
    font-size: .92rem;
    background: #fff;
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31, 111, 235, .25); border-color: var(--primary); }
.is-invalid { border-color: var(--danger) !important; }
.field-error { color: var(--danger); font-size: .8rem; }
.form-actions { display: flex; gap: .5rem; align-items: center; margin-top: .5rem; }

.filters { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 240px; }
.filters select { width: auto; }

.input-suffix { display: flex; align-items: center; gap: .35rem; justify-content: flex-end; }
.input-suffix input { width: 130px; text-align: right; }
.input-suffix span { color: var(--muted); font-size: .8rem; width: 2.2rem; text-align: left; }

.check-list { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .5rem; }
.check-list label, .permission-group label { display: flex; gap: .5rem; align-items: flex-start; cursor: pointer; }
.check-list input, .permission-group input { margin-top: .25rem; }
.permission-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.permission-group { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem 1rem; margin: 0; display: flex; flex-direction: column; gap: .45rem; }
.permission-group legend { font-weight: 600; padding: 0 .35rem; }
.permission-group legend .link { font-weight: 400; margin-left: .5rem; }
code { font-family: ui-monospace, Consolas, monospace; }

details.add-form { margin-top: 1rem; }
details.add-form > summary { list-style: none; }
details.add-form > summary::-webkit-details-marker { display: none; }
details.add-form[open] > summary { margin-bottom: 1rem; }

/* --- detail --- */
dl.details { display: grid; grid-template-columns: 180px 1fr; gap: .4rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); font-size: .88rem; }
dl.details dd { margin: 0; }

/* --- hlásenia --- */
.alert { padding: .7rem 1rem; border-radius: 6px; margin-bottom: 1rem; }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-error { background: var(--error-bg); color: var(--error-text); }

/* --- stránkovanie --- */
.pagination { display: flex; gap: .3rem; align-items: center; justify-content: flex-end; }
.pagination .muted { margin-right: auto; font-size: .85rem; }
.pagination a, .pagination .current {
    padding: .3rem .65rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
}
.pagination .current { background: var(--primary); border-color: var(--primary); color: #fff; }

/* --- prehľad --- */
.widgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.widget { display: block; color: var(--text); margin: 0; }
.widget:hover { text-decoration: none; border-color: var(--primary); }
.widget-value { font-size: 2rem; font-weight: 700; }
.widget-label { color: var(--muted); font-size: .9rem; }
.widget-warn .widget-value { color: #b7791f; }
.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }

/* --- prihlásenie / chyby --- */
body.bare { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-box { width: 100%; max-width: 380px; }
.login-box .field { margin-bottom: .9rem; }
.error-page { max-width: 900px; width: 100%; margin: 2rem auto; }
.trace { background: #f6f8fa; padding: 1rem; overflow-x: auto; font-size: .8rem; border-radius: 6px; }

/* --- tlač dokladov: list A4 (na obrazovke ako náhľad listu, pri tlači strana A4) --- */
@page { size: A4; margin: 12mm 14mm 14mm; }
html:has(.print-doc) { font-size: 11.5px; } /* rovnaká veľkosť písma na obrazovke aj v tlači */
body.bare:has(.print-doc) { display: block; background: #d9dde3; padding: 1.5rem 0; min-height: 100vh; }
.print-doc {
    width: 210mm; min-height: 297mm; margin: 0 auto; padding: 12mm 14mm 14mm;
    background: #fff; box-shadow: 0 4px 18px rgba(0, 0, 0, .18); box-sizing: border-box;
    display: flex; flex-direction: column;
}
.print-actions { display: flex; gap: .5rem; margin-bottom: 1.5rem; font-size: 14px; }
.print-footer { margin-top: auto; padding-top: 1.5rem; font-size: .8rem; color: var(--muted); border-top: 1px solid #d0d5db; }
/* Obálka tlače: tabuľka s opakujúcim sa tfoot (miesto pre pätičku na každej strane) */
.print-layout { border-collapse: collapse; width: 100%; }
.print-layout > tbody > tr > td, .print-layout > tfoot > tr > td { padding: 0; border: none; }
.print-only { display: none; }
.print-footer-fixed { font-size: .8rem; color: var(--muted); border-top: 1px solid #d0d5db; padding-top: 2mm; background: #fff; }
.print-footer-space { height: 16mm; }
.print-parties, .invoice-summary, .invoice-bank, .print-signatures, .totals, .print-head, .print-footer { break-inside: avoid; }
.print-head { border-bottom: 2px solid var(--text); padding-bottom: 1rem; margin-bottom: 1rem; }
.print-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-bottom: 1.5rem; }
.print-table th { background: #f2f2f2; }
.print-sign { margin-top: 3rem; }
.print-stamp { border: 2px solid var(--danger); color: var(--danger); font-weight: 700; text-align: center; padding: .5rem; margin-bottom: 1rem; text-transform: uppercase; letter-spacing: .03em; }
.print-serials { font-size: .8rem; margin-top: .2rem; word-break: break-all; }
.print-blank { min-width: 110px; border-bottom: 1px solid #999 !important; }
/* Podpisy: najprv kto (Vystavil: meno), pod tým miesto na podpis a čiara */
.print-signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2.5rem; margin-top: 2.5rem; font-size: .95rem; }
.print-signatures > div { display: flex; flex-direction: column; }
.print-signatures > div:only-child { grid-column: 3; } /* jediný podpis (faktúra, ponuka, objednávka) vpravo */
.print-sign-line { order: 1; margin-top: 20mm; border-top: 1px solid #333; }
.print-sign-line::after { content: "podpis a pečiatka"; display: block; padding-top: .2rem; font-size: .75rem; color: var(--muted); }
.print-meta { margin-top: 2rem; }
.print-table tr { break-inside: avoid; }
.invoice-head { display: flex; justify-content: space-between; gap: 2rem; align-items: flex-start; }
.invoice-head h1 { margin: 0; }
.invoice-number { font-size: 1.25rem; font-weight: 700; }
.invoice-dates td { padding: .1rem 0 .1rem 1rem; }
.invoice-dates td:first-child { color: var(--muted); padding-left: 0; }
.invoice-bank { display: flex; flex-wrap: wrap; gap: .5rem 2rem; padding: .75rem 1rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1.25rem; }
.invoice-bank > div { display: flex; flex-direction: column; }
.invoice-summary { display: flex; justify-content: space-between; align-items: flex-start; gap: 2rem; margin: 1rem 0 1.5rem; flex-wrap: wrap; }
.invoice-summary .totals { margin-top: 0; margin-left: auto; } /* súčty vždy vpravo (aj bez rekapitulácie DPH či po zalomení) */
.vat-recap { width: auto; }
.inline-form { display: inline; margin: 0; }
/* Vyhľadanie firmy v ORSF vo formulári partnera */
.orsf-lookup { background: #f6f9fe; border: 1px solid #d6e3f8; border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: 1.25rem; }
.orsf-row { display: flex; gap: .5rem; }
.orsf-row input { flex: 1; }
.orsf-status { margin-top: .4rem; min-height: 1.2em; color: var(--muted); }
.orsf-status.orsf-ok { color: var(--success-text); }
.orsf-status.orsf-warn { color: #8a5a00; }
.orsf-status.orsf-error { color: var(--danger); }
.orsf-results { margin-top: .5rem; max-height: 300px; overflow-y: auto; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.orsf-hit { display: flex; flex-direction: column; gap: .1rem; width: 100%; text-align: left; padding: .5rem .75rem; border: none; border-bottom: 1px solid var(--border); background: none; cursor: pointer; font: inherit; color: var(--text); }
.orsf-hit:last-child { border-bottom: none; }
.orsf-hit:hover { background: #f1f6ff; }
.settings-nav { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.settings-nav a { padding: .3rem .75rem; border: 1px solid var(--border); border-radius: 99px; background: var(--surface); font-size: .88rem; }
.settings-form .card { scroll-margin-top: 1rem; }
.settings-form .field > span .badge { font-weight: 400; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--border); }
/* Strany dokladu (dodávateľ / odberateľ) – rovnaký vzhľad na všetkých tlačených dokladoch */
.party-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: .2rem; }
.party-name { font-weight: 700; font-size: 1.05rem; margin-bottom: .15rem; }
.party-ids { border-collapse: collapse; margin-top: .4rem; }
.party-ids td { padding: .05rem 0; vertical-align: top; }
.party-ids td:first-child { color: var(--muted); padding-right: .75rem; white-space: nowrap; }
.party-ids td:last-child { min-width: 8rem; }

@media print {
    /* Celé písmo sa zmenší v rovnakom pomere (relatívne veľkosti .small a pod. sa počítajú z :root) */
    :root { font-size: 11.5px; }
    .no-print { display: none !important; }
    body, body.bare:has(.print-doc) { background: #fff; font-size: 1rem; padding: 0; min-height: 0; }
    /* okraje strany zabezpečí @page, list sa roztiahne na celú šírku */
    .print-doc { width: auto; min-height: 0; padding: 0; margin: 0; box-shadow: none; display: block; }
    /* Pätička: pri tlači pevne na spodku každej strany, miesto pod obsahom rezervuje opakujúci sa tfoot */
    .screen-only { display: none !important; }
    tfoot.print-only { display: table-footer-group; }
    div.print-only { display: block; }
    .print-footer-fixed { position: fixed; left: 0; right: 0; bottom: 0; }
    a { color: inherit; text-decoration: none; }
    * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Na úzkej obrazovke (mobil) list zúž */
@media screen and (max-width: 840px) {
    body.bare:has(.print-doc) { padding: 0; }
    .print-doc { width: 100%; min-height: 0; padding: 1rem; box-shadow: none; }
}

@media (max-width: 900px) {
    .shell { flex-direction: column; }
    .sidebar { width: 100%; padding: .5rem 0; }
    .sidebar nav { display: flex; flex-wrap: wrap; }
    .sidebar .nav-section { display: none; }
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .span-4 { grid-column: span 2; }
    .content { padding: 1rem; }
}
@media (max-width: 560px) {
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
    .span-2, .span-4 { grid-column: span 1; }
    dl.details { grid-template-columns: 1fr; }
    .page-head { flex-direction: column; }
}
