:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #eef2f5;
    --text: #17212b;
    --muted: #66717d;
    --line: #dce3ea;
    --primary: #155eef;
    --primary-dark: #0f46b8;
    --green: #16794c;
    --green-bg: #e8f7ef;
    --amber: #a15c00;
    --amber-bg: #fff4dc;
    --red: #b42318;
    --red-bg: #ffe9e7;
    --shadow: 0 12px 30px rgba(17, 24, 39, .08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
    letter-spacing: 0;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
}

textarea {
    min-height: 104px;
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 700;
}

label input,
label select,
label textarea {
    color: var(--text);
    font-weight: 400;
}

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

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

td small,
.topbar small,
.muted {
    display: block;
    color: var(--muted);
    margin-top: 3px;
}

.app-shell {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 30;
    width: 280px;
    padding: 18px;
    background: #111827;
    color: #fff;
    transform: translateX(-105%);
    transition: transform .2s ease;
}

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

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    font-weight: 800;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: var(--radius);
    background: #23a36b;
    color: #fff;
    font-size: 13px;
}

.nav {
    display: grid;
    gap: 6px;
    margin-top: 18px;
}

.nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
    border-radius: var(--radius);
    padding: 10px 12px;
    color: #d8dee8;
}

.nav a:hover {
    background: rgba(255, 255, 255, .09);
    color: #fff;
}

.main-shell {
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    min-height: 66px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
}

.content {
    display: grid;
    gap: 16px;
    padding: 14px;
}

.panel,
.auth-panel,
.stat-card,
.report-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 14px;
}

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

.section-heading h2,
.panel h2 {
    margin: 0;
    font-size: 18px;
}

.btn,
.icon-btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 800;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-light,
.icon-btn {
    background: var(--surface-2);
    border-color: var(--line);
    color: var(--text);
}

.btn-block {
    width: 100%;
}

.btn-large {
    min-height: 54px;
    font-size: 16px;
}

.form-grid {
    display: grid;
    gap: 14px;
}

.form-panel {
    max-width: 980px;
}

.grid-2,
.grid-3,
.filters-grid,
.stats-grid,
.report-grid {
    display: grid;
    gap: 12px;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 10px;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    padding-top: 10px;
    background: var(--surface);
}

.finance-preview {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.finance-preview div {
    display: grid;
    gap: 4px;
}

.finance-preview span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.finance-preview strong {
    font-size: 17px;
}

.search-form {
    display: flex;
    flex: 1;
    gap: 8px;
    min-width: 240px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

.actions {
    width: 1%;
    white-space: nowrap;
}

.empty {
    color: var(--muted);
    text-align: center;
    padding: 24px;
}

.product-thumb,
.product-photo-preview {
    display: block;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.product-thumb {
    width: 58px;
    height: 58px;
}

.product-thumb-empty {
    display: inline-grid;
    place-items: center;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-align: center;
}

.product-photo-preview {
    width: 160px;
    height: 120px;
}

.stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.stat-card {
    padding: 16px;
}

.stat-card span,
.report-card span {
    color: var(--muted);
    font-weight: 700;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
}

.stat-card.warning {
    border-color: #f2c76b;
    background: var(--amber-bg);
}

.stat-card.danger,
.report-card.danger {
    border-color: #ffb4ae;
    background: var(--red-bg);
}

.stock-badge,
.pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    border-radius: 999px;
    padding: 4px 10px;
    font-weight: 800;
}

.stock-badge.normal,
.pill.entry {
    background: var(--green-bg);
    color: var(--green);
}

.stock-badge.low,
.pill.correction {
    background: var(--amber-bg);
    color: var(--amber);
}

.stock-badge.negative,
.pill.exit {
    background: var(--red-bg);
    color: var(--red);
}

.alert {
    border-radius: var(--radius);
    padding: 12px 14px;
    font-weight: 800;
}

.alert-success {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid #a6e7c4;
}

.alert-error {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid #ffb4ae;
}

.autocomplete {
    position: relative;
}

.suggestions {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    left: 0;
    z-index: 40;
    display: none;
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.suggestions.is-open {
    display: block;
}

.suggestion {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    background: #fff;
    color: var(--text);
    text-align: left;
    cursor: pointer;
}

.suggestion:hover {
    background: var(--surface-2);
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 18px;
}

.auth-shell {
    width: min(100%, 420px);
}

.auth-panel {
    display: grid;
    gap: 16px;
    padding: 22px;
}

.auth-panel h1 {
    margin: 0;
}

.auth-brand {
    color: var(--text);
}

.muted-link,
.reset-link {
    color: var(--primary);
    font-weight: 800;
}

.reset-link {
    overflow-wrap: anywhere;
}

.report-grid {
    grid-template-columns: 1fr;
}

.report-card {
    display: grid;
    gap: 8px;
    padding: 16px;
}

@media (min-width: 760px) {
    .grid-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .filters-grid {
        grid-template-columns: repeat(6, minmax(130px, 1fr));
        align-items: end;
    }

    .stats-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .report-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    .app-shell {
        display: grid;
        grid-template-columns: 280px 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        height: 100vh;
        transform: none;
    }

    .icon-btn {
        display: none;
    }

    .content {
        padding: 22px;
    }
}
