/**
 * Глобальные темы офиса: light / dark
 * html[data-theme="light|dark"]
 */

html {
    --primary-orange: #ff6b00;
    --office-topbar-h: 52px;
    --cab-aside-w: 260px;
    --office-shell-gap: 12px;

    --office-topbar: #2f2f2f;
    --office-topbar-border: rgba(0, 0, 0, 0.28);
    --office-topbar-text: #c8cacc;
    --office-topbar-text-strong: #ffffff;

    --office-bg: #e8edf4;
    --office-pane: #e8edf4;
    --office-card: #ffffff;
    --office-border: #e2e8f0;
    --office-text: #0f172a;
    --office-muted: #64748b;
    --office-soft: #94a3b8;
    --office-shadow: 0 1px 2px rgba(15, 23, 42, 0.05), 0 8px 24px rgba(15, 23, 42, 0.04);

    --office-tab-bg: rgba(255, 255, 255, 0.08);
    --office-tab-active-bg: #fff;
    --office-tab-active-text: #0f172a;
    --office-tab-text: rgba(255, 255, 255, 0.78);
    --office-tab-close: rgba(255, 255, 255, 0.45);

    --office-dropdown-bg: #fff;
    --office-dropdown-border: #e2e8f0;
    --office-dropdown-text: #0f172a;
    --office-dropdown-hover: #fff7ed;

    color-scheme: light;
}

html[data-theme="dark"] {
    --office-topbar: #1a1d21;
    --office-topbar-border: rgba(0, 0, 0, 0.45);
    --office-topbar-text: #a8b0bb;
    --office-topbar-text-strong: #f1f5f9;

    --office-bg: #0f1419;
    --office-pane: #0f1419;
    --office-card: #1a222d;
    --office-border: #2a3544;
    --office-text: #e8eef6;
    --office-muted: #94a3b8;
    --office-soft: #64748b;
    --office-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);

    --office-tab-bg: rgba(255, 255, 255, 0.06);
    --office-tab-active-bg: #252b33;
    --office-tab-active-text: #f8fafc;
    --office-tab-text: rgba(226, 232, 240, 0.72);
    --office-tab-close: rgba(226, 232, 240, 0.4);

    --office-dropdown-bg: #1a222d;
    --office-dropdown-border: #2a3544;
    --office-dropdown-text: #e8eef6;
    --office-dropdown-hover: rgba(255, 107, 0, 0.12);

    color-scheme: dark;
}

/* ── Shell ── */
body {
    background: var(--office-bg);
    color: var(--office-text);
}

.navbar.office-topbar {
    background-color: var(--office-topbar) !important;
    box-shadow: 0 1px 0 var(--office-topbar-border);
    z-index: 20050;
}

/* Модалки живут только в рабочей области: навбар с вкладками остаётся кликабельным */
body:not(.office-embed) .modal-backdrop {
    top: var(--office-topbar-h, 52px);
    height: calc(100% - var(--office-topbar-h, 52px));
}
body:not(.office-embed) .modal {
    top: var(--office-topbar-h, 52px);
    height: calc(100% - var(--office-topbar-h, 52px));
}

/* Большие панели (заявка / обращение / пост): сетка cab-main, зазор 12px */
.office-shell-modal {
    --office-shell-gap: 12px;
    padding: 0 !important;
    overflow: hidden;
}
.office-shell-modal .modal-dialog {
    position: absolute;
    margin: 0;
    max-width: none !important;
    width: auto;
    max-height: none;
    top: var(--office-shell-gap);
    right: var(--office-shell-gap);
    bottom: var(--office-shell-gap);
    left: calc(var(--cab-aside-w, 260px) + var(--office-shell-gap));
    transform: none !important;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    height: auto;
}
.office-shell-modal.fade .modal-dialog {
    transform: none !important;
}
.office-shell-modal .modal-content {
    height: 100%;
    max-height: none !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1 1 auto;
}
@media (max-width: 991.98px) {
    .office-shell-modal {
        --office-shell-gap: 8px;
    }
    .office-shell-modal .modal-dialog {
        left: var(--office-shell-gap);
    }
}

.nav-link {
    color: var(--office-topbar-text) !important;
}
.nav-link:hover,
.nav-link.active {
    color: var(--primary-orange) !important;
    background-color: rgba(255, 107, 0, 0.12);
}

.header-icons,
.balance {
    color: var(--office-topbar-text);
}
.icon-link {
    color: var(--office-topbar-text);
}
.icon-link:hover,
.icon-link:focus,
.icon-link.show {
    color: var(--primary-orange);
    background-color: rgba(255, 107, 0, 0.12);
}

/* активный пункт темы в профиле */
.dropdown-item[data-office-theme].is-on {
    color: var(--primary-orange);
    font-weight: 700;
    background: var(--office-dropdown-hover);
}

/* brand */
.office-brand-btn {
    color: var(--office-topbar-text-strong);
}
.office-brand-text {
    color: var(--office-topbar-text-strong);
}

/* dropdowns */
.dropdown-menu {
    background: var(--office-dropdown-bg);
    border-color: var(--office-dropdown-border);
    color: var(--office-dropdown-text);
}
.dropdown-item {
    color: var(--office-dropdown-text);
}
.dropdown-item:hover,
.dropdown-item:focus {
    background: var(--office-dropdown-hover);
    color: var(--office-dropdown-text);
}
.dropdown-header {
    color: var(--office-muted);
}
.dropdown-divider {
    border-color: var(--office-border);
}

/* tabs */
.office-tab {
    background: var(--office-tab-bg);
    color: var(--office-tab-text);
}
.office-tab.is-active {
    background: var(--office-tab-active-bg);
    color: var(--office-tab-active-text);
}
.office-tab-close {
    color: var(--office-tab-close);
}

/* workspace */
body.office-tabs-on .content-below-navbar > .office-workspace,
.office-tab-pane,
.office-tab-frame {
    background: var(--office-pane) !important;
}
html.office-embed,
body.office-embed {
    background: var(--office-pane) !important;
}

/* ── Dashboard tokens ── */
html[data-theme="dark"] .dash {
    --dash-bg: var(--office-bg);
    --dash-card: var(--office-card);
    --dash-border: var(--office-border);
    --dash-text: var(--office-text);
    --dash-muted: var(--office-muted);
    --dash-soft: var(--office-soft);
    --dash-nav: var(--office-topbar);
    --dash-shadow: var(--office-shadow);
}
html[data-theme="dark"] body:has(.dash) .content-below-navbar {
    background: var(--office-bg);
}
html[data-theme="dark"] .dash-hero {
    background: linear-gradient(180deg, var(--office-topbar) 0%, #15181c 100%);
    border-bottom-color: rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"] .dash-kpi {
    background: var(--office-card);
    border-color: var(--office-border);
    color: var(--office-text);
}
html[data-theme="dark"] .dash-kpi-val { color: var(--office-text); }
html[data-theme="dark"] .dash-kpi-lbl { color: var(--office-muted); }
html[data-theme="dark"] .dash-card {
    background: var(--office-card);
    border-color: var(--office-border);
    color: var(--office-text);
}
html[data-theme="dark"] .dash-card-head {
    background: linear-gradient(180deg, #1a222d 0%, #171e28 100%) !important;
    border-bottom-color: var(--office-border) !important;
}
html[data-theme="dark"] .dash-card-title { color: var(--office-text) !important; }
html[data-theme="dark"] .dash-card-hint { color: var(--office-soft); }
html[data-theme="dark"] .dash-card-body { color: var(--office-text); }
html[data-theme="dark"] .dash-action {
    background: #151c26 !important;
    border-color: var(--office-border) !important;
    color: var(--office-text) !important;
}
html[data-theme="dark"] .dash-action-ico {
    background: var(--office-card) !important;
    border-color: var(--office-border) !important;
    color: var(--office-muted) !important;
}
html[data-theme="dark"] .dash-action:hover .dash-action-ico {
    color: var(--primary-orange) !important;
}
html[data-theme="dark"] .dash-tags,
html[data-theme="dark"] .dash-tags summary {
    background: var(--office-card);
    border-color: var(--office-border);
    color: var(--office-text);
}
html[data-theme="dark"] .dash-empty-chart { color: var(--office-soft); }

/* ── Requests module ── */
html[data-theme="dark"] .req-page {
    --req-bg: #0f1419;
    --req-card: #1a222d;
    --req-border: #2a3544;
    --req-text: #e8eef6;
    --req-muted: #94a3b8;
    --req-soft: #64748b;
    --req-orange-soft: rgba(255, 107, 0, 0.12);
    --req-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
    color: var(--req-text);
}
html[data-theme="dark"] body:has(.req-page) .content-below-navbar,
html[data-theme="dark"] body[data-office-module="requests"] .content-below-navbar {
    background: #0f1419;
}
html[data-theme="dark"] .req-modal .modal-content,
html[data-theme="dark"] .req-modal {
    background: #1a222d;
    color: #e8eef6;
    border-color: #2a3544;
}
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select {
    background-color: #121820;
    border-color: #2a3544;
    color: #e8eef6;
}
html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background-color: #121820;
    border-color: #ff6b00;
    color: #e8eef6;
    box-shadow: 0 0 0 0.2rem rgba(255, 107, 0, 0.18);
}
html[data-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: #e8eef6;
    --bs-table-border-color: #2a3544;
    --bs-table-striped-bg: rgba(255, 255, 255, 0.03);
    --bs-table-hover-bg: rgba(255, 107, 0, 0.08);
    color: #e8eef6;
}
html[data-theme="dark"] .modal-content {
    background: #1a222d;
    color: #e8eef6;
    border-color: #2a3544;
}
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer {
    border-color: #2a3544;
}
html[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(1);
}
html[data-theme="dark"] .text-muted {
    color: #94a3b8 !important;
}
html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .bg-white {
    background-color: #1a222d !important;
    color: #e8eef6;
}
html[data-theme="dark"] .border,
html[data-theme="dark"] .border-bottom,
html[data-theme="dark"] .border-top {
    border-color: #2a3544 !important;
}
html[data-theme="dark"] .card {
    background: #1a222d;
    border-color: #2a3544;
    color: #e8eef6;
}
html[data-theme="dark"] .list-group-item {
    background: #1a222d;
    border-color: #2a3544;
    color: #e8eef6;
}
html[data-theme="dark"] .alert-secondary {
    background: #243041;
    border-color: #2a3544;
    color: #cbd5e1;
}

/* objects overview soft dark */
html[data-theme="dark"] body[data-office-module="objects"] .office-workspace {
    background: #0f1419 !important;
}

/* cabinet follows global theme (no local toggle needed) */
html[data-theme="dark"] .cab,
.cab[data-theme="dark"] {
    --cab-bg: #0f1419;
    --cab-card: #1a222d;
    --cab-border: #2a3544;
    --cab-text: #e8eef6;
    --cab-muted: #94a3b8;
    --cab-soft: #64748b;
    --cab-input-bg: #121820;
    --cab-input-border: #2a3544;
    --cab-table-line: #243041;
    --cab-type-bg: #243041;
    --cab-type-fg: #cbd5e1;
    --cab-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}
html[data-theme="light"] .cab {
    --cab-bg: #e8edf4;
    --cab-card: #ffffff;
    --cab-border: #e2e8f0;
    --cab-text: #0f172a;
    --cab-muted: #64748b;
    --cab-soft: #94a3b8;
    --cab-input-bg: #fff;
    --cab-input-border: #e2e8f0;
    --cab-table-line: #f1f5f9;
    --cab-type-bg: #f1f5f9;
    --cab-type-fg: #475569;
}
