.offline-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: #e65100;
    color: #fff;
    text-align: center;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.01em;
}

:root {
    --bg: #ffffff;
    --surface: #ffffff;
    --primary: #66a532;
    --primary-dark: #4a7a22;
    --text: #1a1a1a;
    --muted: #5a6655;
    --chip-bg: #dff0d0;
    --border: #b8d99a;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    position: relative;
}

/* Шапка */
.sticky-top { position: sticky; top: 0; z-index: 100; background: var(--bg); }

.header {
    background: var(--primary);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,.2);
}
.header h1 { font-size: 17px; font-weight: 600; }
.header-sub { font-size: 12px; opacity: .8; margin-top: 2px; }
.btn-icon { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; padding: 4px; display: inline-flex; align-items: center; justify-content: center; }
.btn-icon svg { display: block; }

/* Контент */
.content { padding: 12px 12px 80px; }

/* Нижняя навигация */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    background: #fff;
    display: flex;
    border-top: 1px solid #e0e0e0;
    box-shadow: 0 -2px 8px rgba(0,0,0,.1);
    z-index: 200;
}
.nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    text-decoration: none;
    color: #9e9e9e;
    font-size: 10px;
    gap: 3px;
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-active { color: var(--primary); }
.nav-badge {
    position: absolute;
    top: 4px;
    right: calc(50% - 18px);
    background: #e53935;
    color: #fff;
    border-radius: 10px;
    font-size: 9px;
    min-width: 16px;
    height: 16px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
}

/* Карточки */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 8px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.card-title { font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.card-sub { font-size: 12px; color: #757575; }
.card-row { display: flex; justify-content: space-between; align-items: center; }

/* Кнопки */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: 8px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-danger  { background: #e53935; color: #fff; }
.btn-outline { background: #fff; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 12px; width: auto; margin-top: 0; border-radius: 6px; }
.btn-add { background: var(--primary); color: #fff; }
.btn-remove { background: #e53935; color: #fff; }

/* Поле поиска */
.search-box {
    background: #fff;
    border-radius: 10px;
    display: flex;
    align-items: center;
    padding: 0 12px;
    margin-bottom: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.search-box input {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 8px;
    font-size: 14px;
    background: transparent;
}
.search-box svg { color: #9e9e9e; width: 18px; height: 18px; }

/* Форма */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 12px; color: #757575; margin-bottom: 4px; display: block; }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1.5px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    outline: none;
    transition: border-color .2s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); }
.form-textarea { resize: vertical; min-height: 70px; }

/* Логин */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: #ffffff;
}
.login-logo {
    font-size: 48px;
    margin-bottom: 4px;
}
.login-title {
    color: var(--primary);
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
    border: 2px solid var(--primary);
    border-radius: 8px;
    padding: 6px 20px;
}
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 32px; }
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
}

/* Количество */
.qty-wrap { display: flex; align-items: center; gap: 8px; }
.qty-btn {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: none;
    font-size: 16px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}
.qty-minus { background: #ffcdd2; color: #c62828; }
.qty-plus  { background: var(--chip-bg); color: var(--primary-dark); }
.qty-val   { font-weight: 600; min-width: 28px; text-align: center; }

/* Бейдж цены */
.price-badge {
    background: var(--chip-bg);
    color: var(--primary-dark);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 13px;
    font-weight: 600;
}
.stock-badge {
    background: #e8f5e9;
    color: #2e7d32;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11px;
}

/* Итог заказа */
.total-bar {
    background: var(--primary);
    color: #fff;
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.total-bar .label { font-size: 13px; opacity: .85; }
.total-bar .amount { font-size: 20px; font-weight: 700; }

/* Toast */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    display: none;
    z-index: 999;
    white-space: nowrap;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast-ok  { background: #388e3c; color: #fff; }
.toast-err { background: #c62828; color: #fff; }

/* Пустой список */
.empty { text-align: center; padding: 48px 16px; color: #9e9e9e; }
.empty-icon { font-size: 48px; margin-bottom: 8px; }

/* Спиннер */
.spinner {
    text-align: center;
    padding: 32px;
    color: #9e9e9e;
    font-size: 13px;
}

/* Статус заказа */
.status-new      { background: #fff3e0; color: #e65100; border-radius: 6px; padding: 2px 8px; font-size: 11px; }
.status-done     { background: #e8f5e9; color: #1b5e20; border-radius: 6px; padding: 2px 8px; font-size: 11px; }

/* ===== Каталог: фильтры, строки, пагинация ===== */

/* Панель фильтров (sticky под шапкой) */
.filter-bar {
    background: var(--bg);
    padding: 10px 12px 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,.05);
}
.filter-bar .search-box { margin-bottom: 8px; }
.group-select { margin-bottom: 0; padding: 8px 10px; font-size: 13px; }

/* Чипы групп (горизонтальный скролл) */
.chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}
.chips::-webkit-scrollbar { height: 4px; }
.chips::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.chip {
    flex: 0 0 auto;
    white-space: nowrap;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: all .15s;
}
.chip-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Заголовок таблицы */
.table-head {
    display: grid;
    grid-template-columns: 56px 1fr 46px 32px 32px 32px 78px;
    gap: 5px;
    padding: 6px 8px;
    margin-top: 8px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary-dark);
    border-bottom: 1px solid var(--border);
}
.table-head .th-r { text-align: right; }

/* Строка-таблица товара */
.row-item {
    display: grid;
    grid-template-columns: 56px 1fr 46px 32px 32px 32px 78px;
    gap: 5px;
    align-items: start;
    background: var(--surface);
    border-radius: 6px;
    padding: 6px 8px;
    margin-bottom: 4px;
    box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.row-in-cart { box-shadow: inset 3px 0 0 var(--primary), 0 1px 2px rgba(0,0,0,.05); }
.col-sap { font-size: 10px; font-family: monospace; color: var(--muted); word-break: break-all; line-height: 1.2; }
.col-name {
    font-size: 12px;
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.col-price { font-size: 12px; font-weight: 700; color: var(--primary-dark); text-align: right; }
.col-stock { font-size: 12px; color: #2e7d32; text-align: right; padding-top: 4px; }
.col-reserve { font-size: 12px; color: #c62828; text-align: right; padding-top: 4px; }
.col-cart { font-size: 12px; color: #e65100; text-align: right; padding-top: 4px; font-weight: 600; }
.col-add { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }

/* ---- Карточный вид: скрыт по умолчанию ---- */
.card-item { display: none; }

@media (max-width: 479px) {
    .table-head { display: none; }
    .row-item { display: none; }
    .card-item {
        display: block;
        background: var(--surface);
        border-radius: 8px;
        padding: 10px 12px;
        margin-bottom: 6px;
        box-shadow: 0 1px 3px rgba(0,0,0,.08);
    }
    .card-in-cart { box-shadow: inset 3px 0 0 var(--primary), 0 1px 3px rgba(0,0,0,.08); }
    .card-name {
        font-size: 14px;
        font-weight: 600;
        line-height: 1.35;
        margin-bottom: 3px;
        overflow-wrap: anywhere;
    }
    .card-meta {
        font-size: 10px;
        color: var(--muted);
        font-family: monospace;
        margin-bottom: 7px;
    }
    .card-row {
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .card-price {
        font-size: 13px;
        font-weight: 700;
        color: var(--primary-dark);
        flex: 0 0 auto;
        white-space: nowrap;
    }
    .card-nums {
        display: flex;
        gap: 10px;
        flex: 1;
    }
    .card-num-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        min-width: 28px;
    }
    .card-num-label {
        font-size: 9px;
        text-transform: uppercase;
        color: var(--muted);
        font-weight: 700;
        line-height: 1;
        margin-bottom: 1px;
    }
    .card-num-val { font-size: 12px; font-weight: 700; }
    .card-num-stock  .card-num-val { color: #2e7d32; }
    .card-num-reserve .card-num-val { color: #c62828; }
    .card-num-cart    .card-num-val { color: #e65100; }
    .card-actions {
        display: flex;
        align-items: center;
        gap: 3px;
        margin-left: auto;
        flex: 0 0 auto;
    }
}
.col-add .qty-btn { width: 26px; height: 26px; font-size: 16px; font-weight: 700; }
.qty-input {
    width: 48px;
    height: 26px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    padding: 0;
    -moz-appearance: textfield;
    color: var(--text);
    background: var(--surface);
}
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; }

/* Пагинация */
.pagination { margin-top: 12px; text-align: center; }
.pagination-top { margin-top: 0; margin-bottom: 10px; }
.pagination-top .page-info { display: none; }
.page-info { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.page-nav { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; }
.page-btn {
    min-width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}
.page-btn:disabled { opacity: .4; cursor: default; }
.page-active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.page-dots { padding: 0 4px; color: var(--muted); align-self: center; }

/* ===== Комбобокс выбора клиента ===== */
.client-combo { position: relative; margin-bottom: 8px; }
.client-combo-row { display: flex; gap: 6px; align-items: stretch; }
.client-input-wrap { flex: 1; position: relative; min-width: 0; }
.client-input, .combo-input {
    width: 100%;
    padding: 10px 30px 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
    outline: none;
}
.client-input:focus, .combo-input:focus { border-color: var(--primary); }
.client-clear {
    position: absolute;
    right: 6px; top: 50%;
    transform: translateY(-50%);
    width: 22px; height: 22px;
    border: none;
    background: #eceff1;
    color: var(--muted);
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
}
.client-mine-btn {
    flex: 0 0 auto;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 8px;
    padding: 0 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.client-mine-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.client-dropdown {
    position: absolute;
    left: 0; right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.15);
    max-height: 280px;
    overflow-y: auto;
    z-index: 300;
    display: none;
    -webkit-overflow-scrolling: touch;
}
.client-dropdown.open { display: block; }
.client-option {
    padding: 10px 12px;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
}
.client-option:last-child { border-bottom: none; }
.client-option.active, .client-option:active { background: var(--chip-bg); }
.client-option-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.client-empty-opt { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ===== Чипы режимов каталога ===== */
.catalog-modes { display: flex; gap: 6px; margin-bottom: 8px; }
.mode-chip {
    flex: 1;
    text-align: center;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 16px;
    padding: 7px 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.mode-chip-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.mode-chip:disabled { opacity: .4; cursor: default; }

/* ===== Редактируемая цена в корзине ===== */
.price-edit {
    width: 92px;
    padding: 5px 8px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-dark);
    background: var(--chip-bg);
    text-align: right;
    outline: none;
    -moz-appearance: textfield;
}
.price-edit:focus { border-color: var(--primary); background: #fff; }
.price-edit::-webkit-outer-spin-button,
.price-edit::-webkit-inner-spin-button { -webkit-appearance: none; }

/* ===== История: панель выбора периода ===== */
.period-bar {
    background: var(--surface);
    border-radius: 10px;
    padding: 10px;
    margin-bottom: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.preset-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}
.preset-btn {
    padding: 12px 4px;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text);
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.preset-btn:active { background: var(--chip-bg); }
.preset-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.date-row { display: flex; align-items: center; gap: 6px; }
.date-row input[type=date] {
    flex: 1;
    min-width: 0;
    padding: 11px 10px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}
.date-dash { color: var(--muted); }
.btn-period {
    padding: 11px 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.btn-period:active { background: var(--primary-dark); }
