* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--color-accent); text-decoration: none; }
a:hover { color: var(--color-accent-hover); }

.nav--plain {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    padding: var(--space-2) var(--space-4);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 1px solid var(--color-border);
}

.nav__logo, .sidebar__logo {
    display: inline-block;
    color: var(--color-text);
    font-weight: 600;
    letter-spacing: 0.22em;
    padding-left: 0.22em; /* компенсирует хвостовой интервал последней буквы — слово встаёт строго по центру */
    font-size: 16px;
    text-transform: uppercase;
    line-height: 1;
}
.nav__logo:hover, .sidebar__logo:hover { color: var(--color-text); }

/* Сайдбар — основная навигация авторизованных разделов ЛК/админки. Заменил
   горизонтальную шапку, когда пунктов стало больше десятка и она начала
   переноситься на вторую строку прямо под лого. */
.app-shell { display: flex; min-height: 100vh; align-items: flex-start; }

.sidebar {
    width: 248px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 22px 14px 14px;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    scrollbar-width: thin;
}

/* Бренд: слово SELEQT по центру панели, под ним подпись раздела — как на сайте, без тёмной «таблетки». */
.sidebar__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 4px 0 18px;
    margin-bottom: 10px;
    border-bottom: 1px solid var(--color-border);
    text-decoration: none;
}
.sidebar__sub { font-size: 10.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--color-text-muted); }

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; padding-bottom: var(--space-2); }
.sidebar__nav a, .sidebar__footer a {
    display: flex;
    align-items: center;
    color: var(--color-text-secondary);
    font-size: 14px;
    padding: 8px 12px;
    border-radius: 10px;
    transition: background .15s, color .15s;
}
.sidebar__nav a:hover, .sidebar__footer a:hover { background: rgba(0, 0, 0, 0.05); color: var(--color-text); }
.sidebar__badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #0071E3; color: #fff; font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
.sidebar__badge--red { background: #E5484D; } .sidebar__badge + .sidebar__badge { margin-left: 4px; }
.sidebar__nav a.is-on { background: var(--color-bg); color: var(--color-accent); font-weight: 600; box-shadow: var(--shadow-soft); }

.sidebar__group-label {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--color-text-muted);
    padding: 16px 12px 5px;
}
.sidebar__nav > .sidebar__group-label:first-child { padding-top: 4px; }

.sidebar__footer {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: var(--space-1);
    border-top: 1px solid var(--color-border);
}
.sidebar__user { display: flex; align-items: center; gap: 10px; padding: 8px 12px 6px; min-width: 0; }
.sidebar__ava { width: 26px; height: 26px; border-radius: 50%; background: var(--color-text); color: #fff; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; flex: none; }
.sidebar__who { font-size: 12.5px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

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

@media (max-width: 768px) {
    .app-shell { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: var(--space-1) var(--space-2);
        padding: 12px var(--space-2);
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        overflow: visible;
    }
    .sidebar__brand { flex-direction: row; gap: 10px; padding: 0; margin: 0; border-bottom: 0; }
    .sidebar__user { display: none; }
    /* Меню — одной прокручиваемой строкой под логотипом, а не столбцом на пол-экрана. */
    .sidebar__nav {
        order: 3;
        flex: 1 0 100%;
        flex-direction: row;
        flex-wrap: nowrap;
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .sidebar__nav a { white-space: nowrap; flex-shrink: 0; }
    .sidebar__group-label { display: none; }
    .sidebar__footer { order: 2; flex-direction: row; border-top: none; padding-top: 0; margin-left: auto; }
    .sidebar__footer a, .sidebar__footer button { white-space: nowrap; }
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-4);
}

.container--narrow { max-width: 480px; }

h1 { font-size: 32px; font-weight: 600; margin: 0 0 var(--space-3); }
h2 { font-size: 22px; font-weight: 600; margin: 0 0 var(--space-2); }
p { color: var(--color-text-secondary); line-height: 1.5; }

.card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    box-shadow: var(--shadow-soft);
    margin-bottom: var(--space-3);
}

.card--sm { border-radius: var(--radius-sm); padding: var(--space-3); }

.field { margin-bottom: var(--space-2); }
.field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 6px;
}
.field input, .field select {
    width: 100%;
    font-family: var(--font-family);
    font-size: 15px;
    padding: 12px 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--color-text);
}
.field input:focus, .field select:focus {
    outline: none;
    border-color: var(--color-accent);
}
.field small { display: block; color: var(--color-text-muted); font-size: 12px; margin-top: 4px; }
.field .error { color: #D70015; font-size: 12px; margin-top: 4px; }

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 var(--space-2);
}
@media (max-width: 640px) {
    .grid-2 { grid-template-columns: 1fr; }
}

.btn {
    display: inline-block;
    font-family: var(--font-family);
    font-size: 15px;
    font-weight: 500;
    padding: 12px 22px;
    border-radius: var(--radius-pill);
    border: none;
    cursor: pointer;
    text-align: center;
}
.btn-primary { background: var(--color-accent); color: #fff; }
.btn-primary:hover { background: var(--color-accent-hover); color: #fff; }
.btn-secondary { background: rgba(0, 0, 0, 0.05); color: var(--color-text); }
.btn-secondary:hover { background: rgba(0, 0, 0, 0.08); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}
.badge-none { background: rgba(110, 110, 115, 0.12); color: var(--color-text-muted); }
.badge-requested, .badge-sent { background: rgba(0, 113, 227, 0.12); color: var(--color-accent); }
.badge-signed { background: rgba(52, 199, 89, 0.14); color: #1D7A34; }
.badge-rejected { background: rgba(215, 0, 21, 0.1); color: #D70015; }

.flash {
    padding: var(--space-2);
    border-radius: var(--radius-sm);
    margin-bottom: var(--space-3);
    font-size: 14px;
}
.flash-info { background: rgba(0, 113, 227, 0.08); color: var(--color-accent); }
.flash-error { background: rgba(215, 0, 21, 0.08); color: #D70015; }
.flash-success { background: rgba(52, 199, 89, 0.1); color: #1D7A34; }
.flash-warning { background: rgba(255, 159, 10, 0.12); color: #6E6E73; }
.flash-with-action { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: var(--space-1); }

/* Чип с удалением по клику (доп. №9): своя маленькая форма без видимой кнопки "Сохранить",
   сабмит происходит по клику на "×" или по отпусканию при перетаскивании — см. team.js. */
.chip-list { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--color-footer); border-radius: var(--radius-pill); padding: 4px 10px; font-size: 13px; cursor: grab; }
.chip.is-dragging { opacity: 0.4; }
.chip button { border: none; background: none; cursor: pointer; color: var(--color-text-muted); font-size: 14px; line-height: 1; padding: 0; }
.chip button:hover { color: #D70015; }

/* Календарная сетка табеля (доп. №9, первый такой экран — нет более старого прецедента). */
.cal-grid { border-collapse: collapse; }
.cal-grid th, .cal-grid td { padding: 4px; text-align: center; font-size: 12px; border-bottom: 1px solid var(--color-border); white-space: nowrap; }
.cal-grid th:first-child, .cal-grid td:first-child { text-align: left; position: sticky; left: 0; background: var(--color-surface); }
.cal-grid td.is-weekend { background: var(--color-footer); }
.cal-grid td.is-holiday { background: rgba(255, 159, 10, 0.15); }
.cal-grid button.cal-cell { border: none; background: none; cursor: pointer; width: 100%; padding: 4px 0; font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 8px; border-bottom: 1px solid var(--color-border); font-size: 14px; }
th { color: var(--color-text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }

.stage-tracker { display: flex; gap: var(--space-1); flex-wrap: wrap; margin: var(--space-2) 0; }
.stage-step {
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    background: var(--color-footer);
    color: var(--color-text-muted);
}
.stage-step.active { background: var(--color-accent); color: #fff; }
.stage-step.done { background: rgba(0, 113, 227, 0.12); color: var(--color-accent); }

/* Global form control baseline — so any raw input/select outside .field
   still picks up the pill/rounded look instead of the browser default. */
input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="tel"], input[type="password"], select, textarea {
    font-family: var(--font-family);
    font-size: 14px;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--color-text);
}
textarea { width: 100%; resize: vertical; }
input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus,
input[type="email"]:focus, input[type="tel"]:focus, input[type="password"]:focus,
select:focus, textarea:focus { outline: none; border-color: var(--color-accent); }

input[type="file"] {
    font-family: var(--font-family);
    font-size: 13px;
    color: var(--color-text-secondary);
}
input[type="file"]::file-selector-button {
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 500;
    padding: 8px 16px;
    border-radius: var(--radius-pill);
    border: none;
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text);
    cursor: pointer;
    margin-right: 10px;
}
input[type="file"]::file-selector-button:hover { background: rgba(0, 0, 0, 0.08); }

input[type="checkbox"] { width: 16px; height: 16px; vertical-align: middle; accent-color: var(--color-accent); }

.qty-input { width: 84px !important; text-align: center; }

.sample-preview {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
}
.sample-preview__badge { font-weight: 600; margin-bottom: 6px; }
.sample-preview--locked {
    border: 2px solid #34C759;
    background: rgba(52, 199, 89, 0.08);
}
.sample-preview--locked .sample-preview__badge { color: #1D7A34; }
.sample-preview--pending {
    border: 2px solid var(--color-accent);
    background: rgba(0, 113, 227, 0.06);
}
.sample-preview--pending .sample-preview__badge { color: var(--color-accent); }
.sample-preview--error {
    border: 2px solid #D70015;
    background: rgba(215, 0, 21, 0.06);
    color: #D70015;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3);
    z-index: 100;
}
/* [hidden] и .modal-overlay имеют равную специфичность — без этого правила
   display:flex перебивает скрытие атрибутом hidden, и модалка (а если их
   несколько на странице — все сразу) виснет поверх всего и блокирует клики. */
.modal-overlay[hidden] { display: none; }
.modal-box {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: var(--space-3);
    max-width: 480px;
    width: 100%;
    box-shadow: var(--shadow-soft);
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--color-border);
    background: #fff;
    color: var(--color-text-secondary);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.05); color: var(--color-text); }

/* Payment status — pill badge + slim progress bar underneath */
.payment-status { display: inline-flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.payment-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}
.payment-badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.payment-badge-unpaid { background: rgba(215, 0, 21, 0.1); color: #D70015; }
.payment-badge-partial { background: rgba(255, 159, 10, 0.14); color: #6E6E73; }
.payment-badge-paid { background: rgba(52, 199, 89, 0.14); color: #1D7A34; }
.payment-bar {
    width: 120px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--color-border);
    overflow: hidden;
}
.payment-bar__fill { height: 100%; background: var(--color-accent); border-radius: var(--radius-pill); }
.payment-badge-paid ~ .payment-bar .payment-bar__fill { background: #1D7A34; }

/* Summary stat cards (задолженность клиента / завода) */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: var(--space-2); margin-bottom: var(--space-3); }
.stat-card {
    min-width: 0;
    background: var(--color-surface);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    box-shadow: var(--shadow-soft);
}
.stat-card__label { font-size: 13px; color: var(--color-text-muted); margin-bottom: 6px; }
.stat-card__value { font-size: 26px; font-weight: 600; color: var(--color-text); }
.stat-card__value small { font-size: 14px; font-weight: 400; color: var(--color-text-muted); }
.stat-card--ok .stat-card__value { color: #1D7A34; }
.stat-card--due .stat-card__value { color: #D70015; }

/* Production progress — grouped by order, one card per order line item */
.order-group {
    background: var(--color-footer);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
}
.order-group:last-child { margin-bottom: 0; }
.order-group__header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-1) var(--space-2);
    margin-bottom: var(--space-2);
}
.order-group__title { font-weight: 600; font-size: 15px; }
.order-group__ship { margin-left: auto; font-size: 13px; color: var(--color-text-secondary); }

.production-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr));
    gap: var(--space-2);
}
.production-card {
    background: #fff;
    border-radius: var(--radius-sm);
    padding: var(--space-2);
    box-shadow: var(--shadow-soft);
}
.production-card__title { font-weight: 600; font-size: 14px; margin-bottom: 2px; }
.production-card__meta { font-size: 12px; color: var(--color-text-muted); margin-bottom: var(--space-2); }
.production-stage { margin-bottom: 10px; }
.production-stage:last-child { margin-bottom: 0; }
.production-stage__row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--color-text-secondary);
    margin-bottom: 4px;
}
.production-stage__row small { color: var(--color-text-muted); }
.production-stage .payment-bar { width: 100%; height: 6px; }

/* Админка: широкие таблицы (журнал, очередь писем) получают больше места. */
.is-admin .container { max-width: 1240px; }

/* --- Адаптивность и таблицы (2026-09-25) ---------------------------------- */

/* Таблицы: если не влезают — прокручиваются внутри карточки, а не вылезают за рамку. */
.table-scroll { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 100%; }
.card .table-scroll { margin-top: 8px; }
.cdek-picker { border-top: 1px solid var(--color-border); padding-top: var(--space-2); }
td { overflow-wrap: break-word; vertical-align: top; }
/* Чекбоксы/радио внутри .field получали width:100% и вставали отдельной строкой над текстом. */
.field input[type="checkbox"], .field input[type="radio"] { width: auto; flex-shrink: 0; }

/* Inline-строки с display:flex в разметке страниц не переносились на узких экранах. */
[style*="display:flex"]:not(label) { flex-wrap: wrap; }
input, select, textarea { max-width: 100%; }
.field input, .field select, .field textarea { min-width: 0; }
td form { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
td .btn, td button { white-space: nowrap; }

@media (max-width: 768px) {
    /* В колонке align-items:flex-start сжимает .app-main по содержимому — растягиваем на всю ширину. */
    .app-shell { align-items: stretch; }
    .app-main { width: 100%; min-width: 0; }
}

@media (max-width: 640px) {
    .container { padding: var(--space-2); }
    .card { padding: var(--space-2); border-radius: 20px; }
    .card--sm { padding: var(--space-2); }
    h1 { font-size: 26px; overflow-wrap: anywhere; }
    h2 { font-size: 19px; }
    .table-scroll--wide > table { min-width: 480px; }
    th, td { padding: 10px 6px; }
}

/* --- Путь клиента: «Следующий шаг» и «Что дальше» ------------------------------------------- */
.next-step {
    background: #fff;
    border: 2px solid var(--color-accent);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    box-shadow: var(--shadow-soft);
    margin-bottom: var(--space-3);
}
.next-step__label { font-size: 13px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--color-accent); margin-bottom: 6px; }
.next-step__title { font-size: 24px; font-weight: 600; line-height: 1.25; margin-bottom: 8px; }
.next-step__why { font-size: 17px; line-height: 1.5; color: var(--color-text-secondary); margin-bottom: var(--space-2); }
.next-step__btn { font-size: 17px; padding: 12px 28px; }
.next-step--hero { padding: var(--space-4); }
.next-step--hero .next-step__title { font-size: 30px; }

.journey { list-style: none; margin: 0; padding: 0; }
.journey__item { display: flex; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-border); }
.journey__item:last-child { border-bottom: none; }
.journey__num {
    flex: 0 0 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
    font-weight: 600; background: var(--color-footer); color: var(--color-text-secondary);
}
.journey__item--current .journey__num { background: var(--color-accent); color: #fff; }
.journey__item--done .journey__num { background: #34C759; color: #fff; }
.journey__title { font-size: 17px; font-weight: 600; }
.journey__why { font-size: 15px; color: var(--color-text-secondary); margin: 4px 0 8px; line-height: 1.45; }
.journey__item--todo { opacity: 0.75; }
details.card summary { cursor: pointer; font-size: 16px; }
details.card[open] summary { margin-bottom: var(--space-1); }

@media (max-width: 640px) {
    .next-step__title { font-size: 21px; }
    .next-step--hero .next-step__title { font-size: 24px; }
    .next-step--hero { padding: var(--space-3); }
    .next-step__btn { display: block; text-align: center; }
}

.sidebar__locked { font-size: 14px; padding: 6px 12px; color: var(--color-text-muted); opacity: 0.7; cursor: default; }
@media (max-width: 768px) { .sidebar__locked { white-space: nowrap; flex-shrink: 0; } }

/* Заявка на вывоз: позиции списком, а не таблицей — поле количества всегда видно, в том числе на телефоне. */
.pickup-list { border-top: 1px solid var(--color-border); }
.pickup-row { display: flex; align-items: center; gap: var(--space-2); padding: 12px 0; border-bottom: 1px solid var(--color-border); }
.pickup-row__name { flex: 1; min-width: 0; }
.pickup-row__name strong { display: block; font-size: 16px; }
.pickup-row__name small { display: block; color: var(--color-text-muted); font-size: 13px; margin-top: 2px; }
.pickup-row input { width: 110px; flex-shrink: 0; }

/* Крупные инструкции пути клиента */
.big-text { font-size: 18px; line-height: 1.5; color: var(--color-text); }
.big-steps { font-size: 17px; line-height: 1.55; padding-left: 22px; margin: var(--space-2) 0; }
.big-steps li { margin-bottom: var(--space-2); }
.big-steps .btn { margin-top: 8px; }
.edo-box { background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-2); margin: var(--space-2) 0; display: flex; flex-direction: column; gap: var(--space-2); }
.edo-box__row { display: flex; align-items: center; gap: var(--space-1) var(--space-2); flex-wrap: wrap; }
.edo-box__label { flex: 0 0 100%; font-size: 14px; color: var(--color-text-muted); font-weight: 600; }
.edo-box__value { font-size: 20px; font-weight: 600; letter-spacing: 0.02em; overflow-wrap: anywhere; user-select: all; }
@media (max-width: 640px) { .edo-box__value { font-size: 15px; } }
