/* ============================================
   ТЕМНАЯ ТЕМА (по умолчанию) - StarAdmin inspired
   ============================================ */
[data-theme="dark"] {
    --bg-primary: #1a1d2e;
    --bg-secondary: #232227;
    --bg-tertiary: #2a2b32;
    --text-primary: #ffffff;
    --text-secondary: #aab2bd;
    --text-muted: #737f8b;
    --border-color: #3a3b40;
    --border-hover: #4a4b50;
    --accent-primary: #5e81f4;
    --accent-hover: #4c6fd9;
    --accent-light: rgba(94, 129, 244, 0.15);
    --success: #34b1aa;
    --warning: #f2a654;
    --danger: #f96868;
    --info: #51b1e1;
    --sidebar-width: 260px;
    --header-height: 60px;
}

/* ============================================
   БАЗОВЫЕ СТИЛИ
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-primary);
    line-height: 1.6;
    background-color: var(--bg-secondary);
}

/* Custom Scrollbar for Dark Theme */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--bg-secondary);
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

*::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

*::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================
   LAYOUT
   ============================================ */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Header */
.app-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: var(--header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    z-index: 1000;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-actions .btn {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.5rem 0.875rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-actions .btn:hover,
.header-actions .btn:focus {
    background-color: var(--bg-tertiary);
    border-color: var(--border-hover);
    color: var(--text-primary);
    box-shadow: none;
}

.header-actions .btn i {
    font-size: 0.875rem;
}

.header-actions .btn.show,
.header-actions .btn:active {
    background-color: var(--bg-tertiary);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

/* Sidebar */
.app-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1001;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.app-sidebar::-webkit-scrollbar {
    width: 4px;
}

.app-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

.app-sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.app-sidebar.collapsed {
    width: 70px;
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    border-bottom: 1px solid var(--border-color);
    position: relative;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-decoration: none;
    transition: all 0.3s ease;
}

.sidebar-logo i {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.sidebar-logo-text {
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

.app-sidebar.collapsed .sidebar-logo-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.app-sidebar.collapsed .sidebar-header {
    flex-direction: column;
    padding: 0 0.5rem;
}

.app-sidebar.collapsed .sidebar-toggle {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    pointer-events: none;
    margin-left: 0;
}

.app-sidebar.collapsed:hover .sidebar-toggle {
    opacity: 1;
    pointer-events: auto;
}

.sidebar-toggle {
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    border-radius: 0.375rem;
    cursor: pointer;
    transition: all 0.2s ease, opacity 0.3s ease;
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.sidebar-toggle i {
    transition: transform 0.3s ease;
}

.app-sidebar.collapsed .sidebar-toggle i {
    transform: rotate(180deg);
}

.sidebar-menu {
    padding: 0.75rem 0;
}

.menu-section {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.menu-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.menu-section-title {
    padding: 0.5rem 1.25rem 0.375rem;
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity 0.2s ease;
}

.app-sidebar.collapsed .menu-section-title {
    opacity: 0;
    height: 0;
    padding: 0;
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 0.5rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.875rem;
    position: relative;
    border-left: 3px solid transparent;
    margin: 0.125rem 0;
}

.menu-item i {
    width: 1.25rem;
    margin-right: 0.75rem;
    font-size: 1rem;
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, color 0.2s ease;
}

.menu-text {
    white-space: nowrap;
    transition: opacity 0.2s ease;
}

.app-sidebar.collapsed .menu-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

.menu-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.menu-item:hover i {
    transform: translateX(3px);
    color: var(--accent-primary);
}

.app-sidebar.collapsed .menu-item:hover {
    padding-left: 1.25rem;
}

.app-sidebar.collapsed .menu-item:hover i {
    transform: scale(1.15);
}

.menu-item.active {
    background: linear-gradient(90deg, var(--accent-light) 0%, transparent 100%);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
    box-shadow: inset 0 0 20px rgba(94, 129, 244, 0.1);
}

.menu-item.active i {
    color: var(--accent-primary);
    text-shadow: 0 0 12px rgba(94, 129, 244, 0.5);
}

.app-sidebar.collapsed .menu-item {
    justify-content: center;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.app-sidebar.collapsed .menu-item i {
    margin-right: 0;
}

/* Sidebar Submenu Dropdown */
.menu-item-dropdown {
    display: flex;
    align-items: center;
    padding: 0.5rem 1.25rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.875rem;
    position: relative;
    border-left: 3px solid transparent;
    cursor: pointer;
    background: transparent;
    border-top: none;
    border-right: none;
    border-bottom: none;
    width: 100%;
    text-align: left;
    margin: 0.125rem 0;
}

.menu-item-dropdown i.menu-icon {
    width: 1.25rem;
    margin-right: 0.75rem;
    font-size: 1rem;
    text-align: center;
    flex-shrink: 0;
    transition: transform 0.2s ease, color 0.2s ease;
}

.menu-item-dropdown .dropdown-arrow {
    margin-left: auto;
    font-size: 0.625rem;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0.6;
}

.menu-item-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
    opacity: 1;
}

.menu-item-dropdown:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.menu-item-dropdown:hover i.menu-icon {
    transform: translateX(3px);
    color: var(--accent-primary);
}

.app-sidebar.collapsed .menu-item-dropdown:hover {
    padding-left: 1.25rem;
}

.menu-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(0, 0, 0, 0.1);
}

.menu-submenu.open {
    max-height: 800px;
    overflow-y: auto;
}

.menu-submenu-item {
    display: flex;
    align-items: center;
    padding: 0.4rem 1.25rem 0.4rem 3rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.8125rem;
    position: relative;
    border-left: 3px solid transparent;
}

.menu-submenu-item::before {
    content: '';
    position: absolute;
    left: 1.75rem;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--border-color);
    transition: all 0.2s ease;
}

.menu-submenu-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.menu-submenu-item:hover::before {
    background: var(--accent-primary);
    transform: scale(1.2);
}

.menu-submenu-item.active {
    background: linear-gradient(90deg, var(--accent-light) 0%, transparent 100%);
    color: var(--accent-primary);
    border-left-color: var(--accent-primary);
    font-weight: 600;
}

.menu-submenu-item.active::before {
    background: var(--accent-primary);
    box-shadow: 0 0 8px rgba(94, 129, 244, 0.6);
}

.app-sidebar.collapsed .menu-item-dropdown {
    justify-content: center;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
}

.app-sidebar.collapsed .menu-item-dropdown i.menu-icon {
    margin-right: 0;
}

.app-sidebar.collapsed .dropdown-arrow {
    display: none;
}

.app-sidebar.collapsed .menu-submenu {
    display: none;
}

/* Sidebar Tooltips for collapsed state */
.app-sidebar.collapsed .menu-item,
.app-sidebar.collapsed .menu-item-dropdown {
    position: relative;
}

.app-sidebar.collapsed .menu-item::after,
.app-sidebar.collapsed .menu-item-dropdown::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%) translateX(10px);
    background: var(--bg-primary);
    color: var(--text-primary);
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    z-index: 1000;
    pointer-events: none;
}

.app-sidebar.collapsed .menu-item:hover::after,
.app-sidebar.collapsed .menu-item-dropdown:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) translateX(15px);
}

/* Sidebar Profile - Top */
.sidebar-profile-top {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.3s ease;
}

.profile-avatar-large {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
    box-shadow: 0 4px 16px rgba(94, 129, 244, 0.3);
    border: 2px solid var(--border-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.profile-avatar-large:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(94, 129, 244, 0.4);
}

.profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.profile-avatar-large span {
    position: relative;
    z-index: 1;
}

.profile-info-large {
    text-align: center;
    width: 100%;
    transition: opacity 0.2s ease;
}

.profile-name-large {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.25rem;
}

.profile-username-large {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-sidebar.collapsed .sidebar-profile-top {
    padding: 0.75rem 0.5rem;
}

.app-sidebar.collapsed .profile-avatar-large {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 0.875rem;
}

.app-sidebar.collapsed .profile-info-large {
    opacity: 0;
    height: 0;
    overflow: hidden;
}

/* Content */
.app-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    padding: 2rem;
    flex: 1;
    min-height: calc(100vh - var(--header-height));
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-sidebar.collapsed ~ .flex-fill .app-content {
    margin-left: 70px;
}

.app-sidebar.collapsed ~ .flex-fill .app-header {
    left: 70px;
}

/* ============================================
   PREVENT CLS (Cumulative Layout Shift)
   ============================================ */

/* Reserve space for all icons */
.fas, .far, .fab, .fal {
    display: inline-block;
    min-width: 1em;
    text-align: center;
}

/* Reserve space for buttons */
button, .btn {
    min-height: 2.25rem; /* 36px */
    contain: layout style;
}

/* Prevent table shifts */
table {
    table-layout: fixed;
    width: 100%;
}

/* ============================================
   DROPDOWN MENUS STYLING
   ============================================ */
.dropdown {
    position: relative;
}

.dropdown-menu {
    position: absolute;
    z-index: 1000;
    display: none;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 0.5rem;
    margin-top: 0.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    min-width: 12rem;
}

.dropdown-menu.show {
    display: block;
    animation: dropdownFadeIn 0.15s ease;
}

.dropdown-menu-end {
    right: 0;
    left: auto;
}

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

.dropdown-item {
    color: var(--text-secondary);
    padding: 0.625rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.dropdown-item:hover,
.dropdown-item:focus {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.dropdown-item i {
    width: 1rem;
    text-align: center;
    opacity: 0;
    flex-shrink: 0;
}

.dropdown-item.active i {
    opacity: 1;
}

.dropdown-item:not(.active) i.fa-check {
    opacity: 0;
}

.dropdown-item.active {
    background-color: var(--accent-light);
    color: var(--accent-primary);
    font-weight: 600;
}

.dropdown-item.text-danger {
    color: var(--danger);
}

.dropdown-item.text-danger i {
    opacity: 0.7;
}

.dropdown-item.text-danger:hover {
    background-color: rgba(249, 104, 104, 0.15);
    color: var(--danger);
}

.dropdown-item.text-danger:hover i {
    opacity: 1;
}

.dropdown-divider {
    border-top: 1px solid var(--border-color);
    margin: 0.5rem 0;
}

.dropdown-toggle {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    transition: all 0.2s ease;
}

.dropdown-toggle:hover,
.dropdown-toggle:focus {
    background-color: var(--bg-tertiary);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.dropdown-toggle::after {
    margin-left: 0.5rem;
}

