        :root {
            --bg: #f9fafb;
            --surface: #ffffff;
            --surface-solid: #ffffff;
            --surface-muted: #f3f4f6;
            --text: #0f172b;
            --text-soft: #4a5565;
            --text-muted: #6a7282;
            --line: #e6e9ee;
            --line-strong: #d1d5dc;
            --brand-primary: #155dfc;
            --brand-secondary: #1447e6;
            --brand-deep: #0f172b;
            --primary: var(--brand-primary);
            --primary-strong: var(--brand-secondary);
            --primary-soft: #dbeafe;
            --danger: #d85a5a;
            --danger-strong: #b83f4f;
            --success: #1f9d68;
            --warning: #d9842b;
            --info: #155dfc;
            --sidebar-width: 260px;
            --sidebar-bg: linear-gradient(180deg, #0f172b 0%, #1447e6 130%);
            --shadow: 0 14px 40px rgba(15, 23, 43, 0.08);
            --shadow-soft: 0 6px 18px rgba(15, 23, 43, 0.06);
        }
        /* Тёмная тема: переопределяем те же переменные */
        body.theme-dark {
            --bg: #0f172a;
            --surface: #1e293b;
            --surface-solid: #1e293b;
            --surface-muted: #273449;
            --text: #e2e8f0;
            --text-soft: #94a3b8;
            --text-muted: #64748b;
            --line: #334155;
            --line-strong: #475569;
            --primary-soft: #1e3a5f;
            --shadow: 0 14px 40px rgba(0, 0, 0, 0.45);
            --shadow-soft: 0 6px 18px rgba(0, 0, 0, 0.35);
        }
        body.theme-dark { background: var(--bg); color: var(--text); }
        body.theme-dark .data-table th { background: var(--surface-muted); color: var(--text); }
        body.theme-dark .data-table td { color: var(--text); border-color: var(--line); }
        body.theme-dark input[type="text"],
        body.theme-dark input[type="number"],
        body.theme-dark input[type="date"],
        body.theme-dark input[type="month"],
        body.theme-dark input[type="search"],
        body.theme-dark input[type="file"],
        body.theme-dark input[type="time"],
        body.theme-dark select,
        body.theme-dark textarea {
            background: var(--surface-muted);
            color: var(--text);
            border: 1px solid var(--line);
        }
        body.theme-dark .modal-content,
        body.theme-dark .modal-content-form { background: var(--surface); color: var(--text); }
        body.theme-dark .modal-header { background: var(--surface); border-bottom-color: var(--line); }
        body.theme-dark .ac-dropdown { background: var(--surface); color: var(--text); border-color: var(--line); }
        body.theme-dark .ac-item { border-bottom-color: var(--line); }
        body.theme-dark .home-card { background: var(--surface); color: var(--text); border-color: var(--line); }
        body.theme-dark tr.row-expired td { background: rgba(255, 193, 7, 0.10) !important; }
        body.theme-dark .filter-row, body.theme-dark .toolbar { color: var(--text); }
        html, body { font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
        html, body { overflow-x: hidden; max-width: 100vw; }
        /* ========= Sidebar layout ========= */
        .app-layout {
            display: grid;
            grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
            min-height: 100vh;
        }
        .sidebar {
            position: sticky;
            top: 0;
            align-self: start;
            width: var(--sidebar-width);
            height: 100vh;
            height: 100dvh; /* iOS Safari: учёт динамического URL-bar */
            background: var(--sidebar-bg);
            color: rgba(255, 255, 255, 0.92);
            display: flex;
            flex-direction: column;
            box-shadow: 4px 0 24px rgba(13, 58, 114, 0.18);
            z-index: 30;
            padding-bottom: env(safe-area-inset-bottom, 0px);
        }
        .sidebar-brand {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 18px 18px 14px;
            border-bottom: 1px solid rgba(255,255,255,0.10);
        }
        .sidebar-logo {
            width: 44px;
            height: 44px;
            object-fit: contain;
            filter: drop-shadow(0 4px 10px rgba(13, 58, 114, 0.35));
        }
        .sidebar-brand-text {
            display: flex;
            flex-direction: column;
            line-height: 1.15;
        }
        .sidebar-brand-text strong {
            font-size: 1.05rem;
            letter-spacing: 0.01em;
        }
        .sidebar-brand-text span {
            font-size: 0.78rem;
            color: rgba(255,255,255,0.7);
        }
        .sidebar-nav {
            flex: 1;
            overflow-y: auto;
            padding: 10px 8px 16px;
            scrollbar-width: thin;
            scrollbar-color: rgba(255,255,255,0.25) transparent;
        }
        .sidebar-nav::-webkit-scrollbar { width: 6px; }
        .sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.20); border-radius: 6px; }
        .sidebar-group {
            margin-bottom: 12px;
        }
        .sidebar-group-title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            width: calc(100% - 8px);
            margin: 0 4px;
            border: 0;
            background: transparent;
            font-family: inherit;
            font-size: 0.66rem;
            text-transform: uppercase;
            letter-spacing: 0.1em;
            color: rgba(255,255,255,0.55);
            padding: 10px 8px 6px;
            cursor: pointer;
            border-radius: 8px;
            transition: background 0.15s ease, color 0.15s ease;
        }
        .sidebar-group-title:hover {
            background: rgba(255,255,255,0.06);
            color: rgba(255,255,255,0.85);
        }
        .sidebar-chevron {
            display: inline-block;
            font-size: 0.7rem;
            line-height: 1;
            transition: transform 0.18s ease;
            opacity: 0.7;
        }
        .sidebar-group.collapsed .sidebar-chevron {
            transform: rotate(-90deg);
        }
        .sidebar-group-items {
            display: flex;
            flex-direction: column;
            overflow: hidden;
            max-height: 800px;
            transition: max-height 0.22s ease;
        }
        .sidebar-group.collapsed .sidebar-group-items {
            max-height: 0;
        }
        .sidebar-link {
            display: flex;
            align-items: center;
            gap: 8px;
            width: 100%;
            text-align: left;
            background: transparent;
            border: 0;
            color: rgba(255,255,255,0.86);
            padding: 9px 12px;
            margin: 2px 4px;
            border-radius: 10px;
            font-size: 0.88rem;
            font-weight: 500;
            cursor: pointer;
            transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
            box-shadow: none;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .sidebar-link:hover {
            background: rgba(255,255,255,0.10);
            color: #fff;
            transform: none;
        }
        .sidebar-link.active {
            background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
            color: #fff;
            box-shadow: 0 8px 20px rgba(23, 105, 214, 0.35);
        }
        .sidebar-link.hidden { display: none !important; }
        .sidebar-user {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 14px 16px;
            border-top: 1px solid rgba(255,255,255,0.10);
            background: rgba(0,0,0,0.10);
        }
        .sidebar-user .user-meta {
            flex: 1;
            min-width: 0;
        }
        .sidebar-user .user-meta strong,
        .sidebar-user .user-meta span {
            display: block;
            color: #fff;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
        .sidebar-user .user-meta span {
            font-size: 0.72rem;
            color: rgba(255,255,255,0.65);
        }
        .sidebar-user .sidebar-logout {
            background: rgba(255,255,255,0.14);
            border: 1px solid rgba(255,255,255,0.18);
            color: #fff;
            padding: 6px 12px;
            margin: 0;
            box-shadow: none;
        }
        .sidebar-user .sidebar-logout:hover {
            background: rgba(255,255,255,0.22);
        }
        .build-stamp {
            position: fixed;
            right: 8px;
            bottom: 8px;
            padding: 4px 8px;
            font-size: 10px;
            font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
            color: rgba(15, 23, 43, 0.55);
            background: rgba(255, 255, 255, 0.92);
            border: 1px solid var(--line);
            border-radius: 6px;
            z-index: 999;
            user-select: text;
            -webkit-user-select: text;
            cursor: text;
            min-width: 180px;
            outline: none;
        }
        .build-stamp:hover { color: var(--text); background: #fff; }
        .build-stamp:focus { box-shadow: 0 0 0 2px var(--primary-soft); }
        .main-content {
            position: relative;
            min-width: 0;
            max-width: 100%;
            height: 100vh;
            overflow: hidden;
        }
        .main-content > .topbar {
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            z-index: 20;
        }
        .main-content > .container {
            position: absolute;
            top: 56px; /* место для топбара (с поиском) */
            left: 0;
            right: 0;
            bottom: 0;
            width: auto !important;
            max-width: none !important;
            min-width: 0;
            padding: 1rem !important;
            display: flex !important;
            flex-direction: column;
            overflow: hidden;
            pointer-events: none;
        }
        @media (max-width: 1024px) {
            .main-content > .container {
                padding: 0.85rem !important;
            }
        }
        @media (max-width: 640px) {
            .main-content > .container {
                padding: 0.6rem !important;
            }
        }
        .main-content > .container > * {
            pointer-events: auto;
        }
        .tab-content.active {
            flex: 1 1 0 !important;
            width: 100% !important;
            max-width: 100% !important;
            min-width: 0;
            min-height: 0;
            height: 100% !important;
            display: flex !important;
            flex-direction: column;
            overflow: hidden;
        }
        .tab-content.active > .scrollable-table {
            flex: 1 1 0 !important;
            width: 100% !important;
            max-width: 100% !important;
            min-width: 0;
            min-height: 0 !important;
            max-height: none !important;
            height: auto !important;
        }
        @media (max-width: 1024px) {
            .main-content > .container {
                width: 100vw !important;
                max-width: 100vw !important;
            }
        }
        /* Tabs whose content is naturally long (analytics, dashboards) should scroll the whole tab vertically.
           Use position:absolute to escape parent flex sizing — flex shorthand
           on .tab-content.active was capping height despite explicit values. */
        #analytics.tab-content.active,
        #power_analytics.tab-content.active,
        #users-admin.tab-content.active,
        #counterparties.tab-content.active,
        #nomenclature.tab-content.active,
        #our_entities.tab-content.active,
        #billing.tab-content.active,
        #one_time_payments.tab-content.active,
        #land_parcels.tab-content.active,
        #home.tab-content.active {
            position: absolute !important;
            top: 1rem !important;
            left: 1rem !important;
            right: 1rem !important;
            bottom: 1rem !important;
            width: auto !important;
            max-width: none !important;
            height: auto !important;
            min-height: 0 !important;
            max-height: none !important;
            flex: none !important;
            overflow-y: auto !important;
            overflow-x: hidden;
            display: block !important;
        }
        .app-layout .container { min-width: 0; }
        .tab-content { min-width: 0; }
        .topbar {
            display: flex;
            align-items: center;
            gap: 12px;
            padding: 10px 16px;
            background: var(--surface-solid);
            border-bottom: 1px solid var(--line);
            position: sticky;
            top: 0;
            z-index: 20;
        }
        /* Бургер виден только на мобиле; на ПК сайдбар всегда открыт */
        .burger-btn {
            background: transparent;
            border: 1px solid var(--line);
            color: var(--text);
            font-size: 22px;
            line-height: 1;
            padding: 4px 10px;
            border-radius: 10px;
            cursor: pointer;
            display: none;
        }
        @media (max-width: 1024px) {
            .burger-btn { display: inline-block; }
        }
        /* Глобальный поиск в шапке */
        .global-search {
            position: relative;
            margin-left: auto;
            min-width: 280px;
            max-width: 480px;
            flex: 0 1 480px;
        }
        .global-search input[type="search"] {
            width: 100%;
            padding: 8px 12px;
            border: 1px solid var(--line);
            border-radius: 10px;
            background: var(--surface-muted, #f3f4f6);
            color: var(--text, #0f172b);  /* явный цвет — иначе после autofill / в dark-mode текст невидим */
            font-size: 13px;
            outline: none;
            transition: border-color 0.15s ease, background 0.15s ease;
        }
        .global-search input[type="search"]::placeholder {
            color: var(--text-soft, #6a7282);
        }
        .global-search input[type="search"]:focus {
            border-color: var(--brand-primary);
            background: #fff;
        }
        .global-search-results {
            position: absolute;
            top: calc(100% + 6px);
            right: 0;
            left: 0;
            max-height: 60vh;
            overflow-y: auto;
            background: #fff;
            color: var(--text, #0f172b);
            border: 1px solid var(--line);
            border-radius: 12px;
            box-shadow: 0 12px 36px rgba(15, 23, 43, 0.18);
            z-index: 2000;  /* выше FAB (1500) и модалок */
            display: none;
        }
        .global-search-results.open { display: block; }
        .gs-item {
            display: block;
            padding: 10px 14px;
            border-bottom: 1px solid var(--line, #eef0f3);
            cursor: pointer;
            transition: background 0.12s ease;
            text-align: left;
            border-radius: 0;
        }
        .gs-item:hover, .gs-item.active { background: var(--primary-soft, #dbeafe); }
        .gs-item:last-child { border-bottom: 0; }
        .gs-item-head {
            display: flex; justify-content: space-between; align-items: center;
            gap: 8px; margin-bottom: 4px;
        }
        .gs-item-type {
            font-size: 10px;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: #fff;
            background: var(--brand-primary);
            padding: 2px 6px;
            border-radius: 6px;
            font-weight: 600;
        }
        .gs-item-type.expense { background: #dc2626; }
        .gs-item-type.terminated { background: #6b7280; }
        .gs-item-id { font-size: 11px; color: var(--text-soft, #6a7282); }
        .gs-item-line { font-size: 13px; color: var(--text); }
        .gs-item-line strong { font-weight: 600; }
        .gs-item-meta { font-size: 11px; color: var(--text-soft, #6a7282); margin-top: 2px; }
        .gs-empty { padding: 14px; text-align: center; color: var(--text-soft); font-size: 13px; }
        .topbar-title {
            font-size: 1.05rem;
            font-weight: 600;
            color: var(--text);
        }
        .app-backdrop {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(13, 58, 114, 0.45);
            backdrop-filter: blur(2px);
            z-index: 25;
        }
        .app-layout .container { max-width: none; padding: 1.5rem 2rem; }
        @media (max-width: 1024px) {
            .app-layout {
                grid-template-columns: minmax(0, 1fr);
            }
            .app-layout .container { padding: 1.25rem; }
            .topbar { display: flex; }
            .sidebar {
                position: fixed;
                top: 0;
                left: 0;
                height: 100vh;
                height: 100dvh;
                max-height: 100vh;
                max-height: 100dvh;
                transform: translateX(-100%);
                transition: transform 0.22s ease;
                overflow: hidden;
            }
            .app-layout.sidebar-open .sidebar { transform: translateX(0); }
            .app-layout.sidebar-open .app-backdrop { display: block; }
        }
        @media (max-width: 640px) {
            .app-layout .container { padding: 0.85rem; }
            :root { --sidebar-width: 78vw; }
        }
tr.orphan-highlight {
    background-color: #ffebee !important;
    animation: pulse-red 1s ease-in-out;
}

@keyframes pulse-red {
    0% { background-color: #ffebee; }
    50% { background-color: #ffcdd2; }
    100% { background-color: #ffebee; }
}
.orphan-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 18px;
    height: 18px;
    padding: 0 6px;
    margin-left: 8px;
    border-radius: 10px;
    background: var(--danger, #d85a5a);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
}
.form-error {
    margin: 12px 0;
    padding: 10px 14px;
    border-radius: 8px;
    background: #fff1f1;
    border: 1px solid #f3c2c2;
    color: var(--danger, #b83f4f);
    font-size: 13px;
    line-height: 1.4;
}
.form-group.invalid input,
.form-group.invalid select,
.form-group.invalid textarea {
    border-color: var(--danger, #d85a5a) !important;
    background: #fff5f5;
}
.form-group .field-error {
    color: var(--danger, #d85a5a);
    font-size: 11.5px;
    margin-top: 4px;
    line-height: 1.3;
}
.btn[disabled],
.btn.is-loading {
    opacity: 0.65;
    pointer-events: none;
    cursor: wait;
}
.btn.is-loading::after {
    content: "";
    display: inline-block;
    margin-left: 8px;
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: btn-spin 0.7s linear infinite;
    vertical-align: -2px;
}
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}
.pagination-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    margin-top: 8px;
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e3e8ee);
    border-radius: 10px;
    font-size: 13px;
}
.pagination-info {
    color: var(--text-soft, #5d7389);
}
.pagination-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.pagination-controls .btn-sm {
    padding: 4px 10px;
    min-width: 32px;
    font-size: 13px;
}
.pagination-controls select {
    padding: 4px 8px;
    border: 1px solid var(--line, #cbd2db);
    border-radius: 6px;
    background: var(--surface-solid, #fff);
    margin-left: 6px;
}
.pagination-page {
    min-width: 70px;
    text-align: center;
    color: var(--text, #17324d);
    font-weight: 500;
}
.scrollable-table tbody tr.empty-state-row td {
    padding: 60px 20px;
    border-right: 0;
    background: var(--surface-solid);
    text-align: center;
    white-space: normal;
    box-shadow: none;
    position: static;
}
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: var(--text-soft);
    max-width: 380px;
    margin: 0 auto;
}
.empty-state-icon {
    font-size: 48px;
    opacity: 0.55;
    margin-bottom: 4px;
}
.empty-state-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--brand-deep);
}
.empty-state-desc {
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--text-soft);
    margin-bottom: 8px;
}
#toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    pointer-events: auto;
    min-width: 240px;
    max-width: 360px;
    padding: 12px 16px;
    border-radius: 12px;
    background: var(--surface-solid);
    color: var(--text);
    font-size: 0.86rem;
    line-height: 1.35;
    box-shadow: 0 14px 30px rgba(15, 23, 43, 0.16);
    border-left: 4px solid var(--brand-primary);
    animation: toast-in 0.2s ease;
}
.toast.toast-success { border-left-color: var(--success); }
.toast.toast-error { border-left-color: var(--danger); }
.toast.toast-warning { border-left-color: var(--warning); }
.toast.toast-leave { animation: toast-out 0.2s ease forwards; }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
    to { opacity: 0; transform: translateY(8px); }
}
@media (max-width: 640px) {
    #toast-container {
        right: 12px;
        left: 12px;
        bottom: 12px;
    }
    .toast { max-width: none; }
}
        * { margin: 0; padding: 0; box-sizing: border-box; }
        body {
            font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            color: var(--text);
            background: var(--bg);
            min-height: 100vh;
        }
        .hidden { display: none !important; }
        .app-shell { min-height: 100vh; }
        .user-meta {
            display: flex;
            flex-direction: column;
            gap: 0.12rem;
        }
        .user-meta strong {
            font-size: 0.88rem;
        }
        .user-meta span {
            font-size: 0.72rem;
        }
        .auth-screen {
            min-height: 100vh;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 1.5rem;
            background:
                radial-gradient(circle at 20% 0%, rgba(21, 93, 252, 0.18), transparent 45%),
                radial-gradient(circle at 80% 100%, rgba(20, 71, 230, 0.22), transparent 50%),
                linear-gradient(135deg, #0f172b 0%, #1447e6 130%);
        }
        .auth-card {
            width: min(440px, 100%);
            background: var(--surface-solid);
            border: 1px solid var(--line);
            border-radius: 24px;
            box-shadow: 0 28px 60px rgba(15, 23, 43, 0.35);
            padding: 2rem;
        }
        .auth-brand {
            display: flex;
            align-items: center;
            gap: 14px;
            margin-bottom: 1.25rem;
            padding: 12px 16px;
            border-radius: 16px;
            background: var(--sidebar-bg);
            color: #fff;
        }
        .auth-logo {
            width: 48px;
            height: 48px;
            object-fit: contain;
            filter: drop-shadow(0 4px 10px rgba(13, 58, 114, 0.4));
        }
        .auth-brand-text strong {
            display: block;
            font-size: 1.05rem;
        }
        .auth-brand-text span {
            font-size: 0.78rem;
            color: rgba(255,255,255,0.75);
        }
        .auth-lede {
            color: var(--text-soft);
            margin-bottom: 1.2rem;
            font-size: 0.92rem;
        }
        .auth-error {
            min-height: 1.2rem;
            color: var(--danger-strong);
            font-size: 0.82rem;
            margin-bottom: 0.8rem;
        }
        .container { max-width: 1400px; margin: 0 auto; padding: 2rem; }
        .tab-content { display: none; }
        .filter-row {
            background: var(--surface);
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
            padding: 1rem;
            border-radius: 18px;
            margin-bottom: 1rem;
            display: flex;
            flex-wrap: wrap;
            gap: 0.75rem;
            align-items: flex-end;
            backdrop-filter: blur(12px);
        }
        .filter-panel { display: flex; flex-direction: column; gap: 0.75rem; width: 100%; }
        .filter-grid { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; width: 100%; }
        .filter-grid-primary { flex-wrap: nowrap; }
        .filter-grid-more {
            padding-top: 0.75rem;
            border-top: 1px solid var(--line);
        }
        .filter-item { display: flex; flex-direction: column; gap: 0.35rem; }
        .filter-grid-primary .filter-item,
        .filter-grid-more .filter-item {
            min-width: 180px;
            flex: 0 1 220px;
        }
        .filter-item label {
            font-size: 0.68rem;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            color: var(--text-soft);
            opacity: 0.9;
        }
        .filter-item select, .filter-item input, .form-group input, .form-group select, #link-income-select {
            padding: 0.7rem 0.85rem;
            border: 1px solid var(--line);
            border-radius: 12px;
            font-size: 0.85rem;
            min-width: 140px;
            background: var(--surface-solid);
            color: var(--text);
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.6);
            transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
        }
        .filter-item select:focus, .filter-item input:focus, .form-group input:focus, .form-group select:focus, #link-income-select:focus {
            outline: none;
            border-color: rgba(43, 116, 217, 0.45);
            box-shadow: 0 0 0 4px rgba(43, 116, 217, 0.14);
        }
        .filter-buttons { display: flex; gap: 0.3rem; margin-left: auto; }
        .filter-buttons button { font-size: 0.76rem; }
        .filter-buttons .btn {
            margin: 0;
            box-shadow: none;
            font-weight: 600;
        }
        .filter-buttons .btn-secondary {
            background: linear-gradient(135deg, rgba(93, 115, 137, 0.92) 0%, rgba(125, 148, 172, 0.92) 100%);
        }
        .filter-clear-button {
            opacity: 0.92;
        }
        .active-filters-panel {
            display: flex;
            flex-direction: column;
            gap: 0.45rem;
        }
        .active-filters-label {
            font-size: 0.66rem;
            font-weight: 700;
            letter-spacing: 0.06em;
            text-transform: uppercase;
            color: var(--text-soft);
        }
        .active-filters-chips {
            display: flex;
            flex-wrap: wrap;
            gap: 0.45rem;
        }
        .filter-chip {
            display: inline-flex;
            align-items: center;
            gap: 0.35rem;
            padding: 0.28rem 0.4rem 0.28rem 0.6rem;
            border-radius: 999px;
            border: 1px solid rgba(120, 146, 176, 0.24);
            background: rgba(255, 255, 255, 0.82);
            color: var(--text-soft);
            font-size: 0.74rem;
            box-shadow: 0 4px 10px rgba(18, 44, 71, 0.04);
        }
        .filter-chip-text {
            max-width: 240px;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .filter-chip-remove {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 18px;
            height: 18px;
            border: none;
            border-radius: 999px;
            background: rgba(93, 115, 137, 0.1);
            color: var(--text-soft);
            cursor: pointer;
            font-size: 0.82rem;
            line-height: 1;
            transition: background 0.18s ease, color 0.18s ease, transform 0.18s ease;
        }
        .filter-chip-remove:hover {
            background: rgba(43, 116, 217, 0.12);
            color: var(--text);
            transform: translateY(-1px);
        }
        .column-selector {
            background: var(--surface);
            padding: 0.95rem 1rem;
            border-radius: 18px;
            margin-bottom: 1rem;
            display: flex;
            flex-wrap: wrap;
            align-items: center;
            gap: 1rem;
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
        }
        .column-selector h4 { margin: 0; font-size: 0.9rem; color: var(--text); }
        .column-checkboxes {
            display: flex;
            flex-wrap: wrap;
            gap: 0.35rem;
            max-height: 72px;
            overflow-y: auto;
            padding-right: 0.25rem;
        }
        .column-checkboxes label {
            display: inline-flex;
            align-items: center;
            gap: 0.38rem;
            padding: 0.2rem 0.5rem;
            font-size: 0.64rem;
            line-height: 1.1;
            cursor: pointer;
            border-radius: 999px;
            border: 1px solid var(--line);
            background: linear-gradient(180deg, rgba(255,255,255,0.98) 0%, rgba(242,247,251,0.96) 100%);
            color: var(--text-soft);
            transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease, color 0.18s ease, background 0.18s ease;
            box-shadow: 0 6px 16px rgba(18, 44, 71, 0.05);
        }
        .column-checkboxes label:hover {
            transform: translateY(-1px);
            border-color: rgba(15, 123, 114, 0.28);
            color: var(--text);
        }
        .column-checkboxes label:has(input:checked) {
            background: linear-gradient(135deg, var(--primary-soft) 0%, rgba(255,255,255,0.98) 100%);
            border-color: rgba(15, 123, 114, 0.35);
            color: var(--primary-strong);
            box-shadow: 0 10px 18px rgba(15, 123, 114, 0.12);
        }
        .column-checkboxes input[type="checkbox"] {
            appearance: none;
            width: 12px;
            height: 12px;
            border-radius: 3px;
            border: 1px solid rgba(108, 138, 168, 0.55);
            background: white;
            display: grid;
            place-items: center;
            transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
            flex-shrink: 0;
            margin: 0;
        }
        .column-checkboxes input[type="checkbox"]::after {
            content: "";
            width: 5px;
            height: 2px;
            border-left: 1.5px solid white;
            border-bottom: 1.5px solid white;
            transform: rotate(-45deg) scale(0);
            transition: transform 0.15s ease;
            margin-top: -2px;
        }
        .column-checkboxes input[type="checkbox"]:checked {
            background: linear-gradient(135deg, var(--primary) 0%, #2b74d9 100%);
            border-color: transparent;
            box-shadow: 0 8px 16px rgba(43, 116, 217, 0.24);
        }
        .column-checkboxes input[type="checkbox"]:checked::after {
            transform: rotate(-45deg) scale(1);
        }
        .column-checkboxes input[type="checkbox"]:focus-visible {
            outline: none;
            box-shadow: 0 0 0 4px rgba(43, 116, 217, 0.16);
        }
        table { width: 100%; background: var(--surface-solid); border-radius: 18px; border-collapse: collapse; font-size: 11px; }
        th, td { padding: 0.4rem; text-align: left; border-bottom: 1px solid #e0e0e0; border-right: 1px solid #e0e0e0; }
        th, td { border-color: var(--line); }
        th {
            background: var(--surface-muted);
            color: var(--brand-deep);
            position: sticky;
            top: 0;
            cursor: pointer;
            user-select: none;
            font-weight: 600;
            letter-spacing: 0.02em;
            font-size: 0.78rem;
            text-transform: uppercase;
        }
        th:hover { background: var(--primary-soft); color: var(--brand-secondary); }
        th.sorted-asc::after { content: " ▲"; color: var(--brand-primary); }
        th.sorted-desc::after { content: " ▼"; color: var(--brand-primary); }
        tr:hover { background: var(--surface-muted); }
        .btn {
            background: linear-gradient(135deg, var(--primary) 0%, #2b74d9 100%);
            color: white;
            padding: 0.72rem 1rem;
            border: none;
            border-radius: 12px;
            cursor: pointer;
            margin: 0.25rem;
            font-weight: 700;
            font-size: 0.83rem;
            letter-spacing: 0.01em;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            gap: 0.45rem;
            box-shadow: 0 12px 24px rgba(34, 95, 157, 0.18);
            transition: transform 0.18s ease, box-shadow 0.18s ease, filter 0.18s ease;
        }
        .btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 16px 28px rgba(34, 95, 157, 0.22);
            filter: saturate(1.05);
        }
        .btn:active {
            transform: translateY(0);
        }
        .btn-danger { background: linear-gradient(135deg, var(--danger) 0%, var(--danger-strong) 100%); }
        .btn-success { background: linear-gradient(135deg, var(--success) 0%, #25b27a 100%); }
        .btn-warning { background: linear-gradient(135deg, var(--warning) 0%, #f0a13d 100%); color: white; }
        .btn-info { background: linear-gradient(135deg, var(--info) 0%, #4a90ff 100%); }
        .btn-sm { padding: 0.32rem 0.45rem; font-size: 0.68rem; border-radius: 9px; }
        .btn-secondary {
            background: linear-gradient(135deg, #5d7389 0%, #7d94ac 100%);
        }
        .scrollable-table {
            overflow-x: scroll;
            overflow-y: auto;
            max-width: 100%;
            min-height: 200px;
            background: var(--surface-solid);
            border-radius: 20px;
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
            -webkit-overflow-scrolling: touch;
        }
        .scrollable-table { scrollbar-width: thin; scrollbar-color: var(--line-strong) var(--surface-muted); }
        .scrollable-table::-webkit-scrollbar {
            -webkit-appearance: none !important;
            height: 14px;
            width: 12px;
            display: block;
        }
        .scrollable-table::-webkit-scrollbar-track { background: var(--surface-muted); border-radius: 0 0 20px 20px; }
        .scrollable-table::-webkit-scrollbar-thumb {
            background: var(--line-strong);
            border-radius: 8px;
            border: 2px solid var(--surface-muted);
        }
        .scrollable-table::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
        .scrollable-table table { width: auto; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: auto; }
        .scrollable-table th,
        .scrollable-table td {
            padding: 10px 12px;
            font-size: 0.86rem;
            white-space: normal;
            overflow-wrap: normal;
            word-break: normal;
            max-width: 30ch;
            vertical-align: middle;
        }
        .scrollable-table thead th {
            position: sticky;
            top: 0;
            background: linear-gradient(180deg, var(--surface-solid) 0%, var(--surface-muted) 100%);
            z-index: 4;
            border-bottom: 1px solid var(--line);
        }
        .scrollable-table tbody tr {
            border-top: 1px solid var(--line);
        }
        .scrollable-table tbody tr:hover {
            background: var(--surface-muted);
        }
        .scrollable-table tbody td:first-child,
        .scrollable-table thead th:first-child {
            position: sticky;
            left: 0;
            z-index: 3;
            background: var(--surface-solid);
            box-shadow: 1px 0 0 var(--line);
        }
        .scrollable-table thead th:first-child {
            z-index: 5;
            background: var(--surface-muted);
        }
        @media (max-width: 1024px) {
            .scrollable-table {
                max-height: calc(100vh - 200px);
                min-height: 60vh;
                border-radius: 14px;
            }
            .scrollable-table th,
            .scrollable-table td {
                padding: 8px 10px;
                font-size: 0.8rem;
            }
        }
        @media (max-width: 640px) {
            .scrollable-table {
                border-radius: 10px;
            }
            .scrollable-table th,
            .scrollable-table td {
                padding: 7px 8px;
                font-size: 0.78rem;
            }
            .toolbar { flex-direction: column; align-items: stretch; }
            .toolbar .btn, .toolbar .filter-item { width: 100%; }
            .filter-row, .column-selector { padding: 0.7rem; border-radius: 12px; }
            .pagination-bar { padding: 8px 10px; }
            .pagination-info { font-size: 12px; }
        }
        .stats { display: flex; gap: 20px; margin: 20px 0 0; flex-wrap: wrap; }
        .stat-card {
            background: var(--surface);
            padding: 1.15rem;
            border-radius: 20px;
            text-align: center;
            flex: 1;
            min-width: 180px;
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
        }
        .stat-number { font-size: 2rem; font-weight: bold; color: var(--primary); }
        .analytics-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 14px;
            margin-bottom: 20px;
        }
        .analytics-card {
            background: var(--surface);
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
            border-radius: 18px;
            padding: 1rem 1.1rem;
        }
        .analytics-label {
            font-size: 0.72rem;
            text-transform: uppercase;
            letter-spacing: 0.06em;
            color: var(--text-soft);
            margin-bottom: 0.35rem;
            font-weight: 700;
        }
        .analytics-value {
            font-size: 1.6rem;
            font-weight: 800;
            color: var(--text);
            letter-spacing: -0.03em;
        }
        .analytics-note {
            margin-top: 0.4rem;
            font-size: 0.78rem;
            color: var(--text-soft);
        }
        .analytics-scope-bar {
            display: flex;
            flex-wrap: wrap;
            align-items: flex-end;
            justify-content: space-between;
            gap: 0.9rem;
            margin-bottom: 1rem;
            padding: 0.9rem 1rem;
            border-radius: 16px;
            background: rgba(255, 255, 255, 0.72);
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
        }
        .analytics-scope-control {
            display: flex;
            align-items: flex-end;
            gap: 0.75rem;
            flex-wrap: wrap;
        }
        .analytics-scope-control .filter-item {
            min-width: 240px;
        }
        .analytics-scope-status {
            font-size: 0.8rem;
            color: var(--text-soft);
            white-space: nowrap;
        }
        .analytics-mode-text {
            font-size: 0.76rem;
            color: var(--text-soft);
        }
        .analytics-panel {
            background: var(--surface);
            border: 1px solid var(--line);
            box-shadow: var(--shadow-soft);
            border-radius: 18px;
            padding: 1rem 1.1rem 1.25rem;
            margin-bottom: 20px;
        }
        .analytics-panel h3 {
            margin-bottom: 0.85rem;
            color: var(--text);
            letter-spacing: -0.02em;
        }
        .analytics-panel-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 16px;
            margin-bottom: 20px;
        }
        .risk-table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.78rem;
        }
        .risk-table th,
        .risk-table td {
            padding: 0.65rem 0.6rem;
            border-bottom: 1px solid var(--line);
            vertical-align: top;
        }
        .risk-table th {
            text-align: left;
            color: var(--text-soft);
            font-size: 0.68rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }
        .risk-chip {
            display: inline-block;
            padding: 0.18rem 0.45rem;
            border-radius: 999px;
            background: rgba(216, 90, 90, 0.12);
            color: var(--danger-strong);
            font-weight: 700;
            font-size: 0.7rem;
        }
        .action-buttons { display: flex; gap: 4px; flex-wrap: nowrap; align-items: center; white-space: nowrap; }
        .action-buttons .btn {
            margin: 0;
            padding: 0.34rem 0.48rem;
            font-size: 0.67rem;
            min-height: 30px;
            box-shadow: 0 8px 18px rgba(34, 95, 157, 0.14);
        }
        .toolbar {
            display: flex;
            flex-wrap: wrap;
            gap: 0.5rem;
            margin-bottom: 1rem;
        }
        .modal {
            display: none;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        .modal-content {
            background: var(--surface-solid);
            padding: 24px;
            border-radius: 22px;
            width: 550px;
            max-height: 80vh;
            overflow-y: auto;
            box-shadow: 0 24px 60px rgba(12, 29, 47, 0.26);
            border: 1px solid rgba(255,255,255,0.45);
        }
        .modal-content-form {
            width: min(760px, 96vw);
            max-height: 90vh;
            padding: 0;
            overflow: hidden;
            display: flex;
            flex-direction: column;
            background: var(--surface-solid, #fff);
            border-radius: 16px;
            box-shadow: 0 20px 60px rgba(15, 23, 43, 0.25);
        }
        /* Edit modal — must overlay preview modal which has equal z-index */
        #billing-edit-modal { z-index: 1100; }
        .modal-form-flex {
            display: flex;
            flex-direction: column;
            min-height: 0;
            flex: 1 1 auto;
        }
        .modal-header {
            position: sticky;
            top: 0;
            z-index: 5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 12px;
            padding: 14px 20px;
            background: var(--surface-solid);
            border-bottom: 1px solid var(--line);
            flex-shrink: 0;
        }
        .modal-header h2 {
            margin: 0;
            font-size: 1.1rem;
            color: var(--text);
        }
        .modal-header-actions {
            display: flex;
            gap: 8px;
            flex-shrink: 0;
        }
        .modal-header-actions .btn {
            margin: 0;
            padding: 0.55rem 0.95rem;
            font-size: 0.82rem;
        }
        .modal-body {
            flex: 1 1 auto;
            overflow-y: auto;
            padding: 18px 20px 22px;
            min-height: 0;
            background: var(--surface-solid, #fff);
        }
        #modal-fields {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
            gap: 12px 18px;
        }
        #modal-fields .form-group {
            margin-bottom: 0;
        }
        #modal-fields .form-group[data-field="notes"],
        #modal-fields .form-group[data-field="description"],
        #modal-fields .form-group[data-field="billing_formula"],
        #modal-fields .form-group[data-field="equipment_list"] {
            grid-column: 1 / -1;
        }
        @media (max-width: 640px) {
            .modal-content-form { width: 100vw; max-height: 100vh; border-radius: 0; }
            .modal-header { padding: 12px 14px; }
            .modal-header h2 { font-size: 1rem; }
            .modal-header-actions .btn { padding: 0.45rem 0.7rem; font-size: 0.78rem; }
            .modal-body { padding: 14px 14px 20px; }
            #modal-fields { grid-template-columns: 1fr; }
        }
        .form-group {
            margin-bottom: 14px;
        }
        .form-group label {
            display: block;
            margin-bottom: 6px;
            font-size: 12px;
            font-weight: 700;
            color: var(--text-soft);
        }
        .form-group input {
            width: 100%;
            padding: 0.8rem 0.85rem;
        }
        .form-group textarea {
            width: 100%;
            min-height: 120px;
            padding: 0.85rem;
            resize: vertical;
            border: 1px solid var(--line);
            border-radius: 14px;
            font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
            font-size: 0.86rem;
            color: var(--text);
            background: var(--surface-solid);
        }
        .form-group textarea:focus {
            outline: none;
            border-color: rgba(43, 116, 217, 0.45);
            box-shadow: 0 0 0 4px rgba(43, 116, 217, 0.14);
        }
        .record-actions-panel {
            margin-top: 1.2rem;
            padding-top: 1rem;
            border-top: 1px solid var(--line);
        }
        .record-actions-panel h3 {
            margin: 0 0 0.85rem;
            font-size: 0.95rem;
        }
        .record-actions-grid {
            display: grid;
            grid-template-columns: 1fr 1.2fr;
            gap: 0.9rem;
        }
        .record-actions-block {
            background: var(--surface-muted);
            border: 1px solid var(--line);
            border-radius: 16px;
            padding: 0.85rem;
        }
        .record-actions-block h4 {
            margin: 0 0 0.65rem;
            font-size: 0.8rem;
            color: var(--text-soft);
            text-transform: uppercase;
            letter-spacing: 0.04em;
        }
        .record-status-list {
            display: flex;
            flex-direction: column;
            gap: 0.55rem;
        }
        .record-status-item {
            display: flex;
            justify-content: space-between;
            gap: 0.75rem;
            align-items: center;
            font-size: 0.82rem;
        }
        .record-status-label {
            color: var(--text-soft);
            font-weight: 700;
        }
        .record-status-value {
            color: var(--text);
            text-align: right;
        }
        .record-primary-actions {
            margin-bottom: 0.2rem;
            /* Кнопки могут не помещаться в одну строку — даём им переноситься. */
            flex-wrap: wrap;
            white-space: normal;
            row-gap: 6px;
        }
        .record-actions-block .action-buttons {
            flex-wrap: wrap;
            white-space: normal;
            row-gap: 6px;
        }
        .record-actions-block .action-buttons .btn {
            flex: 0 0 auto;
        }
        .record-danger-actions {
            margin-top: 0.75rem;
        }
        .record-danger-divider {
            height: 1px;
            background: var(--line);
            margin-bottom: 0.75rem;
        }
        .formula-help {
            background: var(--surface-muted);
            border: 1px solid var(--line);
            border-radius: 14px;
            padding: 0.9rem 1rem;
            font-size: 0.82rem;
            color: var(--text-soft);
            line-height: 1.5;
        }
        .formula-help code {
            background: rgba(15, 123, 114, 0.08);
            color: var(--primary-strong);
            padding: 0.12rem 0.35rem;
            border-radius: 6px;
        }
        .placeholder-card {
            background: var(--surface);
            border: 1px solid var(--line);
            border-radius: 20px;
            box-shadow: var(--shadow-soft);
            padding: 1.2rem 1.3rem;
            line-height: 1.6;
        }
        .placeholder-card h3 {
            margin-bottom: 0.55rem;
        }
        .placeholder-card p {
            color: var(--text-soft);
            margin-bottom: 0.5rem;
        }
        #current-link-info {
            background: var(--surface-muted);
            border: 1px solid var(--line);
            border-radius: 14px;
            padding: 0.9rem 1rem;
            color: var(--text);
            min-height: 48px;
        }
        hr {
            border: none;
            border-top: 1px solid var(--line);
        }
        .admin-grid {
            display: grid;
            grid-template-columns: 1.2fr 1fr;
            gap: 1rem;
        }
        .admin-card {
            background: var(--surface);
            border: 1px solid var(--line);
            border-radius: 20px;
            box-shadow: var(--shadow-soft);
            padding: 1rem;
        }
        .admin-card h3 {
            margin-bottom: 0.85rem;
        }
        .mini-table {
            width: 100%;
            font-size: 0.82rem;
        }
        .mini-table td, .mini-table th {
            padding: 0.55rem;
        }
        .permissions-grid {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 0.75rem;
        }
        .permissions-box {
            border: 1px solid var(--line);
            border-radius: 16px;
            padding: 0.75rem;
            background: var(--surface-muted);
        }
        .permissions-box h4 {
            font-size: 0.82rem;
            margin-bottom: 0.55rem;
        }
        .permissions-box .column-checkboxes {
            max-height: 160px;
        }
        @media (max-width: 900px) {
            .container {
                padding: 1rem;
            }
            .column-selector,
            .filter-row,
            .stat-card,
            .scrollable-table,
            .modal-content {
                border-radius: 16px;
            }
            .admin-grid,
            .permissions-grid,
            .record-actions-grid {
                grid-template-columns: 1fr;
            }
            .filter-grid-primary {
                flex-wrap: wrap;
            }
        }
        @media (max-width: 640px) {
            .btn {
                width: calc(100% - 0.5rem);
            }
            .action-buttons .btn {
                width: 100%;
                margin-inline: 0;
            }
            .column-checkboxes {
                max-height: none;
            }
        }

/* ===== Home / welcome page ===== */
.home-hero {
    text-align: center;
    padding: 38px 20px 28px;
    background: linear-gradient(135deg, var(--brand-primary, #155dfc), var(--brand-deep, #0f172b));
    color: #fff;
    border-radius: 24px;
    margin-bottom: 24px;
    box-shadow: 0 12px 38px rgba(13, 58, 114, 0.18);
}
.home-hero-logo img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.25));
}
.home-hero-title {
    margin: 14px 0 4px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.4px;
}
.home-hero-subtitle {
    font-size: 14px;
    opacity: 0.85;
}
.home-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.home-stat-card {
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e3e8ee);
    border-radius: 14px;
    padding: 14px 16px;
}
.home-stat-label {
    font-size: 12px;
    color: var(--text-soft, #5d7389);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.home-stat-value {
    font-size: 22px;
    font-weight: 600;
    color: var(--brand-deep, #0f172b);
    margin-top: 4px;
}
.home-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}
.home-card {
    text-align: left;
    background: var(--surface, #fff);
    border: 1px solid var(--line, #e3e8ee);
    border-radius: 16px;
    padding: 18px;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
    color: inherit;
    font: inherit;
}
.home-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(15, 23, 43, 0.10);
    border-color: var(--brand-primary, #155dfc);
}
.home-card-emoji {
    font-size: 30px;
    line-height: 1;
    margin-bottom: 10px;
}
.home-card-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--brand-deep, #0f172b);
    margin-bottom: 4px;
}
.home-card-desc {
    font-size: 12.5px;
    color: var(--text-soft, #5d7389);
}

.home-section-title {
    margin: 22px 0 10px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-soft, #5d7389);
    font-weight: 600;
}
.home-section-title:first-of-type { margin-top: 6px; }
.home-card-accent {
    background: linear-gradient(135deg, var(--brand-primary, #155dfc), var(--brand-secondary, #1447e6));
    color: #fff;
    border-color: transparent;
    box-shadow: 0 8px 22px rgba(21, 93, 252, 0.28);
}
.home-card-accent .home-card-title { color: #fff; }
.home-card-accent .home-card-desc { color: rgba(255,255,255,0.85); }
.home-card-accent:hover {
    border-color: transparent;
    box-shadow: 0 14px 32px rgba(21, 93, 252, 0.36);
}

/* ===== Mobile read-only mode ===== */
/* Активно когда body.is-mobile и НЕ установлен флаг body.force-desktop */
body.is-mobile:not(.force-desktop) .action-buttons,
body.is-mobile:not(.force-desktop) .column-selector,
body.is-mobile:not(.force-desktop) .more-filters-toggle,
body.is-mobile:not(.force-desktop) [onclick*="showAddForm"],
body.is-mobile:not(.force-desktop) [onclick*="showCounterpartyModal"],
body.is-mobile:not(.force-desktop) [onclick*="showOurEntityModal"],
body.is-mobile:not(.force-desktop) [onclick*="showNomenclatureModal"],
body.is-mobile:not(.force-desktop) #billing-supplier ~ button,
body.is-mobile:not(.force-desktop) .filter-row .btn,
body.is-mobile:not(.force-desktop) #counterparty-add-button,
body.is-mobile:not(.force-desktop) #our-entity-add-button,
body.is-mobile:not(.force-desktop) #nomenclature-add-button,
body.is-mobile:not(.force-desktop) #billing button[onclick*="billingRecalculate"],
body.is-mobile:not(.force-desktop) #billing button[onclick*="billingCloseMonth"] {
    display: none !important;
}

/* На мобиле billing-карточки месяцев должны переноситься */
body.is-mobile:not(.force-desktop) #billing-months-list > div {
    flex-direction: column;
    align-items: stretch !important;
}
body.is-mobile:not(.force-desktop) #billing-months-list > div > div {
    margin-left: 0 !important;
}

/* Кнопки билинга в строке месяца на мобиле — стек */
body.is-mobile:not(.force-desktop) #billing-months-list > div > div:last-child {
    display: flex;
    flex-wrap: wrap;
}

/* Toggle между PC/Mobile в сайдбаре */
.sidebar-mode-toggle {
    margin: 8px 12px 4px;
    padding: 8px 10px;
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.18);
    color: #fff;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    width: calc(100% - 24px);
    display: block;
}
.sidebar-mode-toggle:hover { background: rgba(255,255,255,0.18); }

/* На мобиле home-stats — в один столбец, hero меньше */
body.is-mobile:not(.force-desktop) .home-hero { padding: 24px 14px 18px; }
body.is-mobile:not(.force-desktop) .home-hero-title { font-size: 22px; }
body.is-mobile:not(.force-desktop) .home-grid { grid-template-columns: repeat(2, 1fr); }
body.is-mobile:not(.force-desktop) .home-card { padding: 12px; }
body.is-mobile:not(.force-desktop) .home-card-emoji { font-size: 22px; }
body.is-mobile:not(.force-desktop) .home-card-title { font-size: 13px; }
body.is-mobile:not(.force-desktop) .home-card-desc { display: none; }

/* На мобиле в модалках full-screen уже работает через @media 640px,
   тут просто убедимся что модалки правок (admin) тоже не показываются */
body.is-mobile:not(.force-desktop) #billing-edit-modal {
    display: none !important;
}

/* На мобилке топбар — брендовый и заметный */
body.is-mobile:not(.force-desktop) .topbar {
    background: linear-gradient(135deg, var(--brand-primary, #155dfc), var(--brand-secondary, #1447e6)) !important;
    border-bottom: 0 !important;
    color: #fff;
    box-shadow: 0 4px 14px rgba(15, 23, 43, 0.18);
}
body.is-mobile:not(.force-desktop) .topbar .topbar-title {
    color: #fff !important;
}
body.is-mobile:not(.force-desktop) .topbar .burger-btn {
    background: rgba(255,255,255,0.18) !important;
    border-color: rgba(255,255,255,0.30) !important;
    color: #fff !important;
}
body.is-mobile:not(.force-desktop) .topbar::after {
    content: "📱 Просмотр";
    margin-left: auto;
    background: rgba(255,255,255,0.22);
    border-radius: 12px;
    padding: 3px 10px;
    font-size: 11px;
    color: #fff;
    font-weight: 500;
}

/* ===== Mobile card view for data tables ===== */
.mobile-cards { display: none; }
body.is-mobile:not(.force-desktop) .mobile-cards {
    display: block;
    padding: 4px 0 80px;
    margin: 0;
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}
.mobile-card {
    background: var(--surface-solid, #fff);
    border: 1px solid var(--line, #e3e8ee);
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: 0 2px 8px rgba(15, 23, 43, 0.04);
}
.mobile-card .mc-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px dashed var(--line, #e3e8ee);
}
.mobile-card .mc-num {
    font-size: 11px;
    color: var(--text-soft, #5d7389);
    font-weight: 600;
}
.mobile-card .mc-doc {
    font-size: 14px;
}
.mobile-card .mc-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 4px 0;
    font-size: 13px;
}
.mobile-card .mc-label {
    color: var(--text-soft, #5d7389);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    min-width: 90px;
}
.mobile-card .mc-value {
    color: var(--text, #0f172b);
    text-align: right;
    word-break: break-word;
    font-weight: 500;
}
.mobile-card .mc-amount .mc-value {
    font-weight: 700;
    color: var(--brand-primary, #155dfc);
    font-size: 15px;
}
.mobile-card .mc-orphan .mc-value {
    color: #9a3412;
}

/* Mobile: естественный page scroll вместо вложенного */
body.is-mobile:not(.force-desktop) .main-content {
    height: auto !important;
    min-height: 100vh !important;
    overflow: visible !important;
}
body.is-mobile:not(.force-desktop) .main-content > .topbar {
    position: sticky !important;
    top: 0;
    z-index: 30;
}
body.is-mobile:not(.force-desktop) .main-content > .container {
    position: static !important;
    height: auto !important;
    width: 100% !important;
    overflow: visible !important;
    pointer-events: auto !important;
    padding: 0.7rem 0.7rem 60px !important;
    display: block !important;
}
body.is-mobile:not(.force-desktop) .main-content > .container > * {
    pointer-events: auto !important;
}
body.is-mobile:not(.force-desktop) .tab-content.active {
    position: static !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    overflow: visible !important;
    flex: none !important;
    display: block !important;
}
body.is-mobile:not(.force-desktop) .mobile-cards {
    flex: none !important;
    overflow: visible !important;
    padding: 4px 0 20px;
}
body.is-mobile:not(.force-desktop) .filter-row {
    display: none !important;
}

/* Mobile: pagination всегда зафиксирована внизу viewport */
body.is-mobile:not(.force-desktop) .pagination-bar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    background: var(--surface-solid, #fff);
    border: 0;
    border-top: 1px solid var(--line, #e3e8ee);
    border-radius: 0;
    box-shadow: 0 -6px 18px rgba(15, 23, 43, 0.10);
    margin: 0;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    flex-wrap: wrap;
    gap: 8px;
}
/* Чтобы карточки не залезали под фиксированную пагинацию */
body.is-mobile:not(.force-desktop) .main-content > .container {
    padding-bottom: 90px !important;
}

/* Card detail modal — для мобилки полный экран */
.cd-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--line, #e3e8ee);
    font-size: 14px;
}
.cd-row:last-child { border-bottom: 0; }
.cd-label {
    color: var(--text-soft, #5d7389);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    flex-shrink: 0;
    min-width: 110px;
}
.cd-value {
    color: var(--text, #0f172b);
    text-align: right;
    word-break: break-word;
    font-weight: 500;
}
.cd-amount .cd-value {
    font-weight: 700;
    color: var(--brand-primary, #155dfc);
    font-size: 16px;
}
/* На мобиле модалка открывается во весь экран и поверх липкой пагинации */
body.is-mobile #card-detail-modal {
    z-index: 60;
}
body.is-mobile #card-detail-modal .modal-content-form {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
    box-sizing: border-box;
    overflow-x: hidden;
}
body.is-mobile #card-detail-modal .modal-body {
    overflow-x: hidden;
    word-break: break-word;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}
body.is-mobile #card-detail-modal .cd-value {
    overflow-wrap: anywhere;
    word-break: break-word;
}
.mobile-card { cursor: pointer; }
.mobile-card:active { background: var(--surface-muted, #f3f4f6); }

.cd-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 0 12px 0;
    margin: -4px 0 8px 0;
    border-bottom: 1px dashed var(--border, #e5e7eb);
}
.cd-actions .btn { flex: 1 1 auto; min-width: 130px; }
body.is-mobile:not(.force-desktop) .cd-actions .btn {
    padding: 12px 8px;
    font-size: 13px;
    min-width: 0;
}

/* Fullscreen прочих модалок на мобиле (links, power, billing edit/preview, форма редактирования, аналитика-разбивка) */
body.is-mobile:not(.force-desktop) #links-modal .modal-content-form,
body.is-mobile:not(.force-desktop) #power-modal .modal-content-form,
body.is-mobile:not(.force-desktop) #billing-edit-modal .modal-content-form,
body.is-mobile:not(.force-desktop) #billing-preview-modal .modal-content-form,
body.is-mobile:not(.force-desktop) #breakdown-modal .modal-content-form,
body.is-mobile:not(.force-desktop) #modal .modal-content-form {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    margin: 0;
    box-sizing: border-box;
}
body.is-mobile:not(.force-desktop) #billing-preview-modal .modal-body,
body.is-mobile:not(.force-desktop) #billing-edit-modal .modal-body,
body.is-mobile:not(.force-desktop) #breakdown-modal .modal-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
/* На мобиле уменьшаем высоту графика разбивки, чтобы таблица была видна */
body.is-mobile:not(.force-desktop) #breakdown-modal #breakdown-chart-wrap {
    height: 240px !important;
}
body.is-mobile:not(.force-desktop) #breakdown-modal .data-table {
    font-size: 13px;
}
body.is-mobile:not(.force-desktop) #breakdown-modal .data-table th,
body.is-mobile:not(.force-desktop) #breakdown-modal .data-table td {
    padding: 6px 8px;
    white-space: nowrap;
}
/* Кнопки «Сохранить»/«Отмена» в шапке — sticky уже есть, но на iOS Safari при вызове из card-detail
   шапка не всегда видна сразу, поэтому форсируем top:0 + safe-area сверху */
body.is-mobile:not(.force-desktop) #modal .modal-header {
    position: sticky;
    top: 0;
    padding-top: calc(12px + env(safe-area-inset-top));
    z-index: 10;
}
body.is-mobile:not(.force-desktop) #modal .modal-header-actions .btn {
    padding: 10px 12px;
    font-size: 14px;
}
body.is-mobile:not(.force-desktop) #modal .modal-body {
    padding-bottom: calc(28px + env(safe-area-inset-bottom));
}

/* Скрытие элементов на мобиле (например, «Закрытие месяца») */
body.is-mobile:not(.force-desktop) .hide-on-mobile {
    display: none !important;
}

/* Подсветка строки с истёкшим end_date */
tr.row-expired td {
    background: rgba(255, 193, 7, 0.16) !important;
}
tr.row-expired:hover td {
    background: rgba(255, 193, 7, 0.26) !important;
}
.mobile-card.mc-expired {
    border-left: 4px solid #f59f00;
    background: rgba(255, 193, 7, 0.08);
}

/* Подсветка строки, у которой сумма к выставлению ≠ сумме по договору
   (применён перерасчёт по простою или ручная правка). Бледный голубой,
   чтобы отличался от истёкших (жёлтый) и при этом был хорошо заметен. */
tr.row-recalced td {
    background: rgba(91, 141, 239, 0.18) !important;
}
tr.row-recalced:hover td {
    background: rgba(91, 141, 239, 0.28) !important;
}
body.theme-dark tr.row-recalced td {
    background: rgba(91, 141, 239, 0.22) !important;
}
/* Если строка одновременно и истёкшая, и пересчитанная — приоритет у "истёкшей" */
tr.row-expired.row-recalced td {
    background: rgba(255, 193, 7, 0.16) !important;
}

/* Цветной бейдж категории услуг (узкая полоска перед содержимым) */
.cat-badge {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 6px;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,0.12);
}

/* Активная кнопка-пресет */
.preset-btn.preset-active {
    background: var(--primary, #155dfc) !important;
    color: #fff !important;
    border-color: var(--primary, #155dfc) !important;
}

/* Пустые значения — красным жирным «не заполнено» */
.cd-row.cd-empty .cd-value {
    color: #dc2626;
    font-weight: 700;
}
.cd-row.cd-empty .cd-label {
    opacity: 0.85;
}

.gs-item-count {
    background: var(--text-muted, #6a7282);
    color: #fff;
    border-radius: 8px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 600;
}

/* Mobile: глобальный поиск сворачивается до кнопки, разворачивается на всю ширину */
body.is-mobile:not(.force-desktop) .global-search {
    min-width: 0;
    max-width: 44px;
    flex: 0 0 44px;
    transition: max-width 0.2s ease, flex-basis 0.2s ease;
}
body.is-mobile:not(.force-desktop) .global-search input[type="search"] {
    width: 100%;
    background: rgba(255,255,255,0.18);
    color: #fff;
    border-color: rgba(255,255,255,0.30);
    font-size: 0; /* скрываем плейсхолдер до раскрытия */
    padding: 8px;
    cursor: pointer;
}
body.is-mobile:not(.force-desktop) .global-search input[type="search"]::placeholder { color: transparent; }
body.is-mobile:not(.force-desktop) .global-search.expanded {
    max-width: none;
    flex: 1 1 auto;
}
body.is-mobile:not(.force-desktop) .global-search.expanded input[type="search"] {
    font-size: 14px;
    padding: 8px 12px;
    cursor: text;
    background: #fff;
    color: var(--text);
}
body.is-mobile:not(.force-desktop) .global-search.expanded input[type="search"]::placeholder { color: var(--text-soft); }
body.is-mobile:not(.force-desktop) .global-search::before {
    content: "🔍";
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
    color: #fff;
    z-index: 1;
}
body.is-mobile:not(.force-desktop) .global-search.expanded::before { display: none; }

/* Mobile: кнопки в карточках месяцев billing — растягиваются */
body.is-mobile:not(.force-desktop) #billing-months-list > div > div:last-child {
    width: 100%;
    margin-top: 6px;
}
body.is-mobile:not(.force-desktop) #billing-months-list > div > div:last-child .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 8px;
    font-size: 13px;
}

/* === Земельные участки: вспомогательные классы === */
.lp-l { display: block; font-size: 12px; color: var(--text-soft, #5d7389); margin-bottom: 3px; }
.lp-i { width: 100%; padding: 6px 10px; border: 1px solid var(--line, #e3e8ee); border-radius: 6px; font: inherit; box-sizing: border-box; }
.lp-i:focus { outline: 2px solid var(--brand-primary, #155dfc); outline-offset: -1px; border-color: transparent; }
.land-tab-btn.active { border-bottom: 2px solid var(--brand-primary, #155dfc) !important; color: var(--brand-primary, #155dfc); font-weight: 600; }
.land-row-overdue     { background: rgba(220, 38, 38, 0.08); }
.land-row-warn        { background: rgba(245, 159, 0, 0.08); }
.land-row-in-progress { background: rgba(245, 159, 0, 0.16); }
.land-row-in-progress td:first-child::before {
    content: "";
}

/* ============================================================
 * 📱 Мобильная адаптация для новых вкладок и модалок
 * ============================================================ */

/* === Этап 1: переключение desktop/mobile видов для земли и разовых === */
.land-mobile-view, .otp-mobile-view { display: none; }
body.is-mobile:not(.force-desktop) .land-desktop-view,
body.is-mobile:not(.force-desktop) .otp-desktop-view {
    display: none;
}
body.is-mobile:not(.force-desktop) .land-mobile-view,
body.is-mobile:not(.force-desktop) .otp-mobile-view {
    display: block;
    padding: 4px 0 80px;
}
/* Карточки внутри этих view используют общий .mobile-card стиль */

/* На мобиле hot-блоки (🔁/💰) занимают полную ширину, не двумя колонками */
@media (max-width: 640px) {
    #land-hot-blocks {
        grid-template-columns: 1fr !important;
    }
    #otp-stats-cards {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* === Глобальный поиск на мобиле: отдельная полная строка под topbar === */
@media (max-width: 640px) {
    /* topbar — flex-wrap, чтобы поиск ушёл на новую строку */
    .topbar {
        flex-wrap: wrap;
    }
    /* поиск занимает всю ширину, переносится в конец строки */
    .global-search {
        order: 99 !important;
        flex: 1 1 100% !important;
        min-width: 0 !important;
        max-width: none !important;
        margin: 8px 0 0 0 !important;
    }
    .global-search input[type="search"] {
        font-size: 16px !important;  /* iOS Safari не делает auto-zoom при таком размере */
        padding: 10px 12px !important;
    }
    /* dropdown с результатами — пошире, на весь viewport */
    .global-search-results {
        left: 0 !important;
        right: 0 !important;
        max-height: 70vh !important;
    }
}

/* === Этап 2: модалка карточки участка — одна колонка на мобиле === */
@media (max-width: 640px) {
    #land-parcel-modal .modal-content-form {
        width: 98vw !important;
        max-height: 96vh !important;
        margin: 1vh auto;
        overflow: hidden !important;  /* scroll только внутри .modal-body, иначе шапка/табы уезжают */
    }
    /* Inline grid-template-columns: 1fr 1fr → одну колонку */
    #land-parcel-modal .land-tab-panel [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    /* span 2 не нужен — он и так на всю ширину */
    #land-parcel-modal .land-tab-panel [style*="grid-column: span 2"] {
        grid-column: auto !important;
    }
    /* Header модалки прибит к верху */
    #land-parcel-modal .modal-header {
        position: sticky;
        top: 0;
        z-index: 12;
        background: var(--surface-solid, #fff);
    }
    /* Табы прибиты сверху, чтобы при скролле длинных вкладок (ТП и ЭЭ
       с секцией документов) они оставались видны и не закрывались содержимым. */
    #land-parcel-modal > .modal-content-form > div:nth-child(2) {
        position: sticky;
        top: 0;
        z-index: 11;
        background: var(--surface-solid, #fff);
        overflow-x: auto;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch;
        box-shadow: 0 1px 0 var(--line, #e3e8ee);
    }
    .land-tab-btn {
        font-size: 12px !important;
        padding: 8px 10px !important;
        white-space: nowrap;
        flex: 0 0 auto;
    }
    /* Платежи по годам (8 колонок) — на мобиле каждый блок занимает строку */
    #lp-payments-list > div > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr 1fr !important;
        gap: 6px !important;
    }
    /* Загрузчик документов — две колонки на одну */
    #lp-docs-uploader [style*="grid-template-columns"],
    #lp-docs-tp-ee-uploader [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
}

/* === Модалка разового платежа: одна колонка на мобиле === */
@media (max-width: 640px) {
    #otp-edit-modal .modal-content-form {
        width: 98vw !important;
        max-height: 96vh !important;
    }
    #otp-edit-modal [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }
    #otp-edit-modal [style*="grid-column: span 2"] {
        grid-column: auto !important;
    }
}

/* === Этап 3.1: Chart.js на мобиле — компактнее === */
@media (max-width: 640px) {
    #power_analytics canvas {
        max-height: 240px !important;
    }
    #power_analytics .analytics-grid {
        grid-template-columns: 1fr !important;
    }
    #power_analytics h3 {
        font-size: 15px;
        margin-top: 14px;
    }
    /* Скрываем самую тяжёлую секцию — capacity check (можно посмотреть с ПК) */
    #power_analytics #pa-capacity table {
        font-size: 11px;
    }
}

/* === Этап 3.2: Главная — компактнее, в один столбец === */
@media (max-width: 640px) {
    #home .home-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }
    #home .home-card {
        padding: 12px 10px !important;
    }
    #home .home-card-emoji {
        font-size: 28px !important;
    }
    #home .home-card-title {
        font-size: 12px !important;
    }
    #home .home-card-subtitle {
        font-size: 10px !important;
    }
    #home .home-section-title {
        font-size: 14px;
        margin: 12px 4px 6px;
    }
}

/* === Этап 3.5: FAB-кнопка ❓ — компактнее на мобиле и не перекрывает actions === */
@media (max-width: 640px) {
    #context-help-fab {
        right: 10px !important;
        bottom: 14px !important;
        width: 32px !important;
        height: 32px !important;
        font-size: 14px !important;
        opacity: 0.85;
    }
}

/* === Контекстная справка — fullscreen на мобиле === */
@media (max-width: 640px) {
    #context-help-modal .modal-content-form {
        width: 100vw !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        height: 100vh !important;
        border-radius: 0 !important;
        margin: 0;
    }
}

/* === Модалка привязки разового платежа === */
@media (max-width: 640px) {
    #otp-link-modal .modal-content-form {
        width: 98vw !important;
        max-height: 96vh !important;
    }
}
