/* Reset et base */
* {
    box-sizing: border-box;
    font-family: Arial, "Segoe UI", Helvetica, sans-serif;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
}

a {
    color: var(--primary);
}

button {
    font-family: inherit;
}

/* ===== APP SHELL ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ===== SIDEBAR (desktop nav) ===== */
.sidebar {
    display: none;
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    flex-direction: column;
    border-right: 1px solid #22303e;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: #22303e;
    letter-spacing: 0.02em;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 4px 0;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-left: 3px solid transparent;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 12.5px;
}

.sidebar-nav a:hover {
    background: var(--sidebar-bg-hover);
    color: #fff;
}

.sidebar-nav a.active {
    background: var(--sidebar-bg-hover);
    border-left-color: var(--sidebar-bg-active);
    color: #fff;
    font-weight: 700;
}

.nav-badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 1;
    padding: 3px 7px;
    border-radius: 999px;
}

.sidebar-group-header {
    display: flex;
    align-items: stretch;
}

.sidebar-group-header a {
    flex: 1;
    min-width: 0;
}

.sidebar-group-toggle {
    flex-shrink: 0;
    width: 30px;
    border: none;
    border-left: 3px solid transparent;
    background: none;
    color: var(--sidebar-text);
    cursor: pointer;
    font-size: 10px;
    transition: transform 0.15s;
}

.sidebar-group-toggle:hover {
    color: #fff;
    background: var(--sidebar-bg-hover);
}

.sidebar-group-toggle.open {
    transform: rotate(180deg);
}

.sidebar-submenu {
    display: none;
    flex-direction: column;
}

.sidebar-submenu.open {
    display: flex;
}

.sidebar-submenu a {
    padding-left: 34px;
    font-size: 12px;
}

.sidebar-section {
    margin-top: 10px;
    padding: 6px 14px 4px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #8ea0b3;
    border-top: 1px solid #22303e;
}

.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid #22303e;
}

.sidebar-household {
    font-size: 11px;
    color: var(--sidebar-text);
    opacity: 0.85;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sidebar-user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sidebar-user-name {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
}

.sidebar-logout {
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 11px;
    border: 1px solid #4a5f74;
    padding: 2px 6px;
}

.sidebar-logout:hover {
    color: #fff;
    border-color: #fff;
}

/* ===== HEADER (title bar + toolbar) ===== */
.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

header {
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border);
    padding: 8px 14px;
}

header h1 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0.01em;
    text-transform: uppercase;
}

.admin-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: -8px -14px 8px;
    padding: 7px 14px;
    background: var(--warning-tint);
    color: var(--warning);
    font-size: 12.5px;
    font-weight: 600;
}

.admin-banner a {
    color: inherit;
    text-decoration: underline;
    white-space: nowrap;
}

.header-user {
    font-size: 11.5px;
    color: var(--muted);
    white-space: nowrap;
    text-decoration: none;
    border: 1px solid transparent;
    padding: 3px 7px;
}

.header-user:hover {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.search-form {
    flex-wrap: wrap;
    margin-top: 8px;
}

.filters-panel {
    display: none;
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.filters-panel.open {
    display: block;
}

/* CONTENT */
.content {
    padding: 12px 14px 80px;
    flex: 1;
}

/* CARD (auth/settings panels) */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 12px 14px;
    margin-bottom: 12px;
}

/* ===== MODAL (product add/edit popup) ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 33, 0.55);
    display: block;
}

.modal-panel {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    margin: 0;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.modal-header h3 {
    margin: 0;
    font-size: 14px;
}

.modal-close {
    text-decoration: none;
    color: var(--muted);
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
    padding: 2px 6px;
    border: 1px solid var(--border);
}

.modal-close:hover {
    color: var(--text);
    border-color: var(--text);
}

/* ===== EXPIRY ALERT BANNER ===== */
.alert-banner {
    border-left: 4px solid var(--danger);
}

.alert-group + .alert-group {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-light);
}

.alert-heading {
    display: block;
    font-size: 12.5px;
    margin-bottom: 4px;
}

.alert-danger-text { color: var(--danger); }
.alert-warning-text { color: var(--warning); }

.alert-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.alert-list li {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
    font-size: 12.5px;
}

.alert-list a {
    text-decoration: none;
}

.alert-action {
    margin-left: auto;
    font-weight: 700;
    color: var(--primary);
}

/* ===== STAT ROW (flat summary strip) ===== */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1px;
    margin-bottom: 12px;
    background: var(--border);
    border: 1px solid var(--border);
}

.stat-tile {
    background: var(--surface);
    padding: 8px 12px;
}

.stat-tile .stat-value {
    font-size: 19px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-tile .stat-label {
    font-size: 10.5px;
    color: var(--muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.stat-tile.stat-warning .stat-value { color: var(--warning); }
.stat-tile.stat-danger .stat-value { color: var(--danger); }
.stat-tile.stat-ok .stat-value { color: var(--ok); }

/* ===== BADGES (flat, square, outlined) ===== */
.badge {
    display: inline-block;
    padding: 1px 6px;
    border: 1px solid currentColor;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1.5;
}

.badge-ok { background: var(--ok-tint); color: var(--ok); }
.badge-warning { background: var(--warning-tint); color: var(--warning); }
.badge-danger { background: var(--danger-tint); color: var(--danger); }
.badge-neutral { background: var(--bg); color: var(--muted); }

/* ===== DATA TABLE (dense grid) ===== */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    overflow-x: auto;
}

table.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 5px 10px;
    text-align: left;
    border: 1px solid var(--border-light);
    font-size: 12.5px;
    line-height: 1.4;
}

.data-table thead th {
    background: var(--toolbar-bg);
    color: var(--text);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 700;
    border-color: var(--border);
}

.data-table th a {
    color: inherit;
    text-decoration: none;
}

.data-table th a:hover {
    text-decoration: underline;
}

.data-table tbody tr:nth-child(even) {
    background: #f6f8fa;
}

.data-table tbody tr:hover {
    background: var(--primary-tint);
}

.data-table .cell-title {
    font-weight: 700;
    color: var(--text);
}

.data-table .cell-sub {
    color: var(--muted);
    font-size: 11.5px;
}

.data-table .cell-actions {
    display: flex;
    gap: 12px;
    white-space: nowrap;
}

.data-table .cell-actions a {
    text-decoration: none;
    font-weight: 700;
    font-size: 12px;
}

.data-table .row-form {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.data-table .row-form input,
.data-table .row-form select {
    padding: 3px 5px;
    border: 1px solid var(--border);
    font-size: 12px;
    background: var(--surface);
}

.data-table .row-form input[type="number"] { width: 70px; }
.data-table .row-form input[type="date"] { width: 130px; }

.mini-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

@media (min-width: 768px) {
    .mini-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.empty-state {
    padding: 24px 14px;
    text-align: center;
    color: var(--muted);
    font-size: 12.5px;
}

/* legacy list styles (unused by current markup, kept flat for safety) */
.item-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 4px;
}

.item-title a {
    text-decoration: none;
    color: var(--text);
}

.item-meta {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 8px;
}

.item-meta .type {
    color: var(--primary);
    font-weight: 700;
}

.item-actions {
    display: flex;
    border-top: 1px solid var(--border);
    margin-top: 8px;
}

.item-actions a {
    flex: 1;
    padding: 8px 0;
    text-align: center;
    text-decoration: none;
    font-size: 13px;
    color: var(--primary);
    font-weight: 700;
}

.item-actions a + a {
    border-left: 1px solid var(--border);
}

/* ===== TAB BAR (mobile bottom nav) ===== */
.tabbar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 52px;
    background: var(--toolbar-bg);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 20;
}

.tab {
    flex: 1;
    text-align: center;
    font-size: 10.5px;
    color: var(--muted);
    padding-top: 6px;
}

.tab.active {
    color: var(--primary);
    font-weight: 700;
}

.tab button {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: inherit;
    font: inherit;
    padding: 0;
    cursor: pointer;
}

select option.bold {
	font-weight: bold;
}

/* Buttons */
button, .btn {
    cursor: pointer;
}

/* Toolbar "add" button (replaces the old floating circular button) */
.toolbar-add {
    position: fixed;
    bottom: 60px;
    right: 12px;
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary-hover);
    font-size: 13px;
    font-weight: 700;
    padding: 8px 14px;
    text-decoration: none;
    z-index: 21;
}

/* ===== DESKTOP (>= 768px): sidebar takes over, table stays a table ===== */
@media (min-width: 768px) {
    .sidebar {
        display: flex;
    }

    .tabbar,
    .toolbar-add {
        display: none;
    }

    .content {
        padding: 14px 20px 24px;
        max-width: 1180px;
    }

    header {
        padding: 10px 20px;
    }

    .content.card-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        align-content: start;
        gap: 1px;
        background: var(--border);
        border: 1px solid var(--border);
    }

    .content.card-grid .card {
        margin-bottom: 0;
        border: none;
    }

    .content:not(.card-grid) .stock-form,
    .content:not(.card-grid) > form,
    .content:not(.card-grid) > .card {
        max-width: 460px;
    }

    .content:not(.card-grid) > .card + .card {
        margin-top: 12px;
    }
}

/* ===== MOBILE (< 768px): off-canvas sidebar drawer ===== */
@media (max-width: 767px) {
    .sidebar {
        display: flex;
        position: fixed;
        inset: 0 auto 0 0;
        width: 82%;
        max-width: 300px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 33, 0.55);
        z-index: 99;
    }

    .sidebar-backdrop.open {
        display: block;
    }
}

/* ===== MOBILE (< 768px): data tables collapse into stacked rows ===== */
@media (max-width: 767px) {
    table.data-table,
    .data-table thead,
    .data-table tbody,
    .data-table tr {
        display: block;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tr {
        background: var(--surface);
        border-bottom: 2px solid var(--border);
    }

    .data-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        border-left: none;
        border-right: none;
    }

    .data-table td::before {
        content: attr(data-label);
        font-size: 10.5px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        color: var(--muted);
        flex-shrink: 0;
    }

    .data-table td.cell-actions-td::before {
        content: none;
    }

    .data-table .cell-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .data-table .row-form {
        width: 100%;
        justify-content: flex-end;
    }
}
