/*
 * Единый стиль рабочих страниц портала (админка, поддержка, кабинет):
 * заголовок страницы, карточки, фильтры, плотные таблицы, статусы, кнопки.
 *
 * Принципы:
 *  - вся страница — колонка .adm-page с одинаковым вертикальным шагом;
 *  - таблица плотная (13px, строки ~34px); «узкие» колонки сжаты до содержимого
 *    (.c-fit, .c-id, .c-date, .c-act), всё свободное место получает одна
 *    смысловая колонка (.c-main) — поэтому на широком экране нет «воздуха»;
 *  - поля и кнопки одной высоты (32px; в строках таблицы — 26px).
 */

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

/* ——— Заголовок страницы ——— */
.adm-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
}

.adm-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--text-heading);
}

.adm-sub {
    margin: 2px 0 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-muted);
}

.adm-head__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    font-size: 13px;
}

.adm-head__actions a:not(.adm-btn) {
    color: var(--accent);
    text-decoration: none;
}

.adm-head__actions a:not(.adm-btn):hover {
    text-decoration: underline;
}

.adm-h2 {
    margin: 0;
    font-size: 15px;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text-heading);
}

.adm-hint {
    margin: 0;
    font-size: 12px;
    line-height: 1.45;
    color: var(--text-muted);
}

.adm-hint--warn {
    color: var(--warning-text);
}

/* ——— Карточка ——— */
.adm-card {
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    min-width: 0;
}

.adm-card--narrow {
    max-width: 560px;
}

.adm-card__title {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-heading);
}

.adm-card--notice {
    background: var(--warning-bg);
    border-color: #f3d6a2;
}

/* ——— Форма-строка (фильтры, «создать») ——— */
.adm-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 12px;
}

.adm-form--stack {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.adm-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.adm-field > label,
.adm-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.adm-field--grow {
    flex: 1 1 220px;
}

.adm-input,
.adm-select {
    height: 32px;
    padding: 0 10px;
    font-size: 13px;
    line-height: 1.2;
    font-family: inherit;
    border: 1px solid var(--border-input);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    min-width: 0;
}

textarea.adm-input {
    height: auto;
    padding: 6px 10px;
    line-height: 1.4;
}

.adm-w-xs { width: 90px; }
.adm-w-sm { width: 130px; }
.adm-w-md { width: 190px; }
.adm-w-lg { width: 260px; }

.adm-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    font-size: 13px;
    color: var(--text-secondary);
}

.adm-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 14px;
}

.adm-grid-2 .adm-input,
.adm-grid-2 .adm-select,
.adm-field--full .adm-input,
.adm-field--full .adm-select {
    width: 100%;
}

/* ——— Подвкладки внутри раздела ——— */
.adm-tabs {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 2px;
    width: fit-content;
    padding: 3px;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.adm-tab {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: 6px;
}

.adm-tab:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.adm-tab.active {
    color: var(--accent);
    font-weight: 600;
    background: var(--bg-card);
    border-color: rgba(0, 120, 212, 0.22);
}

.adm-check-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-secondary);
    cursor: pointer;
}

.adm-check-row input {
    margin-top: 3px;
}

@media (max-width: 640px) {
    .adm-grid-2 {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* ——— Кнопки ——— */
.adm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 32px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    line-height: 1;
    white-space: nowrap;
    text-decoration: none;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
}

.adm-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.adm-btn--ghost {
    background: var(--bg-card);
    border-color: var(--border-input);
    color: var(--text-secondary);
}

.adm-btn--ghost:hover {
    background: var(--bg-hover);
    border-color: var(--accent);
    color: var(--accent);
}

.adm-btn--danger {
    background: var(--bg-card);
    border-color: #f0b4ae;
    color: var(--danger-text);
}

.adm-btn--danger:hover {
    background: var(--danger-bg);
    border-color: var(--danger-text);
    color: var(--danger-text);
}

.adm-btn--sm {
    height: 26px;
    padding: 0 10px;
    font-size: 12px;
}

.adm-btn:disabled,
.adm-btn[disabled] {
    opacity: .45;
    cursor: not-allowed;
}

.adm-actions {
    display: inline-flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.adm-actions form {
    margin: 0;
}

/* ——— Таблица ——— */
.adm-table-wrap {
    overflow-x: auto;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
}

.adm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    line-height: 1.35;
    text-align: left;
    color: var(--text-primary);
}

.adm-table th {
    padding: 7px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.adm-table td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.adm-table tbody tr:last-child td {
    border-bottom: 0;
}

.adm-table tbody tr:hover td {
    background: var(--bg-panel);
}

/* Ширины колонок */
.adm-table .c-id,
.adm-table .c-fit,
.adm-table .c-date,
.adm-table .c-act {
    width: 1px; /* сжать до содержимого (nowrap); остаток получает .c-main */
    white-space: nowrap;
}

.adm-table .c-id {
    color: var(--text-muted);
}

.adm-table .c-date {
    font-size: 12px;
    color: var(--text-muted);
}

.adm-table .c-act {
    text-align: right;
}

.adm-table .c-main {
    width: 100%; /* смысловая колонка забирает всё свободное место */
    min-width: 140px;
}

.adm-table .c-wrap {
    min-width: 140px;
}

.adm-table .c-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.adm-table .sub,
.adm-sub-line {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.3;
}

.adm-table .ellipsis {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.adm-table .adm-empty {
    padding: 18px 12px;
    text-align: center;
    color: var(--text-muted);
}

/* Групповая строка внутри таблицы (роль компонента, раздел каталога) */
.adm-table tr.adm-group-row td {
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-panel);
}

.adm-table tr.adm-group-row:hover td {
    background: var(--bg-panel);
}

.adm-section-label {
    margin: 0;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ——— Метки статуса и моноширинные значения ——— */
.adm-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
    background: #f0f0f0;
    color: var(--text-secondary);
}

.adm-chip--ok { background: var(--success-bg); color: var(--success-text); }
.adm-chip--warn { background: var(--warning-bg); color: var(--warning-text); }
.adm-chip--bad { background: var(--danger-bg); color: var(--danger-text); }
.adm-chip--info { background: var(--accent-bg); color: var(--accent-hover); }

.adm-code {
    display: inline-block;
    padding: 0 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.6;
    background: #f1f3f5;
    border-radius: 4px;
    white-space: nowrap;
}

.adm-code--wrap {
    max-width: 170px;
    white-space: normal;
    word-break: break-all;
    vertical-align: top;
}

/* ——— Выпадающая сессия (токены) ——— */
.adm-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.adm-details {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
}

.adm-details > summary {
    list-style: none;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
}

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

.adm-details > summary:hover {
    background: var(--bg-panel);
}

.adm-details[open] > summary .adm-chevron {
    transform: rotate(90deg);
}

.adm-chevron {
    display: inline-block;
    color: var(--text-muted);
    font-size: 11px;
    transition: transform .15s ease;
}

.adm-details__body {
    padding: 8px 12px 12px;
    border-top: 1px solid var(--border-color);
}

/* Строка сессии: сетка с теми же ширинами, что у соседних таблиц */
.adm-sess {
    display: grid;
    grid-template-columns: 14px minmax(150px, 1.1fr) minmax(110px, .6fr) minmax(160px, 1.4fr) minmax(110px, .7fr) 80px minmax(80px, auto);
    gap: 4px 14px;
    align-items: center;
    font-size: 13px;
}

.adm-sess--head {
    padding: 0 13px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
}

.adm-sess__num { text-align: right; font-variant-numeric: tabular-nums; }
.adm-sess__st { text-align: right; }

@media (max-width: 900px) {
    .adm-sess {
        grid-template-columns: 14px 1fr 1fr;
    }

    .adm-sess--head {
        display: none;
    }

    .adm-sess__num,
    .adm-sess__st {
        text-align: left;
    }
}

/* ——— Дашборд: плитки показателей и двухколоночная раскладка ——— */
.adm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.adm-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-card);
    min-width: 0;
}

.adm-stat__label {
    font-size: 12px;
    color: var(--text-muted);
}

.adm-stat__value {
    font-size: 22px;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text-heading);
}

.adm-stat__meta {
    font-size: 12px;
    line-height: 1.35;
    color: var(--text-secondary);
}

.adm-stat__meta a,
.adm-links a {
    color: var(--accent);
    text-decoration: none;
}

.adm-stat__meta a:hover,
.adm-links a:hover {
    text-decoration: underline;
}

.adm-split {
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr);
    gap: 14px;
    align-items: start;
}

.adm-links {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    font-size: 13px;
}

.adm-bullets {
    margin: 0;
    padding-left: 18px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-secondary);
}

.adm-bullets li + li {
    margin-top: 4px;
}

.adm-bullets a {
    color: var(--accent);
    text-decoration: none;
}

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

/* ——— Мобильные ——— */
@media (max-width: 640px) {
    .adm-page {
        gap: 10px;
    }

    .adm-card {
        padding: 10px 12px;
    }

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

    .adm-form .adm-input,
    .adm-form .adm-select,
    .adm-form .adm-btn {
        width: 100%;
    }

    .adm-field--grow {
        flex: 0 0 auto;
        max-width: none !important;
    }

    .adm-table th,
    .adm-table td {
        padding: 6px 10px;
    }
}

/* ——— Группировка строк с раскрытием ——— */
.adm-table tr.adm-row-collapsed { display: none; }
.adm-table tr.adm-group-head td {
    padding: 0;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
}
.adm-table tr.adm-group-head:hover td { background: var(--bg-hover); }
.adm-group-head__btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 6px 12px;
    border: 0;
    background: transparent;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    text-align: left;
    cursor: pointer;
}
.adm-group-head__chev { font-size: 20px; color: var(--text-muted); transition: transform .15s; }
.adm-group-head.is-collapsed .adm-group-head__chev { transform: rotate(-90deg); }
.adm-group-head__label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.adm-group-head__badges { display: inline-flex; gap: 4px; }
.adm-group-head__badges .adm-chip { font-size: 11px; padding: 0 7px; }
.adm-group-head__count {
    margin-left: auto;
    min-width: 22px;
    padding: 0 7px;
    border-radius: 999px;
    background: #e7e9ee;
    color: var(--text-secondary);
    font-size: 11.5px;
    font-weight: 600;
    text-align: center;
}
/* В сгруппированном виде поле «организация» уже вынесено в заголовок группы */
.adm-table.is-grouped .js-org { display: none; }
.adm-table.is-grouped tbody tr:not(.adm-group-head):not(.adm-detail-row) td:first-child { padding-left: 32px; }

/* Переключатель вида над таблицей */
.adm-viewbar { display: flex; align-items: center; gap: 12px; margin-left: auto; align-self: flex-end; }
.adm-viewbar[hidden], .adm-viewbar [hidden] { display: none; }
.adm-switch { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-secondary); cursor: pointer; user-select: none; height: 32px; }
.adm-switch input { position: absolute; opacity: 0; pointer-events: none; }
.adm-switch__track { position: relative; width: 32px; height: 18px; border-radius: 999px; background: #c9ced6; transition: background .15s; flex: 0 0 auto; }
.adm-switch__track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.adm-switch input:checked + .adm-switch__track { background: var(--accent); }
.adm-switch input:checked + .adm-switch__track::after { transform: translateX(14px); }
.adm-switch input:focus-visible + .adm-switch__track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Составные ячейки */
.adm-table .t1 { display: block; font-weight: 500; color: var(--text-primary); }
.adm-table .sub.ellipsis { max-width: 220px; }
.adm-chips { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; max-width: 380px; }
.adm-chips .adm-chip { font-size: 11px; padding: 0 7px; }
.adm-chips .adm-chip--extra { display: none; }
.adm-chips.is-open .adm-chip--extra { display: inline-flex; }
.adm-chip--more { cursor: pointer; border: 0; font: inherit; font-size: 11px; background: #e7e9ee; color: var(--text-secondary); }
.adm-chip--more:hover { background: #d9dde4; }
.adm-chips-inline { display: inline-flex; flex-wrap: nowrap; gap: 4px; align-items: center; }
.adm-table .c-w220 { min-width: 220px; }

/* Журнал: раскрывающаяся строка подробностей */
.adm-detail-row { display: none; }
.adm-detail-row.is-open { display: table-row; }
.adm-detail-row td { background: var(--bg-panel); padding: 8px 12px 10px 32px; }
.adm-detail-row pre {
    margin: 0;
    padding: 8px 10px;
    max-height: 240px;
    overflow: auto;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #fff;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
}
.adm-expander { padding: 0 6px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.adm-expander[aria-expanded="true"] { background: var(--accent-bg); color: var(--accent-hover); border-color: transparent; }

/* Модальное окно (общее для админки) */
.adm-modal { position: fixed; inset: 0; z-index: 4000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .5); backdrop-filter: blur(2px); }
.adm-modal[hidden] { display: none; }
.adm-modal__dialog { display: flex; flex-direction: column; width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); background: var(--bg-card); border-radius: 12px; box-shadow: 0 20px 50px rgba(15, 23, 42, .3); overflow: hidden; }
.adm-modal__head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--border-color); }
.adm-modal__head h2 { margin: 0; font-size: 18px; font-weight: 600; flex: 1 1 auto; }
.adm-modal__close { width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--text-muted); font-size: 22px; line-height: 1; cursor: pointer; }
.adm-modal__close:hover { background: var(--bg-hover); color: var(--text-primary); }
.adm-modal__body { display: grid; gap: 12px; padding: 16px 20px; overflow-y: auto; }
.adm-modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border-color); background: var(--bg-panel); }

/* Выбор пользователя из списка (поиск + результаты) */
.adm-picker { display: grid; gap: 6px; }
.adm-picker__list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border-color); border-radius: 8px; background: #fff; }
.adm-picker__item { display: flex; flex-direction: column; gap: 1px; width: 100%; padding: 7px 10px; border: 0; border-bottom: 1px solid var(--border-color); background: transparent; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.adm-picker__item:last-child { border-bottom: 0; }
.adm-picker__item:hover:not(:disabled), .adm-picker__item.is-selected { background: var(--accent-bg); }
.adm-picker__item:disabled { opacity: .5; cursor: not-allowed; }
.adm-picker__item small { color: var(--text-muted); font-size: 12px; }
.adm-picker__empty { padding: 12px; text-align: center; color: var(--text-muted); font-size: 13px; }
.adm-picked { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--accent-bg); font-size: 13px; }
.adm-picked[hidden] { display: none; }
@media (max-width: 640px) {
    .adm-viewbar { margin-left: 0; width: 100%; flex-wrap: wrap; }
    .adm-table .sub.ellipsis { max-width: 220px; }
}
.adm-picker__item[hidden], .adm-picker__empty[hidden] { display: none; }
