/* ==========================================================================
   Админ-панель: левое меню, сетка, таблицы
   ========================================================================== */

.admin-wrapper {
    display: flex;
    gap: 24px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px clamp(16px, 4vw, 32px);
    min-height: calc(100vh - 200px);
}

.admin-sidebar {
    width: 280px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 0;
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--nav-h) + 24px);
    height: fit-content;
    max-height: calc(100vh - var(--nav-h) - 48px);
    overflow-y: auto;
}

.admin-sidebar__header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.admin-sidebar__logo {
    font-size: 1.5rem;
}

.admin-sidebar__title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-0);
}

.admin-sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 12px;
}

/* Элемент меню — ссылка */
.admin-menu__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--fast) var(--ease);
    position: relative;
    font-size: 0.92rem;
    font-weight: 500;
}

.admin-menu__link:hover {
    background: var(--surface-hover);
    color: var(--text-0);
}

.admin-menu__link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.admin-menu__link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: var(--radius-full);
}

/* Группа меню */
.admin-menu__group {
    margin-top: 8px;
}

.admin-menu__group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    color: var(--text-3);
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    user-select: none;
    transition: color var(--fast) var(--ease);
}

.admin-menu__group-header:hover {
    color: var(--text-2);
}

/* Анимированная стрелка */
.admin-menu__arrow {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    transition: transform var(--base) var(--ease);
    color: var(--accent);
}

.admin-menu__arrow svg {
    width: 14px;
    height: 14px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.admin-menu__group.open .admin-menu__arrow {
    transform: rotate(90deg);
}

.admin-menu__group-items {
    display: none;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
}

.admin-menu__group.open .admin-menu__group-items {
    display: flex;
}

/* Ссылка внутри группы */
.admin-menu__group-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px 8px 28px;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--fast) var(--ease);
    position: relative;
    font-size: 0.88rem;
    font-weight: 500;
}

.admin-menu__group-link:hover {
    background: var(--surface-hover);
    color: var(--text-0);
}

.admin-menu__group-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.admin-menu__group-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: var(--radius-full);
}

/* Бейдж */
.admin-menu__badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    font-weight: 600;
    min-width: 20px;
    text-align: center;
}

/* Индикатор загрузки */
.admin-menu__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-3);
    font-size: 0.85rem;
}

.admin-menu__spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: admin-menu-spin 0.6s linear infinite;
}

@keyframes admin-menu-spin {
    to { transform: rotate(360deg); }
}

/* Основной контент */
.admin-content {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
}

.admin-content__header {
    margin-bottom: 24px;
}

.admin-content__header h1 {
    margin-bottom: 4px;
}

.admin-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    padding: 20px;
    text-align: center;
    border-radius: var(--radius);
}

.stat-card__icon {
    font-size: 1.8rem;
    margin-bottom: 8px;
}

.stat-card__num {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-0);
    margin-bottom: 4px;
}

.stat-card__label {
    color: var(--text-3);
    font-size: 0.85rem;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.admin-table th {
    color: var(--text-2);
    font-weight: 600;
    font-size: 0.85rem;
}

/* Адаптивность для админ-панели */
@media (max-width: 1024px) {
    .admin-wrapper {
        flex-direction: column;
        padding: 16px;
        gap: 16px;
    }

    .admin-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 300px;
        height: 100vh;
        z-index: 99;
        transform: translateX(-100%);
        padding-top: var(--nav-h);
        box-shadow: var(--shadow-lg);
        border-radius: 0;
        overflow-y: auto;
    }

    .admin-sidebar.open {
        transform: translateX(0);
    }

    .admin-content {
        width: 100%;
        padding-left: 0;
    }
}

@media (max-width: 768px) {
    .admin-wrapper {
        padding: 12px;
        gap: 12px;
    }

    .admin-sidebar {
        width: 280px;
    }

    .admin-stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card__num {
        font-size: 1.5rem;
    }

    .admin-table {
        font-size: 0.85rem;
    }

    .admin-table th,
    .admin-table td {
        padding: 8px;
    }

    .roles-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .admin-wrapper {
        padding: 8px;
    }

    .admin-sidebar {
        width: 100%;
    }

    .admin-stats-grid {
        grid-template-columns: 1fr;
    }

    .admin-content__header h1 {
        font-size: 1.5rem;
    }
}

/* ==========================================================================
   Роли и права
   ========================================================================== */

.roles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.role-card {
    background: var(--bg-1);
    border: 1px solid var(--border);
    padding: 20px;
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
}

.role-card__header {
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.role-card__header h3 {
    margin: 0 0 6px;
    font-size: 1.1rem;
    color: var(--text-0);
}

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-3);
    color: var(--text-2);
    font-size: 0.75rem;
    font-family: var(--mono);
    border-radius: var(--radius-sm);
}

.role-permissions {
    flex: 1;
    margin-bottom: 16px;
}

.perm-group {
    margin-bottom: 12px;
}

.perm-group-title {
    display: block;
    margin-bottom: 8px;
    color: var(--text-2);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.perm-item {
    display: flex;
    align-items: center;
    padding: 8px;
    background: var(--bg-2);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.2s;
    border-radius: var(--radius-sm);
}

.perm-item .perm-label {
    flex: 1;
}

.perm-item:hover {
    background: var(--bg-3);
}

.perm-checkbox {
    appearance: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    background: var(--bg-1);
    margin-right: 10px;
    position: relative;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
}

.perm-checkbox:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.perm-checkbox:checked::after {
    content: '✓';
    position: absolute;
    color: #fff;
    font-size: 12px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.perm-label {
    font-weight: 500;
    font-size: 0.9rem;
}

.perm-desc {
    font-size: 0.75rem;
    color: var(--text-3);
    margin-left: auto;
}

.perm-exclude .perm-item {
    background: rgba(239, 68, 68, 0.05);
    border: 1px solid rgba(239, 68, 68, 0.1);
}

.role-card__footer {
    text-align: right;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.save-role-perms {
    opacity: 0.7;
    transition: opacity 0.2s;
    border-radius: var(--radius-sm);
}

.save-role-perms.changed {
    opacity: 1;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* ==========================================================================
   Меню пользователя (левое меню)
   ========================================================================== */

.user-sidebar {
    width: 260px;
    background: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 0;
    flex-shrink: 0;
    position: sticky;
    top: calc(var(--nav-h) + 24px);
    height: fit-content;
    max-height: calc(100vh - var(--nav-h) - 48px);
    overflow-y: auto;
}

.user-sidebar__header {
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-sidebar__logo {
    font-size: 1.5rem;
}

.user-sidebar__title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-0);
}

.user-sidebar__nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 12px;
}

/* Элемент меню пользователя */
.user-menu__link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-2);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--fast) var(--ease);
    position: relative;
    font-size: 0.92rem;
    font-weight: 500;
}

.user-menu__link:hover {
    background: var(--surface-hover);
    color: var(--text-0);
}

.user-menu__link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.user-menu__link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: var(--accent);
    border-radius: var(--radius-full);
}

/* Индикатор загрузки */
.user-menu__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-3);
    font-size: 0.85rem;
}

.user-menu__spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: user-menu-spin 0.6s linear infinite;
}

@keyframes user-menu-spin {
    to { transform: rotate(360deg); }
}

/* Макет с боковым меню для обычных страниц */
.user-page {
    display: flex;
    gap: 24px;
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px clamp(16px, 4vw, 32px);
    min-height: calc(100vh - 200px);
}

.user-content {
    flex: 1;
    min-width: 0;
}

@media (max-width: 768px) {
    .user-page {
        flex-direction: column;
        padding: 16px;
        gap: 16px;
    }

    .user-sidebar {
        width: 100%;
        height: auto;
        position: relative;
        top: 0;
        max-height: none;
    }

    .user-sidebar__nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
        padding: 0;
    }

    .user-menu__link {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* ==========================================================================
   WYSIWYG Редактор (локальный)
   ========================================================================== */

.editor-wrapper {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 8px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
}

.editor-toolbar button {
    background: var(--bg-1);
    border: 1px solid var(--border);
    color: var(--text-0);
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.82rem;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.editor-toolbar button:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

.editor-toolbar button:active {
    transform: scale(0.95);
}

.editor-sep {
    width: 1px;
    background: var(--border);
    margin: 2px 4px;
}

.editor-area {
    min-height: 300px;
    max-height: 500px;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-0);
    color: var(--text-0);
    font-family: Inter, sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
    outline: none;
}

.editor-area:focus {
    background: var(--bg-1);
}

.editor-area h2 {
    font-size: 1.5rem;
    margin: 16px 0 8px;
    color: var(--text-0);
}

.editor-area h3 {
    font-size: 1.25rem;
    margin: 12px 0 6px;
    color: var(--text-0);
}

.editor-area pre {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.editor-area code {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85rem;
}

.editor-area table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
}

.editor-area table th,
.editor-area table td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}

.editor-area table th {
    background: var(--bg-2);
    font-weight: 600;
}

.editor-area img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
}

.editor-area blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-2);
    font-style: italic;
}

.editor-toolbar--secondary {
    border-top: 1px solid var(--border);
}

.editor-toolbar__group {
    display: flex;
    gap: 2px;
    align-items: center;
}

.editor-statusbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
    background: var(--bg-2);
    border-top: 1px solid var(--border);
    font-size: 0.78rem;
    color: var(--text-3);
}

.editor-statusbar__html-toggle {
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    transition: all 0.15s ease;
}

.editor-statusbar__html-toggle:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.editor-area hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 16px 0;
}

.editor-area h1 {
    font-size: 1.8rem;
    margin: 20px 0 10px;
    color: var(--text-0);
}

.editor-area a {
    color: var(--accent);
    text-decoration: underline;
}
