/*
 * components.css — компоненты дизайн-системы Коллект-CRM.
 *
 * Значения — только из tokens.css. Подключается последним в <head>
 * (после extra_head), поэтому перекрывает styles.css и стили модулей.
 *
 * Два слоя:
 *   1) новые компоненты: .page-head, .seg (трек вкладок), .toolbar,
 *      .search-field, .dt (таблица на CSS grid), .bulk-bar;
 *   2) единый вид старых классов (.btn, .card, .tabs, input.inp, select.sel,
 *      table, .tag, .modal), чтобы экраны, которые ещё не переведены,
 *      выглядели так же.
 */

/* ============================================================ типографика */

h1, h2, h3, h4 {
    color: var(--text);
}

.num,
.tnum {
    font-variant-numeric: tabular-nums;
}

.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.small { font-size: 12px; }
.sub { font-size: 12.5px; color: var(--muted); }

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

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

:root[data-theme="dark"] a:hover {
    color: var(--accent-soft-text);
}

/* ================================================================ иконки */

.icon {
    flex: none;
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.icon--18 {
    width: 18px;
    height: 18px;
}

/* ===================================================== заголовок страницы */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px 24px;
}

.page-head__main {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}

.page-eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

.page-title {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 12px;
    min-width: 0;
}

.page-title h1 {
    margin: 0;
    color: var(--text);
    font-size: 26px;
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.02em;
    overflow-wrap: anywhere;
}

.page-count {
    color: var(--muted);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.page-actions form {
    margin: 0;
}

/* ================================================================ кнопки */

/* :is() даёт специфичность a.btn — как у правил styles.css, но мы позже. */
:is(a, button, span, label, summary).btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-sizing: border-box;
    min-height: 40px;
    min-width: 40px;
    padding: 0 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-control);
    border-radius: 10px;
    box-shadow: none;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

:is(a, button, span, label, summary).btn:hover {
    color: var(--text);
    background: var(--surface-muted);
    border-color: var(--border-control);
}

:is(a, button, span, label, summary).btn:focus-visible {
    outline: var(--focus);
    outline-offset: var(--focus-offset);
}

:is(a, button, span, label, summary).btn > :is(svg, i) {
    flex: none;
    font-size: 15px;
}

:is(a, button).btn > svg {
    width: 16px;
    height: 16px;
}

/* Основная */
:is(a, button).btn:is(.pri, .primary) {
    color: var(--on-accent);
    background: var(--accent);
    border-color: var(--accent);
    padding: 0 16px;
}

:is(a, button).btn:is(.pri, .primary):hover {
    color: var(--on-accent);
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    filter: none;
}

/* «Пилюля» — второстепенная навигация в шапке */
:is(a, button).btn.pill {
    color: var(--pill-text);
    background: var(--pill-bg);
    border-color: transparent;
}

:is(a, button).btn.pill:hover {
    color: var(--pill-text);
    background: var(--pill-hover);
}

/* Квадратная кнопка-иконка */
:is(a, button).btn.icon-btn {
    width: 40px;
    padding: 0;
}

/* Маленькая — в плотных панелях и строках */
:is(a, button, span).btn.sm {
    min-height: 36px;
    min-width: 36px;
    padding: 0 12px;
    font-size: 13px;
    border-radius: 8px;
}

:is(a, button).btn.on {
    color: var(--accent-soft-text);
    background: var(--accent-soft);
    border-color: var(--accent-border);
    font-weight: 500;
}

:is(a, button).btn:is(.danger, .bad) {
    color: var(--bad-text);
    background: var(--surface);
    border-color: var(--bad-border);
}

:is(a, button).btn:is(.danger, .bad):hover {
    color: var(--bad-text);
    background: var(--bad-bg);
}

:is(a, button).btn.ghost {
    background: transparent;
    border-color: transparent;
}

:is(a, button).btn.ghost:hover {
    background: var(--nav-hover);
}

button.btn:disabled,
a.btn[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
}

/* В тулбарах высота 42 */
.toolbar :is(a, button, span, label, summary).btn {
    min-height: 42px;
    min-width: 42px;
}

.toolbar :is(a, button).btn.icon-btn {
    width: 42px;
}

/* ================================================================== поля */

:is(input.inp, select.sel, textarea.inp, .field),
:is(input, select, textarea).desk-input {
    box-sizing: border-box;
    min-height: 42px;
    padding: 0 14px;
    color: var(--text);
    background-color: var(--surface);
    border: 1px solid var(--border-control);
    border-radius: 10px;
    box-shadow: none;
    font: inherit;
    font-size: 14px;
}

:is(textarea.inp, textarea.field, textarea.desk-input) {
    padding: 10px 14px;
    line-height: 1.5;
}

:is(input.inp, select.sel, textarea.inp, .field, .desk-input)::placeholder {
    color: var(--muted);
    opacity: 1;
}

:is(input.inp, select.sel, textarea.inp, .field, .desk-input):hover {
    border-color: var(--chevron);
}

:is(input.inp, select.sel, textarea.inp, .field, .desk-input):focus {
    outline: var(--focus);
    outline-offset: 0;
    border-color: var(--accent);
    box-shadow: none;
}

:is(input.inp, select.sel, textarea.inp, .field, .desk-input):disabled {
    color: var(--muted);
    background-color: var(--surface-muted);
}

:is(select.sel, select.field) {
    padding-right: 36px;
}

select:is(.sel, .field, .desk-input):is([multiple], [size]) {
    padding: 6px 8px;
}

input[type="checkbox"],
input[type="radio"] {
    accent-color: var(--accent);
}

/* =================================================================== поиск */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.search-field {
    position: relative;
    display: flex;
    align-items: center;
    flex: 1 1 320px;
    min-width: 0;
}

.search-field > .icon,
.search-field > svg {
    position: absolute;
    left: 14px;
    width: 17px;
    height: 17px;
    color: var(--muted);
    pointer-events: none;
}

.search-field > input {
    width: 100%;
    padding-left: 41px;
}

/* =============================================== вкладки: трек-сегменты */

.seg-scroll {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
}

.seg-scroll::-webkit-scrollbar {
    display: none;
}

.seg {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 4px;
    background: var(--tabs-track);
    border-radius: 12px;
}

.seg > :is(a, button) {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex: none;
    min-height: 36px;
    padding: 0 12px;
    color: var(--text-2);
    background: transparent;
    border: 0;
    border-radius: 9px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s, color .15s;
}

.seg > :is(a, button):hover {
    color: var(--text);
}

.seg > :is(a, button):is(.active, .on, [aria-current="page"], [aria-selected="true"]) {
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--tab-active-shadow);
}

.seg-count {
    min-width: 18px;
    box-sizing: border-box;
    padding: 1px 7px;
    color: var(--text-2);
    background: var(--tab-count-bg);
    border-radius: 999px;
    font-size: 12px;
    line-height: 16px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.seg-count.is-zero {
    color: var(--muted);
    background: transparent;
}

.seg > :is(.active, .on, [aria-current="page"]) .seg-count {
    color: var(--accent-soft-text);
    background: var(--accent-soft);
}

/* Старые вкладки (.tabs button.on) — тот же трек */
.tabs {
    display: flex;
    width: fit-content;
    max-width: calc(100% - 24px);
    box-sizing: border-box;
    gap: 2px;
    margin: 12px;
    padding: 4px;
    overflow-x: auto;
    background: var(--tabs-track);
    border: 0;
    border-radius: 12px;
}

.tabs button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    margin: 0;
    padding: 0 12px;
    color: var(--text-2);
    border: 0;
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 500;
}

.tabs button.on {
    color: var(--text);
    background: var(--surface);
    border: 0;
    box-shadow: var(--tab-active-shadow);
    font-weight: 500;
}

.tabs button .b {
    margin: 0;
    padding: 1px 7px;
    color: var(--text-2);
    background: var(--tab-count-bg);
    border-radius: 999px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
}

.tabs button.on .b {
    color: var(--accent-soft-text);
    background: var(--accent-soft);
}

/* ============================================================== карточки */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: none;
}

.card > h3 {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.card > h3 .hint {
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 400;
}

.kpi .lbl {
    color: var(--muted);
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
}

.kpi .val {
    font-variant-numeric: tabular-nums;
}

/* ================================================================ бейджи */

.tag {
    padding: 2px 9px;
    border: 0;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    padding: 2px 9px;
    color: var(--ok-text);
    background: var(--ok-bg);
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-pill.is-neutral { color: var(--text-2); background: var(--tabs-track); }
.status-pill.is-warn { color: var(--warn-text); background: var(--warn-bg); }
.status-pill.is-bad { color: var(--bad-text); background: var(--bad-bg); }
.status-pill.is-info { color: var(--accent-soft-text); background: var(--accent-soft); }

/* ======================================================= обычные таблицы */

.tblwrap {
    max-width: 100%;
    overflow-x: auto;
}

table {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

th {
    padding: 12px 16px;
    color: var(--muted);
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
}

th .sort-link.on,
th a[aria-sort],
th .sort-link:hover {
    color: var(--text);
}

td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-row);
}

tbody tr.clk:hover,
tbody tr:hover > td {
    box-shadow: inset 0 0 0 9999px var(--row-hover);
}

tbody tr.clk.on,
tbody tr[data-selected="true"] {
    background: var(--row-selected);
}

/* ============================================ таблица-эталон на CSS grid */

.dt-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

.dt-scroll {
    position: relative; /* иначе абсолютные .vh в шапке не режутся скроллом и растягивают страницу на телефоне */
    max-width: 100%;
    overflow-x: auto;
}

.dt {
    min-width: 1080px;
    font-variant-numeric: tabular-nums;
}

.dt-head,
.dt-row {
    display: grid;
    grid-template-columns: var(--dt-cols);
    column-gap: 14px;
    align-items: center;
    padding: 14px 20px;
}

.dt-head {
    padding-top: 12px;
    padding-bottom: 12px;
    color: var(--muted);
    background: var(--surface-muted);
    font-size: 12.5px;
    font-weight: 500;
}

.dt-head a {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: inherit;
    text-decoration: none;
}

.dt-head a:hover,
.dt-head .is-sorted,
.dt-head [aria-sort] {
    color: var(--text);
}

.dt-row {
    border-top: 1px solid var(--border-row);
}

.dt-row:hover {
    box-shadow: inset 0 0 0 9999px var(--row-hover);
}

.dt-row.is-selected,
.dt-row[data-selected="true"] {
    background: var(--row-selected);
}

.dt-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    color: var(--text-2);
    font-size: 13.5px;
    overflow-wrap: anywhere;
}

.dt-cell--end {
    align-items: flex-end;
    text-align: right;
}

.dt-cell--check {
    align-items: flex-start;
}

.dt-cell input[type="checkbox"],
.dt-head input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--accent);
    cursor: pointer;
}

.dt-main {
    color: var(--text);
    font-size: 14px;
    font-weight: 500;
}

a.dt-main {
    text-decoration: none;
}

a.dt-main:hover {
    color: var(--accent-text);
}

.dt-sub {
    color: var(--muted);
    font-size: 12.5px;
}

.dt-sub--sm {
    font-size: 12px;
}

.dt-sub--warn {
    color: var(--warn-text);
    font-size: 12px;
}

.dt-money {
    color: var(--text);
    font-size: 14.5px;
    font-weight: 500;
    white-space: nowrap;
}

.dt-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 12px 20px;
    color: var(--muted);
    border-top: 1px solid var(--border);
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
}

.dt-empty {
    padding: 40px 20px;
    border-top: 1px solid var(--border-row);
    text-align: center;
}

.dt-empty h3 {
    margin: 0 0 6px;
    font-size: 15px;
    font-weight: 600;
}

.dt-empty p {
    margin: 0 0 14px;
    color: var(--muted);
}

/* ============================================ плавающая массовая панель */

.bulk-hint {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.bulk-bar {
    position: sticky;
    bottom: 20px;
    z-index: 5;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    color: var(--bulk-text);
    background: var(--bulk-bg);
    border-radius: 14px;
    box-shadow: var(--bulk-shadow);
    font-size: 13.5px;
}

.bulk-bar[hidden] {
    display: none;
}

/* «Документы ▾» — редкие действия свёрнуты, чтобы панель оставалась в один-два ряда. */
.bulk-menu {
    position: relative;
}

.bulk-menu > summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    background: var(--bulk-btn);
    cursor: pointer;
    list-style: none;
    user-select: none;
}

.bulk-menu > summary::-webkit-details-marker {
    display: none;
}

.bulk-menu > summary:hover,
.bulk-menu[open] > summary {
    background: var(--bulk-btn-hover);
}

.bulk-menu > summary:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
}

.bulk-menu__list {
    position: absolute;
    right: 0;
    bottom: calc(100% + 8px);
    z-index: 6;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    min-width: 260px;
    padding: 6px;
    background: var(--bulk-bg);
    border-radius: 12px;
    box-shadow: var(--bulk-shadow);
}

.bulk-menu__list > button {
    justify-content: flex-start;
    text-align: left;
}

.bulk-menu__row {
    display: flex;
    gap: 6px;
}

.bulk-menu__row select {
    max-width: 190px;
}

.bulk-bar__group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.bulk-bar__divider {
    flex: none;
    width: 1px;
    height: 24px;
    background: var(--bulk-divider);
}

.bulk-bar__count {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.bulk-bar :is(button, select) {
    box-sizing: border-box;
    min-height: 34px;
    padding: 0 12px;
    color: var(--bulk-text);
    background: transparent;
    border: 0;
    border-radius: 8px;
    font: inherit;
    font-size: 13.5px;
    cursor: pointer;
}

.bulk-bar button:hover {
    background: var(--bulk-btn-hover);
}

.bulk-bar select {
    max-width: 240px;
    padding-right: 30px;
    background-color: var(--bulk-btn);
    text-overflow: ellipsis;
}

.bulk-bar select:hover {
    background-color: var(--bulk-btn-hover);
}

.bulk-bar select option {
    color: var(--text);
    background: var(--surface);
}

.bulk-bar button.is-primary {
    color: var(--bulk-primary-text);
    background: var(--bulk-primary-bg);
    font-weight: 500;
}

.bulk-bar button.is-primary:hover {
    background: var(--bulk-primary-bg);
    opacity: .9;
}

.bulk-bar__clear {
    display: inline-grid;
    place-items: center;
    width: 30px;
    min-height: 30px;
    padding: 0;
}

.bulk-bar label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    color: var(--bulk-text);
    cursor: pointer;
}

.bulk-bar :is(button, select):focus-visible {
    outline: 2px solid var(--bulk-text);
    outline-offset: 2px;
}

/* ================================================================ модалки */

.mask {
    background: var(--overlay);
    backdrop-filter: none;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
}

.modal > header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal > header b {
    font-size: 16px;
    font-weight: 600;
}

.modal > header .x {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    padding: 0;
    color: var(--muted);
    border-radius: 8px;
}

.modal > header .x:hover {
    background: var(--nav-hover);
}

.modal .body {
    padding: 18px 20px;
}

/* ========================================================= уведомления */

.note {
    border-radius: 12px;
}

/* ============================================================ адаптив */

@media (max-width: 600px) {
    .page-title h1 {
        font-size: 22px;
    }

    .page-actions {
        justify-content: flex-start;
    }

    .bulk-bar {
        bottom: 12px;
    }

    .bulk-bar__divider {
        display: none;
    }
}

/* ============================================ вход, регистрация, смена пароля */

body.login-body {
    min-height: 100vh;
    margin: 0;
    padding: 24px 16px;
    box-sizing: border-box;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
}

.login-card {
    width: min(420px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 1px 2px rgba(23, 26, 33, .04);
}

.login-card .pad {
    padding: 28px;
}

.login-card h1 {
    margin: 0 0 4px;
    color: var(--text-brand, var(--text));
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    box-sizing: border-box;
    border: 1px solid var(--sidebar-border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--accent);
}

.login-logo svg {
    fill: currentColor;
    stroke: currentColor;
    stroke-width: 1.6;
    stroke-linejoin: round;
}

.login-card .sub {
    margin: 0 0 22px;
    color: var(--muted);
    font-size: 14px;
}

.login-card .form-stack {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-card .form-stack label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 500;
}

.login-card input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.login-card select {
    width: 100%;
    height: 42px;
    box-sizing: border-box;
    padding: 0 14px;
    border: 1px solid var(--border-control);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}

.login-card input::placeholder {
    color: var(--muted);
    opacity: .8;
}

.login-card input:focus,
.login-card select:focus {
    outline: var(--focus);
    outline-offset: 1px;
    border-color: var(--accent);
}

.login-card .btn.pri,
.login-card .btn.primary {
    height: 44px;
    margin-top: 6px;
    border: 0;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-size: 14.5px;
    font-weight: 500;
}

.login-card .btn.pri:hover,
.login-card .btn.primary:hover {
    background: var(--accent-hover);
}

.login-card .login-orgs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: -4px;
}

.login-card .login-orgs .btn.sm {
    height: 28px;
    padding: 0 10px;
    border: 0;
    border-radius: 999px;
    background: var(--pill-bg);
    color: var(--pill-text);
    font-size: 12.5px;
}

.login-card .login-alt {
    margin: 18px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--border-row);
    font-size: 13.5px;
}

.login-card .login-alt a {
    color: var(--accent);
    text-decoration: none;
}

.login-card .form-error {
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--bad-soft, #FDECEC);
    color: var(--bad, #B42318);
    font-size: 13px;
}

.login-note {
    margin-top: 14px;
    border-radius: 10px;
}

/* ============================================ утилиты вместо inline-стилей */
.u-mt { margin-top: 16px; }
.u-mb { margin-bottom: 16px; }
.u-my { margin: 16px 0; }
.u-m0 { margin: 0; }
.u-mt-8 { margin-top: 8px; }
.u-mt-10 { margin-top: 10px; }
.u-mt-12 { margin-top: 12px; }
.u-mt-16 { margin-top: 16px; }
.u-mb-6 { margin-bottom: 6px; }
.u-mb-8 { margin-bottom: 8px; }
.u-my-6 { margin: 6px 0; }
.u-ml-8 { margin-left: 8px; }
.u-list { margin: 4px 0 8px; padding-left: 18px; }
.u-flex { display: flex; }
.u-inline { display: inline; }
.u-gap-6 { gap: 6px; }
.u-gap-8 { gap: 8px; }
.u-gap-12 { gap: 12px; }
.u-gap-16 { gap: 16px; }
.u-gap-10-18 { gap: 10px 18px; }
.u-center { align-items: center; }
.u-wrap { flex-wrap: wrap; }
.u-self-end { align-self: end; }
.u-pre { white-space: pre-wrap; }
.u-plain { color: inherit; text-decoration: none; }
.u-minw-280 { min-width: 280px; }
.u-maxw-none { max-width: none; }
.u-w100 { width: 100%; }
.u-fs-20 { font-size: 20px; }

/* Поля без класса (Django-виджеты по умолчанию) — в том же стиле, что .field,
   чтобы в тёмной теме не оставалось светлых «дыр». :where — без веса: правила
   конкретных экранов (селект сортировки и т.п.) должны перебивать этот фолбэк. */
.main :where(input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]):not([type="range"]), select, textarea):not([class]) {
    box-sizing: border-box;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--border-control);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}

.main textarea:not([class]) {
    padding: 10px 14px;
}

.main :where(input, select, textarea):not([class]):focus {
    outline: var(--focus);
    outline-offset: 1px;
    border-color: var(--accent);
}

/* ============================================ отчёты: общие детали
   Карточки показателей, пустое состояние, плашка-предупреждение, легенда,
   заголовок карточки с таблицей, сегменты внутри панели фильтров. */

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 16px;
}

.kpi {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    padding: 18px 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
}

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

.kpi__value {
    color: var(--text);
    font-size: 26px;
    font-weight: 600;
    line-height: 1.2;
    letter-spacing: -0.01em;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

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

.kpi__sub.is-warn { color: var(--warn-text); }
.kpi__sub.is-ok { color: var(--ok-text); }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 48px 20px;
    text-align: center;
}

.empty-state__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    margin-bottom: 6px;
    border-radius: 12px;
    color: var(--text-2);
    background: var(--tabs-track);
}

.empty-state__icon .icon { width: 20px; height: 20px; }
.empty-state__icon.is-info { color: var(--accent-soft-text); background: var(--accent-soft); }
.empty-state__icon.is-ok { color: var(--ok-text); background: var(--ok-bg); }

.empty-state h3 {
    margin: 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
}

.empty-state p {
    max-width: 60ch;
    margin: 0;
    color: var(--muted);
    font-size: 13.5px;
    line-height: 1.55;
}

.empty-state__actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}

.empty-state__steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 6px 0 4px;
    padding: 0;
    list-style: none;
    counter-reset: step;
    text-align: left;
}

.empty-state__steps li {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-2);
    font-size: 14px;
    counter-increment: step;
}

.empty-state__steps li::before {
    content: counter(step);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 26px;
    height: 26px;
    border-radius: 50%;
    color: var(--accent-soft-text);
    background: var(--accent-soft);
    font-size: 12.5px;
    font-weight: 600;
}

.alert-warn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    color: var(--warn-text);
    background: var(--warn-bg);
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
}

.alert-warn > .icon {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    align-self: flex-start;
    margin-top: 1px;
}

.alert-warn__text {
    flex: 1 1 auto;
    min-width: 0;
}

.alert-warn__text b {
    display: block;
    font-weight: 600;
}

.alert-warn__text b.is-inline {
    display: inline;
}

:is(a, button).btn.warn {
    flex: none;
    color: var(--surface);
    background: var(--warn-text);
    border-color: transparent;
}

:is(a, button).btn.warn:hover {
    filter: brightness(1.08);
}

.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 18px;
    color: var(--muted);
    font-size: 12.5px;
}

.legend > span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend i {
    width: 9px;
    height: 9px;
    border-radius: 2px;
    background: currentColor;
}

/* Заголовок карточки над таблицей: «Журнал 1» */
.card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 22px 14px;
}

.card-title h2 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
}

.card-title .seg-count {
    font-size: 12px;
}

/* Сегменты в панели фильтров: подпись сверху, трек высотой как поле */
.seg.seg--field {
    min-height: 42px;
    box-sizing: border-box;
}

.seg > label {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 0 12px;
    color: var(--text-2);
    border-radius: 9px;
    font-size: 13.5px;
    font-weight: 500;
    white-space: nowrap;
    cursor: pointer;
}

.seg > label:hover {
    color: var(--text);
}

.seg > label.active {
    color: var(--text);
    background: var(--surface);
    box-shadow: var(--tab-active-shadow);
}

/* ============================================ список слева, карточка справа
   Организация, отделы, поля, роли, почтовые ящики, транки. */

.md-layout {
    display: grid;
    grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .md-layout {
        grid-template-columns: minmax(0, 1fr);
    }
}

.md-list,
.md-detail {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.md-list {
    padding-bottom: 8px;
}

.md-list__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 16px 16px 12px 22px;
}

.md-list__head h2 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
    font-size: 16px;
    font-weight: 600;
}

.md-list__search {
    margin: 0 12px 8px;
}

.md-list__empty {
    padding: 24px 22px;
    color: var(--muted);
    font-size: 13.5px;
    text-align: center;
}

.md-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 2px 8px;
    padding: 10px 14px;
    color: var(--text);
    border-radius: 12px;
    text-decoration: none;
    cursor: pointer;
}

.md-item:hover {
    background: var(--row-hover);
}

.md-item.is-active,
.md-item[aria-current] {
    background: var(--accent-soft);
}

.md-item__main {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.md-item__title {
    color: var(--text);
    font-size: 14.5px;
    font-weight: 500;
}

.md-item.is-active .md-item__title,
.md-item[aria-current] .md-item__title {
    color: var(--accent-soft-text);
}

.md-item__sub {
    color: var(--muted);
    font-size: 12.5px;
}

.md-detail__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 20px 28px;
    border-bottom: 1px solid var(--border-row);
}

.md-detail__head h2 {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin: 0;
    color: var(--text);
    font-size: 18px;
    font-weight: 600;
}

.md-detail__meta {
    color: var(--muted);
    font-size: 13px;
}

.md-section {
    padding: 22px 28px;
    border-top: 1px solid var(--border-row);
}

.md-detail__head + .md-section {
    border-top: 0;
}

.md-section > h3 {
    margin: 0 0 14px;
    color: var(--text);
    font-size: 15px;
    font-weight: 600;
}

.md-foot {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 16px 28px;
    background: var(--surface-muted);
    border-top: 1px solid var(--border-row);
    border-radius: 0 0 16px 16px;
}

.md-foot__end {
    margin-left: auto;
}

/* Поля формы сеткой: подпись над полем, подсказка под ним */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px 20px;
}

.form-grid .span-all {
    grid-column: 1 / -1;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    color: var(--text-2);
    font-size: 13px;
    font-weight: 500;
}

.form-field :is(input:not([type="checkbox"]):not([type="radio"]), select, textarea) {
    width: 100%;
    min-height: 42px;
    box-sizing: border-box;
}

.form-hint {
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 400;
    line-height: 1.45;
}

.form-hint.is-bad,
.form-error-text {
    color: var(--bad-text);
    font-size: 12.5px;
    font-weight: 400;
}

/* Тумблер: <label class="switch"><input type="checkbox"><span class="switch__track"></span><span class="switch__text"><b>…</b><small>…</small></span></label> */
.switch {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    cursor: pointer;
}

.switch > input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.switch__track {
    position: relative;
    flex: 0 0 44px;
    width: 44px;
    height: 26px;
    margin-top: 1px;
    border-radius: 999px;
    background: var(--border-control);
    transition: background-color .15s;
}

.switch__track::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(23, 26, 33, .2);
    transition: transform .15s;
}

.switch > input:checked + .switch__track {
    background: var(--accent);
}

.switch > input:checked + .switch__track::after {
    transform: translateX(18px);
}

.switch > input:focus-visible + .switch__track {
    outline: var(--focus);
    outline-offset: 2px;
}

.switch > input:disabled + .switch__track {
    opacity: .5;
}

/* Старый тумблер в styles.css (.switch input:disabled) делает скрытый input видимым — второй тумблер рядом. */
.switch:has(> .switch__track) > input:disabled {
    opacity: 0;
}

.switch__text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    color: var(--text);
    font-size: 14.5px;
    font-weight: 500;
}

.switch__text small {
    color: var(--muted);
    font-size: 13px;
    font-weight: 400;
}

/* Мягкая кнопка «+ Добавить» и текстовая красная «Удалить» */
:is(a, button).btn.soft {
    color: var(--accent-soft-text);
    background: var(--accent-soft);
    border-color: transparent;
}

:is(a, button).btn.soft:hover {
    filter: brightness(.97);
}

:is(a, button).btn-link-danger {
    padding: 0;
    color: var(--bad-text);
    background: none;
    border: 0;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}

:is(a, button).btn-link-danger:hover {
    text-decoration: underline;
}

/* Чип-переключатель: «✓ Администратор», «+ Аудитор» */
.chip-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    color: var(--text-2);
    border: 1px solid var(--border-control);
    border-radius: 999px;
    font-size: 13.5px;
    font-weight: 500;
    cursor: pointer;
}

.chip-toggle > input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chip-toggle:has(> input:checked) {
    color: var(--accent-soft-text);
    background: var(--accent-soft);
    border-color: var(--nav-active-border);
}

.chip-toggle:has(> input:focus-visible) {
    outline: var(--focus);
    outline-offset: 2px;
}

/* Плашка-успех вверху страницы */
.alert-ok {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    color: var(--ok-text);
    background: var(--ok-bg);
    border-radius: 14px;
    font-size: 14px;
    font-weight: 500;
}

/* Ключ — значение: «Клиент  ООО …» */
.kv-list {
    display: grid;
    grid-template-columns: minmax(140px, 220px) minmax(0, 1fr);
    gap: 12px 20px;
    margin: 0;
    font-size: 14px;
}

.kv-list dt {
    color: var(--muted);
}

.kv-list dd {
    margin: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

.kv-list code,
.code-chip {
    padding: 2px 8px;
    color: var(--text);
    background: var(--surface-muted);
    border-radius: 6px;
    font-family: var(--mono);
    font-size: 13px;
}

/* Старое правило styles.css «label:not(.switch) > input[type=checkbox]» давало чекбоксу место внутри чипа */
label.chip-toggle > input[type="checkbox"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
}

/* «← Назад» — квадратная кнопка в строке надзаголовка, без отдельного ряда сверху */
.back-btn {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    box-sizing: border-box;
    color: var(--text-2);
    background: var(--surface);
    border: 1px solid var(--border-control);
    border-radius: 10px;
    text-decoration: none;
}

.back-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.back-btn:focus-visible {
    outline: var(--focus);
    outline-offset: 2px;
}

.back-btn .icon {
    width: 16px;
    height: 16px;
}

.page-eyebrow:has(> .back-btn) {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Справа внизу плавают софтфон и «Чаты» — запас снизу, чтобы они не закрывали последние кнопки страницы */
.main {
    padding-bottom: 112px;
}

body.messenger-page-layout .main {
    padding-bottom: 32px;
}

/* Телефон: сайдбар-шапка и контент — два ряда flex; на коротких страницах ряды не растягиваются по высоте экрана */
@media (max-width: 899px) {
    .app {
        align-content: flex-start;
    }
}
