/* =========================================================================
   Fakturační systém – design systém. Světlý režim, modrý akcent, bez frameworku.
   ========================================================================= */

:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e4e7ec;
    --border-strong: #d0d5dd;
    --text: #111927;
    --text-muted: #667085;

    --accent: #2f6feb;
    --accent-hover: #2456bf;
    --accent-weak: #eaf1fe;

    --ok: #0f7b3f;  --ok-bg: #e7f5ec;
    --warn: #8a5a00; --warn-bg: #fdf3e3;
    --err: #b42318; --err-bg: #fef3f2;

    --radius: 8px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 6px 20px rgba(16, 24, 40, .12);

    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 20px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
p { margin: 0 0 12px; }

.num, .money { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--text-muted); }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.hint--error { color: var(--err); }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ── App shell ─────────────────────────────────────────────── */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar__inner {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    flex-wrap: wrap;
}
.brand {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    letter-spacing: -.01em;
}
.brand:hover { text-decoration: none; }

.nav-toggle { display: none; }
.nav-toggle-label {
    display: none;
    margin-left: auto;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    user-select: none;
}

.mainnav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
}
.mainnav a {
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
.mainnav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.mainnav a[aria-current="page"] { color: var(--accent); background: var(--accent-weak); }

.topbar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 13px;
}
.linkbtn {
    background: none;
    border: 0;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    padding: 4px;
}
.linkbtn:hover { text-decoration: underline; }

.idle-countdown {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    cursor: pointer;
    font: inherit;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    line-height: 1;
    padding: 4px 9px;
}
.idle-countdown:hover { color: var(--text); }
.idle-countdown.is-low {
    background: var(--warn-bg);
    border-color: var(--warn);
    color: var(--warn);
    font-weight: 600;
}

.wrap {
    max-width: 1200px;
    margin: 24px auto 64px;
    padding: 0 16px;
}

/* ── Karta / panel ────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 16px;
}
.card__title { margin: -4px 0 16px; }

/* ── Statistiky ───────────────────────────────────────────── */
.stat-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}
@media (max-width: 760px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 16px 18px;
}
.stat-tile__label { font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; }
.stat-tile__value { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-tile__value--sm { font-size: 16px; }
.stat-tile__value--err { color: var(--err); }
.stat-tile__sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.chart-wrap { position: relative; height: 170px; }
.chart-wrap canvas { max-width: 100%; }

/* ── Tlačítka ─────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color .12s, border-color .12s;
}
.btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); text-decoration: none; }
.btn--outline { background: var(--surface); color: var(--accent); }
.btn--outline:hover { background: var(--accent-weak); }
.btn--subtle { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--subtle:hover { background: var(--surface-2); color: var(--text); }
.btn--danger { background: var(--surface); color: var(--err); border-color: #f0c4bf; }
.btn--danger:hover { background: var(--err-bg); }
.btn--sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn--icon { padding: 0 10px 0 8px; gap: 5px; }
.btn--icon svg { flex: 0 0 auto; }
.btn--ico { padding: 0; width: 30px; }
.btn--ico.btn--sm { width: 30px; }
.btn--ico svg { flex: 0 0 auto; display: block; }
.btn--ico.has-badge { position: relative; overflow: visible; }
.ico-badge {
    position: absolute; top: -5px; right: -5px;
    min-width: 15px; height: 15px; padding: 0 3px;
    border-radius: 8px; background: var(--accent); color: #fff;
    font-size: 10px; line-height: 15px; font-weight: 700; text-align: center;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ── Formuláře ────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field > label,
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 5px;
}
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], select, textarea {
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-weak);
}
.field--error input, .field--error select { border-color: var(--err); }

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.check input { width: auto; height: auto; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.grid--tight { gap: 12px; }

/* ── Našeptávač klienta ───────────────────────────────────── */
.client-picker { position: relative; }
.client-picker.is-enhanced .client-select { display: none; }
.client-picker:not(.is-enhanced) .client-search { display: none; }
.client-results {
    list-style: none;
    margin: 4px 0 0;
    padding: 4px;
    position: absolute;
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    max-height: 240px;
    overflow-y: auto;
}
.client-results li {
    padding: 7px 9px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13.5px;
}
.client-results li:hover { background: var(--accent-weak); }
.grid--sidebar { grid-template-columns: minmax(300px, 360px) 1fr; align-items: start; }
@media (max-width: 760px) { .grid--sidebar { grid-template-columns: 1fr; } }

/* ── Tabulka ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}
table.data th {
    text-align: left;
    padding: 10px 12px;
    background: var(--surface-2);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
}
table.data td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
table.data tbody tr:hover td { background: var(--surface-2); }
table.data td.actions { white-space: nowrap; text-align: right; }
table.data td.actions form { display: inline; }
table.data td.actions .btn { margin-left: 4px; }
tr.is-paid td { color: var(--text-muted); }
tr.is-cancelled td { color: var(--text-muted); text-decoration: line-through; }

/* ── Odznaky stavu ────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-muted);
}
.badge--issued { background: var(--accent-weak); color: var(--accent-hover); }
.badge--paid { background: var(--ok-bg); color: var(--ok); }
.badge--draft { background: var(--warn-bg); color: var(--warn); }
.badge--cancelled { background: var(--surface-2); color: var(--text-muted); }

/* ── Flash ────────────────────────────────────────────────── */
.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 13.5px;
}
.flash--ok { background: var(--ok-bg); color: var(--ok); }
.flash--error { background: var(--err-bg); color: var(--err); }
.flash--warn { background: var(--warn-bg); color: var(--warn); }
.flash__x {
    margin-left: auto;
    background: none;
    border: 0;
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    opacity: .6;
}
.flash__x:hover { opacity: 1; }

/* ── Editor položek faktury ───────────────────────────────── */
.items { display: flex; flex-direction: column; gap: 8px; }
.item-row {
    display: grid;
    grid-template-columns: 1fr 84px 128px 132px 36px;
    gap: 8px;
    align-items: start;
}
.item-row__label { display: none; }
.item-row .remove-item { padding: 0; width: 36px; height: 38px; font-size: 18px; }

/* ── Filtry ───────────────────────────────────────────────── */
.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
    margin-bottom: 16px;
}
.filters label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.filters select { width: auto; }

/* ── Součet / total ───────────────────────────────────────── */
.total-line {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 2px solid var(--border-strong);
    text-align: right;
    font-size: 17px;
    font-weight: 700;
}
.total-line .num { font-size: 19px; }

/* ── Prázdný stav ─────────────────────────────────────────── */
.empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}
.empty p { margin-bottom: 16px; }

/* ── Login ────────────────────────────────────────────────── */
.login-shell {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%;
    max-width: 380px;
    margin: 6vh auto 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 28px;
}
.login-card h1 { text-align: center; margin-bottom: 20px; }

/* ── Utility ──────────────────────────────────────────────── */
.stack > * + * { margin-top: 12px; }
details > summary { cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details > summary::marker { content: ""; }
.row-split { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.nowrap { white-space: nowrap; }

/* =========================================================================
   Responzivita
   ========================================================================= */
@media (max-width: 760px) {
    .topbar__inner { min-height: 52px; padding-top: 6px; padding-bottom: 6px; }
    .nav-toggle-label { display: inline-block; margin-left: auto; }
    .mainnav {
        display: none;
        order: 4;
        flex-basis: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding-bottom: 6px;
    }
    .mainnav a { padding: 11px 12px; border-radius: var(--radius-sm); }
    .topbar__user {
        display: none;
        order: 3;
        flex-basis: 100%;
        justify-content: flex-end;
        padding: 8px 0 4px;
        border-top: 1px solid var(--border);
    }
    .nav-toggle:checked ~ .mainnav { display: flex; }
    .nav-toggle:checked ~ .topbar__user { display: flex; }
}

@media (max-width: 720px) {
    /* Tabulka → karty */
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data thead { position: absolute; left: -9999px; }
    table.data tr {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow-sm);
        margin-bottom: 12px;
        padding: 6px 4px;
    }
    table.data td {
        border: 0;
        border-bottom: 1px solid var(--surface-2);
        display: flex;
        justify-content: space-between;
        gap: 16px;
        padding: 9px 12px;
        text-align: right;
    }
    table.data tr td:last-child { border-bottom: 0; }
    table.data td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
    }
    table.data td.actions { text-align: right; flex-wrap: wrap; justify-content: flex-end; }
    table.data td.actions::before { content: ""; }
    table.data td.actions .btn { margin: 2px 0 2px 4px; }

    .item-row {
        grid-template-columns: 1fr;
        gap: 6px;
        border: 1px solid var(--border);
        border-radius: var(--radius-sm);
        padding: 12px;
        background: var(--surface-2);
    }
    .item-row__label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); }
    .item-row .btn { justify-self: end; }

    .wrap { margin-top: 16px; }
    h1 { font-size: 20px; }
}
