/* ---------------------------------------------------------------------------
   Салон «Память» — визуальный стиль.
   Взят с сайта клиента bkmemory.ru: Noto Sans, чёрно-бело-серая палитра,
   кнопки #292929, радиус 10px, тонкие рамки.
   Только оформление: цвета, карточки, вкладки, таблица, значки.
   Никакой бизнес-логики здесь нет.
   --------------------------------------------------------------------------- */

@import url('../fonts/noto-sans.css');

:root {
    --font: 'Noto Sans', Arial, sans-serif;
    --bg: #f5f5f5;
    --card: #ffffff;
    --text: #000000;
    --muted: #949494;
    --border: #ebebeb;
    --primary: #292929;
    --primary-hover: #000000;
    --success: #2f7d4f;
    --success-bg: #eef6f0;
    --warning: #9a6a12;
    --warning-bg: #faf3e6;
    --danger: #b03a3a;
    --danger-bg: #fbeeee;
    --purple: #4b4b4b;
    --purple-bg: #f0f0f0;
    --radius: 10px;
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
}

input[type="checkbox"], input[type="radio"] { accent-color: #292929; }
::selection { background: #292929; color: #fff; }
a { color: #292929; }
a:hover { color: #000000; }

/* ----------------------------- Шапка сайта ------------------------------- */
.topbar {
    background: #000000;
    color: #fff;
    padding: 10px 22px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid #1c1c1c;
    /* Шапка по ширине экрана: отступы внутри суммы ширины, а не сверху —
       иначе на телефоне шапка вылезает вправо на их величину. */
    box-sizing: border-box;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; }
.brand-logo { height: 42px; width: auto; display: block; }
.brand h1 { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.topnav { display: flex; align-items: center; gap: 16px; font-size: 13px; }
.topnav a { color: #d6d6d6; text-decoration: none; letter-spacing: 0.2px; white-space: nowrap; }
.topnav a:hover { color: #fff; }
.topnav a.nav-btn {
    background: #fff; color: #000000; padding: 7px 14px; border-radius: 8px;
    font-weight: 600; text-decoration: none;
}
.topnav a.nav-btn:hover { background: #ebebeb; }

.role-switcher {
    display: flex; align-items: center; gap: 10px; background: #111111;
    padding: 6px 12px; border-radius: 8px; border: 1px solid #262626;
    white-space: nowrap;
}
.role-switcher .hint { font-size: 11px; color: #8a8a8a; letter-spacing: 0.3px; }
@media (max-width: 1560px) {
    .role-switcher .hint { display: none; }
}
.role-badge { padding: 4px 10px; border-radius: 6px; font-weight: 600; font-size: 11px; letter-spacing: 0.4px; text-transform: uppercase; }
.role-manager { background: #3a3a3a; color: #fff; }
.role-admin { background: #ffffff; color: #000000; }
.role-management { background: #1f1f1f; color: #cfcfcf; border: 1px solid #3a3a3a; }

.container { max-width: 1400px; margin: 0 auto; padding: 20px; }

/* ------------------------------ KPI-карточки ----------------------------- */
.kpi-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px; margin-bottom: 20px;
}
.kpi-card {
    background: var(--card); padding: 16px 18px; border-radius: var(--radius);
    border: 1px solid var(--border);
}
.kpi-title {
    font-size: 11px; color: var(--muted); text-transform: uppercase;
    font-weight: 600; letter-spacing: 0.5px; margin-bottom: 8px;
}
.kpi-value { font-size: 26px; font-weight: 600; letter-spacing: -0.2px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 5px; }
.kpi-alert { border-left: 3px solid var(--danger); }
.kpi-warn { border-left: 3px solid var(--warning); }
.kpi-ok { border-left: 3px solid var(--success); }
.kpi-admin-only { border-left: 3px solid var(--primary); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }

/* --------------------------- Панель вкладок-папок ------------------------ */
.toolbar {
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 12px; margin-bottom: 16px;
}
.folder-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.tab-btn {
    padding: 9px 15px; border-radius: var(--radius); border: 1px solid var(--border);
    background: var(--card); cursor: pointer; font-weight: 600; font-size: 13px;
    color: var(--text); display: flex; align-items: center; gap: 7px;
    transition: 0.18s; font-family: inherit; text-decoration: none;
}
.tab-btn:hover { border-color: #c9c9c9; background: #fafafa; }
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-btn.tab-alert { border-color: #e3b3b3; color: var(--danger); }
.tab-btn.tab-alert.active { background: var(--danger); color: #fff; border-color: var(--danger); }
.tab-count { background: rgba(0, 0, 0, 0.08); padding: 1px 7px; border-radius: 10px; font-size: 11px; }
.tab-btn.active .tab-count { background: rgba(255, 255, 255, 0.22); color: #fff; }

.actions-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.search-input {
    padding: 9px 13px; border: 1px solid var(--border); border-radius: var(--radius);
    width: 280px; font-family: inherit; font-size: 13px; background: #fff; color: var(--text);
}
.search-input:focus { outline: none; border-color: #292929; }

.btn {
    padding: 9px 16px; border-radius: var(--radius); border: none; font-weight: 600;
    cursor: pointer; font-size: 13px; display: inline-flex; align-items: center;
    gap: 7px; text-decoration: none; font-family: inherit;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: #fff; border: 1px solid #e2e2e2; color: var(--text); }
.btn-outline:hover { background: #f5f5f5; border-color: #c9c9c9; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 10px; font-size: 12px; border-radius: 8px; }

/* -------------------------------- Таблица -------------------------------- */
.table-wrap {
    background: var(--card); border-radius: var(--radius); border: 1px solid var(--border);
    overflow-x: auto; margin-bottom: 16px;
}
.table-wrap table { width: 100%; border-collapse: collapse; text-align: left; }
.table-wrap th {
    background: #fafafa; padding: 12px 14px; font-size: 11px; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table-wrap td { padding: 13px 14px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
.table-wrap tbody tr:hover td { background: #fafafa; }
.table-wrap tbody tr.row-click { cursor: pointer; }
.table-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.row-total { font-size: 14px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; }

.badge {
    display: inline-block; padding: 3px 9px; border-radius: 6px; font-size: 11px;
    font-weight: 600; margin-right: 4px; margin-bottom: 2px; white-space: nowrap;
}
.b-monument { background: #f0f0f0; color: #292929; }
.b-tile { background: #faf3e6; color: #8a5a12; }
.b-fence { background: #f2f2f2; color: #292929; }
.b-cross { background: #f4f4f4; color: #292929; }
.b-table { background: #f2f2f2; color: #292929; }
.b-other { background: #ebebeb; color: #292929; }
.b-status { padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; display: inline-block; background: var(--purple-bg); color: var(--purple); }
.b-status.st-done { background: var(--success-bg); color: var(--success); }
.b-status.st-installed { background: #f0f0f0; color: #292929; }
.b-status.st-cancelled { background: #ebebeb; color: #949494; text-decoration: line-through; }
.b-status.st-in_salon { background: var(--warning-bg); color: var(--warning); }

.pay-badge { font-weight: 600; font-size: 12px; line-height: 1.45; padding: 4px 9px; border-radius: 6px; display: inline-block; }
.pay-none { background: var(--danger-bg); color: var(--danger); }
.pay-part { background: var(--warning-bg); color: var(--warning); }
.pay-full { background: var(--success-bg); color: var(--success); }

.alert-tag {
    display: inline-block; background: var(--danger-bg); color: var(--danger);
    font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 5px;
    margin-top: 4px; margin-right: 4px;
}
.muted-small { font-size: 12px; color: var(--muted); }
.muted-tiny { font-size: 11px; color: var(--muted); }
.text-primary { color: var(--primary); }
.text-danger { color: var(--danger); }

/* ------------------------- Сводка по папкам (карточки) ------------------- */
.folder-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px; margin-top: 22px;
}
.folder-card {
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 14px 16px; text-decoration: none; color: var(--text);
    display: block; transition: 0.15s;
}
.folder-card:hover { border-color: #949494; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.07); }
.folder-card .fc-title { font-weight: 700; font-size: 13px; display: flex; justify-content: space-between; align-items: center; }
.folder-card .fc-count { font-size: 20px; font-weight: 700; margin: 6px 0 2px; }
.folder-card .fc-empty { color: #dcdcdc; }
.folder-card .fc-money { font-size: 12px; color: var(--muted); }

.section-h { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; margin: 26px 0 10px; }
.hint-box { background: #fdf9ef; border: 1px solid #ecd9b0; color: #8a5a12; border-radius: 10px; padding: 14px 16px; font-size: 13px; }

/* =================== КАРТОЧКА ЗАКАЗА (МОДАЛЬНОЕ ОКНО) ==================== */
.modal-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.62);
    z-index: 60; padding: 18px; overflow-y: auto;
}
.modal-backdrop.open { display: block; }
.modal {
    background: var(--card); border-radius: var(--radius); max-width: 1180px; margin: 0 auto;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); overflow: hidden;
    /* Окно никогда не шире экрана: на телефоне карточка заказа иначе
       раздувается до ширины своих полей и уезжает вправо. */
    width: 100%; box-sizing: border-box;
}
.modal-header {
    padding: 15px 22px; background: #000000; color: #fff;
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; flex-wrap: wrap;
}
.modal-header h2 { font-size: 16px; font-weight: 600; margin: 0; letter-spacing: 0.2px; }
.modal-header .modal-sub { font-size: 12px; opacity: 0.75; }
.modal-header .btn {
    background: transparent; color: #fff; border: 1px solid #3a3a3a;
}
.modal-header .btn:hover { background: #1a1a1a; border-color: #5a5a5a; }
.modal-body { padding: 18px 22px; }
.modal-footer {
    padding: 14px 22px; background: #fafafa; border-top: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    flex-wrap: wrap; gap: 10px;
}
.modal-footer .modal-totals { font-size: 15px; font-weight: 600; }

.section-box {
    border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
    margin-bottom: 14px; background: #fff; min-width: 0;
}
.section-box.box-plain { background: #fafafa; }
.section-box.box-warn { background: #fdf9ef; border-color: #ecd9b0; }
.section-title {
    font-weight: 600; font-size: 14px; margin: 0 0 12px 0; color: #000000;
    display: flex; justify-content: space-between; align-items: center;
    border-bottom: 1px solid #ebebeb; padding-bottom: 9px; flex-wrap: wrap; gap: 8px;
}
.section-box.box-warn .section-title { color: #8a5a12; border-color: #ecd9b0; }

/* Сетка полей карточки */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(185px, 1fr)); gap: 12px; }
.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-group.col-2 { grid-column: span 2; }
.form-group.col-full { grid-column: 1 / -1; }
.form-group label { font-size: 11px; font-weight: 600; color: #292929; letter-spacing: 0.3px; }
.form-group .field-value {
    padding: 8px 11px; border: 1px solid var(--border); border-radius: 8px;
    font-size: 13px; background: #fafafa; min-height: 36px;
}
.form-group .field-value.field-money { background: #f2f8f4; border-color: #b9d8c4; font-weight: 600; }
.form-group .field-value.field-empty { color: #949494; }

/* Редактируемые поля карточки (пересчёт сумм) */
.form-group .field-input {
    padding: 8px 11px; border: 1px solid #e2e2e2; border-radius: 8px;
    font-size: 13px; font-family: inherit; background: #fff; min-height: 36px;
    color: var(--text); width: 100%; box-sizing: border-box;
}
.form-group .field-input:focus {
    outline: none; border-color: #292929;
    box-shadow: 0 0 0 3px rgba(41, 41, 41, 0.10);
}
.form-group .field-input.is-changed { border-color: #b8862b; background: #fdf9ef; }
.save-status { font-size: 12px; font-weight: 600; }
.save-status.ok { color: var(--success); }
.save-status.err { color: var(--danger); }

/* Вкладки карточки («скрепка») */
.clip-tabs { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 1px solid #ebebeb; padding-bottom: 10px; flex-wrap: wrap; }
.clip-tab {
    padding: 9px 15px; border-radius: var(--radius); border: 1px solid var(--border);
    background: #fafafa; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--text);
    font-family: inherit; transition: 0.18s;
}
.clip-tab:hover { border-color: #c9c9c9; }
.clip-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.clip-pane { display: none; }
.clip-pane.active { display: block; }

.subtotal-box {
    background: #f7f7f7; border: 1px solid #e2e2e2; padding: 12px 16px; border-radius: var(--radius);
    font-weight: 600; font-size: 15px; color: #000000;
    display: flex; justify-content: space-between; align-items: center; margin-top: 12px;
}
.card-order-head {
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    flex-wrap: wrap; margin-bottom: 10px;
}
.card-order-head .card-order-title { font-weight: 600; font-size: 14px; }
.pay-row-total { font-weight: 600; }

/* ---------------------- Платежи в карточке заказа ------------------------- */
.pay-add-box {
    background: #fafafa; border: 1px solid var(--border); padding: 14px;
    border-radius: var(--radius); display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
}
.pay-actions { white-space: nowrap; }
.pay-actions .btn + .btn { margin-left: 4px; }
.pay-comment { max-width: 320px; word-break: break-word; }

/* ---------------- Доп. товары и услуги в карточке заказа ------------------ */
.extras-table td { padding: 8px 10px; }
.extras-table .field-input { width: 100%; box-sizing: border-box; }
.extras-table .extra-qty, .extras-table .extra-price { text-align: right; }
.extras-table .extra-sum { font-weight: 700; white-space: nowrap; }
.readonly-mode .extras-add-box { display: none; }

.pay-dialog-backdrop {
    display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.7);
    z-index: 90; padding: 18px; overflow-y: auto;
}
.pay-dialog-backdrop.open {
    display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh;
}
.pay-dialog {
    background: #fff; border-radius: var(--radius); width: 100%; max-width: 470px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4); overflow: hidden;
}
.pay-dialog-head {
    padding: 13px 18px; background: #000000; color: #fff;
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    font-weight: 600; font-size: 14px;
}
.pay-dialog-x {
    background: transparent; border: none; color: #fff; cursor: pointer;
    font-size: 16px; line-height: 1; padding: 4px 6px; border-radius: 6px; font-family: inherit;
}
.pay-dialog-x:hover { background: rgba(255, 255, 255, 0.18); }
.pay-dialog-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
.pay-dialog-body .field-input { width: 100%; box-sizing: border-box; }
.pay-dialog-body textarea.field-input { resize: vertical; min-height: 70px; }
.pay-dialog .form-group[hidden] { display: none; }
.pay-dialog-foot {
    padding: 12px 18px; background: #fafafa; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

/* ----------------------------- Эскиз (холст) ------------------------------ */
.sketch-toolbar {
    display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px;
}
.sketch-toolbar .btn.active-tool {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.sketch-sep { width: 1px; height: 24px; background: #ebebeb; }
.sketch-ctl {
    display: flex; align-items: center; gap: 6px; font-size: 12px;
    font-weight: 600; color: #292929;
}
.sketch-ctl input[type="range"] { width: 100px; }
.sketch-ctl select {
    padding: 5px 8px; border: 1px solid #dcdcdc; border-radius: 6px;
    font-family: inherit; font-size: 12px; background: #fff; color: var(--text);
}
.sketch-ctl input[type="text"] {
    padding: 5px 8px; border: 1px solid #dcdcdc; border-radius: 6px;
    font-family: inherit; font-size: 12px; background: #fff; color: var(--text);
    flex: 1; min-width: 150px; box-sizing: border-box;
}
.sketch-ctl input[type="text"]:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}
.sketch-pad-wrap {
    border: 1px solid var(--border); border-radius: 10px;
    background: #fff; overflow: hidden;
}
canvas.sketch-pad {
    display: block; width: 100%; height: auto; background: #fff;
    cursor: crosshair; touch-action: none;
}

/* ==========================================================================
   ШАГ 7: ВХОД ПО PIN-КОДУ, РОЛИ, СМЕНА ПОЛЬЗОВАТЕЛЯ
   ========================================================================== */

/* --- Универсальное поле ввода (в таблицах и окнах входа) --- */
.field-input {
    padding: 7px 10px; border: 1px solid #dcdcdc; border-radius: 6px;
    font-size: 13px; font-family: inherit; background: #fff; min-height: 34px;
    color: var(--text); box-sizing: border-box;
}
.field-input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

/* --- Бейдж роли --- */
.role-management { background: #292929; color: #fff; }
.user-chip .role-badge { padding: 3px 8px; font-size: 11px; border-radius: 6px; }

/* --- Кто сейчас работает (в шапке) --- */
.user-chip {
    display: flex; align-items: center; gap: 8px; padding: 5px 8px;
    border-radius: 10px; cursor: pointer;
    background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.12);
}
.user-chip:hover { background: rgba(255, 255, 255, 0.14); }
.user-ava {
    width: 30px; height: 30px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex: 0 0 auto;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta b { font-size: 12px; color: #fff; }
.user-meta small { font-size: 11px; color: #949494; }

/* --- Плашка «только просмотр» --- */
.view-banner {
    background: var(--warning-bg); color: #8a5a12; border-bottom: 1px solid #ecd9b0;
    padding: 8px 20px; font-size: 13px; text-align: center;
}

/* --- Сообщения после действий --- */
.flash-wrap {
    max-width: 1400px; margin: 12px auto 0; padding: 0 20px;
    display: flex; flex-direction: column; gap: 6px;
}
.flash { padding: 9px 14px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.flash-ok { background: var(--success-bg); color: var(--success); border-color: #b9d8c4; }
.flash-error { background: var(--danger-bg); color: var(--danger); border-color: #e3b3b3; }

/* --- Экран входа: всегда влезает в окно браузера, без прокрутки --- */
.login-body {
    margin: 0; height: 100vh; height: 100dvh; overflow: hidden;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center; padding: 2vh 16px;
    box-sizing: border-box; position: relative;
    background: #000 url('../img/hero-sky.jpg') center / cover no-repeat;
    font-family: var(--font);
}
.login-body::before {
    content: ''; position: fixed; inset: 0; z-index: 0;
    background: rgba(0, 0, 0, 0.55);
}
.login-logo {
    position: relative; z-index: 1; height: clamp(30px, 6vh, 54px); width: auto;
    margin-bottom: clamp(8px, 2vh, 20px); display: block;
}
.pin-card {
    position: relative; z-index: 1;
    width: 340px; max-width: 100%; background: #fff; border-radius: var(--radius);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
    padding: clamp(14px, 2.6vh, 26px) clamp(14px, 2.4vw, 24px) clamp(10px, 1.8vh, 18px);
    box-sizing: border-box;
}
.pin-card-sm { width: 330px; padding: 20px 18px 14px; }
.pin-brand { text-align: center; margin-bottom: 4px; }
.pin-brand-title { font-size: clamp(15px, 2.4vh, 18px); font-weight: 600; color: #000000; line-height: 1.3; }
.pin-brand-sub {
    font-size: 11px; color: var(--muted); margin-top: 4px;
    text-transform: uppercase; letter-spacing: 0.5px;
}

.pin-clock { margin: clamp(8px, 1.6vh, 16px) 0 2px; text-align: center; }
.pin-clock-time {
    font-size: clamp(20px, 4vh, 32px); font-weight: 600; color: #000000; letter-spacing: 1px;
    font-variant-numeric: tabular-nums; line-height: 1.1;
}
.pin-clock-date { font-size: 12px; color: var(--muted); margin-top: 4px; }

.pin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pin-title { font-size: 16px; font-weight: 700; color: #000000; }
.pin-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.pin-x {
    border: none; background: transparent; font-size: 16px; color: #a0a0a0;
    cursor: pointer; padding: 2px 6px; border-radius: 6px; line-height: 1;
}
.pin-x:hover { background: #f5f5f5; color: #000000; }

.pin-dots { display: flex; gap: 12px; justify-content: center;
    margin: clamp(8px, 1.6vh, 14px) 0 clamp(10px, 1.8vh, 16px); }
.pin-dots span {
    width: 16px; height: 16px; border-radius: 50%;
    border: 2px solid #dcdcdc; background: #fff; transition: background 0.12s, border-color 0.12s;
}
.pin-dots span.filled { background: var(--primary); border-color: var(--primary); }
/* PIN от 6 до 8 цифр: лишние точки не показываем, пока не начнут вводить. */
.pin-dots span.hidden-dot { display: none; }

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.pin-key {
    padding: clamp(7px, 1.6vh, 14px) 0; font-size: clamp(15px, 2.2vh, 18px);
    font-weight: 600; font-family: inherit;
    border: 1px solid var(--border); border-radius: 10px;
    background: #fafafa; color: var(--text); cursor: pointer;
}
.pin-key:hover { background: #ebebeb; }
.pin-key:active { transform: translateY(1px); }
.pin-key-aux { background: #fff; color: var(--muted); font-size: 15px; }

.pin-error {
    min-height: 18px; margin-top: clamp(4px, 1vh, 10px); font-size: 12px; font-weight: 600;
    color: var(--danger); text-align: center; opacity: 0;
}
.pin-error-visible { opacity: 1; }

.pin-submit { width: 100%; margin-top: clamp(4px, 1vh, 8px); }
.pin-hint { margin-top: clamp(6px, 1.2vh, 14px); font-size: 11px; color: #a0a0a0; text-align: center; line-height: 1.4; }
@media (max-height: 560px) {
    .pin-hint { display: none; }
}

/* --- Первая дверь входа: логин+пароль или Яндекс (до PIN) --- */
.gate-card { width: 380px; }
.gate-form { display: block; }
.gate-section-title {
    font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px;
    margin: clamp(6px, 1.2vh, 12px) 0 6px;
}
.gate-label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0 3px; }
.gate-input {
    width: 100%; box-sizing: border-box; padding: 9px 11px; font-family: inherit;
    font-size: 15px; color: var(--text); background: #fff;
    border: 1px solid var(--border); border-radius: 9px; outline: none;
}
.gate-input:focus { border-color: #000000; box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.06); }
.gate-captcha-row { display: flex; gap: 8px; align-items: center; }
.gate-captcha {
    height: 54px; width: 100%; max-width: 168px; border: 1px solid var(--border); border-radius: 8px;
    background: #fff; image-rendering: pixelated; flex: 0 0 auto; object-fit: contain;
}
.gate-captcha-input { width: 100%; letter-spacing: 4px; text-align: center; }
.gate-submit { width: 100%; margin-top: 10px; }
.gate-divider {
    display: flex; align-items: center; gap: 10px; margin: 12px 0 10px;
    color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px;
}
.gate-divider::before, .gate-divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
}
.gate-yandex {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border);
    background: #fc3f1d; color: #fff; text-decoration: none; font-size: 14px; font-weight: 600;
}
.gate-yandex:hover { background: #e5310f; color: #fff; }
.gate-yandex-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; border-radius: 50%; background: #fff; color: #fc3f1d;
    font-weight: 700; font-size: 13px; line-height: 1;
}
.gate-lock {
    margin: 8px 0 2px; padding: 8px 10px; border-radius: 8px; font-size: 12px;
    background: var(--danger-bg); color: var(--danger); border: 1px solid #e3b3b3;
    text-align: center;
}

/* --- Окно «Смена пользователя» --- */
.pin-backdrop {
    display: none; position: fixed; inset: 0; z-index: 120; padding: 16px;
    background: rgba(15, 23, 42, 0.6); align-items: center; justify-content: center;
    box-sizing: border-box;
}
.pin-backdrop.open { display: flex; }

.pin-own { margin-top: 12px; border-top: 1px solid #ebebeb; padding-top: 10px; }
.pin-own summary { cursor: pointer; font-size: 12px; color: var(--primary); font-weight: 600; }
.pin-own-form { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.pin-own-form label {
    font-size: 11px; font-weight: 600; color: #292929;
    display: flex; flex-direction: column; gap: 3px;
}
.pin-own-form .field-input { width: 100%; }
.pin-foot { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; align-items: center; }
.pin-link { font-size: 12px; color: #292929; text-decoration: underline; }
.pin-link:hover { color: #000000; }
.pin-link-btn { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; }

/* --- Режим просмотра в карточке заказа --- */
.readonly-mode .field-input {
    background: #f5f5f5; color: var(--muted); cursor: not-allowed;
}
.readonly-mode .field-input:focus { box-shadow: none; border-color: var(--border); }
.readonly-mode canvas.sketch-pad { pointer-events: none; cursor: default; }

/* --- Таблица пользователей --- */
.table-wrap tbody tr.row-inactive td { background: #fafafa; color: #949494; }

/* ==========================================================================
   ШАГ 8: БЫСТРАЯ ПРОДАЖА
   ========================================================================== */
.qs-delete { display: flex; gap: 6px; align-items: center; }
.qs-delete .field-input { width: 150px; min-height: 30px; padding: 4px 8px; font-size: 12px; }
.qs-delete .btn { white-space: nowrap; }

.nowrap { white-space: nowrap; }

/* Шаг 9: бейдж «в продаже» в каталоге */
.badge.b-active { background: var(--success-bg); color: var(--success); }

/* ==========================================================================
   ШАГ 10: старые страницы (объект и форма заказа) в дизайне салона
   ========================================================================== */
.is-hidden { display: none !important; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.radio-label {
    display: flex; align-items: center; gap: 7px;
    font-size: 13px; color: var(--text); cursor: pointer;
}
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-group { margin: 0; }

/* ==========================================================================
   ШАГ 12: главный экран v3 и карточка заказа v3
   ========================================================================== */
.topnav { display: flex; gap: 14px; align-items: center; font-size: 13px; }
.topnav a { color: #e2e2e2; text-decoration: none; }
.topnav a:hover { color: #fff; }
.role-switcher-hint { font-size: 12px; color: #949494; }

.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.sortable:hover { color: var(--primary); }
.sort-arrow { font-size: 10px; opacity: 0.85; }
#ordersTbody tr[data-order-id] { cursor: pointer; }

.split-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; }
.price-input { background: #f2f8f4; border-color: #b9d8c4 !important; font-weight: 700; }
.price-picker { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.price-picker select {
    width: 100%; padding: 7px 8px; border: 1px solid #dcdcdc; border-radius: 6px;
    font-size: 13px; font-family: inherit; background: #fff; color: var(--text);
    min-height: 34px;
}
.price-picker select:focus { outline: none; border-color: var(--primary); }
.rare-tile { display: none; }
.canvas-wrap {
    border: 1px dashed var(--border); border-radius: 8px; padding: 14px;
    background: #fafafa; display: flex; flex-direction: column; gap: 10px;
    align-items: center; justify-content: center; min-height: 260px;
}
.empty-row td { text-align: center; color: var(--muted); }
.tab-btn.tab-alert { border-color: #e3b3b3; color: var(--danger); }
.tab-btn.tab-alert.active { background: var(--danger); color: #fff; border-color: var(--danger); }
#orderCardV3Modal .modal { max-width: 1180px; }
#crmV3Dialog { z-index: 200; }
@media (max-width: 1000px) {
    .split-2 { grid-template-columns: 1fr; }
}

/* Шаг 14: панель инструментов эскиза внутри карточки */
.canvas-wrap { min-height: 0; border-style: solid; }
.canvas-tools { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; width: 100%; }
.canvas-tools .btn.active-tool { background: var(--primary); color: #fff; border-color: var(--primary); }
.canvas-prop-bar {
    width: 100%; background: #f5f5f5; border: 1px solid #d0d0d0; border-radius: 6px;
    padding: 6px 8px; font-size: 12px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
canvas.sketch-pad { width: auto; height: auto; max-width: 100%; cursor: crosshair; }
.sketch-hint { font-size: 11px; color: var(--muted); text-align: center; }
.readonly-mode .canvas-tools, .readonly-mode .canvas-prop-bar { display: none; }

/* Шаг 14: ровная сетка полей рядом с холстом */
.split-2 .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
.split-2 .form-group { align-self: start; }
.split-2 .canvas-wrap { align-self: start; }

/* ==========================================================================
   ШАГ 15: печать бланков (предпросмотр и печать)
   ========================================================================== */
#print-modal { z-index: 160; }
#print-modal .modal { max-width: 850px; }
.print-sheet {
    background: #fff; color: #000; padding: 28px 34px; border: 1px solid #949494;
    font-family: Georgia, "Times New Roman", serif; font-size: 13px; line-height: 1.45;
}
.print-line { border-bottom: 1px solid #000; display: inline-block; min-width: 120px; padding: 0 6px; font-weight: bold; }
.sketch-box {
    border: 2px solid #000; height: 280px; display: flex; align-items: center;
    justify-content: center; color: #949494; font-family: Arial, sans-serif;
    font-size: 12px; overflow: hidden;
}
.lined-block p { border-bottom: 1px solid #000; min-height: 22px; margin: 4px 0; padding-left: 4px; }

@media print {
    /* Бланк (памятник/цех/плитка/ограда) должен печататься ОДНИМ листом.
       Раньше прятали только .no-print, а окно предпросмотра и всё, что за ним,
       оставалось в раскладке печати. В том числе окно карточки заказа: на
       телефоне оно «экран на всю высоту + прокрутка внутри» (шаг 22), и
       браузер режет его на страницы — получалась пачка пустых листов.
       Теперь при печати вся страница выводится из потока, рамка окна
       предпросмотра не занимает места, а мелкие поля/подписи невидимы. */
    html, body {
        margin: 0 !important; padding: 0 !important;
        min-height: 0 !important; height: auto !important;
        background: #fff !important; overflow: visible !important;
    }
    body * { visibility: hidden; }
    /* Прокрутка — прямой источник лишних листов: во всех контейнерах ее нет. */
    body * { overflow: visible !important; }
    .topbar, .view-banner, .flash-wrap, footer, .mobile-nav { display: none !important; }
    .container { padding: 0 !important; max-width: none !important; }

    /* ГЛАВНОЕ правило: при печати остаются только окно предпросмотра и сам
       бланк. Все остальные окна (карточка заказа — она на телефоне на весь
       экран с прокруткой), главный экран, шапка и подвал выключаются, а не
       только прячутся: скрытое через visibility может тех же листов дать.
       По этой причине списки ниже не зависят от того, в каком порядке
       браузер применил правила или отменил display окна скриптом.
       Окно предпросмотра при загрузке страницы переносится прямо в <body>
       (см. base.html): внутри <main> оно попадало под запрет ниже, и в
       бумагу уходил пустой лист. */
    body > *:not(#print-modal):not(.print-modal),
    #print-modal .modal-header,
    #print-modal .modal-footer { display: none !important; }

    #print-modal, #print-area, #print-area * { visibility: visible; }
    /* Окно предпросмотра на телефоне — fixed на весь экран. Для печати его
       рамка не должна занимать лист: печатается только сам бланк.
       ВАЖНО: height: 0 у окна НЕЛЬЗЯ — бланк живёт внутри окна (окно открыто
       внутри <main class="container">), высота 0 обрезает его, и в бумагу
       уходит пустой лист. Поэтому высота — по содержимому. */
    #print-modal {
        display: block !important; position: static !important; inset: auto !important;
        padding: 0 !important; background: none !important;
        height: auto !important; min-height: 0 !important; max-height: none !important;
        overflow: visible !important;
        /* Ширина листа — по бумаге, а не по окну телефона: иначе браузер
           отрезает правую часть бланка (там Детали изготовления, цены). */
        width: auto !important; max-width: none !important;
    }
    #print-modal .modal {
        display: block !important; position: static !important;
        max-width: none !important; width: auto !important;
        height: auto !important; min-height: 0 !important; max-height: none !important;
        margin: 0 !important;
        border-radius: 0 !important; box-shadow: none !important;
    }
    #print-modal .modal-body {
        display: block !important; position: static !important;
        padding: 0 !important; background: #fff !important;
        flex: 0 0 auto !important;
        height: auto !important; min-height: 0 !important;
    }
    #print-area {
        position: static !important; width: auto !important;
        margin: 0 !important; border: none !important;
        padding: 0 !important; border-radius: 0 !important;
    }
    #print-area .print-sheet { padding: 0 !important; }
    #print-area div, #print-area p { break-inside: avoid-page; }
    #print-area img { max-width: 100% !important; }
    .sketch-box { break-inside: avoid-page; }

    /* Эти поля всегда пустые на бланке — на листе лишние. */
    #orderCardV3Box input, #orderCardV3Box select, #orderCardV3Box textarea,
    #orderCardV3Box canvas, #orderCardV3Box button, #orderCardV3Box .canvas-tools,
    #orderCardV3Box .modal-footer { display: none !important; }
    .no-print { display: none !important; }
}

/* Телефон: бланк на печать уходит так, как нарисован на компьютере.
   Окно предпросмотра на телефоне на всю ширину экрана, бланк внутри
   прокручивается вбок. Без этого размеры «поля + подпись» в процентах
   считаются от узкого экрана, и на бумаге бланк съезжает и обрезается. */
@media (max-width: 760px) {
    #print-modal .modal-body { overflow-x: auto; }
    #print-area {
        width: 760px;
        flex: 0 0 auto;
    }
}

/* ==================== СТАРТОВЫЙ ЭКРАН (две плашки) ==================== */
.launcher {
    max-width: 1040px; margin: 0 auto;
    min-height: calc(100vh - 240px);
    display: flex; flex-direction: column; justify-content: center;
}
.launcher-head { text-align: center; margin-bottom: 26px; }
.launcher-clock { margin-bottom: 8px; }
.launcher-date { font-size: 13px; color: var(--muted); }
.launcher-time {
    font-size: 36px; font-weight: 700; color: #000000; line-height: 1.1;
    font-variant-numeric: tabular-nums; letter-spacing: 1px;
}
.launcher-hello { font-size: 22px; font-weight: 700; color: #000000; margin: 6px 0 2px; }
.launcher-sub { margin: 0; color: var(--muted); font-size: 14px; }

.launcher-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.launcher-tile {
    display: flex; flex-direction: column; gap: 7px;
    padding: 28px 26px 24px; border-radius: var(--radius);
    border: 1px solid var(--border); background: #fff; color: inherit;
    text-decoration: none;
    transition: border-color 0.2s, background-color 0.2s;
}
.launcher-tile:hover { border-color: #292929; background: #fafafa; }
.launcher-icon { font-size: 30px; line-height: 1; }
.launcher-title { font-size: 20px; font-weight: 600; color: #000000; }
.launcher-desc { font-size: 13px; color: var(--muted); line-height: 1.5; }
.launcher-meta {
    margin-top: 12px; font-size: 11px; font-weight: 600; color: #292929;
    text-transform: uppercase; letter-spacing: 0.5px;
}
.launcher-sale .launcher-meta { color: var(--success); }
.launcher-hint { margin-top: 22px; text-align: center; font-size: 12px; color: #a0a0a0; }

@media (max-width: 760px) {
    .launcher-tiles { grid-template-columns: 1fr; }
    .launcher-time { font-size: 30px; }
}

/* ==================== ПЛАШКА «ФИНАНСОВАЯ СВОДКА» ==================== */
.launcher-finance {
    display: flex; align-items: center; gap: 16px; margin-top: 18px;
    padding: 18px 22px; border-radius: var(--radius); border: 1px solid var(--border);
    background: #fff; color: inherit; text-decoration: none;
    transition: border-color 0.2s, background-color 0.2s;
}
.launcher-finance:hover { border-color: #292929; background: #fafafa; }
.launcher-finance-text { display: flex; flex-direction: column; gap: 3px; }
.launcher-finance .launcher-title { font-size: 16px; }

/* ==================== ФИНАНСОВАЯ СВОДКА ==================== */
.fin-head {
    display: flex; justify-content: space-between; align-items: flex-end;
    gap: 16px; flex-wrap: wrap; margin-bottom: 16px;
}
.fin-page-title { font-size: 22px; font-weight: 700; margin: 0; }
.fin-period { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fin-period .field-input { width: auto; min-width: 150px; }
.fin-sheet {
    background: #fff; border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px;
}
.fin-print-head {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 16px;
    border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 16px;
}
.fin-print-title { font-size: 16px; font-weight: 700; }
.fin-print-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.fin-print-stamp { font-size: 11px; color: var(--muted); white-space: nowrap; }
.fin-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.fin-card { border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.fin-label {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); font-weight: 600;
}
.fin-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.fin-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }
.fin-h {
    font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); margin: 20px 0 10px; font-weight: 600;
}
.fin-products { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.fin-product { border: 1px solid var(--border); border-radius: 8px; padding: 14px; }
.fin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fin-table th, .fin-table td {
    padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left;
}
.fin-table th {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--muted); font-weight: 600;
}
.fin-table .num { text-align: right; white-space: nowrap; }
.fin-table tfoot th {
    border-top: 2px solid #292929; font-size: 12px; color: var(--text);
    text-transform: none; letter-spacing: 0;
}
.fin-table-narrow { max-width: 360px; }
.fin-foot {
    margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border);
    font-size: 12px; color: var(--muted);
}
.debt-value { color: var(--danger); font-weight: 600; white-space: nowrap; }
#dashTable th:last-child, #dashTable td:last-child { white-space: nowrap; }

@media (max-width: 900px) {
    .fin-grid { grid-template-columns: repeat(2, 1fr); }
    .fin-products { grid-template-columns: 1fr; }
}

@media print {
    /* Сводка печатается в обычном потоке, чтобы длинная таблица переносилась
       на следующие страницы, а не обрезалась. */
    .topbar, .view-banner, .flash-wrap, footer, .mobile-nav { display: none !important; }
    .container { padding: 0 !important; max-width: none !important; }
    #print-area.fin-sheet { position: static; width: auto; border: none; padding: 0; }
    .fin-sheet { border: none; padding: 0; }
    .fin-grid { grid-template-columns: repeat(4, 1fr); }
    .fin-products { grid-template-columns: repeat(3, 1fr); }
    .fin-table { font-size: 11px; }
    .fin-h { margin: 14px 0 8px; }
    .fin-card, .fin-product, .fin-table tr { break-inside: avoid; }
}

/* ==========================================================================
   ШАГ 22: БРАУЗЕР ТЕЛЕФОНА

   Салон работает в том числе с телефона: менеджер приезжает на кладбище и
   открывает CRM прямо с руки. Всё ниже — только оформление, логика не меняется.

   Полотно (до 760 px):
   • шапка сжимается: логотип + кто сейчас работает (PIN) + кнопка «меню»;
   • навигация — нижнее меню с крупными кнопками под большой палец;
   • таблицы с длинными формулировками превращаются в карточки: каждая строка —
     отдельный блок, у каждого значения своя подпись (td-label, data-label);
   • поля — не мельче 16 px (iOS иначе сам увеличивает страницу при нажатии);
     высота нажатия — от 44 px;
   • карточка заказа — на весь экран, вкладки — горизонтальной лентой,
     «Сохранить» — закреплено внизу;
   • кнопка «Новый заказ» прилипает к низу списка заказов.
   Полотно (до 1000 px): формы карточки заказа — в одну колонку.
   ========================================================================== */

/* Видимые только на малом экране подписи столбцов и короткий итог карточки. */
.td-label { display: none; }
.modal-totals-short { display: none; }

/* Плашка «Выйти полностью» в окне смены пользователя. */
.pin-full-exit {
    display: flex; align-items: flex-start; gap: 8px; margin-top: 4px;
    font-size: 12px; color: #4b4b4b; line-height: 1.35; cursor: pointer;
}
.pin-full-exit input { margin-top: 2px; width: 18px; height: 18px; flex: 0 0 auto; }

/* Нижнее меню: на компьютере его нет — там шапка. */
.mobile-nav { display: none; }
.topnav a.is-here { color: #fff; }
/* «☰» — только на телефоне (см. медиазапрос ниже). */
.nav-toggle { display: none; }

@media (max-width: 1000px) {
    /* Сетка полей карточки заказа — по одному в ряд: на телефоне два поля
       в ширину не влезают без переносов в подписях. */
    .split-2 .form-grid { grid-template-columns: minmax(0, 1fr); }
    .split-2 { gap: 12px; }
    .form-group.col-2 { grid-column: auto; }
    .price-picker { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
    :root { --radius: 12px; }

    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    body {
        font-size: 15px;
        padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px));
    }

    /* --------------------------- Не уезжать вбок -------------------------- */
    /* У лент разделов («Все заказы», «Памятники»…) своя горизонтальная
       прокрутка. Пока браузер считал их содержимое шире экрана, вправо
       уезжала ВСЯ страница (скриншот 24.11.2026: 956 px на экране 390 px).
       Здесь — запасы по ширине; сама проверка (сколько метров вбок уезжает
       страница) стоит в конце этого блока, когда все правила уже прочитаны. */
    html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
    .folder-tabs, #dashTabs, #catTabs, .toolbar {
        max-width: 100%; box-sizing: border-box;
    }

    /* ------------------------------- Шапка -------------------------------- */
    /* Шапка всегда в одну строку и не шире экрана: логотип, кто работает
       (нажатие — смена по PIN), «☰». Иначе «главная кнопка» раздувает страницу. */
    .topbar {
        padding: 6px 8px;
        padding-top: calc(6px + env(safe-area-inset-top, 0px));
        gap: 6px;
        flex-wrap: wrap;
        position: relative;
    }
    .brand { gap: 0; flex: 0 1 auto; min-width: 0; }
    .brand-logo { height: 32px; max-width: 150px; object-fit: contain; }
    .topnav { display: none; }
    /* «☰» на телефоне — выпадающая лента разделов под шапкой. */
    .topnav.nav-open {
        display: flex; flex-wrap: nowrap; overflow-x: auto;
        order: 3; flex: 1 1 100%; width: 100%;
        padding: 2px 0 4px; gap: 4px;
        scrollbar-width: none;
    }
    .topnav.nav-open::-webkit-scrollbar { display: none; }
    .topnav.nav-open a {
        flex: 0 0 auto; padding: 9px 12px; border-radius: 9px;
        background: rgba(255, 255, 255, 0.10); font-size: 13px;
    }
    .nav-toggle { display: inline-flex; }

    .role-switcher {
        margin-left: auto; flex: 0 0 auto;
        gap: 4px; padding: 2px; background: transparent; border: 0;
        white-space: nowrap;
    }
    /* Шапка на телефоне — только логотип и «☰»: имя сотрудника в ней не
       помещается и выпихивало всю страницу вправо. Смена пользователя —
       кнопкой «Смена PIN» в меню «☰» (и на любом экране она же в подвале). */
    .role-switcher .user-chip { display: none; }
    .role-switcher-hint { display: none; }
    .user-chip { gap: 6px; padding: 3px 6px; }
    .user-ava { width: 28px; height: 28px; font-size: 11px; }
    .user-meta b { max-width: 88px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .user-meta small { display: none; }
    .user-chip .role-badge { font-size: 9px; padding: 2px 5px; letter-spacing: 0.2px; }

    /* Нажатие пальцем по «кто работает» открывает смену по PIN. */
    .user-chip, .user-chip * { cursor: pointer; }

    .nav-toggle {
        display: inline-flex; align-items: center; justify-content: center;
        width: 40px; height: 40px; border-radius: 10px; flex: 0 0 auto;
        border: 1px solid rgba(255, 255, 255, 0.22); background: rgba(255, 255, 255, 0.06);
        color: #fff; font: inherit; font-size: 18px; line-height: 1; cursor: pointer;
    }

    .view-banner { font-size: 12.5px; padding: 7px 12px; text-align: left; line-height: 1.4; }

    .container { padding: 10px; }
    main.container { padding-bottom: 4px; }

    /* Простые «шайбы» на весь экран: KPI — по два в ряд. */
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
    .kpi-card { padding: 10px 12px; }
    .kpi-title { font-size: 10px; margin-bottom: 3px; }
    .kpi-value { font-size: 20px; }
    .kpi-sub { font-size: 10.5px; }
    .kpi-card.kpi-admin-only .kpi-value { font-size: 18px; }

    .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .folder-card { padding: 10px 12px; }
    .folder-card .fc-count { font-size: 18px; }

    .section-h { margin: 16px 0 8px; }
    .section-box { padding: 10px 12px; }
    .section-title { font-size: 13.5px; }

    /* ----------------------------- Панели-папки --------------------------- */
    .toolbar, .actions-bar, .fin-head, .fin-period { flex-direction: column; align-items: stretch; gap: 6px; }
    /* На телефоне и «кнопки-вертушки», и поля — на всю ширину, без вылезания. */
    .toolbar, .actions-bar, .fin-head, .fin-period { max-width: 100%; }
    .actions-bar > *,
    .fin-head > *, .fin-period > * { max-width: 100%; box-sizing: border-box; }
    .toolbar { margin-bottom: 10px; }
    .folder-tabs {
        flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden;
        margin: 0 -10px; padding: 2px 10px 6px;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .folder-tabs::-webkit-scrollbar { display: none; }
    .tab-btn { flex: 0 0 auto; padding: 9px 13px; font-size: 13px; }
    .actions-bar .btn,
    .actions-bar .search-input,
    .actions-bar form { width: 100%; box-sizing: border-box; }
    .actions-bar .btn { justify-content: center; }
    .search-input { width: 100%; font-size: 16px; padding: 11px 13px; }

    /* ---------------------------- Таблицы в блоки ------------------------- */
    /* Каждая строка-заказ превращается в карточку: шапки таблицы нет,
       у каждого значения подпись из .td-label / data-label. */
    .table-wrap { margin-bottom: 10px; }
    .table-wrap table { display: block; width: 100%; }
    .table-wrap thead { display: none; }
    .table-wrap tbody { display: block; }
    .table-wrap tbody tr {
        display: block; padding: 10px 12px;
        border-bottom: 10px solid var(--bg);
    }
    .table-wrap tbody tr:last-child { border-bottom: 0; }
    .table-wrap tbody tr:hover td { background: transparent; }
    .table-wrap tbody td {
        display: block; padding: 3px 0 !important;
        border: 0; width: auto !important; min-width: 0 !important;
        white-space: normal !important;
    }
    .table-wrap tbody td:empty { display: none; }
    .table-wrap .td-label {
        display: block; font-size: 10px; color: var(--muted);
        text-transform: uppercase; letter-spacing: 0.4px;
        font-weight: 600; margin-bottom: 1px;
    }
    /* Длинные предупреждения («Ждём фото/отправку уже 99 дн.») на телефоне
       переносятся, а не вылезают за край экрана. */
    .alert-tag { white-space: normal; }
    /* Телефон заказчика: тап — позвонить. Ссылка без «синего Интернета». */
    a.tel-link { color: inherit; text-decoration: underline; text-decoration-color: #c9c9c9; }
    a.tel-link:hover { color: #000; }
    .table-wrap .row-click,
    .table-wrap tbody tr[data-order-id] { cursor: pointer; }
    .table-empty, .empty-row td { padding: 24px 10px !important; }

    /* Строки таблицы заказов: номер и дата — первой строкой карточки,
       заказ (№) справа. Итоги — внизу крупно. */
    #dashTable tbody td:first-child .td-label { display: none; }
    #dashTable tbody td:first-child { margin-bottom: 2px; }
    #dashTable tbody td:first-child strong { font-size: 17px; }
    #dashTable tbody td:first-child .muted-small { margin-left: 6px; }

    /* Платежи, журнал продаж, пользователи: подпись поля над значением. */
    .pay-actions { white-space: normal; }
    .pay-comment { max-width: none; }
    .qs-delete { flex-direction: column; align-items: stretch; }
    .qs-delete .field-input { width: 100%; font-size: 16px; }

    /* Сводка по папкам — карточками. */
    .fin-page-title { font-size: 19px; }
    .fin-sheet { padding: 12px; }
    .fin-print-head { flex-wrap: wrap; gap: 6px; }
    .fin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .fin-cell, .fin-card { padding: 10px 12px; }
    .fin-value { font-size: 18px; }
    .fin-table th, .fin-table td { padding: 6px 6px; font-size: 12px; }

    /* -------------------------------- Кнопки ------------------------------ */
    .btn { padding: 11px 15px; font-size: 14px; min-height: 44px; justify-content: center; }
    .btn-sm { padding: 9px 12px; font-size: 13px; min-height: 40px; }
    .modal-actions .btn, .actions-bar .btn, .gate-submit, .pin-submit { min-height: 48px; }

    /* ----------------------------- Поля ввода ----------------------------- */
    .field-input,
    .form-group .field-input,
    .gate-input,
    .search-input,
    .form-group input:not([type="checkbox"]):not([type="radio"]),
    .form-group select,
    .form-group textarea,
    .pay-add-box input,
    .pay-add-box select,
    .sketch-ctl input[type="text"],
    .sketch-ctl select {
        font-size: 16px;
        min-height: 44px;
    }
    .form-group .field-input, .form-group select, .form-group textarea { width: 100%; }
    .form-group label { font-size: 12px; }
    .form-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
    input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

    /* --------------------------- Карточка заказа -------------------------- */
    .modal-backdrop, .pin-backdrop, .pay-dialog-backdrop {
        padding: 0 !important;
        padding-top: env(safe-area-inset-top, 0px) !important;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    .modal-backdrop.open { display: block; }
    .modal {
        border-radius: 0; min-height: 100vh; min-height: 100dvh;
        box-shadow: none; display: flex; flex-direction: column;
    }
    #orderCardV3Modal .modal, #print-modal .modal { width: 100%; max-width: none; }
    #orderCardV3Modal .modal { width: 100%; max-width: none; }
    .modal-header {
        padding: 10px 12px; gap: 8px; flex-wrap: nowrap;
        position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
    }
    .modal-header h2 { font-size: 14px; }
    .modal-header > div { gap: 6px !important; }
    .modal-header .btn { padding: 8px 10px; font-size: 12.5px; min-height: 40px; white-space: nowrap; }
    .modal-body { padding: 10px 12px; flex: 1 1 auto; }

    /* Вкладки бланков — лентой, чтобы все пять видны без прокрутки страницы. */
    .clip-tabs {
        flex-wrap: nowrap; gap: 6px; overflow-x: auto; overflow-y: hidden;
        margin: 0 -12px 10px; padding: 2px 12px 8px;
        position: sticky; top: calc(env(safe-area-inset-top, 0px) + 52px); z-index: 20;
        background: #fff; border-bottom: 0;
        box-shadow: 0 6px 8px -8px rgba(0, 0, 0, 0.25);
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .clip-tabs::-webkit-scrollbar { display: none; }
    .clip-tab {
        flex: 0 0 auto; padding: 8px 11px; font-size: 12.5px; white-space: nowrap;
    }

    .subtotal-box { flex-wrap: wrap; gap: 4px; font-size: 13.5px; padding: 10px 12px; }
    .subtotal-box > span:last-child { font-size: 17px; }

    /* Карточка заказа — на весь экран: прокрутка внутри окна, а не под ним. */
    #orderCardV3Modal {
        overflow: hidden;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    #orderCardV3Modal .modal {
        height: 100vh; height: 100dvh; min-height: 0;
        overflow-y: auto; overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    #orderCardV3Box { min-height: 0; }

    /* Холст эскиза и его инструменты. */
    .canvas-wrap { padding: 8px; gap: 8px; }
    .canvas-tools { gap: 5px; }
    .canvas-tools .btn { min-height: 38px; padding: 7px 9px; font-size: 12.5px; }
    .canvas-prop-bar { font-size: 12px; gap: 6px; }
    .sketch-ctl { flex: 1 1 100%; }
    .sketch-ctl input[type="range"] { width: 100%; flex: 1; }
    canvas.sketch-pad {
        touch-action: none;              /* рисование пальцем, а не прокрутка страницы */
        -webkit-user-select: none; user-select: none;
        -webkit-tap-highlight-color: transparent;
        max-width: 100%;
    }
    .sketch-hint { font-size: 11px; }

    /* Нижняя полоса карточки: короткий итог и главные кнопки.
       Прокручивается вместе с формой (внизу, после всех вкладок), поэтому
       не накрывает поля на телефоне, где экран и так маленький. */
    .modal-footer {
        position: sticky; left: 0; right: 0; width: 100%; box-sizing: border-box;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
        flex-wrap: wrap; gap: 8px;
        box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.08);
    }
    #footerTotals { display: none !important; }
    .modal-totals-short {
        display: block; order: 0; flex: 1 1 100%;
        font-size: 13px; font-weight: 600; white-space: nowrap;
        overflow: hidden; text-overflow: ellipsis;
    }
    .modal-actions { order: 1; flex: 1 1 100%; gap: 8px !important; }
    .modal-actions .btn { flex: 1 1 auto; }

    /* Бланк печати (предпросмотр). */
    .print-sheet { padding: 12px; font-size: 12px; }
    .print-modal .modal-header > div { flex-wrap: wrap; }
    #print-modal .modal-header > div button { flex: 0 0 auto; }

    /* Диалоги «причина» / правки каталога — снизу экрана, как листы. */
    .pay-dialog-backdrop.open { padding: 0; padding-top: 12vh; }
    .pay-dialog { width: 100% !important; max-width: none !important; border-radius: 16px 16px 0 0; }
    .pay-dialog-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }

    /* ------------------------ Нижнее меню ------------------------- */
    .mobile-nav {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
        background: #0b0b0b; border-top: 1px solid #1f1f1f;
        padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
    }
    .mobile-nav a {
            display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px; padding: 6px 2px; min-height: 52px; border-radius: 10px;
        color: #b9b9b9; text-decoration: none;
        min-width: 0; overflow: hidden;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-nav a.active { color: #fff; background: rgba(255, 255, 255, 0.10); }
    .mn-icon { font-size: 19px; line-height: 1; }
    .mn-label {
        font-size: 10.5px; font-weight: 600; letter-spacing: 0.2px;
        max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }

    /* Подписи в подвале дублируют шапку — на телефоне лишние. */
    footer { display: none; }

    /* Сетка-решётка — сетка, а не «гибкий» контейнер: её ширина никогда не
       раздувается от содержимого (иначе страница лезет вправо). */
    .kpi-grid, .fin-grid, .folder-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-grid.set-inline, .fin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
    .kpi-card, .fin-card, .fin-product { min-width: 0; }
    .kpi-value, .fin-value { overflow-wrap: anywhere; }

    /* Экран входа: всё влезает, поля не мельче. */
    .login-body { padding: 8px 10px; }
    .pin-card, .gate-card { width: 100%; max-width: 420px; }
    .pin-key { padding: 12px 0; font-size: 19px; }
    .gate-input { font-size: 17px; min-height: 48px; }
    .gate-captcha { height: 56px; }

    /* Инструменты эскиза — горизонтальной лентой со своей прокруткой:
       набор кнопок не должен съедать половину экрана над самим рисунком. */
    .canvas-tools {
        flex-wrap: nowrap; justify-content: flex-start;
        overflow-x: auto; overflow-y: hidden; padding-bottom: 4px;
        scrollbar-width: none; -webkit-overflow-scrolling: touch;
    }
    .canvas-tools::-webkit-scrollbar { display: none; }
    .canvas-tools .btn { flex: 0 0 auto; }

    /* Таблицы, которые не превращаются в блоки (сводка с цифрами и переносами),
       прокручиваются вбок внутри своей рамки, а не ломаются по словам. */
    .table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-scroll .fin-table { min-width: 560px; }
    .table-scroll .fin-table-narrow { min-width: 260px; }

    /* ------------- Каталог, пользователи, резервные копии --------------- */
    /* В этих таблицах подписи колонок берутся из data-label на ячейке. */
    .table-wrap tbody td[data-label]:not(:empty)::before {
        content: attr(data-label);
        display: block; font-size: 10px; color: var(--muted);
        text-transform: uppercase; letter-spacing: 0.4px;
        font-weight: 600; margin-bottom: 1px;
    }
    #catTabs, .folder-tabs { -webkit-overflow-scrolling: touch; }
}

/* Телефон в горизонтальной ориентации: низкое окно — не мешаем прокрутке. */
@media (max-width: 760px) and (max-height: 480px) {
    .modal-header { position: static; }
    .clip-tabs { position: static; }
}

/* Телефон: широкие части карточки заказа сжимаются под экран.
   Раньше эти правила стояли внутри первого блока «до 760 px» — до
   настроек вкладок и холста, — и их перебивали правила, объявленные ниже
   в том же блоке: сетка полей оставалась двухколоночной на 906 px,
   кнопки инструментов не сжимались, панели «+ оплата» не переносились,
   и карточка раздувалась в 2,5 раза шире телефона. */
@media (max-width: 760px) {
    .form-grid,
    .split-2 .form-grid {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 10px;
    }
    .form-group.col-2, .form-group.col-full { grid-column: auto; }
    .split-2 { gap: 12px; min-width: 0; }

    /* Заголовок бланка: длинное название переносится, кнопка — следующей строкой. */
    .section-title { flex-wrap: wrap; align-items: flex-start; gap: 6px; }
    .section-title > * { min-width: 0; max-width: 100%; }
    .section-title .muted-small { flex: 1 1 100%; font-size: 11.5px; line-height: 1.35; }

    /* Кнопки инструментов эскиза: переносятся по строкам и по ширине экрана. */
    .canvas-tools { flex-wrap: wrap; justify-content: flex-start; overflow-x: visible; }
    .canvas-tools .btn { flex: 0 0 auto; max-width: 100%; }

    /* Панели «Добавить из каталога» / «Внести оплату»: полем — на всю ширину. */
    .pay-add-box { align-items: stretch; }
    .pay-add-box > *,
    .pay-add-box > .form-group { width: 100% !important; min-width: 0 !important; max-width: 100%; }
    .pay-add-box .btn { justify-content: center; }

    .modal-header h2 { min-width: 0; overflow-wrap: anywhere; }
    .modal-header > div { flex-wrap: wrap; justify-content: flex-end; min-width: 0; }

    /* Доп. товары и услуги: таблица прокручивается вбок внутри своей рамки. */
    #tab-extras .table-wrap {
        overflow-x: auto; -webkit-overflow-scrolling: touch;
        scrollbar-width: thin;
    }
    #tab-extras .extras-table { min-width: 620px; }

    /* Ленты разделов: полоса прокрутки тонкая, но видимая — и место под неё
       заложено, чтобы последняя кнопка не пряталась под полосой. */
    .folder-tabs, #dashTabs, #catTabs {
        padding-bottom: 6px;
        scrollbar-width: thin;
    }

    /* Последнее слово за телефоном — здесь, в конце блока: страница вбок
       не прокручивается вовсе. Ленты листаются сами, полоса у них есть. */
    html, body { overflow-x: clip; width: 100%; max-width: 100%; }
}

/* Последнее слово за телефоном: подписи столбцов видит только он. */
@media (max-width: 760px) {
    .table-wrap .td-label { display: block; }
}
