/*
 * Тема админки поверх Bootstrap 5.3.
 * Разметка — стандартные классы Bootstrap; здесь только оформление каркаса (меню, шапка)
 * и общий вид таблиц/карточек/форм. Цвета — через переменные ниже.
 */

:root {
    --admin-sidebar-w: 264px;
    --admin-topbar-h: 56px;
    --admin-sidebar-bg: #111827;
    --admin-sidebar-color: #9ca3af;
    --admin-sidebar-hover-bg: rgba(255, 255, 255, .06);
    --admin-sidebar-active-bg: rgba(59, 130, 246, .16);
    --admin-sidebar-active-color: #fff;
    --admin-accent: #3b82f6;
    /* Зелёный бренда — theme.colors.green витрины (frontend/styles/theme.ts) */
    --sunction-orange: #ff6a00;
    --sunction-tile: linear-gradient(135deg, #ffb020, #ff6a00);
    --admin-page-bg: #f4f5f7;
    --admin-surface: #fff;
    --admin-border: #e5e7eb;
    --admin-muted-bg: #f9fafb;
    --admin-radius: .625rem;
    --admin-shadow: 0 1px 2px rgba(16, 24, 40, .05);
    --bs-body-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-border-color: var(--admin-border);
}

/* Админка плотная: 1rem = 14px, вместе с ним масштабируются отступы и контролы */
html {
    font-size: 14px;
}

body.admin {
    background: var(--admin-page-bg);
    min-height: 100vh;
}

/* ---------- Боковое меню ---------- */

.sidebar-panel {
    --bs-offcanvas-width: var(--admin-sidebar-w);
    --bs-offcanvas-bg: var(--admin-sidebar-bg);
    display: flex;
    flex-direction: column;
    color: var(--admin-sidebar-color);
}

@media (min-width: 992px) {
    .admin-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        z-index: 1030;
        width: var(--admin-sidebar-w);
        background: var(--admin-sidebar-bg);
    }

    .sidebar-panel {
        height: 100%;
    }

    .admin-main {
        margin-left: var(--admin-sidebar-w);
    }
}

.sidebar-brand {
    display: flex;
    align-items: center;
    height: var(--admin-topbar-h);
    padding: 0 1rem 0 1.15rem;
    flex-shrink: 0;
}

.sidebar-brand-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    color: #fff;
    font-weight: 600;
    font-size: 1.1rem;
    text-decoration: none;
}

.sidebar-brand-link:hover {
    color: #fff;
}

.sidebar-logo {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    /* Знак магазина на оранжевой плитке (S-315, решение Efim 02.12.2026); тот же вид — favicon.svg */
    background: var(--sunction-tile);
    color: #fff;
}

.sidebar-search {
    position: relative;
    padding: .25rem 1rem .75rem;
    flex-shrink: 0;
}

.sidebar-search .bi {
    position: absolute;
    left: 1.7rem;
    top: calc(.25rem + .5em);
    font-size: .85rem;
    opacity: .6;
    pointer-events: none;
}

.sidebar-search .form-control {
    padding-left: 2rem;
    background-color: rgba(255, 255, 255, .06);
    border-color: transparent;
}

.sidebar-search .form-control:focus {
    border-color: rgba(255, 255, 255, .2);
    box-shadow: none;
}

.sidebar-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 0 .65rem 1rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .15) transparent;
}

.sidebar-nav {
    margin: 0;
}

.sidebar-item + .sidebar-item {
    margin-top: 2px;
}

.sidebar-link,
.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .5rem .65rem;
    border-radius: .5rem;
    color: var(--admin-sidebar-color);
    text-decoration: none;
    line-height: 1.3;
    transition: background-color .15s, color .15s;
}

.sidebar-link:hover,
.sidebar-sublink:hover {
    background: var(--admin-sidebar-hover-bg);
    color: #e5e7eb;
}

.sidebar-link.active,
.sidebar-sublink.active {
    background: var(--admin-sidebar-active-bg);
    color: var(--admin-sidebar-active-color);
}

.sidebar-link.active-parent {
    color: #e5e7eb;
}

.sidebar-icon {
    font-size: 1.05rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-label {
    flex: 1 1 auto;
    min-width: 0;
}

.sidebar-chevron {
    font-size: .7rem;
    transition: transform .2s;
}

.sidebar-link.collapsed .sidebar-chevron {
    transform: rotate(-90deg);
}

.sidebar-subnav {
    margin: 2px 0 .35rem;
}

.sidebar-sublink {
    padding: .38rem .65rem .38rem 2.6rem;
    font-size: .95rem;
}

.sidebar-sublink.active {
    position: relative;
}

.sidebar-sublink.active::before {
    content: "";
    position: absolute;
    left: 1.25rem;
    top: 50%;
    width: 6px;
    height: 6px;
    margin-top: -3px;
    border-radius: 50%;
    background: var(--admin-accent);
}

.sidebar-subheader {
    padding: .7rem .65rem .25rem 2.6rem;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: #6b7280;
}

.sidebar-divider {
    margin: .4rem .65rem .4rem 2.6rem;
    border-top: 1px solid rgba(255, 255, 255, .08);
}

.sidebar-footer {
    padding: .75rem 1.15rem;
    font-size: .8rem;
    color: #6b7280;
    border-top: 1px solid rgba(255, 255, 255, .06);
    flex-shrink: 0;
}

/* Поиск по меню прячет лишнее (см. admin.js) */
.sidebar-nav .is-filtered-out {
    display: none !important;
}

/* ---------- Шапка ---------- */

.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: .75rem;
    min-height: var(--admin-topbar-h);
    padding: .5rem 1.5rem;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: saturate(180%) blur(8px);
    border-bottom: 1px solid var(--admin-border);
}

.admin-breadcrumbs {
    min-width: 0;
}

.admin-breadcrumbs .breadcrumb {
    flex-wrap: nowrap;
    overflow: hidden;
    font-size: .95rem;
}

.admin-breadcrumbs .breadcrumb-item {
    white-space: nowrap;
}

.admin-breadcrumbs .breadcrumb-item.active {
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--bs-body-color);
    font-weight: 500;
}

.admin-breadcrumbs a {
    color: var(--bs-secondary-color);
    text-decoration: none;
}

.admin-breadcrumbs a:hover {
    color: var(--bs-link-color);
}

.btn-icon {
    --bs-btn-padding-x: .45rem;
    --bs-btn-padding-y: .2rem;
    font-size: 1.35rem;
    line-height: 1;
    border: 0;
}

.btn-user {
    --bs-btn-padding-x: .35rem;
    --bs-btn-padding-y: .25rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    border: 0;
    border-radius: 2rem;
}

.btn-user:hover,
.btn-user.show {
    background: var(--admin-muted-bg);
}

/* С клавиатуры было не видно, что выбраны «Модули» или имя (ревью 04.12.2026) */
.btn-user:focus-visible,
.btn-launcher:focus-visible {
    outline: 2px solid var(--admin-accent);
    outline-offset: 2px;
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: #e0e7ff;
    color: #3730a3;
    font-size: .8rem;
    font-weight: 600;
}

/* ---------- Контент ---------- */

.admin-content {
    padding: 1.5rem;
}

@media (max-width: 575.98px) {
    .admin-content,
    .admin-topbar {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

.admin-content h1 {
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: -.01em;
    margin-bottom: 1.1rem;
}

.admin-content h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.admin-content h3 {
    font-size: 1.12rem;
    font-weight: 600;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header h1 {
    margin-bottom: .25rem;
}

.btn {
    --bs-btn-font-weight: 500;
    --bs-btn-border-radius: .5rem;
}

.btn-sm {
    --bs-btn-border-radius: .4rem;
}

.form-control,
.form-select {
    border-radius: .5rem;
}

.form-label {
    font-weight: 500;
    margin-bottom: .35rem;
}

.form-text,
.hint-block {
    display: block;
    margin-top: .3rem;
    color: var(--bs-secondary-color);
    font-size: .9em;
}

.error-summary {
    color: var(--bs-danger-text-emphasis);
    background: var(--bs-danger-bg-subtle);
    border: 1px solid var(--bs-danger-border-subtle);
    border-radius: var(--admin-radius);
    padding: .75rem 1.25rem;
    margin: 0 0 1rem;
}

.error-summary ul {
    margin-bottom: 0;
}

/* Карточки */
.card {
    --bs-card-border-color: var(--admin-border);
    --bs-card-border-radius: var(--admin-radius);
    --bs-card-inner-border-radius: calc(var(--admin-radius) - 1px);
    --bs-card-cap-bg: var(--admin-surface);
    box-shadow: var(--admin-shadow);
}

.card-header {
    font-weight: 600;
}

.card-header .card-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

/* Формы CRUD (<div class="xxx-form">) — на белой карточке */
.admin-content div[class$="-form"] > form,
.admin-content div[class$="-search"] > form {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.admin-content div[class$="-form"] > form .card {
    box-shadow: none;
}

/* ---------- Таблицы ---------- */

.table {
    --bs-table-bg: var(--admin-surface);
    --bs-table-hover-bg: #f5f8ff;
    --bs-table-striped-bg: var(--admin-muted-bg);
}

.table > :not(caption) > * > * {
    padding: .6rem .75rem;
}

.table.table-sm > :not(caption) > * > * {
    padding: .35rem .5rem;
}

.table > thead th {
    background: var(--admin-muted-bg);
    color: #4b5563;
    font-weight: 600;
    font-size: .92rem;
    border-bottom-width: 1px;
}

.table > thead th a {
    color: inherit;
    text-decoration: none;
}

.table > thead th a:hover {
    color: var(--bs-link-color);
}

/* GridView: таблица в рамке-карточке */
.grid-view .table-responsive {
    background: var(--admin-surface);
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
    box-shadow: var(--admin-shadow);
    margin-bottom: 1rem;
}

.grid-view .table-responsive > .table {
    margin-bottom: 0;
}

.grid-view .table-responsive > .table > :not(caption) > tr:last-child > *,
.grid-view .table-responsive > .table > tbody > tr:last-child > * {
    border-bottom-width: 0;
}

.grid-view .table-responsive > .table > thead > tr:first-child > th:first-child {
    border-top-left-radius: var(--admin-radius);
}

.grid-view .table-responsive > .table > thead > tr:first-child > th:last-child {
    border-top-right-radius: var(--admin-radius);
}

.grid-view th,
.grid-view td:last-child {
    white-space: nowrap;
}

.grid-view .filters td {
    background: var(--admin-surface);
    padding-top: .45rem;
    padding-bottom: .45rem;
}

.grid-view .filters input,
.grid-view .filters select {
    min-width: 50px;
}

.grid-view .filters .form-control,
.grid-view .filters .form-select {
    padding-top: .3rem;
    padding-bottom: .3rem;
    font-size: .92rem;
}

/* иконки действий в ActionColumn */
.grid-view td a > .bi {
    font-size: 1.05rem;
}

.grid-view td a:has(> .bi:only-child) {
    display: inline-block;
    padding: .1rem .2rem;
    border-radius: .35rem;
    color: var(--bs-secondary-color);
}

.grid-view td a:has(> .bi:only-child):hover {
    background: var(--admin-muted-bg);
    color: var(--bs-link-color);
}

.grid-view .empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--bs-secondary-color);
}

/* стрелки сортировки */
a.asc::after,
a.desc::after {
    display: inline-block;
    padding-left: .3rem;
    font-family: "bootstrap-icons";
    font-size: .8em;
    line-height: 1;
    vertical-align: -.05em;
}

a.asc::after {
    content: "\f148";
}

a.desc::after {
    content: "\f128";
}

.pagination {
    flex-wrap: wrap;
    --bs-pagination-border-radius: .5rem;
}

/* DetailView */
.detail-view {
    background: var(--admin-surface);
}

.detail-view th {
    width: 28%;
    background: var(--admin-muted-bg);
    color: #4b5563;
    font-weight: 500;
}

.not-set {
    color: var(--bs-secondary-color);
    font-style: italic;
}

/* ---------- Прочее ---------- */

.bi-spin {
    display: inline-block;
    animation: bi-spin 1s linear infinite;
}

@keyframes bi-spin {
    to {
        transform: rotate(360deg);
    }
}

/* Превью блоков CMS (backend/components/block): рендереры выдают колонки то прямо в .row, то в обёртке —
   как в Bootstrap 3, раскладываем их float'ами, а не флексом */
.cms-block.row {
    display: block;
}

.cms-block.row::after {
    content: "";
    display: table;
    clear: both;
}

.cms-block [class*="col-"] {
    float: left;
}

.cms-block.row > a {
    width: auto;
    padding: 0;
}

/* бывший jumbotron Bootstrap 3 */
.jumbotron {
    padding: 2rem;
    margin-bottom: 1rem;
    border-radius: var(--admin-radius);
    background-color: var(--bs-tertiary-bg);
}

/* Во вьюхах много <select class="form-control"> (Html::dropDownList) — в Bootstrap 5 у такого селекта
   нет стрелки, рисуем как у .form-select */
select.form-control:not([multiple]):not([size]) {
    padding-right: 2.25rem;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 16px 12px;
}

/* Поле с подписью слева: шаблон '<div class="input-group"><span class="input-group-text">…</span>{input}</div>{error}' */
.input-group > .select2-container {
    flex: 1 1 auto;
    width: 1% !important;
}

.input-group > .input-group-text + .select2-container .select2-selection {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* ошибка под input-group: в Bootstrap 5 .invalid-feedback видна, только если стоит рядом с полем */
.input-group:has(.is-invalid) ~ .invalid-feedback {
    display: block;
}

/* ActiveForm с 'layout' => 'inline' (yii2-bootstrap5 ставит класс form-inline, а в Bootstrap 5 его нет) */
.form-inline {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: .5rem;
}

.form-inline > * {
    margin-bottom: 0;
}

.form-inline > .col-12 {
    width: auto;
}

/* кнопки во всю ширину, идущие стопкой (бывший .btn-block) */
.btn.w-100 + .btn.w-100 {
    margin-top: .35rem;
}

/* Плитки разделов на главной */
.dashboard-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: .5rem;
    background: #eef2ff;
    color: #4f46e5;
    font-size: 1rem;
}

.dashboard-links {
    columns: 2;
    column-gap: 1rem;
}

.dashboard-links li {
    break-inside: avoid;
    padding: .15rem 0;
}

.dashboard-links a {
    text-decoration: none;
}

.dashboard-links a:hover {
    text-decoration: underline;
}

/* ---------- Страница входа ---------- */

body.blank {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    background: radial-gradient(1200px 600px at 10% -10%, #e0e7ff 0, transparent 60%),
    radial-gradient(900px 500px at 110% 110%, #ffedd5 0, transparent 55%),
    var(--admin-page-bg);
}

.blank-wrap {
    width: 100%;
    max-width: 400px;
}

.blank-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .65rem;
    margin-bottom: 1.25rem;
    font-size: 1.3rem;
    font-weight: 600;
}

.blank-card {
    box-shadow: 0 10px 30px rgba(16, 24, 40, .08);
}

.blank-card > .card-body {
    padding: 2rem;
}

/* Поле мельче 16px iPhone приближает вместе со страницей; ссылкам рядом — высота под палец, место в вёрстке то же */
@media (max-width: 767.98px) {
    .blank-card .form-control {
        font-size: 16px;
    }

    .blank-card a:not(.btn) {
        position: relative;
    }

    .blank-card a:not(.btn)::after {
        content: "";
        position: absolute;
        inset: -.75rem -.5rem;
    }
}

/* «Мои устройства» карточками: кнопка «Забыть» была за краем таблицы (шестое ревью 04.12.2026) — и на телефоне, и на 992–1299 px,
   где профиль уже в две колонки */
@media (max-width: 767.98px), (min-width: 992px) and (max-width: 1299.98px) {
    .device-table thead {
        display: none;
    }

    .device-table,
    .device-table tbody {
        display: block;
    }

    .device-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: .15rem .75rem;
        align-items: center;
        padding: .6rem 0;
        border-bottom: 1px solid var(--admin-border);
    }

    .device-table tr > td {
        display: block;
        grid-column: 1;
        padding: 0;
        border: 0;
        background: none;
        box-shadow: none;
    }

    .device-table tr > td[data-label] {
        font-size: .85rem;
    }

    .device-table tr > td[data-label]::before {
        content: attr(data-label) ": ";
        color: var(--bs-secondary-color);
    }

    .device-table tr > td:last-child {
        grid-column: 2;
        grid-row: 1;
    }
}

/* Аналитика оформления: крупная цифра и столбики по дням */
.checkout-kpi {
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.2;
}

.checkout-bars {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 180px;
    padding-top: 1.25rem;
}

.checkout-bar {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
}

.checkout-bar-group {
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 1px;
    width: 100%;
    height: 100%;
}

.checkout-bar-fill {
    flex: 1 1 0;
    max-width: 16px;
    min-height: 1px;
    border-radius: 3px 3px 0 0;
}

.checkout-fill-opened { background: #93c5fd; }
.checkout-fill-rejected { background: #f59e0b; }
.checkout-fill-placed { background: #16a34a; }

.checkout-legend {
    display: inline-block;
    width: .7rem;
    height: .7rem;
    margin-right: .35rem;
    border-radius: 2px;
    vertical-align: -1px;
}

.checkout-bar-label {
    position: absolute;
    bottom: -1.3rem;
    font-size: .7rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
}

.checkout-bars + p {
    margin-top: 1.75rem !important;
}

/* ---------- Модули Sunction ID (S-315): меню в шапке и плитки на главной ---------- */

/* Значок модуля: цвет модуля по тексту, тот же цвет прозрачной заливкой — читается на любом фоне */
.module-icon {
    --module-color: var(--admin-accent);
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: .5rem;
    background: color-mix(in srgb, var(--module-color) 14%, transparent);
    color: var(--module-color);
    font-size: 1rem;
}

.module-icon-lg {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
}

.module-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.module-launcher-menu {
    width: min(320px, calc(100vw - 2rem));
    padding: .35rem;
}

.module-launcher-menu .dropdown-header {
    padding: .35rem .65rem .5rem;
}

.module-launcher-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .5rem .65rem;
    border-radius: .5rem;
    white-space: normal;
}

.module-launcher-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
    line-height: 1.25;
}

.module-launcher-name {
    font-weight: 600;
    color: var(--bs-body-color);
}

.module-launcher-role {
    font-size: .85rem;
    color: var(--bs-secondary-color);
    overflow: hidden;
    text-overflow: ellipsis;
}

.module-launcher-out {
    margin-left: auto;
    font-size: .85rem;
    color: var(--bs-secondary-color);
    opacity: 0;
}

.module-launcher-item:hover .module-launcher-out,
.module-launcher-item:focus-visible .module-launcher-out,
.module-tile:hover .module-launcher-out,
.module-tile:focus-visible .module-launcher-out {
    opacity: 1;
}

.module-tiles-title {
    font-size: .8rem;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--bs-secondary-color);
    margin: 1.25rem 0 .75rem;
}

.module-tile {
    text-decoration: none;
    color: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.module-tile:hover,
.module-tile:focus-visible {
    border-color: var(--admin-accent);
    box-shadow: 0 2px 8px rgba(16, 24, 40, .08);
}

@media (prefers-reduced-motion: reduce) {
    .module-tile {
        transition: none;
    }
}

/* Кнопка меню «Модули» в шапке: значок + подпись в рамке, чтобы читалась как кнопка */
.btn-launcher {
    --bs-btn-padding-x: .75rem;
    --bs-btn-padding-y: .3rem;
    display: flex;
    align-items: center;
    gap: .45rem;
    border: 1px solid var(--admin-border);
    border-radius: 2rem;
    background: var(--admin-surface);
    font-weight: 500;
    cursor: pointer;
}

.btn-launcher .bi {
    font-size: 1rem;
    color: var(--admin-accent);
}

.btn-launcher:hover,
.btn-launcher.show {
    background: var(--admin-muted-bg);
    border-color: var(--admin-accent);
}

@media (max-width: 767.98px) {
    .btn-launcher {
        --bs-btn-padding-x: .55rem;
    }
}

/* Знак магазина над формой входа Sunction ID (S-315): размер задан в разметке — без сдвигов */
.blank-logo {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 15px;
    background: var(--sunction-tile);
    color: #fff;
}

/* Доступ к модулю в карточке модуля (S-315): сотрудник — роли — кнопка в строку, на телефоне столбиком */
.module-access-list {
    display: grid;
    gap: .5rem;
}

.module-access-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr) auto;
    gap: .5rem .75rem;
    align-items: center;
    padding: .5rem 0;
    border-bottom: 1px solid var(--admin-border);
}

.module-access-row:last-child {
    border-bottom: 0;
}

.module-access-who,
.module-access-roles {
    min-width: 0;
}

@media (max-width: 575.98px) {
    .module-access-row {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Плашка «Вы смотрите как …» (S-315): постоянная высота, текст в одну строку с обрезкой — без сдвигов */
.impersonation-bar {
    display: flex;
    align-items: center;
    gap: .6rem;
    height: 44px;
    padding: 0 1.5rem;
    background: #b42318;
    color: #fff;
    font-size: .95rem;
    overflow: hidden;
}

.impersonation-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 991.98px) {
    .impersonation-bar {
        padding: 0 1rem;
    }
}

/* Список сотрудников (S-315): фильтры в строку, таблица на компьютере, карточки на телефоне */
.user-filters-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)) auto;
    gap: .5rem;
    align-items: center;
}

.user-filter-actions {
    display: flex;
    gap: .5rem;
}

/* Select2 до инициализации: индикатор загрузки kartik на 4px выше готового поля — строка фильтров
   прыгала (CLS). Прячем его: поле всё равно появляется за доли секунды */
.user-filters .kv-plugin-loading,
.module-access-filters .kv-plugin-loading,
.log-filters .kv-plugin-loading {
    display: none;
}

/* …а исходный select kartik до запуска прячет совсем — место под поле держим сами, той же высоты */
.user-filters select[data-krajee-select2]:not(.select2-hidden-accessible),
.module-access-filters select[data-krajee-select2]:not(.select2-hidden-accessible),
.log-filters select[data-krajee-select2]:not(.select2-hidden-accessible) {
    /* !important — kartik пишет в select инлайн width/height 1px */
    display: block !important;
    visibility: hidden;
    width: 100% !important;
    height: calc(1.5em + .75rem + 2px) !important;
}

/* Пункт списка, видимый только от 768 px: в Bootstrap такого класса нет, а без него шаг про QR-код в мастере
   второго шага был скрыт и на компьютере (второе ревью 02.12.2026) */
@media (min-width: 768px) {
    .d-md-list-item {
        display: list-item !important;
    }
}

.user-list-card {
    overflow: visible;
}

/* Длинная почта и строка «Пригласил: … («модуль»)» не раздвигают таблицу за край карточки: колонка с именем
   ограничена, текст в ней обрезается многоточием (второе ревью 02.12.2026) */
@media (min-width: 768px) {
    .user-list .user-cell-who {
        max-width: 16rem;
    }

    .user-list .user-who {
        max-width: 100%;
        min-width: 0;
    }

    .user-list .user-who-text {
        min-width: 0;
        overflow: hidden;
    }
}

/* Название модуля не рвётся по слогам; почта и «Пригласил: …» целиком, когда место есть. Пороги — по самой широкой строке:
   «Деактивирован», «Последний вход» с временем */
@media (min-width: 1200px) {
    .user-list .user-cell-who {
        max-width: 16rem;
    }

    .user-list .user-cell-modules {
        min-width: 7.5rem;
    }

    .user-list .user-cell-roles {
        max-width: 15rem;
    }
}

/* Места на все колонки нет — имя важнее даты добавления, она есть в карточке */
@media (min-width: 1200px) and (max-width: 1269.98px) {
    .user-list th:nth-child(6),
    .user-list .user-cell-created {
        display: none;
    }
}

@media (min-width: 1350px) {
    .user-list .user-cell-who {
        max-width: 20rem;
    }

    .user-list .user-cell-modules {
        min-width: 8.5rem;
    }
}

@media (min-width: 1440px) {
    .user-list .user-cell-who {
        max-width: 26rem;
    }
}

.user-list thead th {
    font-size: .8rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    background: var(--admin-muted-bg);
}

.user-sort {
    color: inherit;
    text-decoration: none;
}

.user-sort:hover,
.user-sort.active {
    color: var(--bs-body-color);
}

.user-row {
    cursor: pointer;
}

.user-row:hover > td {
    background: var(--admin-muted-bg);
}

.user-row.is-muted .user-name,
.user-row.is-muted .user-avatar {
    opacity: .6;
}

.user-who {
    display: flex;
    align-items: center;
    gap: .75rem;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.user-avatar {
    --avatar-hue: 210;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: hsl(var(--avatar-hue) 70% 92%);
    color: hsl(var(--avatar-hue) 55% 32%);
    font-size: .8rem;
    font-weight: 600;
}

.user-who-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-email {
    font-size: .8rem;
    color: var(--bs-secondary-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip {
    background: var(--admin-muted-bg);
    color: var(--bs-body-color);
    border: 1px solid var(--admin-border);
    font-weight: 500;
    margin: 0 .25rem .25rem 0;
}

/* Разрешение сверх ролей — пунктиром: это не роль, а отдельная галочка в карточке сотрудника */
.user-chip-perm {
    background: transparent;
    border-style: dashed;
    font-weight: 400;
}

.user-chip-more {
    cursor: pointer;
}

/* Несколько модулей — в несколько строк, а не одной длинной меткой */
.user-chip-owner {
    max-width: 100%;
    white-space: normal;
    text-align: start;
    background: transparent;
}

.user-module {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    margin: 0 .6rem .25rem 0;
    font-size: .85rem;
    max-width: 100%;
    overflow-wrap: anywhere; /* длинное название переносится, а не раздвигает таблицу за край экрана */
}

.module-icon-sm {
    flex: none;
    width: 22px;
    height: 22px;
    border-radius: .35rem;
    font-size: .75rem;
}

.user-cell-login,
.user-cell-created {
    white-space: nowrap;
    font-size: .875rem;
}

@media (min-width: 1270px) {
    .user-filter-sort {
        display: none;
    }
}

@media (max-width: 1269.98px) {
    .user-filters-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .user-filter-search,
    .user-filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 767.98px) {
    .user-filters-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
}

/* Карточками — и на планшете, и в узком окне ноутбука: семь колонок туда не помещались, и кнопки уезжали за край экрана
   (шестое ревью 04.12.2026) */
@media (max-width: 1199.98px) {
    .user-list thead {
        display: none;
    }

    .user-list,
    .user-list tbody {
        display: block;
    }

    .user-list .user-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: .35rem .75rem;
        padding: .85rem 1rem;
        border-bottom: 1px solid var(--admin-border);
    }

    .user-list .user-row > td {
        display: block;
        padding: 0;
        border: 0;
        background: none;
    }

    .user-list .user-cell-who {
        grid-column: 1;
        grid-row: 1;
    }

    .user-list .user-cell-actions {
        grid-column: 2;
        grid-row: 1;
    }

    .user-list .user-row > td[data-label] {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: .25rem;
        padding-left: calc(36px + .75rem);
        font-size: .85rem;
    }

    .user-list .user-row > td[data-label]::before {
        content: attr(data-label) ":";
        color: var(--bs-secondary-color);
        margin-right: .15rem;
    }
}

/* «Порядок» и «Найти» — в одной строке */
@media (min-width: 768px) and (max-width: 1269.98px) {
    .user-filter-actions {
        grid-column: auto;
    }
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    .user-list .user-row {
        grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
    }

    .user-list .user-cell-who {
        grid-column: 1 / 4;
        max-width: none;
    }

    .user-list .user-cell-actions {
        grid-column: 4;
    }

    /* Статус, вход и дата — в одну строку: карточка ниже, людей на экране больше */
    .user-list .user-row > td.user-cell-status {
        grid-column: 1;
    }

    .user-list .user-row > td.user-cell-login {
        grid-column: 2;
        padding-left: 0;
    }

    .user-list .user-row > td.user-cell-created {
        grid-column: 3 / -1;
        padding-left: 0;
    }
}

/* «У кого доступ» в карточке модуля (S-315): поиск + роль + кнопка в строку, таблица; на телефоне карточки */
.module-access-filters {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto;
    gap: .5rem;
    align-items: center;
}

.module-access-table thead th {
    font-size: .8rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    background: var(--admin-muted-bg);
}

.module-access-table .module-access-who {
    max-width: 320px;
}

@media (max-width: 1199.98px) {
    .module-access-filters {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    }

    .module-access-filters > .input-group {
        grid-column: 1 / -1;
    }
}

@media (max-width: 767.98px) {
    .module-access-filters {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (min-width: 1200px) {
    .module-access-table .module-access-actions {
        white-space: nowrap;
    }
}

@media (max-width: 1199.98px) {
    .module-access-table thead {
        display: none;
    }

    .module-access-table,
    .module-access-table tbody {
        display: block;
    }

    .module-access-table tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        gap: .35rem;
        padding: .75rem 0;
        border-bottom: 1px solid var(--admin-border);
    }

    .module-access-table tr > td {
        display: block;
        padding: 0;
        border: 0;
        max-width: none;
    }

    .module-access-table td.module-access-actions {
        display: flex;
        flex-wrap: wrap;
        gap: .4rem;
    }
}

@media (min-width: 768px) and (max-width: 1199.98px) {
    .module-access-table tr {
        grid-template-columns: minmax(0, 1fr) auto;
        column-gap: 1rem;
    }

    .module-access-table tr > td.module-access-who {
        max-width: none;
    }

    .module-access-table tr > td.module-access-granted {
        text-align: end;
    }

    .module-access-table tr > td.module-access-actions {
        grid-column: 2;
        grid-row: 1;
        justify-content: flex-end;
        align-self: center;
    }
}

/* Второй фактор (S-315): «или» на входе, варианты в мастере, QR и коды восстановления */
.login-or {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--bs-secondary-color);
    font-size: .85rem;
}

.login-or::before,
.login-or::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--admin-border);
}

.mfa-option {
    padding: 1rem;
    border: 1px solid var(--admin-border);
    border-radius: var(--admin-radius);
}

.mfa-option-icon {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: .6rem;
    background: color-mix(in srgb, var(--sunction-orange) 14%, transparent);
    color: var(--sunction-orange);
    font-size: 1.25rem;
}

/* Размер QR задан заранее — без сдвига вёрстки */
.mfa-qr {
    width: 200px;
    height: 200px;
}

.mfa-qr svg {
    display: block;
    width: 100%;
    height: 100%;
}

.mfa-secret {
    font-size: .95rem;
    word-break: break-all;
}

.mfa-codes {
    columns: 2;
    column-gap: 2rem;
    padding-left: 1.5rem;
    font-size: 1rem;
}

.mfa-codes code {
    font-size: 1rem;
    letter-spacing: .05em;
    color: var(--bs-body-color);
}

/* Карточка модуля: «У кого доступ» — ежедневная работа ответственного, настройки подключения ниже (ревью 02.12.2026) */
.identity-client-view {
    display: flex;
    flex-direction: column;
}

.identity-client-view > .module-access-card {
    order: 1;
}

.identity-client-view > .module-settings {
    order: 2;
}

/* «Как подключить» в «Модулях» (S-315): инструкция разработчику модуля — читается как статья */
.module-guide {
    max-width: 920px;
}
.module-guide-values th {
    width: 16rem;
    font-weight: 500;
    white-space: normal;
}
/* На телефоне название строки — над значением: адреса длинные, в узкой колонке они рвались по буквам */
@media (max-width: 575.98px) {
    .module-guide-values th,
    .module-guide-values td {
        display: block;
        width: auto;
    }
    .module-guide-values th {
        padding-bottom: 0;
        border-bottom: 0;
        color: var(--bs-secondary-color);
        font-size: .875rem;
    }
    .module-guide-values td {
        padding-top: .125rem;
    }
}
.module-guide-toc {
    padding: .75rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    font-size: .9375rem;
}
.module-guide-toc ol {
    columns: 2 18rem;
    padding-left: 1.25rem;
}
/* Переход к «У кого доступ» (поиск, фильтр, сортировка) — не под липкую шапку */
#access {
    scroll-margin-top: 4.5rem;
}
.module-guide-text h2 {
    margin-top: 2.25rem;
    font-size: 1.375rem;
    scroll-margin-top: 4.5rem;
}
.module-guide-text h3 {
    margin-top: 1.5rem;
    font-size: 1.0625rem;
}
.module-guide-text pre {
    padding: .75rem 1rem;
    border-radius: .5rem;
    background: var(--bs-tertiary-bg);
    font-size: .8125rem;
    white-space: pre;
    overflow-x: auto;
}
.module-guide-text li + li {
    margin-top: .25rem;
}
.module-guide-text table code,
.module-guide-values code {
    word-break: break-word;
}
