/* ========== АвтоГраф — тема Bootstrap 5.3 (сланец + корпоративный синий) ========== */
:root,
[data-bs-theme="light"] {
    --ag-dark: #0f172a;
    --ag-accent: #3b82f6;
    --ag-accent-hover: #60a5fa;
    --ag-accent-muted: rgba(37, 99, 235, 0.12);
    --ag-on-accent: #0f172a;
    --bs-primary: #1d4ed8;
    --bs-primary-rgb: 29, 78, 216;
    --bs-secondary: #64748b;
    /* В паре с --bs-secondary-color (подписи, .text-body-secondary) */
    --bs-secondary-rgb: 71, 85, 105;
    --bs-body-font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --bs-body-font-size: 0.9375rem;
    --bs-body-font-weight: 400;
    --bs-body-line-height: 1.62;
    --bs-body-bg: #ffffff;
    --bs-body-color-rgb: 15, 23, 42;
    --bs-body-bg-rgb: 255, 255, 255;
    /* Полосы футера, table-stripe и т.п. — нейтральный серый без «синего» сланца */
    --bs-secondary-bg: #fafafa;
    --bs-tertiary-bg: #f5f5f5;
    --bs-body-color: #0f172a;
    /* Приглушённый текст: контрастнее «#666/#64748b» для подписей и второстепенных строк */
    --bs-secondary-color: #475569;
    --bs-tertiary-color: #94a3b8;
    --bs-emphasis-color: #0f172a;
    --bs-border-color: #e5e7eb;
    --bs-border-radius: 0.5rem;
    --bs-border-radius-lg: 0.75rem;
    --bs-link-color: #1d4ed8;
    --bs-link-hover-color: #2563eb;
    --bs-heading-color: #0f172a;
    --bs-headings-font-weight: 500;
    --ag-card-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
    --ag-navbar-shadow: 0 4px 24px rgba(15, 23, 42, 0.12);
}

body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, .h1, h2, .h2, h3, .h3, h4, .h4, h5, .h5, h6, .h6 {
    letter-spacing: -0.02em;
}

[data-bs-theme="dark"] {
    --ag-dark: #020617;
    --ag-accent: #60a5fa;
    --ag-accent-hover: #93c5fd;
    --ag-accent-muted: rgba(59, 130, 246, 0.14);
    --ag-on-accent: #0f172a;
    --bs-primary: #3b82f6;
    --bs-primary-rgb: 59, 130, 246;
    --bs-secondary: #94a3b8;
    /* Тот же оттенок, что --bs-secondary-color (читаемые подписи / .text-body-secondary) */
    --bs-secondary-rgb: 203, 213, 225;
    --bs-body-font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --bs-body-font-size: 0.9375rem;
    --bs-body-font-weight: 400;
    --bs-body-line-height: 1.62;
    --bs-body-bg: #020617;
    --bs-body-color: #f1f5f9;
    --bs-body-color-rgb: 241, 245, 249;
    --bs-body-bg-rgb: 2, 6, 23;
    --bs-secondary-bg: #1e293b;
    --bs-tertiary-bg: #0f172a;
    --bs-secondary-color: #cbd5e1;
    --bs-tertiary-color: #94a3b8;
    --bs-emphasis-color: #f8fafc;
    --bs-border-color: #334155;
    --bs-link-color: #93c5fd;
    --bs-link-hover-color: #bfdbfe;
    --bs-heading-color: #f8fafc;
    --ag-card-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 8px 32px rgba(0, 0, 0, 0.35);
    --ag-navbar-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

/* Шапка: градиент, тонкая линия акцента */
.ag-navbar {
    background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #0f172a 100%);
    background-size: 200% 200%;
    box-shadow: var(--ag-navbar-shadow);
    border-bottom: 1px solid rgba(59, 130, 246, 0.28);
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}
[data-bs-theme="dark"] .ag-navbar {
    background: linear-gradient(135deg, #020617 0%, #0f172a 45%, #1e3a8a 100%);
    background-size: 200% 200%;
    border-bottom-color: rgba(59, 130, 246, 0.22);
}
.ag-navbar .navbar-brand {
    font-weight: 700;
    letter-spacing: -0.03em;
    flex-shrink: 0;
}

/* Воздух между блоками шапки (логотип — меню — пользователь) */
@media (min-width: 992px) {
    .ag-navbar .navbar-collapse.ag-navbar-collapse {
        gap: 0.75rem 1.5rem;
    }
    .ag-navbar .ag-navbar-nav-user {
        border-left: 1px solid rgba(255, 255, 255, 0.14);
        padding-left: 1.25rem !important;
        margin-left: 0.25rem;
    }
}

/* Пункты меню: больше горизонтальных отступов, чтобы не сливались */
.ag-navbar.navbar-dark .navbar-nav .nav-link {
    color: rgba(248, 250, 252, 0.88);
    font-weight: 500;
    padding: 0.55rem 0.75rem;
    border-radius: 0.375rem;
    transition: color 0.15s ease, background-color 0.15s ease;
}
@media (min-width: 992px) {
    .ag-navbar.navbar-dark .navbar-nav .nav-link {
        padding: 0.5rem 1rem;
    }
}

/* Пункты основного меню — фраза в одну строку (не «Личный» / «кабинет») */
.ag-navbar .navbar-nav.me-auto > .nav-item > .nav-link {
    white-space: nowrap;
}
@media (min-width: 992px) {
    .ag-navbar .navbar-nav.me-auto > .nav-item {
        flex-shrink: 0;
    }
}
.ag-navbar.navbar-dark .navbar-nav .nav-link:hover,
.ag-navbar.navbar-dark .navbar-nav .nav-link:focus {
    color: #fff;
    background-color: rgba(59, 130, 246, 0.14);
}
.navbar-dark .navbar-toggler {
    border-color: rgba(255, 255, 255, 0.25);
    color: rgba(255, 255, 255, 0.95);
}
.text-ag-accent {
    color: var(--ag-accent) !important;
}

/* Логотип в шапке — крупнее пунктов меню */
.ag-brand-mark {
    display: block;
    width: 42px;
    height: 42px;
}
@media (min-width: 992px) {
    .ag-brand-mark {
        width: 48px;
        height: 48px;
    }
}
.ag-brand-title {
    font-size: 1.2rem;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1.15;
}
@media (min-width: 992px) {
    .ag-brand-title {
        font-size: 1.35rem;
        font-weight: 500;
    }
}

/* Выпадающие группы меню */
.ag-navbar .dropdown-menu.ag-nav-dropdown {
    margin-top: 0.35rem;
    border-radius: var(--bs-border-radius-lg);
    padding: 0.35rem;
    min-width: 13rem;
    border-color: var(--bs-border-color);
    background-color: #fff;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.12);
}
.ag-navbar .dropdown-item {
    border-radius: var(--bs-border-radius);
    font-size: 0.9rem;
    padding: 0.45rem 0.75rem;
    color: var(--bs-emphasis-color);
}
.ag-navbar .dropdown-item:hover,
.ag-navbar .dropdown-item:focus {
    background-color: rgba(37, 99, 235, 0.08);
    color: #1e40af;
}
.ag-navbar .dropdown-item:active {
    background-color: #1d4ed8;
    color: #fff;
}
.ag-navbar .dropdown-item:active .text-primary {
    color: #fff !important;
}
.ag-navbar .dropdown-toggle::after {
    margin-left: 0.35em;
    vertical-align: 0.12em;
}
[data-bs-theme="dark"] .ag-navbar .dropdown-menu.ag-nav-dropdown {
    background-color: #0f172a;
    border-color: #334155;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
[data-bs-theme="dark"] .ag-navbar .dropdown-item {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .ag-navbar .dropdown-item:hover,
[data-bs-theme="dark"] .ag-navbar .dropdown-item:focus {
    background-color: rgba(59, 130, 246, 0.12);
    color: #bfdbfe;
}
[data-bs-theme="dark"] .ag-navbar .dropdown-item:active {
    background-color: #2563eb;
    color: #fff;
}

/* Переключатель темы в шапке — компактные кнопки без !important */
.navbar .theme-toggle.btn-group > .btn.theme-btn {
    padding: 0.2rem 0.45rem;
    font-size: 0.875rem;
    line-height: 1;
    border-width: 1px;
}
.navbar .theme-toggle.btn-group > .btn.theme-btn i {
    font-size: 0.9rem;
}
.theme-toggle .theme-btn.active {
    background-color: #93c5fd;
    color: var(--ag-on-accent);
    border-color: #93c5fd;
}

/* Footer в тёмной теме */
[data-bs-theme="dark"] .footer {
    background-color: var(--bs-body-bg) !important;
    border-color: var(--bs-border-color) !important;
}

/* Хлебные крошки */
.breadcrumb {
    font-size: 0.875rem;
}
.breadcrumb-item a {
    text-decoration: none;
}

/* Кнопки: компактнее дефолта Bootstrap (размеры бренда) */
.btn,
a.btn {
    --bs-btn-font-weight: 400;
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}
.btn:hover {
    transform: none;
}
.btn-sm {
    padding: 0.25rem 0.55rem;
    font-size: 0.8125rem;
    border-radius: 0.4rem;
}
.btn-lg {
    padding: 0.5rem 1rem;
    font-size: 0.9375rem;
}

/* Primary — корпоративный синий */
.btn-primary {
    --bs-btn-bg: #1d4ed8;
    --bs-btn-border-color: #1d4ed8;
    --bs-btn-hover-bg: #1e40af;
    --bs-btn-hover-border-color: #1e40af;
    --bs-btn-active-bg: #1e3a8a;
    --bs-btn-active-border-color: #1e3a8a;
    --bs-btn-color: #fff;
    --bs-btn-hover-color: #fff;
    --bs-btn-active-color: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.btn-primary:hover {
    box-shadow: 0 4px 14px rgba(29, 78, 216, 0.32);
}
[data-bs-theme="dark"] .btn-primary {
    --bs-btn-bg: #2563eb;
    --bs-btn-border-color: #2563eb;
    --bs-btn-hover-bg: #1d4ed8;
    --bs-btn-hover-border-color: #1d4ed8;
    --bs-btn-active-bg: #1e40af;
    --bs-btn-active-border-color: #1e40af;
}

/* Вторичный акцент — янтарь (сохранение / альтернативный CTA) */
.btn-warning {
    background: linear-gradient(180deg, #fcd34d 0%, #fbbf24 100%);
    border-color: #f59e0b;
    color: #422006;
    --bs-btn-font-weight: 400;
}
.btn-warning:hover {
    background: linear-gradient(180deg, #fde68a 0%, #fcd34d 100%);
    border-color: #d97706;
    color: #422006;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.35);
}

/* Карточки: мягкая тень и чёткая граница */
main .card {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius-lg);
    box-shadow: var(--ag-card-shadow);
    overflow: hidden;
}
main .card.shadow-sm {
    box-shadow: var(--ag-card-shadow) !important;
}
/* Единый вид контента карточек и заголовков */
main .card .card-body {
    color: var(--bs-body-color);
}
main .card .card-header:not(.bg-primary):not(.bg-danger):not(.bg-warning) {
    color: var(--bs-heading-color);
    font-weight: 600;
}
.module-card-hover .card-title {
    font-weight: 600;
    font-size: 1.0625rem;
    letter-spacing: -0.02em;
    line-height: 1.35;
    color: var(--bs-emphasis-color);
}

/* Просмотр ТТН / закупки: таблица реквизитов (двухколоночная), light/dark */
.shipment-detail-spec,
.purchase-detail-spec {
    table-layout: fixed;
    width: 100%;
}
.shipment-detail-spec tbody th,
.purchase-detail-spec tbody th {
    width: 30%;
    max-width: 12.5rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--bs-secondary-color);
    background-color: var(--bs-tertiary-bg);
    border-color: var(--bs-border-color);
    vertical-align: top;
    padding: 0.5rem 0.75rem;
}
.shipment-detail-spec tbody td,
.purchase-detail-spec tbody td {
    border-color: var(--bs-border-color);
    color: var(--bs-body-color);
    vertical-align: top;
    padding: 0.5rem 0.75rem;
    line-height: 1.45;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.shipment-detail-spec tbody tr:last-child th,
.shipment-detail-spec tbody tr:last-child td,
.purchase-detail-spec tbody tr:last-child th,
.purchase-detail-spec tbody tr:last-child td {
    border-bottom-width: 0;
}
.shipment-detail-note,
.purchase-detail-note {
    white-space: pre-wrap;
}
@media (min-width: 576px) {
    .shipment-detail-spec tbody th,
    .purchase-detail-spec tbody th {
        max-width: 13.5rem;
        padding: 0.65rem 1rem;
    }
    .shipment-detail-spec tbody td,
    .purchase-detail-spec tbody td {
        padding: 0.65rem 1rem;
    }
}
/* Позиции ТТН на экране: сетка как при печати, без «растягивания» за карточку */
.shipment-print-items {
    table-layout: fixed;
    width: 100%;
}
.shipment-print-items thead th {
    white-space: normal;
    line-height: 1.25;
    font-size: 0.8125rem;
    vertical-align: bottom;
    hyphens: auto;
}
.shipment-print-items .shipment-print-items-col-num {
    font-size: 0.75rem;
}
.shipment-print-items--cols5 th:nth-child(1),
.shipment-print-items--cols5 td:nth-child(1) {
    width: 4%;
}
.shipment-print-items--cols5 th:nth-child(2),
.shipment-print-items--cols5 td:nth-child(2) {
    width: 52%;
}
.shipment-print-items--cols5 th:nth-child(3),
.shipment-print-items--cols5 td:nth-child(3),
.shipment-print-items--cols5 th:nth-child(4),
.shipment-print-items--cols5 td:nth-child(4),
.shipment-print-items--cols5 th:nth-child(5),
.shipment-print-items--cols5 td:nth-child(5) {
    width: 14.66%;
}
.shipment-print-items--cols6 th:nth-child(1),
.shipment-print-items--cols6 td:nth-child(1) {
    width: 4%;
}
.shipment-print-items--cols6 th:nth-child(2),
.shipment-print-items--cols6 td:nth-child(2) {
    width: 40%;
}
.shipment-print-items--cols6 th:nth-child(3),
.shipment-print-items--cols6 td:nth-child(3),
.shipment-print-items--cols6 th:nth-child(4),
.shipment-print-items--cols6 td:nth-child(4),
.shipment-print-items--cols6 th:nth-child(5),
.shipment-print-items--cols6 td:nth-child(5),
.shipment-print-items--cols6 th:nth-child(6),
.shipment-print-items--cols6 td:nth-child(6) {
    width: 14%;
}
.shipment-print-items td:nth-child(2) {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.shipment-print-root .table-responsive {
    min-width: 0;
}

/* Позиции закупки: три колонки без горизонтального переполнения */
.purchase-detail-items {
    table-layout: fixed;
    width: 100%;
}
.purchase-detail-items th:nth-child(1),
.purchase-detail-items td:nth-child(1) {
    width: 3.25rem;
}
.purchase-detail-items th:nth-child(3),
.purchase-detail-items td:nth-child(3) {
    width: 5.5rem;
}
.purchase-detail-items td:nth-child(2) {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Вложенные блоки «деталей» внутри одной card — без лишней тени, спокойный фон */
main .card > .card-body .detail-card {
    background: var(--bs-secondary-bg);
    border: 1px solid var(--bs-border-color);
    border-left: 3px solid rgba(var(--bs-primary-rgb), 0.55);
    border-radius: var(--bs-border-radius);
    box-shadow: none;
    padding: 1rem 1.125rem;
}
[data-bs-theme="dark"] main .card > .card-body .detail-card {
    background: rgba(255, 255, 255, 0.07);
    border-color: var(--bs-border-color);
    border-left-color: var(--bs-primary);
    color: var(--bs-body-color);
}

/* Второстепенный текст и подсказки (вместо инлайна color:#666) */
.ag-help,
.form-text.ag-form-hint {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--bs-secondary-color);
}
[data-bs-theme="dark"] .ag-help,
[data-bs-theme="dark"] .form-text.ag-form-hint {
    color: var(--bs-secondary-color);
    opacity: 1;
}

/* Карточки модулей на дашборде */
.module-card-hover {
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    border-color: var(--bs-border-color) !important;
}
.module-card-hover:hover {
    transform: translateY(-3px);
    border-color: rgba(37, 99, 235, 0.3) !important;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1), 0 0 0 1px rgba(59, 130, 246, 0.1);
}
[data-bs-theme="dark"] .module-card-hover:hover {
    border-color: rgba(59, 130, 246, 0.35) !important;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(59, 130, 246, 0.12);
}
.module-card-hover .display-6 {
    font-size: 2.25rem;
    opacity: 0.92;
}

/* Иконка модуля на дашборде */
.ag-module-icon-wrap {
    width: 3.5rem;
    height: 3.5rem;
    background: linear-gradient(145deg, rgba(29, 78, 216, 0.1) 0%, rgba(59, 130, 246, 0.06) 100%);
    border: 1px solid rgba(37, 99, 235, 0.18);
    transition: transform 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}
.module-card-hover:hover .ag-module-icon-wrap {
    transform: scale(1.05);
    border-color: rgba(37, 99, 235, 0.32);
    background: linear-gradient(145deg, rgba(29, 78, 216, 0.14) 0%, rgba(59, 130, 246, 0.1) 100%);
}
[data-bs-theme="dark"] .ag-module-icon-wrap {
    background: linear-gradient(145deg, rgba(59, 130, 246, 0.12) 0%, rgba(15, 23, 42, 0.45) 100%);
    border-color: rgba(59, 130, 246, 0.22);
}

/* Статусы заявок — бейджи (единая палитра с style.css) */
.badge-status-new { background-color: #e8eef7; color: #334155; }
.badge-status-in_progress { background-color: #fff4cc; color: #92400e; }
.badge-status-sent { background-color: #dbeafe; color: #1e40af; }
.badge-status-completed { background-color: #dcfce7; color: #166534; }
.badge-status-cancelled { background-color: #eceff3; color: #475569; }
.badge-status-urgent { background-color: #dc3545; color: #fff; }

/* Приоритеты — бейджи */
.badge.priority-low { background-color: #e5e7eb; color: #374151; }
.badge.priority-medium { background-color: #dbeafe; color: #1d4ed8; }
.badge.priority-high { background-color: #fed7aa; color: #c2410c; }
.badge.priority-urgent { background-color: #fecaca; color: #b91c1c; }

/* Таблицы — заголовок: глубокий сланец, читаемые ссылки */
.table thead th {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: #f8fafc;
    border-color: #334155;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: none;
    letter-spacing: 0.01em;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
    vertical-align: middle;
}
.table thead th a.text-white {
    color: #f8fafc !important;
}
.table thead th a.text-white:hover {
    color: var(--ag-accent) !important;
}
[data-bs-theme="dark"] .table thead th {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: #f8fafc;
    border-color: var(--bs-border-color);
}
/* Заголовки .table-light не перекрывать */
.table thead.table-light th {
    background: var(--bs-secondary-bg);
    color: var(--bs-emphasis-color);
    border-color: var(--bs-border-color);
    text-transform: none;
    letter-spacing: normal;
    font-size: inherit;
}
[data-bs-theme="dark"] .table thead.table-light th {
    background-color: #1e293b !important;
    color: #f1f5f9 !important;
}

/* Формы — фокус акцент (ниже переопределяется style.css для .form-input / .form-select АвтоГраф) */
.form-control:focus,
.form-select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.2);
}

/* Панели фильтров: одинаковая высота .form-control-sm и .form-select-sm (Bootstrap задаёт их по-разному) */
.form-control.form-control-sm,
.form-select.form-select-sm {
    min-height: calc(1.5em + 0.5rem + 2px);
}

/* Поля форм Django без form-control — привести к виду Bootstrap.
   Не трогать .form-input / .form-textarea / .form-select (style.css) — иначе в card-body они перебиваются и расходятся по высоте с селектами. */
.card-body select:not([class*="form-select"]):not([class*="form-control"]),
.card-body input[type="text"]:not([class*="form-control"]):not([class*="form-input"]),
.card-body input[type="number"]:not([class*="form-control"]):not([class*="form-input"]),
.card-body input[type="date"]:not([class*="form-control"]):not([class*="form-input"]),
.card-body input[type="email"]:not([class*="form-control"]):not([class*="form-input"]),
.card-body input[type="password"]:not([class*="form-control"]):not([class*="form-input"]),
.card-body textarea:not([class*="form-control"]):not([class*="form-textarea"]) {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.5;
    color: var(--bs-body-color);
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
}
.card-body select:focus:not([class*="form-select"]),
.card-body input:focus:not([class*="form-input"]),
.card-body textarea:focus:not([class*="form-textarea"]) {
    border-color: #2563eb;
    outline: 0;
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.2);
}

/* Ссылки — поведение и цвета из reboot Bootstrap (--bs-link-*) */

/* Сохранение совместимости со старыми классами статусов (если где-то остались) */
.status-new { background-color: #e8eef7; color: #334155; }
.status-in-progress { background-color: #fff4cc; color: #92400e; }
.status-sent { background-color: #dbeafe; color: #1e40af; }
.status-completed { background-color: #dcfce7; color: #166534; }
.status-cancelled { background-color: #eceff3; color: #475569; }
.status-urgent { background-color: #ffe5e5; color: #d90429; }

/* Пагинация */
.pagination .page-link:hover {
    background-color: var(--ag-accent-muted);
    border-color: #2563eb;
    color: #1d4ed8;
}
.pagination .page-item.active .page-link {
    background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
    border-color: #1e40af;
    color: #fff;
}
[data-bs-theme="dark"] .pagination .page-item.active .page-link {
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    border-color: #60a5fa;
    color: #fff;
}

/* Модальное подтверждение удаления — заголовок */
.modal-header.bg-danger {
    background-color: #dc3545;
    color: #fff;
    border-bottom: none;
}

/* Пустые состояния */
.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--bs-secondary-color);
}

/* Помощь: FAQ и таблица прав */
.help-container { max-width: 900px; }
.help-section { margin-bottom: 1.5rem; }
.help-section h2 { font-size: 1.1rem; font-weight: 600; }
.faq-item {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}
.faq-question {
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    background: var(--bs-secondary-bg);
    transition: background 0.2s;
}
.faq-question:hover { background: var(--bs-tertiary-bg); }
.faq-question.active { background: linear-gradient(90deg, rgba(59, 130, 246, 0.14) 0%, rgba(29, 78, 216, 0.08) 100%); color: var(--bs-emphasis-color); border-left: 3px solid #2563eb; }
.faq-icon { transition: transform 0.2s; }
.faq-question.active .faq-icon { transform: rotate(180deg); }
.faq-answer { max-height: 0; overflow: hidden; transition: max-height 0.3s; }
.faq-answer.active { max-height: 2000px; }
.faq-answer-content { padding: 1rem; }
.permissions-table { width: 100%; font-size: 0.875rem; }
.permissions-table th { background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%); color: #f8fafc; padding: 0.5rem 0.75rem; }
.permissions-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--bs-border-color); }
.permission-yes { color: var(--bs-success); font-weight: 600; }
.permission-no { color: var(--bs-danger); font-weight: 600; }
.permission-partial { color: #1d4ed8; font-weight: 600; }
[data-bs-theme="dark"] .permission-partial { color: #60a5fa; }

/* Модальное окно подтверждения удаления (confirm_delete.js) */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.modal-overlay.show {
    display: flex;
}
.modal-confirm {
    background: var(--bs-body-bg);
    border-radius: var(--bs-border-radius-lg);
    box-shadow: var(--bs-box-shadow-lg);
    max-width: 500px;
    width: 100%;
    overflow: hidden;
}
.modal-confirm-header {
    background: var(--bs-danger);
    color: #fff;
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.modal-confirm-icon { font-size: 1.5rem; }
.modal-confirm-title { margin: 0; font-size: 1.25rem; font-weight: 600; }
.modal-confirm-body { padding: 1.25rem 1.5rem; }
.modal-confirm-message { margin-bottom: 1rem; }
.modal-confirm-warning {
    background: var(--bs-warning-bg-subtle);
    border-left: 4px solid var(--bs-warning);
    padding: 0.5rem 0.75rem;
    border-radius: var(--bs-border-radius);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.modal-confirm-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }
.modal-btn { padding: 0.5rem 1rem; border-radius: var(--bs-border-radius); font-weight: 500; cursor: pointer; border: 1px solid transparent; }
.modal-btn-cancel { background: var(--bs-secondary-bg); color: var(--bs-body-color); border-color: var(--bs-border-color); }
.modal-btn-delete { background: var(--bs-danger); color: #fff; border-color: var(--bs-danger); }

/* Индикатор загрузки (confirm_delete.js) */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.9);
    z-index: 1060;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1rem;
}
.loading-overlay.show { display: flex; }
.loading-spinner {
    width: 3rem;
    height: 3rem;
    border: 3px solid var(--bs-border-color);
    border-top-color: var(--ag-accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-weight: 600; }
[data-bs-theme="dark"] .loading-overlay { background: rgba(0,0,0,0.85); }

/* ========== ТЁМНАЯ ТЕМА: все разделы, читаемость ========== */
[data-bs-theme="dark"] {
    color-scheme: dark;
}
[data-bs-theme="dark"] body {
    background-color: #020617;
    color: #f1f5f9;
}
[data-bs-theme="dark"] main {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .card {
    background-color: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .card-header {
    background-color: #1e293b !important;
    border-bottom-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .card-header.bg-light {
    background-color: #1e293b !important;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .card-header.bg-primary {
    background: linear-gradient(90deg, #1e40af 0%, #0f172a 100%) !important;
    color: #fff;
}
[data-bs-theme="dark"] .card-body {
    background-color: #0f172a;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .bg-light {
    background-color: #1e293b !important;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .footer,
[data-bs-theme="dark"] footer.bg-light {
    background-color: #020617 !important;
    border-top-color: #334155 !important;
    color: #94a3b8 !important;
}
[data-bs-theme="dark"] .breadcrumb-item a {
    color: #93c5fd;
}
[data-bs-theme="dark"] .breadcrumb-item.active {
    color: #94a3b8;
}
[data-bs-theme="dark"] .text-muted {
    color: var(--bs-secondary-color) !important;
}
/* Явно: вторичный цвет текста на тёмном фоне */
[data-bs-theme="dark"] .text-body-secondary {
    color: rgba(var(--bs-secondary-rgb), var(--bs-text-opacity, 1)) !important;
}
[data-bs-theme="dark"] .list-group-item {
    background-color: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .list-group-item-action:hover {
    background-color: #1e293b;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .dropdown-menu {
    background-color: #0f172a;
    border-color: #334155;
}
[data-bs-theme="dark"] .dropdown-item {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .dropdown-item:hover {
    background-color: #1e293b;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .dropdown-item-text {
    color: #94a3b8 !important;
}
[data-bs-theme="dark"] .dropdown-divider {
    border-color: #334155;
}
[data-bs-theme="dark"] .table {
    color: #f1f5f9;
    border-color: #334155;
}
[data-bs-theme="dark"] .table thead:not(.table-light) th {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%) !important;
    color: #f8fafc !important;
    border-color: #475569;
}
[data-bs-theme="dark"] .table td,
[data-bs-theme="dark"] .table tbody th {
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .table-hover tbody tr:hover td {
    background-color: rgba(59, 130, 246, 0.08);
    color: #f1f5f9;
}
[data-bs-theme="dark"] .table-bordered {
    border-color: #334155;
}
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: #020617;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .form-control::placeholder {
    color: #64748b;
}
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: #020617;
    border-color: #3b82f6;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .form-label {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .form-check-label {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .btn-outline-primary {
    border-color: #60a5fa;
    color: #93c5fd;
}
[data-bs-theme="dark"] .btn-outline-primary:hover {
    background-color: #2563eb;
    border-color: #2563eb;
    color: #fff;
}
[data-bs-theme="dark"] .btn-outline-secondary {
    border-color: #475569;
    color: #94a3b8;
}
[data-bs-theme="dark"] .btn-outline-secondary:hover {
    background-color: #334155;
    border-color: #475569;
    color: #f8fafc;
}
[data-bs-theme="dark"] .btn-outline-danger {
    border-color: #f85149;
    color: #f85149;
}
[data-bs-theme="dark"] .btn-outline-danger:hover {
    background-color: #da3633;
    border-color: #da3633;
    color: #fff;
}
[data-bs-theme="dark"] .alert {
    border-width: 1px;
    border-style: solid;
}
[data-bs-theme="dark"] .alert-success {
    background-color: #1a2e1a;
    border-color: #238636;
    color: #7ee787;
}
[data-bs-theme="dark"] .alert-danger {
    background-color: #2e1a1a;
    border-color: #da3633;
    color: #ff7b72;
}
[data-bs-theme="dark"] .alert-warning {
    background-color: #2e2a1a;
    border-color: #9e6a03;
    color: #d4a72c;
}
[data-bs-theme="dark"] .alert-info {
    background-color: #1a2a3a;
    border-color: #1f6feb;
    color: #79b8ff;
}
[data-bs-theme="dark"] .pagination .page-link {
    background-color: #1e293b;
    border-color: #334155;
    color: #93c5fd;
}
[data-bs-theme="dark"] .pagination .page-link:hover {
    background-color: #334155;
    border-color: #475569;
    color: #bfdbfe;
}
[data-bs-theme="dark"] .pagination .page-item.disabled .page-link {
    background-color: #0f172a;
    border-color: #334155;
    color: #64748b;
}
[data-bs-theme="dark"] .empty-state {
    color: #94a3b8;
}
[data-bs-theme="dark"] .empty-state a {
    color: #93c5fd;
}
[data-bs-theme="dark"] .empty-state a:hover {
    color: #bfdbfe;
}
[data-bs-theme="dark"] .module-card-hover {
    background-color: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .module-card-hover:hover {
    background-color: #1e293b;
}
[data-bs-theme="dark"] .module-card-hover .card-title {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .spare-part-row.bg-light {
    background-color: #1e293b !important;
}
[data-bs-theme="dark"] .faq-item {
    background-color: #0f172a;
    border-color: #334155;
}
[data-bs-theme="dark"] .faq-question {
    background-color: #1e293b;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .faq-question:hover {
    background-color: #334155;
}
[data-bs-theme="dark"] .faq-question.active {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.18) 0%, rgba(15, 23, 42, 0.55) 100%);
    color: #f8fafc;
    border-left-color: #3b82f6;
}
[data-bs-theme="dark"] .faq-answer-content {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .permissions-table th {
    background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%);
    color: #f8fafc;
    border-color: #475569;
}
[data-bs-theme="dark"] .permissions-table td {
    color: #f1f5f9;
    border-color: #334155;
}
[data-bs-theme="dark"] .permissions-table tbody tr:hover {
    background-color: #1e293b;
}
[data-bs-theme="dark"] .progress {
    background-color: #1e293b;
}
[data-bs-theme="dark"] .h1, [data-bs-theme="dark"] .h2, [data-bs-theme="dark"] .h3,
[data-bs-theme="dark"] .h4, [data-bs-theme="dark"] .h5, [data-bs-theme="dark"] .h6,
[data-bs-theme="dark"] h1, [data-bs-theme="dark"] h2, [data-bs-theme="dark"] h3,
[data-bs-theme="dark"] h4, [data-bs-theme="dark"] h5, [data-bs-theme="dark"] h6 {
    color: #f8fafc;
}
[data-bs-theme="dark"] .card .text-primary {
    color: var(--ag-accent) !important;
}
[data-bs-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}
[data-bs-theme="dark"] .table-warning {
    background-color: rgba(210, 153, 34, 0.15);
}
[data-bs-theme="dark"] .table-warning td {
    color: #f1f5f9;
}
/* Страница входа в тёмной теме */
[data-bs-theme="dark"] .login-page {
    background: linear-gradient(145deg, #020617 0%, #0f172a 45%, #1e3a8a 100%);
}
[data-bs-theme="dark"] .login-card.card {
    background-color: #0f172a;
    border-color: #334155;
}
[data-bs-theme="dark"] .login-card .card-body {
    background-color: #0f172a;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .login-card .form-control {
    background-color: #020617;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .login-card .form-label,
[data-bs-theme="dark"] .login-card a {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .login-card a:hover {
    color: #93c5fd;
}
[data-bs-theme="dark"] .login-card .text-muted {
    color: #94a3b8 !important;
}
[data-bs-theme="dark"] .login-card hr {
    border-color: #334155;
}
/* Та же тёмная карточка для auth_layout (.ag-auth-card) */
[data-bs-theme="dark"] .ag-auth-card.card {
    background-color: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
    box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.45);
}
[data-bs-theme="dark"] .ag-auth-card .form-control {
    background-color: #020617;
    border-color: #334155;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .ag-auth-card .form-label,
[data-bs-theme="dark"] .ag-auth-card a:not(.btn) {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .ag-auth-card a:not(.btn):hover {
    color: #93c5fd;
}
[data-bs-theme="dark"] .ag-auth-card .text-muted {
    color: #94a3b8 !important;
}
[data-bs-theme="dark"] .ag-auth-card hr {
    border-color: #334155;
}
