:root {
    /* Dark CRM */
    --bg-main: #0b1220;
    --bg-card: #0f1a30;
    --bg-soft: rgba(255,255,255,0.06);
    --accent: #60a5fa;
    --accent-soft: rgba(96,165,250,0.14);
    --accent-danger: #ef4444;
    --accent-success: #16a34a;
    --text-main: #e5e7eb;
    --text-muted: rgba(229,231,235,0.72);
    --border-soft: rgba(148,163,184,0.18);
    --radius-lg: 18px;
    --radius-md: 12px;
    --shadow-soft: 0 18px 45px rgba(0, 0, 0, 0.35);
    --shadow-light: 0 8px 24px rgba(0, 0, 0, 0.25);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
        "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    background: var(--bg-main);
    min-height: 100vh;
}

/* ========== LAYOUT ========== */

.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: rgba(10, 16, 30, 0.96);
    color: #e5e7eb;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar__logo {
    font-weight: 700;
    font-size: 20px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar__menu {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 11px;
    border-radius: 999px;
    text-decoration: none;
    color: #e5e7eb;
    font-size: 13px;
    white-space: nowrap;
}

.sidebar__link span.badge {
    margin-left: auto;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(248, 250, 252, 0.08);
    font-size: 11px;
}

.sidebar__link--active,
.sidebar__link:hover {
    background: rgba(96,165,250,0.18);
    color: #ffffff;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: transparent;
}

.topbar {
    padding: 14px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.topbar__left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.topbar__title {
    font-size: 20px;
    font-weight: 600;
}

.topbar__subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    color: var(--text-muted);
}

.topbar__avatar {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    background: rgba(96,165,250,0.22); /* flat */
    border: 1px solid rgba(96,165,250,0.35);
}

.content {
    padding: 10px 22px 22px;
}

/* ========== COMPAT / HELPERS (legacy markup) ========== */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 12px;
}

.page-title {
    margin: 0 0 12px;
    font-size: 20px;
    font-weight: 600;
}

.muted { color: var(--text-muted); }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }

.w-100 { width: 100%; }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.p-4 { padding: 16px; }

.row { display: flex; flex-wrap: wrap; gap: 12px; }
.col-auto { flex: 0 0 auto; }
.col-md-4 { flex: 1 1 260px; }
.align-items-end { align-items: flex-end; }
.g-2 { gap: 12px; }

.table-responsive,
.table-wrapper {
    overflow: auto;
}

/* ========== PAGE / CARDS ========== */

.page {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.page-header__title {
    font-size: 20px;
    font-weight: 600;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: var(--shadow-soft);
    border: 1px solid var(--border-soft);
}

.card__title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}

.card-metric .card__label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.card-metric .card__value {
    font-size: 20px;
    font-weight: 600;
}

/* ========== TABLES ========== */

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th,
.table td {
    padding: 7px 9px;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
}

.table th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
}

/* ========== FORM CONTROLS ========== */
.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea,
.form-control,
.form-select {
    width: 100%;
    padding: 9px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-soft);
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
    outline: none;
}

select { cursor: pointer; }

.input:focus,
.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus {
    border-color: rgba(96,165,250,0.55);
    box-shadow: 0 0 0 3px rgba(96,165,250,0.18);
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12px; color: var(--text-muted); }

/* ========== BUTTONS (compat) ========== */
.btn,
.btn-primary,
.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 12px;
    border-radius: 12px;
    border: 1px solid rgba(96,165,250,0.25);
    background: rgba(96,165,250,0.18);
    color: #fff;
    text-decoration: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}

.btn:hover,
.btn-primary:hover,
.btn-secondary:hover {
    background: rgba(96,165,250,0.26);
}

/* ========== ALERTS (compat) ========== */
.alert {
    border-radius: 14px;
    padding: 10px 12px;
    border: 1px solid var(--border-soft);
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
}

.alert--success,
.alert-success,
.alert--ok {
    border-color: rgba(22,163,74,0.35);
    background: rgba(22,163,74,0.12);
}

.alert--error,
.alert-danger,
.alert--danger {
    border-color: rgba(239,68,68,0.35);
    background: rgba(239,68,68,0.10);
}

/* ========== LINKS ========== */
a { color: var(--accent); }
a:hover { color: #93c5fd; }

.table tr:nth-child(even) td {
    background: var(--bg-soft);
}

/* ========== FORMS / BUTTONS ========== */

.form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form--inline {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form__row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.form__label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

.form__label--full {
    flex: 1 1 100%;
}

/* текстовые и селекты пусть остаются широкими */
input[type="text"],
input[type="date"],
select {
    padding: 7px 9px;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    font-size: 13px;
    background: #ffffff;
    color: #0b1220; /* фикс: читаемый текст на белом фоне */
    min-width: 150px;
}

/* числа — компактнее по умолчанию */
input[type="number"] {
    padding: 7px 9px;
    border-radius: 10px;
    border: 1px solid var(--border-soft);
    font-size: 13px;
    background: #ffffff;
    color: #0b1220; /* фикс: читаемый текст на белом фоне */
    min-width: 80px;   /* вместо 150px */
}

/* фикс: плейсхолдер не должен сливаться с введённым текстом */
input::placeholder,
textarea::placeholder {
    color: rgba(15, 23, 42, 0.45);
}


.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13px;
    cursor: pointer;
    background: rgba(96,165,250,0.18);
    border: 1px solid rgba(96,165,250,0.25);
    color: #fff;
    box-shadow: none;
}

.btn--ghost {
    background: transparent;
    color: var(--accent);
    border: 1px solid rgba(96,165,250,0.25);
    box-shadow: none;
}

/* ========== BADGES / ALERTS ========== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 10px;
    background: var(--accent-soft);
    color: var(--accent);
}

.badge--danger {
    background: rgba(239,68,68,0.12);
    color: #fecaca;
}

.badge--success {
    background: rgba(22,163,74,0.14);
    color: #bbf7d0;
}

/* legacy duplicate alert styles (keep aligned with new scheme above) */
.alert { margin-bottom: 8px; }
.alert--success { border-color: rgba(22,163,74,0.35); background: rgba(22,163,74,0.12); }
.alert--error { border-color: rgba(239,68,68,0.35); background: rgba(239,68,68,0.10); }

/* ========== RESPONSIVE ========== */

@media (max-width: 900px) {
    .layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        align-items: center;
        padding: 10px 10px;
        overflow-x: hidden; /* no horizontal scroll */
        gap: 10px;
    }

    .sidebar__logo {
        font-size: 16px;
        margin-right: 8px;
    }

    .sidebar__menu {
        flex-direction: row;
        gap: 4px;
        flex-wrap: wrap;
    }

    .sidebar__link {
        font-size: 11px;
        padding: 6px 9px;
        white-space: normal;
    }

    .main {
        min-height: calc(100vh - 56px);
    }

    .topbar {
        padding: 10px 14px;
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }

    .content {
        padding: 8px 12px 16px;
    }

    .form--inline {
        flex-direction: column;
        align-items: stretch;
    }

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

@media (max-width: 600px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }

    /* Mobile tables -> card rows */
    table.table.table--mobile {
        display: block;
        width: 100%;
    }

    table.table.table--mobile thead {
        display: none;
    }

    table.table.table--mobile tbody {
        display: block;
    }

    table.table.table--mobile tr {
        display: block;
        border: 1px solid var(--border-soft);
        background: rgba(255,255,255,0.03);
        border-radius: 14px;
        padding: 10px 10px;
        margin-bottom: 10px;
    }

    table.table.table--mobile td {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 10px;
        padding: 6px 0;
        border-bottom: 1px solid rgba(148,163,184,0.12);
        text-align: left;
        white-space: normal;
    }

    table.table.table--mobile td:last-child {
        border-bottom: none;
    }

    table.table.table--mobile td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: 11px;
        color: var(--text-muted);
        text-transform: uppercase;
        letter-spacing: .06em;
        max-width: 48%;
    }

    table.table.table--mobile td .muted,
    table.table.table--mobile td small {
        display: block;
    }

    /* Stock filters (remove leftover inline CSS blocks) */
    .stock-filters {
        display: flex;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }

    .stock-filters .form__label {
        min-width: 0;
    }
}
