:root {
    --primary: #4f46e5;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

/* Base Styles */
* { box-sizing: border-box; }
body { 
    font-family: 'Inter', system-ui, -apple-system, sans-serif; 
    background: var(--bg-body); 
    color: var(--text-main); 
    margin: 0; 
    line-height: 1.5;
}

/* Layout */
.app-layout { 
    display: grid; 
    grid-template-columns: 260px 1fr; 
    min-height: 100vh; 
}

.main-content {
    padding: 2rem;
    width: 100%;
}

/* Sidebar */
.sidebar { 
    background: #1e293b; 
    color: white; 
    padding: 1.5rem; 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
    position: sticky;
    top: 0;
}

.sidebar-profile {
    padding-bottom: 1.5rem;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.sidebar-avatar, .sidebar-avatar-placeholder {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    margin: 0 auto 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    object-fit: cover;
}

.sidebar-avatar { border: 2px solid var(--primary); }
.sidebar-avatar-placeholder { 
    background: var(--primary); 
    font-size: 1.5rem; 
    font-weight: bold; 
}

.user-name { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; }
.user-role-badge { 
    background: rgba(255,255,255,0.1); 
    padding: 2px 8px; 
    border-radius: 4px; 
    font-size: 0.7rem; 
    color: #cbd5e1; 
}

.sidebar nav { flex: 1; }
.sidebar a { 
    color: #cbd5e1; 
    text-decoration: none; 
    padding: 0.75rem; 
    border-radius: var(--radius); 
    margin-bottom: 0.5rem; 
    display: block; 
    transition: 0.2s;
}
.sidebar a:hover { background: rgba(255,255,255,0.05); }
.sidebar a.active { background: var(--primary); color: white; }

.sidebar-footer { padding-top: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }

/* Components */
.card { 
    background: var(--bg-card); 
    padding: 1.5rem; 
    border-radius: var(--radius); 
    box-shadow: var(--shadow); 
    border: 1px solid var(--border); 
    margin-bottom: 1.5rem;
}

.btn { 
    cursor: pointer; 
    padding: 0.6rem 1.2rem; 
    border-radius: var(--radius); 
    border: none; 
    font-weight: 500; 
    transition: 0.2s; 
    display: inline-block;
    text-decoration: none;
    text-align: center;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { filter: brightness(1.1); }

.form-control { 
    width: 100%; 
    padding: 0.6rem; 
    margin-bottom: 1rem; 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    font-size: 1rem;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 0.75rem; border-bottom: 1px solid var(--border); }

.w-full { width: 100%; }
.text-center { text-align: center; }

/* Mobile Navigation Toggle */
.mobile-nav-toggle {
    display: none;
    position: fixed;
    top: 15px;
    right: 15px; /* Перенес направо, чтобы не мешать тексту */
    z-index: 1001;
    background: #1e293b;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 4px;
    cursor: pointer;
}

.mobile-nav-toggle span, 
.mobile-nav-toggle span::before, 
.mobile-nav-toggle span::after {
    display: block;
    width: 20px;
    height: 2px;
    background: white;
    position: absolute;
    left: 10px;
    transition: 0.3s;
}
.mobile-nav-toggle span::before { content: ""; top: -6px; left: 0; }
.mobile-nav-toggle span::after { content: ""; top: 6px; left: 0; }

/* Responsive */
@media (max-width: 768px) {
    .app-layout { grid-template-columns: 1fr; }
    
    .sidebar {
        position: fixed;
        left: -265px;
        top: 0;
        bottom: 0;
        z-index: 1000;
        transition: transform 0.3s ease;
        width: 260px;
    }
    
    .sidebar.active { transform: translateX(265px); }
    
    .mobile-nav-toggle { display: block; }
    
    .main-content { padding: 1rem; padding-top: 70px; }

    /* Бургер превращается в крестик */
    .sidebar.active ~ .mobile-nav-toggle span { background: transparent; }
    .sidebar.active ~ .mobile-nav-toggle span::before { transform: rotate(45deg); top: 0; }
    .sidebar.active ~ .mobile-nav-toggle span::after { transform: rotate(-45deg); top: 0; }
}

/* Сетка профиля с отступом от сайдбара */
.profile-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 2.5rem; /* Увеличенный промежуток между колонками */
    margin-left: 0.5rem; /* Дополнительный отступ от края контентной области */
}

/* Стили аватара в профиле */
.avatar-big { margin-bottom: 1.5rem; }
.profile-img-preview {
    width: 150px; 
    height: 150px; 
    border-radius: 50%; 
    object-fit: cover; 
    border: 4px solid var(--primary);
}
.avatar-placeholder-big {
    width: 150px; 
    height: 150px; 
    border-radius: 50%; 
    background: #e2e8f0; 
    line-height: 150px; 
    font-size: 3rem; 
    margin: 0 auto;
}

.badge-role {
    background: var(--primary); 
    color: white; 
    padding: 6px 16px; 
    border-radius: 20px; 
    font-size: 0.8rem;
    font-weight: 600;
}

.divider { margin: 1.5rem 0; border: 0; border-top: 1px solid var(--border); }
.btn-upload { display: block; margin-bottom: 0.5rem; cursor: pointer; }
.profile-stats { margin-top: 2rem; text-align: left; font-size: 0.85rem; color: var(--text-muted); }

/* Вспомогательные классы для форм */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.section-margin { margin-bottom: 2rem; }
.section-desc { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; }
.readonly-input { background: #f1f5f9; cursor: not-allowed; }
.btn-dark { background: #1e293b; color: white; }

/* Адаптивность для мобильных устройств */
@media (max-width: 1024px) {
    .profile-grid {
        grid-template-columns: 1fr; /* Колонки встают друг под друга */
        gap: 1.5rem;
        margin-left: 0;
    }
    
    .side-col {
        max-width: 400px;
        margin: 0 auto; /* Центрируем блок с аватаром на планшетах */
        width: 100%;
    }
}

@media (max-width: 640px) {
    .form-row {
        grid-template-columns: 1fr; /* Поля формы встают в один ряд */
        gap: 0;
    }
    
    .main-content {
        padding: 1rem; /* Уменьшаем отступы страницы на телефонах */
    }
}
/* Сетка админки */
.admin-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1.5rem; }

/* Логи */
.log-list { max-height: 400px; overflow-y: auto; font-size: 0.85rem; }
.log-item { padding: 8px 0; border-bottom: 1px solid var(--border); }
.log-item small { color: var(--text-muted); margin-right: 8px; }

/* Модальное окно */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 2000;
    padding: 1rem;
}
.modal-content { width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto; position: relative; }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.close { font-size: 2rem; text-decoration: none; color: var(--text-main); }

/* Переключатели (Toggle) */
.access-row { display: flex; justify-content: space-between; align-items: center; padding: 10px; background: #f8fafc; border-radius: 8px; margin-bottom: 5px; }
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 20px; }
input:checked + .slider { background-color: var(--primary); }

@media (max-width: 900px) {
    .admin-grid { grid-template-columns: 1fr; }
    .desktop-only { display: none; }
}
/* Сетка модалки: на десктопе 2 колонки, на мобилках 1 */
.modal-body-grid {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 20px;
}

@media (max-width: 768px) {
    .modal-body-grid {
        grid-template-columns: 1fr;
    }
    .logs-part {
        margin-top: 20px;
        padding-top: 20px;
        border-top: 2px solid var(--border);
    }
}

/* Стили логов в профиле */
.user-log-container {
    background: #f1f5f9;
    padding: 10px;
    border-radius: 8px;
    font-size: 0.85rem;
}
.log-row-mini {
    padding: 6px 0;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}
.log-date { color: #64748b; white-space: nowrap; }

/* Пагинация */
.pagination {
    display: flex;
    gap: 5px;
    margin-top: 15px;
    flex-wrap: wrap;
}
.page-link {
    padding: 4px 10px;
    background: #fff;
    border: 1px solid var(--border);
    text-decoration: none;
    color: var(--text-main);
    border-radius: 4px;
    font-size: 0.8rem;
}
.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
/* Цветные плашки ролей */
.badge-role {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: white;
}

/* Красный для админа */
.badge-role.admin {
    background-color: #dc2626; /* Red */
}

/* Синий для обычного пользователя */
.badge-role.user {
    background-color: #2563eb; /* Blue */
}

/* Серый для новых или деактивированных */
.badge-role.new {
    background-color: #64748b; /* Slate */
}
/* --- Система адаптивных таблиц (Cards on Mobile) --- */
@media (max-width: 768px) {
    .table-responsive {
        border: none;
    }

    .table-responsive table, 
    .table-responsive thead, 
    .table-responsive tbody, 
    .table-responsive th, 
    .table-responsive td, 
    .table-responsive tr { 
        display: block; 
    }

    /* Скрываем заголовки таблицы */
    .table-responsive thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .table-responsive tr {
        background: var(--bg-card);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 1rem;
        padding: 0.5rem;
        box-shadow: var(--shadow);
    }

    .table-responsive td { 
        border: none;
        position: relative;
        padding-left: 50% !important; 
        text-align: right !important;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        border-bottom: 1px solid #f1f5f9;
    }

    .table-responsive td:last-child { border-bottom: none; }

    /* Вставляем название колонки через content */
    .table-responsive td:before { 
        content: attr(data-label);
        position: absolute;
        left: 10px;
        width: 45%; 
        padding-right: 10px; 
        white-space: nowrap;
        text-align: left;
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.8rem;
    }
}