* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
    padding: 0;
    /* Адаптация под вырезы и системные панели (iPhone и т.п.) */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    transition: background 0.3s ease, color 0.3s ease;
}

/* Тёмная тема */
body.dark-theme {
    background: #0f0f1a;
    color: #e0e0e0;
}

body.dark-theme .card {
    background: #1e1e2f;
    box-shadow: 0 4px 24px rgba(0,0,0,0.3);
}

body.dark-theme h1, body.dark-theme h2, body.dark-theme h3 {
    color: #ffffff;
}

body.dark-theme input, body.dark-theme select, body.dark-theme textarea {
    background: #2a2a3e;
    border-color: #4a4a60;
    color: #fff;
}

body.dark-theme input:disabled {
    background: #222232;
    color: #aaa;
}

body.dark-theme table th {
    background: #2a2a3e;
    color: #fff;
    border-bottom-color: #4a4a60;
}

body.dark-theme table td {
    border-bottom-color: #2a2a3e;
    background: #1e1e2f;
}

body.dark-theme tr:hover td {
    background: #2f2f42;
}

body.dark-theme .btn-icon:hover {
    background: #3a3a52;
}

body.dark-theme .alert-success {
    background: #1e3a2e;
    color: #a3d9b1;
    border-left-color: #2e7d5e;
}

body.dark-theme .alert-error {
    background: #4a2525;
    color: #f5c2c2;
    border-left-color: #c0392b;
}

/* Google Material Symbols */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
    font-size: 1.4rem;
    display: inline-block;
    line-height: 1;
}

/* ===== САЙДБАР ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100%;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: #fff;
    color: #333;
    border-right: 1px solid #e9ecef;
    box-shadow: 2px 0 12px rgba(0,0,0,0.03);
    transition: width 0.3s ease, background 0.3s ease;
}

body.dark-theme .sidebar {
    background: #151526;
    color: #e0e0e0;
    border-right-color: #2a2a3e;
}

.sidebar.collapsed {
    width: 60px;
}

.sidebar.collapsed .sidebar-user,
.sidebar.collapsed .sidebar-nav a span:not(.material-symbols-outlined),
.sidebar.collapsed .sidebar-footer button span:not(.material-symbols-outlined),
.sidebar.collapsed .sidebar-footer .btn-logout span:not(.material-symbols-outlined) {
    display: none;
}

.sidebar.collapsed .sidebar-nav a,
.sidebar.collapsed .sidebar-footer button,
.sidebar.collapsed .sidebar-footer .btn-logout {
    justify-content: center;
    padding: 12px 0;
}

.sidebar.collapsed .material-symbols-outlined {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-nav a {
    position: relative;
}

.sidebar.collapsed .sidebar-nav a:hover::after {
    content: attr(data-title);
    position: absolute;
    left: 60px;
    background: #333;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 10;
    font-size: 0.85rem;
}

.sidebar-user {
    padding: 20px 20px 16px;
    border-bottom: 1px solid #f1f3f5;
    font-size: 0.95rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

body.dark-theme .sidebar-user {
    border-bottom-color: #2a2a3e;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 11px 20px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    font-size: 0.95rem;
    color: #555;
    white-space: nowrap;
    overflow: hidden;
    border-left: 3px solid transparent;
}

body.dark-theme .sidebar-nav a {
    color: #aaa;
}

.sidebar-nav a:hover {
    background: rgba(67,97,238,0.05);
    color: #333;
}

body.dark-theme .sidebar-nav a:hover {
    background: rgba(67,97,238,0.1);
    color: #e0e0e0;
}

.sidebar-nav a.active {
    background: rgba(67,97,238,0.08);
    border-left: 3px solid #4361ee;
    color: #4361ee;
    font-weight: 500;
}

body.dark-theme .sidebar-nav a.active {
    background: rgba(67,97,238,0.15);
    color: #7b93ff;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid #f1f3f5;
}

body.dark-theme .sidebar-footer {
    border-top-color: #2a2a3e;
}

.sidebar-footer button,
.sidebar-footer .btn-logout {
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: #777;
    padding: 10px 0;
    cursor: pointer;
    font-size: 0.95rem;
    transition: color 0.2s;
}

body.dark-theme .sidebar-footer button,
body.dark-theme .sidebar-footer .btn-logout {
    color: #aaa;
}

.sidebar-footer button:hover,
.sidebar-footer .btn-logout:hover {
    color: #4361ee;
}

/* ===== КНОПКИ СВОРАЧИВАНИЯ САЙДБАРА ===== */
.sidebar-toggle-desktop {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 14px 0;
    background: transparent;
    border: none;
    border-bottom: 1px solid #f1f3f5;
    cursor: pointer;
    color: #777;
    font-size: 1.6rem;
    transition: color 0.2s, background 0.2s;
}

.sidebar-toggle-desktop:hover {
    color: #4361ee;
    background: rgba(67,97,238,0.03);
}

body.dark-theme .sidebar-toggle-desktop {
    color: #aaa;
    border-bottom-color: #2a2a3e;
}

body.dark-theme .sidebar-toggle-desktop:hover {
    color: #7b93ff;
    background: rgba(67,97,238,0.1);
}

/* Мобильная кнопка-бургер (фиксированная, снаружи) */
.sidebar-toggle {
    display: none; /* скрыта на десктопах */
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 10001;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 1.8rem;
    line-height: 1;
    cursor: pointer;
    color: #555;
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    transition: color 0.2s, background 0.2s, box-shadow 0.2s, transform 0.1s;
}

body.dark-theme .sidebar-toggle {
    background: rgba(21,21,38,0.85);
    border-color: rgba(255,255,255,0.1);
    color: #ccc;
}

.sidebar-toggle:hover {
    color: #4361ee;
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
}

body.dark-theme .sidebar-toggle:hover {
    color: #7b93ff;
}

.sidebar-toggle:active {
    transform: scale(0.95);
}

/* ===== ОСНОВНОЙ КОНТЕНТ ===== */
.main-content {
    margin-left: 260px;
    transition: margin-left 0.3s ease;
    padding: 28px;
    min-height: 100vh;
}

.main-content.expanded {
    margin-left: 60px;
}

/* ===== КАРТОЧКИ ===== */
.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    padding: 24px;
    margin-bottom: 24px;
    transition: box-shadow 0.2s ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* ===== ТАБЛИЦЫ ===== */
.table-responsive {
    overflow-x: auto;
    margin-top: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

th {
    text-align: left;
    padding: 12px 16px;
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

td {
    padding: 10px 16px;
    border-bottom: 1px solid #f1f5f9;
    white-space: nowrap;
    background: #fff;
}

tr:hover td {
    background: #f8fafc;
}

body.dark-theme tr:hover td {
    background: #2f2f42;
}

/* ===== ФОРМЫ ===== */
input, select, textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67,97,238,0.15);
    outline: none;
}

/* ===== КНОПКИ ===== */
.btn-primary {
    background: #4361ee;
    color: #fff;
    border: none;
    padding: 10px 22px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover {
    background: #3451d1;
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: #e9ecef;
    color: #333;
    border: none;
    padding: 10px 22px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    background: #dfe2e6;
}

.btn-danger {
    background: #e94560;
    color: #fff;
    border: none;
    padding: 10px 22px;
    border-radius: 8px;
    cursor: pointer;
}

.btn-danger:hover {
    background: #d13350;
}

/* ===== ЛОГОТИП ===== */
.header .logo {
    max-height: 50px;
    max-width: 200px;
    height: auto;
    width: auto;
    object-fit: contain;
}

/* Адаптивный размер логотипа */
@media (min-width: 1200px) {
    .header .logo {
        max-height: 70px;
        max-width: 280px;
    }
}

@media (min-width: 1600px) {
    .header .logo {
        max-height: 90px;
        max-width: 360px;
    }
}

@media (max-width: 768px) {
    .header .logo {
        max-height: 40px;
        max-width: 160px;
    }
}

/* ===== МОДАЛЬНЫЕ ОКНА (с размытием) ===== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 9999;
    display: none;
    animation: fadeIn 0.2s ease;
}

.modal-backdrop.active {
    display: block;
}

.modal-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    width: 90%;
    max-width: 420px;
    z-index: 10000;
    overflow: hidden;
    display: none;
    animation: slideUp 0.25s ease;
}

.modal-dialog.active {
    display: block;
}

body.dark-theme .modal-dialog {
    background: #2d2d3f;
    color: #e0e0e0;
}

.modal-header {
    padding: 20px 20px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
}

body.dark-theme .modal-header {
    border-bottom-color: #4a4a60;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.4rem;
    color: #2c3e50;
}

body.dark-theme .modal-header h2 {
    color: #fff;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: #888;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #e94560;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    text-align: right;
    padding: 0 20px 20px;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translate(-50%, -40%); opacity: 0; }
    to { transform: translate(-50%, -50%); opacity: 1; }
}

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }

    .main-content {
        margin-left: 0 !important;
        padding: 16px;
        /* учитываем вырезы экрана */
        padding-top: calc(16px + env(safe-area-inset-top));
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .sidebar-toggle {
        display: block;
    }

    .sidebar-toggle-desktop {
        display: none;
    }

    .card {
        padding: 16px;
    }

    table {
        font-size: 0.8rem;
    }

    .btn-primary, .btn-secondary {
        width: 100%;
        justify-content: center;
        margin-bottom: 8px;
    }
}

@media (max-width: 480px) {
    .main-content {
        padding: 12px;
        padding-top: calc(12px + env(safe-area-inset-top));
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    .card {
        padding: 12px;
    }
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.3rem; }
}

/* Утилиты */
.text-center { text-align: center; }
.mt-20 { margin-top: 20px; }
.mb-20 { margin-bottom: 20px; }