:root {
    --c-bg: #f4f5f7;
    --c-fg: #1f2937;
    --c-muted: #6b7280;
    --c-border: #e5e7eb;
    --c-card: #ffffff;
    --c-primary: #2563eb;
    --c-primary-hover: #1d4ed8;
    --c-ok-bg: #d1fae5;
    --c-ok-fg: #065f46;
    --c-err-bg: #fee2e2;
    --c-err-fg: #991b1b;
    --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--c-fg);
    background: var(--c-bg);
    font-size: 16px;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--c-muted); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border: 1px solid var(--c-border);
    background: white;
    color: var(--c-fg);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
}
.btn:hover { background: #f9fafb; }
.btn-primary {
    background: var(--c-primary);
    color: white;
    border-color: var(--c-primary);
}
.btn-primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn-link {
    background: transparent;
    border: none;
    color: var(--c-primary);
    padding: 0.55rem 0.5rem;
}
.btn-link:hover { text-decoration: underline; background: transparent; }

/* ---------- Alerts ---------- */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin: 1rem 0; }
.alert-ok { background: var(--c-ok-bg); color: var(--c-ok-fg); }
.alert-error { background: var(--c-err-bg); color: var(--c-err-fg); }

/* ---------- Login ---------- */
.page-login {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}
.login-card {
    background: var(--c-card);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    width: 100%;
    max-width: 400px;
}
.login-card h1 { margin: 0 0 1.5rem; text-align: center; }
.login-card label { display: block; margin-bottom: 1rem; font-size: 0.9rem; color: var(--c-muted); }
.login-card input {
    width: 100%;
    padding: 0.7rem 0.9rem;
    margin-top: 0.3rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 1rem;
}
.login-card button { width: 100%; padding: 0.8rem; font-size: 1rem; }

/* ---------- Topbar ---------- */
.topbar {
    background: var(--c-card);
    padding: 0.75rem 1.25rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--c-border);
    flex-wrap: wrap;
    gap: 0.5rem;
}
.topbar__left, .topbar__right { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.topbar__nav { display: flex; gap: 0.25rem; }
.topbar__link {
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius);
    color: var(--c-fg);
    text-decoration: none;
}
.topbar__link:hover { background: #f3f4f6; text-decoration: none; }
.topbar__link.is-active { background: var(--c-primary); color: white; }
.topbar__link.is-active:hover { background: var(--c-primary-hover); }

/* ---------- Card ---------- */
.card {
    background: var(--c-card);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin: 1rem 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

/* ---------- Badge ---------- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}
.badge-open   { background: #fef3c7; color: #92400e; }
.badge-closed { background: #e5e7eb; color: #374151; }

/* ---------- Inventories list ---------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--c-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.data-table th, .data-table td {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid #f3f4f6;
    text-align: left;
    vertical-align: middle;
}
.data-table thead th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--c-muted);
    font-size: 0.9rem;
}
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .actions { text-align: right; white-space: nowrap; }
.inv-create__form { display: flex; gap: 0.6rem; align-items: end; flex-wrap: wrap; }
.inv-create__form label { display: flex; flex-direction: column; gap: 0.3rem; min-width: 280px; flex: 1; }
.inv-create__form input {
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 1rem;
}

/* ---------- Inventory page ---------- */
.page-inventory main.container--wide,
.container--wide {
    max-width: none;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.inv-header h1 { margin: 0 0 0.25rem; }
.inv-totals {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.75rem;
    margin: 0.75rem 0;
    padding: 0.75rem 1rem;
}
.totals__row { display: flex; flex-direction: column; gap: 0.15rem; }
.totals__row strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.inv-table-wrap {
    overflow-x: auto;
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.inv-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
}
/* Šířky sloupců (sumují se na ~100 %). Položka roztažitelná. */
.inv-table col.c-name  { width: auto; }
.inv-table col.c-qty   { width: 6.5%; }
.inv-table col.c-money { width: 8%; }

.inv-table thead th {
    position: sticky;
    top: 0;
    background: #f9fafb;
    z-index: 2;
    padding: 0.55rem 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--c-muted);
    text-align: right;
    line-height: 1.15;
    white-space: normal;
    border-bottom: 1px solid var(--c-border);
    vertical-align: bottom;
}
.inv-table thead th.c-name { text-align: left; }
.inv-table tbody td {
    padding: 0.55rem 0.5rem;
    border-bottom: 1px solid #f3f4f6;
    font-size: 0.92rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    vertical-align: middle;
}
.inv-table tbody td.c-name {
    text-align: left;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    line-height: 1.3;
}
.inv-table tbody tr.inv-row { transition: background 0.1s ease; }
.inv-table tbody tr.inv-row:nth-child(even) td { background: #fafbfc; }
.inv-table tbody tr.inv-row:hover td { background: #f0f7ff; }
.inv-table tbody tr.inv-row:last-child td { border-bottom: none; }
/* Extra prostor pod hlavičkou kategorie pro první řádek */
.inv-cat__head + .inv-row td { padding-top: 0.85rem; }
.inv-cat__head + .inv-row td.c-name { padding-top: 0.95rem; }

.inv-cat__head th {
    position: sticky;
    top: 56px;
    z-index: 1;
    background: linear-gradient(to bottom, #eef2ff, #e0e7ff);
    padding: 0.65rem 0.7rem 0.7rem;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e3a8a;
    border-top: 3px solid #c7d2fe;
    border-bottom: 1px solid #c7d2fe;
    letter-spacing: 0.01em;
}
.inv-cat__head + .inv-row td { border-top: 1px solid transparent; }
.inv-table .qty-input {
    width: 100%;
    max-width: 100%;
    padding: 0.3rem 0.45rem;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    text-align: right;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
}
.inv-table .qty-input:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.inv-table .qty-input.is-saving { background: #fef9c3; }
.inv-table .qty-input.is-saved { background: #d1fae5; transition: background 0.5s ease; }
.inv-table .qty-input.is-error { background: #fee2e2; }
.inv-table .qty-input:disabled { background: #f3f4f6; cursor: not-allowed; }

/* Pod šířkou 1100 px povolíme horizontální scroll, ale s rozumnou min-width */
@media (max-width: 1100px) {
    .inv-table { table-layout: auto; min-width: 1080px; }
    .inv-table .qty-input { width: 90px; }
}
@media (max-width: 720px) {
    .inv-table .qty-input { width: 80px; }
    .totals__row strong { font-size: 1rem; }
    .inv-header { gap: 0.5rem; }
}

/* ---------- Container ---------- */
.container { max-width: 1100px; margin: 0 auto; padding: 1rem 1.25rem 3rem; }

/* ---------- Toolbar ---------- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    margin: 0.5rem 0 1rem;
}
.toolbar__sync { margin-right: auto; }
.toolbar__search { display: flex; gap: 0.4rem; align-items: center; }
.toolbar__search input[type="search"] {
    padding: 0.55rem 0.8rem;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 1rem;
    min-width: 220px;
}
.toolbar__info { width: 100%; font-size: 0.9rem; }
.counts { margin-bottom: 0.75rem; font-size: 0.95rem; }
.empty { padding: 2rem; text-align: center; color: var(--c-muted); }

/* ---------- Items table ---------- */
.items {
    width: 100%;
    border-collapse: collapse;
    background: var(--c-card);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.items thead th {
    text-align: left;
    background: #f9fafb;
    padding: 0.7rem 0.9rem;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--c-muted);
}
.items tbody td {
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}
.items tbody tr:last-child td { border-bottom: none; }
.items tbody tr:hover { background: #fafbfc; }
.items .num { text-align: right; white-space: nowrap; }
.items .col-check { width: 56px; text-align: center; }

/* Custom checkbox */
.chk { display: inline-flex; align-items: center; cursor: pointer; }
.chk input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chk span {
    width: 26px;
    height: 26px;
    border: 2px solid var(--c-border);
    border-radius: 6px;
    display: inline-block;
    background: white;
    transition: all 0.15s ease;
    position: relative;
}
.chk input:checked + span {
    background: var(--c-primary);
    border-color: var(--c-primary);
}
.chk input:checked + span::after {
    content: "";
    position: absolute;
    left: 7px;
    top: 2px;
    width: 7px;
    height: 13px;
    border: solid white;
    border-width: 0 3px 3px 0;
    transform: rotate(45deg);
}
.chk input:focus + span { box-shadow: 0 0 0 3px rgba(37,99,235,0.25); }

/* ---------- Price input v /items.php ---------- */
.col-price { width: 130px; white-space: nowrap; }
.price-input {
    width: 80px;
    padding: 0.3rem 0.4rem;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    text-align: right;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
    box-sizing: border-box;
}
.price-input:focus {
    outline: none;
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}
.price-input.is-override {
    border-color: #f59e0b;
    background: #fffbeb;
    font-weight: 600;
}
.price-input.is-saving { background: #fef9c3; }
.price-input.is-saved  { background: #d1fae5; transition: background 0.5s ease; }
.price-input.is-error  { background: #fee2e2; border-color: #ef4444; }
.price-suffix { margin-left: 0.3rem; font-size: 0.85rem; }

/* ---------- Tree (categories → items) ---------- */
.tree { display: flex; flex-direction: column; gap: 0.5rem; }
.tree-controls { display: flex; gap: 0.25rem; }
.tree-group {
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    overflow: hidden;
}
.tree-group__head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.9rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    background: #f9fafb;
    border-bottom: 1px solid transparent;
}
.tree-group[open] > .tree-group__head {
    border-bottom-color: var(--c-border);
}
.tree-group__head::-webkit-details-marker { display: none; }
.tree-group__name { flex: 1; font-weight: 600; }
.tree-group__count { font-variant-numeric: tabular-nums; }
.tree-group__chev {
    display: inline-block;
    transition: transform 0.15s ease;
    color: var(--c-muted);
    font-size: 1.2rem;
    line-height: 1;
}
.tree-group:not([open]) > .tree-group__head .tree-group__chev {
    transform: rotate(-90deg);
}
.tree-group .items { box-shadow: none; border-radius: 0; background: transparent; }
.tree-group .items tbody tr:first-child td { border-top: none; }

/* Indeterminate (částečně vybráno) – jiné vizuální odlišení */
.chk input[data-indeterminate="1"]:not(:checked) + span,
.chk input.is-indeterminate:not(:checked) + span {
    background: var(--c-primary);
    border-color: var(--c-primary);
    opacity: 0.55;
}
.chk input[data-indeterminate="1"]:not(:checked) + span::after,
.chk input.is-indeterminate:not(:checked) + span::after {
    content: "";
    position: absolute;
    left: 4px; top: 9px; right: 4px;
    height: 4px;
    background: white;
    border-radius: 2px;
    transform: none;
    border: none;
}

/* ---------- Mobile: table → cards ---------- */
@media (max-width: 720px) {
    .items, .items thead, .items tbody, .items tr, .items td, .items th { display: block; }
    .items thead { display: none; }
    .items { background: transparent; box-shadow: none; }
    .items tbody tr {
        background: var(--c-card);
        border-radius: var(--radius);
        margin-bottom: 0.75rem;
        padding: 0.75rem;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
        position: relative;
    }
    .items tbody td {
        border: none;
        padding: 0.25rem 0;
        padding-left: 5.5rem;
        position: relative;
        min-height: 1.5rem;
    }
    .items tbody td.col-check {
        position: absolute;
        top: 0.75rem;
        right: 0.75rem;
        padding: 0;
        width: auto;
    }
    .items tbody td[data-label]::before {
        content: attr(data-label) ":";
        position: absolute;
        left: 0;
        font-weight: 600;
        color: var(--c-muted);
        font-size: 0.85rem;
        width: 5rem;
    }
    .items .num { text-align: left; }
    .toolbar__sync { width: 100%; }
    .toolbar__sync .btn { width: 100%; }
    .toolbar__search { width: 100%; }
    .toolbar__search input[type="search"] { flex: 1; min-width: 0; }
    .tree-controls { width: 100%; }
    .tree-group .items tbody tr {
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        border-top: 1px solid #f3f4f6;
        background: transparent;
    }
    .tree-group .items tbody tr:first-child { border-top: none; }
}
