/* Базовая настройка страницы: отступы, цвета и общие переменные. */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        html {
            -webkit-text-size-adjust: 100%;
            text-size-adjust: 100%;
        }
        [hidden] {
            display: none !important;
        }
        :root {
            --sidebar-width: 250px;
            --primary: #0d6efd;
            --primary-dark: #0a58ca;
            --success: #198754;
            --warning: #ffc107;
            --danger: #dc3545;
            --gray-100: #f8f9fa;
            --gray-200: #e9ecef;
            --gray-300: #dee2e6;
            --gray-600: #6c757d;
            --gray-800: #343a40;
            --shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.08);
            --radius: 0.5rem;
            --transition: 0.25s ease;
        }
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: #f1f4f9;
            display: flex;
            min-height: 100vh;
            color: #1e293b;
        }
        a {
            text-decoration: none;
            color: inherit;
        }
        button,
        .btn,
        .sidebar-nav a,
        .pagination button,
        .close-modal {
            touch-action: manipulation;
        }
        i.fas {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 1.1em;
            height: 1.1em;
            line-height: 1;
            flex-shrink: 0;
        }
        i.fas svg {
            width: 1em;
            height: 1em;
            fill: none;
            stroke: currentColor;
            stroke-width: 2;
            stroke-linecap: round;
            stroke-linejoin: round;
        }
        /* Тонкая прокрутка не отвлекает от таблиц. */
        ::-webkit-scrollbar {
            width: 6px;
        }
        ::-webkit-scrollbar-track {
            background: #e9ecef;
        }
        ::-webkit-scrollbar-thumb {
            background: #adb5bd;
            border-radius: 8px;
        }

        /* Левое меню держит навигацию и название организации. */
        .sidebar {
            width: var(--sidebar-width);
            background: #0f172a;
            color: #e2e8f0;
            display: flex;
            flex-direction: column;
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            z-index: 1000;
            transition: transform var(--transition);
            overflow-y: auto;
            overflow-x: hidden;
        }
        .sidebar-brand {
            padding: 1.25rem 1.5rem;
            border-bottom: 1px solid rgba(255, 255, 255, 0.06);
            display: flex;
            align-items: center;
            gap: 0.75rem;
            font-weight: 700;
            font-size: 1.1rem;
            color: #f8fafc;
            flex-shrink: 0;
        }
        .sidebar-brand i {
            font-size: 1.6rem;
            color: #60a5fa;
        }
        .sidebar-brand span {
            white-space: nowrap;
        }
        .sidebar-nav {
            flex: 1;
            padding: 0.75rem 0;
        }
        .sidebar-nav .nav-label {
            font-size: 0.65rem;
            text-transform: uppercase;
            letter-spacing: 0.08em;
            color: #64748b;
            padding: 0.5rem 1.5rem 0.25rem;
            font-weight: 600;
        }
        .sidebar-nav a {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            padding: 0.6rem 1.5rem;
            color: #cbd5e1;
            font-size: 0.9rem;
            transition: background var(--transition), color var(--transition);
            border-left: 3px solid transparent;
            cursor: pointer;
        }
        .sidebar-nav a:hover,
        .sidebar-nav a.active {
            background: rgba(255, 255, 255, 0.06);
            color: #f8fafc;
            border-left-color: #60a5fa;
        }
        .sidebar-nav a i {
            width: 1.25rem;
            text-align: center;
            font-size: 1rem;
        }
        .sidebar-footer {
            padding: 0.75rem 1.5rem;
            border-top: 1px solid rgba(255, 255, 255, 0.06);
            font-size: 0.75rem;
            color: #64748b;
            text-align: center;
            flex-shrink: 0;
        }
        .sidebar-backdrop {
            display: none;
            visibility: hidden;
            pointer-events: none;
        }

        /* Основная область подстраивается под фиксированное меню. */
        .main {
            margin-left: var(--sidebar-width);
            flex: 1;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }
        .topbar {
            background: #ffffff;
            padding: 0.75rem 2rem;
            border-bottom: 1px solid var(--gray-200);
            display: flex;
            align-items: center;
            justify-content: space-between;
            position: sticky;
            top: 0;
            z-index: 500;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        .topbar-left {
            display: flex;
            align-items: center;
            gap: 1rem;
        }
        .topbar-left .hamburger {
            display: none;
            font-size: 1.3rem;
            background: none;
            border: none;
            color: var(--gray-800);
            cursor: pointer;
        }
        .topbar-left h2 {
            font-size: 1.15rem;
            font-weight: 600;
        }
        .topbar-right {
            display: flex;
            align-items: center;
            gap: 1rem;
            font-size: 0.9rem;
        }
        .topbar-right .badge-org {
            background: #eef2ff;
            color: #4338ca;
            padding: 0.25rem 0.75rem;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        .topbar-right .user-info {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            min-width: 0;
        }
        .topbar-right .user-info i {
            font-size: 1.3rem;
            color: var(--gray-600);
        }
        .topbar-right .user-info span {
            font-weight: 600;
            color: #1e293b;
            white-space: nowrap;
        }

        .content {
            padding: 1.5rem 2rem 2rem;
            flex: 1;
        }

        /* Разделы показываются по одному, остальные остаются скрытыми. */
        .page {
            display: none;
            animation: fadeIn 0.3s ease;
        }
        .page.active {
            display: block;
        }
        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: translateY(6px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* Карточки и сетки собирают данные в спокойные рабочие блоки. */
        .card {
            background: #fff;
            border-radius: var(--radius);
            box-shadow: var(--shadow);
            padding: 1.25rem 1.5rem;
            margin-bottom: 1.25rem;
            border: 1px solid var(--gray-200);
        }
        .card-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1rem;
            flex-wrap: wrap;
            gap: 0.5rem;
        }
        .card-header h3 {
            font-size: 1rem;
            font-weight: 600;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .card-header h3 i {
            color: var(--primary);
        }
        .card-header .actions {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
        }
        .card form label {
            display: block;
            margin: 0.55rem 0 0.25rem;
            font-size: 0.84rem;
            font-weight: 600;
            color: #334155;
        }
        .card form input,
        .card form select,
        .card form textarea {
            width: 100%;
            padding: 0.55rem 0.7rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            background: #fff;
            color: #0f172a;
            font: inherit;
            min-height: 2.35rem;
        }
        .card form input:focus,
        .card form select:focus,
        .card form textarea:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.14);
        }
        .card form[style*="display:flex"] label {
            margin-top: 0;
        }

        .budget-settings-card .budget-form {
            display: grid;
            gap: 0.7rem;
        }
        .budget-settings-card .budget-form label {
            margin: 0;
        }
        .budget-settings-card .budget-form input,
        .budget-settings-card .budget-form select {
            height: 2.55rem;
        }
        .budget-section-title {
            margin: 1.2rem 0 0.85rem;
            padding-top: 1.1rem;
            border-top: 1px solid var(--gray-200);
            color: #0f172a;
            font-size: 0.95rem;
            font-weight: 700;
        }
        #serviceSettingsForm {
            margin-top: 0;
        }
        .budget-settings-card .form-row {
            grid-template-columns: repeat(3, minmax(0, 1fr));
        }
        .settings-actions {
            margin-top: 1rem;
        }
        .settings-submit {
            justify-content: center;
            min-width: 190px;
            width: auto;
        }
        .budget-form-actions {
            margin-top: 0.9rem;
        }
        .budget-save-btn {
            width: auto;
            min-width: 155px;
            justify-content: center;
            padding-inline: 1rem;
        }
        .budget-chart-card {
            min-height: 430px;
        }
        .budget-chart-controls {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 0.75rem;
            margin-bottom: 0.75rem;
        }
        .budget-chart-controls label {
            display: grid;
            gap: 0.3rem;
            font-size: 0.84rem;
            font-weight: 600;
            color: #334155;
        }
        .budget-chart-controls input {
            width: 100%;
            padding: 0.55rem 0.7rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            font: inherit;
        }
        .budget-chart-summary {
            display: flex;
            flex-wrap: wrap;
            gap: 0.9rem 1.25rem;
            margin-top: 0.9rem;
            color: var(--gray-600);
            font-size: 0.9rem;
        }
        .budget-chart-summary strong {
            color: #0f172a;
        }
        .budget-progress-layout {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            align-items: center;
        }
        .budget-progress-main {
            flex: 2 1 18rem;
            min-width: 0;
        }
        .budget-progress-meta {
            font-size: 0.8rem;
            margin-top: 0.1rem;
        }
        .budget-planned-panel {
            flex: 1 1 9rem;
            min-width: 8rem;
            text-align: right;
        }
        .budget-planned-panel div {
            font-size: 0.75rem;
            color: var(--gray-600);
        }
        .budget-planned-panel strong {
            display: block;
            font-size: 1.1rem;
            color: #0f172a;
            margin-top: 0.15rem;
        }
        .report-form {
            display: grid;
            grid-template-columns: repeat(4, minmax(9rem, 1fr)) auto auto;
            gap: 0.75rem;
            align-items: end;
        }
        .report-field {
            display: grid;
            gap: 0.25rem;
            min-width: 0;
        }
        .report-field label {
            font-size: 0.82rem;
            font-weight: 600;
            color: #334155;
            margin: 0;
        }
        .report-field input,
        .report-field select {
            width: 100%;
            min-width: 0;
            min-height: 2.55rem;
            padding: 0.55rem 0.7rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            background: #fff;
            color: #0f172a;
            font: inherit;
        }
        .report-actions {
            display: flex;
        }
        .report-actions .btn {
            width: 100%;
            justify-content: center;
            white-space: nowrap;
        }

        .grid-2 {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1.25rem;
        }
        .grid-3 {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 1.25rem;
        }
        .grid-4 {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1.25rem;
        }
        #kpiContainer {
            margin-bottom: 0.85rem;
        }
        .admin-info-grid {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 1.25rem;
        }
        .admin-info-card {
            margin-bottom: 1.25rem;
        }
        .role-list,
        .settings-list {
            display: grid;
            gap: 0.65rem;
        }
        .role-list div,
        .settings-list div {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 1rem;
            padding: 0.65rem 0.75rem;
            border: 1px solid var(--gray-200);
            border-radius: 0.375rem;
            background: #f8fafc;
        }
        .role-list strong,
        .settings-list strong {
            color: #0f172a;
            font-size: 0.9rem;
        }
        .role-list span,
        .settings-list span {
            color: var(--gray-600);
            font-size: 0.83rem;
            text-align: right;
        }

        .kpi-card {
            background: #fff;
            border-radius: var(--radius);
            padding: 1rem 1.25rem;
            border: 1px solid var(--gray-200);
            box-shadow: var(--shadow);
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }
        .kpi-card .icon {
            width: 44px;
            height: 44px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.3rem;
            color: #fff;
            flex-shrink: 0;
        }
        .kpi-card .icon.blue {
            background: #3b82f6;
        }
        .kpi-card .icon.green {
            background: #22c55e;
        }
        .kpi-card .icon.orange {
            background: #f59e0b;
        }
        .kpi-card .icon.red {
            background: #ef4444;
        }
        .kpi-card .info {
            flex: 1;
            min-width: 0;
        }
        .kpi-card .info .value {
            font-size: 1.5rem;
            font-weight: 700;
            line-height: 1.2;
        }
        .kpi-card .info .label {
            font-size: 0.8rem;
            color: var(--gray-600);
        }

        /* Таблицы рассчитаны на частую работу и быструю проверку строк. */
        .table-wrap {
            overflow-x: auto;
        }
        .table-wrap::-webkit-scrollbar {
            height: 6px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            font-size: 0.875rem;
        }
        table th {
            text-align: left;
            padding: 0.6rem 0.5rem;
            border-bottom: 2px solid var(--gray-200);
            font-weight: 600;
            color: var(--gray-800);
            white-space: nowrap;
        }
        table td {
            padding: 0.6rem 0.5rem;
            border-bottom: 1px solid var(--gray-200);
            vertical-align: middle;
        }
        table tr:hover td {
            background: #fafbfc;
        }
        .status-badge {
            display: inline-block;
            padding: 0.2rem 0.6rem;
            border-radius: 20px;
            font-size: 0.7rem;
            font-weight: 600;
            white-space: nowrap;
        }
        .status-badge.success {
            background: #dcfce7;
            color: #166534;
        }
        .status-badge.warning {
            background: #fef3c7;
            color: #92400e;
        }
        .status-badge.danger {
            background: #fee2e2;
            color: #991b1b;
        }
        .status-badge.info {
            background: #dbeafe;
            color: #1e40af;
        }
        .status-badge.secondary {
            background: #e9ecef;
            color: #4b5563;
        }

        .btn {
            display: inline-flex;
            align-items: center;
            gap: 0.4rem;
            padding: 0.65rem 1rem;
            border: none;
            border-radius: 0.375rem;
            font-size: 0.92rem;
            font-weight: 600;
            cursor: pointer;
            transition: all var(--transition);
            background: var(--gray-200);
            color: var(--gray-800);
            min-height: 2.65rem;
        }
        .btn:hover {
            opacity: 0.85;
        }
        .btn-primary {
            background: var(--primary);
            color: #fff;
        }
        .btn-primary:hover {
            background: var(--primary-dark);
        }
        .btn-success {
            background: var(--success);
            color: #fff;
        }
        .btn-danger {
            background: var(--danger);
            color: #fff;
        }
        .btn-warning {
            background: var(--warning);
            color: #1e293b;
        }
        .btn-sm {
            padding: 0.48rem 0.7rem;
            font-size: 0.82rem;
            min-height: 2.25rem;
        }
        .logout-btn {
            padding: 0.72rem 1.12rem;
            font-size: 0.95rem;
            min-height: 2.8rem;
            border-color: rgba(13, 110, 253, 0.24);
            color: #0f172a;
            background: #ffffff;
            box-shadow: 0 0.25rem 0.7rem rgba(15, 23, 42, 0.08);
        }
        .logout-btn:hover {
            background: #fff5f5;
            border-color: rgba(220, 53, 69, 0.28);
            color: #b42333;
            opacity: 1;
        }
        .btn-outline {
            background: transparent;
            border: 1px solid var(--gray-300);
        }
        .btn-outline:hover {
            background: var(--gray-100);
        }

        /* Прогресс бюджета показывает остаток без лишних расчетов. */
        .progress-bar-wrap {
            background: var(--gray-200);
            border-radius: 20px;
            height: 1rem;
            overflow: hidden;
            margin: 0.25rem 0;
        }
        .progress-bar-fill {
            height: 100%;
            border-radius: 20px;
            background: var(--primary);
            transition: width 0.6s ease;
        }
        .progress-bar-fill.warning {
            background: var(--warning);
        }
        .progress-bar-fill.danger {
            background: var(--danger);
        }

        /* Модальные окна используются для коротких форм редактирования. */
        .modal-overlay {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(0, 0, 0, 0.4);
            backdrop-filter: blur(4px);
            display: none;
            align-items: center;
            justify-content: center;
            z-index: 9999;
            padding: 1rem;
        }
        .modal-overlay.open {
            display: flex;
        }
        .modal-box {
            background: #fff;
            border-radius: var(--radius);
            max-width: 580px;
            width: 100%;
            max-height: 90vh;
            overflow-y: auto;
            padding: 1.5rem 2rem 2rem;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
            animation: modalIn 0.2s ease;
        }
        @keyframes modalIn {
            from {
                transform: scale(0.95);
                opacity: 0;
            }
            to {
                transform: scale(1);
                opacity: 1;
            }
        }
        .modal-box h3 {
            margin-bottom: 1.25rem;
            font-size: 1.1rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }
        .modal-box .close-modal {
            margin-left: auto;
            background: none;
            border: none;
            font-size: 1.3rem;
            cursor: pointer;
            color: var(--gray-600);
        }
        .modal-box .close-modal:hover {
            color: #000;
        }
        .modal-box label {
            display: block;
            font-weight: 500;
            font-size: 0.85rem;
            margin-bottom: 0.2rem;
            margin-top: 0.75rem;
        }
        .modal-box input,
        .modal-box select,
        .modal-box textarea {
            width: 100%;
            padding: 0.5rem 0.75rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            font-size: 0.9rem;
            transition: border var(--transition);
            background: #fff;
        }
        .modal-box input:focus,
        .modal-box select:focus,
        .modal-box textarea:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
        }
        .modal-box .form-row {
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 0.75rem;
        }
        .modal-box .form-actions {
            display: flex;
            gap: 0.5rem;
            margin-top: 1.5rem;
            justify-content: flex-end;
            border-top: 1px solid var(--gray-200);
            padding-top: 1rem;
        }

        /* Уведомления мягко подтверждают действие и сами исчезают. */
        .toast-container {
            position: fixed;
            bottom: 1.5rem;
            right: 1.5rem;
            z-index: 99999;
            display: flex;
            flex-direction: column;
            gap: 0.5rem;
            max-width: 360px;
            width: 100%;
        }
        .toast {
            background: #1e293b;
            color: #f8fafc;
            padding: 0.75rem 1rem;
            border-radius: var(--radius);
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
            display: flex;
            align-items: center;
            gap: 0.75rem;
            animation: slideUp 0.3s ease;
            border-left: 4px solid var(--primary);
        }
        .toast.success {
            border-left-color: var(--success);
        }
        .toast.error {
            border-left-color: var(--danger);
        }
        .toast.warning {
            border-left-color: var(--warning);
        }
        .welcome-toast {
            position: fixed;
            top: 1.1rem;
            right: 1.1rem;
            z-index: 99998;
            display: flex;
            align-items: center;
            gap: 0.8rem;
            min-width: min(360px, calc(100vw - 2rem));
            padding: 0.9rem 1rem;
            background: #ffffff;
            border: 1px solid rgba(25, 135, 84, 0.18);
            border-left: 4px solid var(--success);
            border-radius: 0.5rem;
            box-shadow: 0 1.2rem 2.8rem rgba(15, 23, 42, 0.18);
            transform: translateY(-0.6rem);
            opacity: 0;
            transition: transform 0.28s ease, opacity 0.28s ease;
        }
        .welcome-toast.show {
            transform: translateY(0);
            opacity: 1;
        }
        .welcome-toast i {
            color: var(--success);
            font-size: 1.35rem;
        }
        .welcome-toast strong,
        .welcome-toast span {
            display: block;
        }
        .welcome-toast strong {
            color: #0f172a;
            font-size: 0.96rem;
        }
        .welcome-toast span {
            color: var(--gray-600);
            font-size: 0.86rem;
            margin-top: 0.12rem;
        }

        .pagination {
            display: flex;
            align-items: center;
            justify-content: flex-end;
            gap: 0.35rem;
            margin-top: 0.85rem;
            flex-wrap: wrap;
        }
        .pagination button,
        .pagination span {
            min-width: 2.2rem;
            min-height: 2.1rem;
            padding: 0.35rem 0.55rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            background: #fff;
            color: #334155;
            font: inherit;
            font-size: 0.86rem;
        }
        .pagination button {
            cursor: pointer;
        }
        .pagination button.active {
            background: var(--primary);
            border-color: var(--primary);
            color: #fff;
            font-weight: 700;
        }
        .pagination button:disabled,
        .pagination span {
            cursor: default;
            opacity: 0.55;
        }
        @keyframes slideUp {
            from {
                transform: translateY(20px);
                opacity: 0;
            }
            to {
                transform: translateY(0);
                opacity: 1;
            }
        }
        .toast .toast-close {
            margin-left: auto;
            background: none;
            border: none;
            color: #94a3b8;
            cursor: pointer;
            font-size: 1rem;
        }
        .toast .toast-close:hover {
            color: #fff;
        }

        /* На узких экранах меню прячется, а формы становятся в одну колонку. */
        @media (max-width: 1200px) {
            .content {
                padding: 1.15rem;
            }
            .topbar {
                padding: 0.75rem 1.15rem;
            }
            .grid-4 {
                grid-template-columns: 1fr 1fr;
            }
            .card {
                padding: 1.1rem;
            }
            .budget-chart-card {
                min-height: 400px;
            }
        }
        @media (max-width: 992px) {
            .grid-3 {
                grid-template-columns: 1fr 1fr;
            }
            .grid-2 {
                grid-template-columns: 1fr;
            }
            .admin-info-grid {
                grid-template-columns: 1fr;
            }
        }
        @media (max-width: 992px) {
            :root {
                --sidebar-width: 280px;
            }
            .sidebar {
                transform: translateX(-100%);
                box-shadow: 0 20px 60px rgba(15, 23, 42, 0.35);
                width: min(82vw, 320px);
            }
            .sidebar.open {
                transform: translateX(0);
            }
            body.sidebar-open {
                overflow: hidden;
            }
            .sidebar-backdrop {
                position: fixed;
                inset: 0;
                display: block;
                visibility: hidden;
                background: rgba(15, 23, 42, 0.45);
                opacity: 0;
                pointer-events: none;
                transition: opacity var(--transition);
                z-index: 900;
            }
            body.sidebar-open .sidebar-backdrop {
                visibility: visible;
                opacity: 1;
                pointer-events: auto;
            }
            .main {
                margin-left: 0;
            }
            .topbar-left .hamburger {
                display: inline-flex;
                align-items: center;
                justify-content: center;
                width: 2.45rem;
                height: 2.45rem;
                border-radius: 0.45rem;
                background: #f8fafc;
                border: 1px solid var(--gray-200);
            }
            .topbar {
                padding: 0.7rem 0.9rem;
                align-items: center;
            }
            .topbar-left {
                width: 100%;
                justify-content: flex-start;
            }
            .topbar-left h2 {
                min-width: 0;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .topbar-right {
                width: 100%;
                justify-content: flex-start;
                font-size: 0.8rem;
                gap: 0.55rem;
                overflow-x: auto;
                padding-bottom: 0.1rem;
            }
            .content {
                padding: 0.85rem;
            }
            .grid-4 {
                grid-template-columns: 1fr 1fr;
            }
            .grid-3 {
                grid-template-columns: 1fr;
            }
            .budget-chart-controls {
                grid-template-columns: 1fr;
            }
            .budget-settings-card .form-row {
                grid-template-columns: 1fr;
            }
            .modal-box {
                width: min(94vw, 620px);
                max-height: 92vh;
                overflow-y: auto;
                padding: 1rem;
            }
            .modal-box .form-row {
                grid-template-columns: 1fr;
            }
            .topbar-right .badge-org {
                display: inline-flex;
                max-width: 100%;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .card-header {
                align-items: flex-start;
                gap: 0.75rem;
            }
            .card-header h3 {
                line-height: 1.3;
            }
            .card-header .actions {
                width: 100%;
                justify-content: flex-start;
            }
            .card-header .actions .btn {
                flex: 1 1 12rem;
                justify-content: center;
            }
            .btn {
                min-height: 2.35rem;
            }
            .table-wrap {
                margin-left: -0.5rem;
                margin-right: -0.5rem;
                padding: 0 0.5rem;
            }
            table {
                min-width: 720px;
            }
            .toast-container {
                left: 0.75rem;
                right: 0.75rem;
                top: 0.75rem;
            }
            .toast {
                min-width: 0;
                width: 100%;
            }
            .pagination {
                justify-content: flex-start;
            }
        }
        @media (max-width: 480px) {
            .grid-4 {
                grid-template-columns: 1fr;
            }
            .topbar {
                gap: 0.45rem;
            }
            .topbar-right {
                display: grid;
                grid-template-columns: 1fr auto;
                align-items: center;
                overflow: visible;
            }
            .topbar-right .badge-org {
                grid-column: 1 / -1;
                max-width: 100%;
                width: 100%;
                justify-content: center;
            }
            .logout-btn {
                min-width: 5.75rem;
                justify-content: center;
            }
            .kpi-card .info .value {
                font-size: 1.2rem;
            }
            .topbar-right .user-info span {
                display: inline-block;
                max-width: 48vw;
                overflow: hidden;
                text-overflow: ellipsis;
            }
            .sidebar {
                width: 88vw;
            }
            .sidebar-nav a {
                padding: 0.78rem 1.25rem;
            }
            .content {
                padding: 0.65rem;
            }
            .card {
                padding: 0.9rem;
                margin-bottom: 0.85rem;
            }
            .chart-container.tall {
                height: 250px;
            }
            .modal-box input,
            .modal-box select,
            .modal-box textarea {
                font-size: 16px;
            }
            .form-actions {
                flex-direction: column-reverse;
            }
            .form-actions .btn {
                width: 100%;
            }
        }
        @media (max-width: 640px) {
            .table-wrap {
                overflow: visible;
                margin-left: 0;
                margin-right: 0;
                padding: 0;
            }
            .table-wrap table {
                min-width: 0;
                border-collapse: separate;
                border-spacing: 0 0.65rem;
            }
            .table-wrap thead {
                display: none;
            }
            .table-wrap tbody,
            .table-wrap tr,
            .table-wrap td {
                display: block;
                width: 100%;
            }
            .table-wrap tr {
                padding: 0.75rem;
                border: 1px solid var(--gray-200);
                border-radius: var(--radius);
                background: #ffffff;
                box-shadow: 0 0.35rem 1rem rgba(15, 23, 42, 0.06);
            }
            .table-wrap td {
                display: grid;
                grid-template-columns: minmax(7.5rem, 42%) minmax(0, 1fr);
                gap: 0.75rem;
                align-items: start;
                padding: 0.45rem 0;
                border-bottom: 1px solid #edf2f7;
                overflow-wrap: anywhere;
            }
            .table-wrap td:last-child {
                border-bottom: 0;
            }
            .table-wrap td::before {
                content: attr(data-label);
                color: var(--gray-600);
                font-weight: 700;
                font-size: 0.78rem;
            }
            .table-wrap td[colspan] {
                display: block;
                text-align: center;
            }
            .table-wrap td[colspan]::before {
                display: none;
            }
            .table-wrap td .btn {
                margin: 0 0.25rem 0.25rem 0;
                position: relative;
                z-index: 1;
                pointer-events: auto;
            }
            .truncate {
                max-width: none;
                white-space: normal;
            }
            .pagination {
                justify-content: center;
            }
            .pagination button,
            .pagination span {
                min-width: 2.35rem;
                min-height: 2.35rem;
            }
            .budget-chart-summary {
                display: grid;
                gap: 0.55rem;
            }
        }

        /* Небольшие служебные классы для повторяющихся состояний. */
        .text-center {
            text-align: center;
        }
        .text-muted {
            color: var(--gray-600);
        }
        .mt-1 {
            margin-top: 0.5rem;
        }
        .mb-1 {
            margin-bottom: 0.5rem;
        }
        .flex {
            display: flex;
        }
        .flex-between {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .gap-1 {
            gap: 0.5rem;
        }
        .gap-2 {
            gap: 1rem;
        }
        .form-row {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 0.75rem;
        }
        .fw-bold {
            font-weight: 700;
        }
        .w-full {
            width: 100%;
        }
        .truncate {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 120px;
        }

        /* Контейнеры графиков держат стабильную высоту. */
        .chart-container {
            position: relative;
            height: 200px;
        }
        .chart-container canvas {
            display: block;
            width: 100%;
            height: 100%;
        }
        .chart-container.tall {
            height: 280px;
        }

        /* Пустое состояние выглядит спокойно и не ломает верстку. */
        .empty-state {
            text-align: center;
            padding: 2rem 0;
            color: var(--gray-600);
        }
        .empty-state i {
            font-size: 2.5rem;
            color: var(--gray-300);
            margin-bottom: 0.5rem;
        }

        /* Страница входа отделена визуально от рабочей части системы. */
        body.login-page {
            display: grid;
            min-height: 100vh;
            background:
                linear-gradient(135deg, rgba(15, 23, 42, 0.94), rgba(13, 110, 253, 0.70)),
                #0f172a;
            color: #1e293b;
        }
        .login-shell {
            display: grid;
            place-items: center;
            width: 100%;
            min-height: 100vh;
            grid-template-rows: 1fr auto;
            padding: 1rem;
        }
        .login-footer {
            align-self: end;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
            width: 100vw;
            color: #e2e8f0;
            font-size: 0.84rem;
            text-align: center;
            padding: 0.72rem 1rem;
            margin: 0.85rem calc(50% - 50vw) 0;
            background: rgba(15, 23, 42, 0.86);
            border-top: 1px solid rgba(96, 165, 250, 0.18);
            border-radius: 0;
            box-shadow: 0 0.75rem 2rem rgba(2, 6, 23, 0.18);
        }
        .login-footer i {
            color: #60a5fa;
        }
        .login-panel {
            width: min(100%, 420px);
            background: #ffffff;
            border: 1px solid rgba(226, 232, 240, 0.9);
            border-radius: 0.5rem;
            box-shadow: 0 24px 70px rgba(2, 6, 23, 0.28);
            padding: 0;
            overflow: hidden;
        }
        .login-brand {
            display: flex;
            align-items: center;
            gap: 0.8rem;
            padding: 1.25rem 1.35rem;
            margin-bottom: 0;
            background: #0f172a;
            color: #f8fafc;
        }
        .login-brand i {
            width: 2.3rem;
            height: 2.3rem;
            border-radius: 0.5rem;
            background: rgba(96, 165, 250, 0.16);
            color: #60a5fa;
            font-size: 1.35rem;
        }
        .login-brand strong,
        .login-brand span {
            display: block;
        }
        .login-brand span {
            color: #94a3b8;
            font-size: 0.82rem;
            margin-top: 0.15rem;
        }
        .login-panel h1 {
            font-size: 1.35rem;
            margin: 1.35rem 1.35rem 0.95rem;
        }
        .login-form {
            display: grid;
            gap: 0.65rem;
            padding: 0 1.35rem 1.35rem;
        }
        .login-form label {
            font-weight: 600;
            font-size: 0.88rem;
        }
        .login-form input {
            width: 100%;
            padding: 0.65rem 0.75rem;
            border: 1px solid var(--gray-300);
            border-radius: 0.375rem;
            font-size: 1rem;
        }
        .login-form input:focus {
            outline: none;
            border-color: var(--primary);
            box-shadow: 0 0 0 0.15rem rgba(13, 110, 253, 0.15);
        }
        .login-alert {
            border: 1px solid rgba(220, 53, 69, 0.25);
            background: rgba(220, 53, 69, 0.08);
            color: #b42333;
            border-radius: 0.375rem;
            padding: 0.6rem 0.75rem;
            font-size: 0.9rem;
        }
        .login-submit {
            justify-content: center;
            gap: 0.5rem;
            margin-top: 0.35rem;
            min-height: 2.65rem;
            font-weight: 700;
            box-shadow: 0 0.65rem 1.4rem rgba(13, 110, 253, 0.2);
        }

        @media (max-width: 480px) {
            .login-panel {
                width: 100%;
            }
        }

        /* Финальные мобильные правила стоят в конце файла, чтобы их не перебивали базовые классы. */
        @media (max-width: 1200px) {
            .chart-container.tall {
                height: 270px;
            }
        }
        @media (max-width: 768px) {
            body {
                overflow-x: hidden;
            }
            .chart-container.tall {
                height: 260px;
            }
            .budget-chart-card {
                min-height: 0;
            }
            .flex-between {
                gap: 0.45rem;
                flex-wrap: wrap;
            }
            .login-shell {
                padding: 0.9rem;
            }
        }
        @media (max-width: 640px) {
            .table-wrap {
                overflow: visible;
                margin-left: 0;
                margin-right: 0;
                padding: 0;
            }
            .table-wrap table {
                min-width: 0;
                border-collapse: separate;
                border-spacing: 0 0.65rem;
            }
            .table-wrap thead {
                display: none;
            }
            .table-wrap tbody,
            .table-wrap tr,
            .table-wrap td {
                display: block;
                width: 100%;
            }
            .table-wrap tr {
                padding: 0.75rem;
                border: 1px solid var(--gray-200);
                border-radius: var(--radius);
                background: #ffffff;
                box-shadow: 0 0.35rem 1rem rgba(15, 23, 42, 0.06);
            }
            .table-wrap td {
                display: grid;
                grid-template-columns: minmax(7.5rem, 42%) minmax(0, 1fr);
                gap: 0.75rem;
                align-items: start;
                padding: 0.45rem 0;
                border-bottom: 1px solid #edf2f7;
                overflow-wrap: anywhere;
            }
            .table-wrap td:last-child {
                border-bottom: 0;
            }
            .table-wrap td::before {
                content: attr(data-label);
                color: var(--gray-600);
                font-weight: 700;
                font-size: 0.78rem;
            }
            .table-wrap td[colspan] {
                display: block;
                text-align: center;
            }
            .table-wrap td[colspan]::before {
                display: none;
            }
            .table-wrap td .btn {
                margin: 0 0.25rem 0.25rem 0;
            }
            .truncate {
                max-width: none;
                white-space: normal;
                overflow: visible;
                text-overflow: clip;
            }
            .pagination {
                justify-content: center;
            }
            .budget-chart-summary {
                display: grid;
                gap: 0.55rem;
            }
        }
        @media (max-width: 480px) {
            .content {
                padding: 0.65rem;
            }
            .card {
                padding: 0.9rem;
                margin-bottom: 0.85rem;
            }
            .chart-container.tall {
                height: 245px;
            }
            .login-brand {
                padding: 1rem;
            }
            .login-panel h1 {
                margin: 1.1rem 1rem 0.8rem;
                font-size: 1.2rem;
            }
            .login-form {
                padding: 0 1rem 1rem;
            }
            .login-footer {
                width: 100vw;
            }
        }
        @media (max-width: 380px) {
            .table-wrap td {
                grid-template-columns: 1fr;
                gap: 0.25rem;
            }
            .topbar-right {
                grid-template-columns: 1fr;
            }
            .logout-btn {
                width: 100%;
            }
        }

        /* Финальная мобильная полировка: интерфейс должен быть удобным с пальца, а не просто ужатым. */
        @media (max-width: 992px) {
            .main {
                width: 100%;
                min-width: 0;
            }
            .content {
                width: 100%;
                max-width: 100vw;
            }
            .grid-2,
            .grid-3 {
                grid-template-columns: 1fr;
            }
            .report-form {
                grid-template-columns: repeat(2, minmax(0, 1fr));
            }
            .report-actions {
                min-width: 0;
            }
            .sidebar {
                width: min(88vw, 340px);
            }
            .sidebar-nav a {
                min-height: 2.8rem;
            }
        }

        @media (max-width: 768px) {
            .topbar {
                position: sticky;
                top: 0;
                padding: 0.65rem;
            }
            .topbar-left {
                display: grid;
                grid-template-columns: auto minmax(0, 1fr);
                gap: 0.65rem;
            }
            .topbar-left .hamburger {
                min-width: 2.6rem;
                min-height: 2.6rem;
            }
            .topbar-right {
                display: grid;
                grid-template-columns: minmax(0, 1fr) auto;
                width: 100%;
                gap: 0.5rem;
                overflow: visible;
            }
            .topbar-right .badge-org {
                grid-column: 1 / -1;
                justify-content: center;
                min-height: 2.25rem;
                border-radius: 0.45rem;
            }
            .topbar-right .user-info {
                min-width: 0;
            }
            .topbar-right .user-info span {
                min-width: 0;
                overflow: hidden;
                text-overflow: ellipsis;
                white-space: nowrap;
            }
            .logout-btn {
                min-height: 2.5rem;
                padding-inline: 0.85rem;
                justify-content: center;
            }
            .content {
                padding: 0.75rem;
            }
            .card {
                padding: 0.9rem;
                margin-bottom: 0.85rem;
                border-radius: 0.45rem;
            }
            .card-header {
                margin-bottom: 0.75rem;
            }
            .card-header h3 {
                font-size: 0.98rem;
                line-height: 1.3;
            }
            .card-header .actions {
                width: 100%;
            }
            .card-header .actions .btn,
            .settings-submit,
            .budget-save-btn {
                width: 100%;
                min-width: 0;
            }
            .grid-4 {
                grid-template-columns: repeat(2, minmax(0, 1fr));
                gap: 0.75rem;
            }
            .kpi-card {
                padding: 0.85rem;
                gap: 0.65rem;
                min-width: 0;
            }
            .kpi-card .icon {
                width: 40px;
                height: 40px;
                border-radius: 10px;
            }
            .kpi-card .info .value {
                font-size: 1.22rem;
                overflow-wrap: anywhere;
            }
            .kpi-card .info .label {
                line-height: 1.25;
            }
            .budget-progress-layout {
                display: grid;
                grid-template-columns: 1fr;
                gap: 0.75rem;
            }
            .budget-planned-panel {
                min-width: 0;
                text-align: left;
                padding: 0.7rem;
                border: 1px solid var(--gray-200);
                border-radius: 0.45rem;
                background: #f8fafc;
            }
            .budget-progress-meta {
                display: grid;
                grid-template-columns: 1fr;
                gap: 0.3rem;
            }
            .budget-chart-controls,
            .budget-settings-card .form-row,
            .form-row,
            .report-form {
                grid-template-columns: 1fr;
            }
            .report-actions .btn {
                min-height: 2.75rem;
            }
            .card form input,
            .card form select,
            .card form textarea,
            .report-field input,
            .report-field select,
            .budget-chart-controls input,
            .modal-box input,
            .modal-box select,
            .modal-box textarea {
                min-height: 2.75rem;
                font-size: 16px;
            }
            .chart-container,
            .chart-container.tall {
                height: clamp(230px, 66vw, 330px);
            }
            .budget-chart-card .chart-container.tall {
                height: clamp(260px, 72vw, 360px);
            }
            .budget-chart-summary {
                grid-template-columns: 1fr;
                font-size: 0.88rem;
            }
            .modal-overlay.open {
                align-items: flex-start;
                padding: 0.5rem;
            }
            .modal-box {
                width: 100%;
                max-width: none;
                max-height: calc(100dvh - 1rem);
                padding: 0.95rem;
                border-radius: 0.55rem;
            }
            .modal-box > .flex-between:first-child {
                position: sticky;
                top: -0.95rem;
                z-index: 2;
                background: #fff;
                padding: 0.1rem 0 0.7rem;
                border-bottom: 1px solid var(--gray-200);
                margin-bottom: 0.75rem;
            }
            .close-modal {
                min-width: 2.4rem;
                min-height: 2.4rem;
            }
            .form-actions {
                display: grid;
                grid-template-columns: 1fr;
                gap: 0.5rem;
            }
            .form-actions .btn {
                width: 100%;
                justify-content: center;
            }
        }

        @media (max-width: 560px) {
            .grid-4 {
                grid-template-columns: 1fr;
            }
            .content {
                padding: 0.55rem;
            }
            .card {
                padding: 0.8rem;
            }
            .topbar-right {
                grid-template-columns: 1fr;
            }
            .logout-btn {
                width: 100%;
            }
            .sidebar {
                width: min(92vw, 360px);
            }
            .sidebar-brand {
                padding: 1rem 1.1rem;
            }
            .sidebar-nav a {
                padding: 0.82rem 1.1rem;
                font-size: 0.95rem;
            }
            .table-wrap td {
                grid-template-columns: minmax(7rem, 38%) minmax(0, 1fr);
                gap: 0.55rem;
                font-size: 0.9rem;
            }
            .table-wrap tr {
                padding: 0.7rem;
            }
            .status-badge {
                white-space: normal;
                text-align: center;
            }
            .pagination {
                gap: 0.25rem;
            }
            .pagination button,
            .pagination span {
                min-width: 2.45rem;
                min-height: 2.45rem;
            }
            .login-shell {
                padding: 0.75rem;
            }
            .login-panel {
                width: 100%;
            }
        }

        @media (max-width: 390px) {
            .table-wrap td {
                grid-template-columns: 1fr;
            }
            .table-wrap td::before {
                margin-bottom: 0.15rem;
            }
            .btn {
                width: 100%;
                justify-content: center;
            }
            .table-wrap td .btn {
                width: auto;
                min-width: 2.5rem;
            }
        }
