/* ========================================
   Цветовая палитра — тёмная тема
======================================== */

:root {
    color-scheme: dark;

    --background: #0f172a;
    --surface: #1e293b;
    --surface-secondary: #172033;
    --surface-hover: #293548;

    --border: #334155;

    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;

    --accent: #818cf8;
    --accent-solid: #4f46e5;
    --accent-hover: #4338ca;
    --accent-background: #312e81;
    --accent-text: #e0e7ff;

    --success: #4ade80;
    --success-background: #14532d;

    --warning: #facc15;
    --warning-background: #713f12;

    --danger: #f87171;
    --danger-background: #450a0a;

    --info: #60a5fa;
    --info-background: #1e3a8a;

    --shadow: 0 4px 16px rgba(0, 0, 0, 0.15);

    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;
    --topbar-height: 64px;

    --radius-small: 6px;
    --radius: 10px;
    --radius-large: 14px;

    --transition: 0.18s ease;

    --font-family: -apple-system, BlinkMacSystemFont,
        "Segoe UI", Arial, sans-serif;
}


/* ========================================
   Светлая тема
======================================== */

html[data-theme="light"] {
    color-scheme: light;

    --background: #f1f5f9;
    --surface: #ffffff;
    --surface-secondary: #f8fafc;
    --surface-hover: #e2e8f0;

    --border: #dbe3ec;

    --text: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;

    --accent: #4f46e5;
    --accent-solid: #4f46e5;
    --accent-hover: #4338ca;
    --accent-background: #e0e7ff;
    --accent-text: #3730a3;

    --success: #166534;
    --success-background: #dcfce7;

    --warning: #854d0e;
    --warning-background: #fef9c3;

    --danger: #b91c1c;
    --danger-background: #fee2e2;

    --info: #1d4ed8;
    --info-background: #dbeafe;

    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}


/* ========================================
   Общие настройки
======================================== */

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

body {
    min-height: 100vh;
    margin: 0;

    background: var(--background);
    color: var(--text);

    font-family: var(--font-family);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

img {
    max-width: 100%;
    display: block;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

::selection {
    background: var(--accent-background);
    color: var(--accent-text);
}


/* ========================================
   Полоса прокрутки
======================================== */

* {
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

::-webkit-scrollbar-track {
    background: transparent;
}


/* ========================================
   SVG-иконки
======================================== */

.nav-icon {
    width: 20px;
    height: 20px;

    flex-shrink: 0;

    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
}


/* ========================================
   Боковое меню
======================================== */

.sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;

    z-index: 100;

    width: var(--sidebar-width);

    display: flex;
    flex-direction: column;

    padding: 18px 14px;

    background: var(--surface);
    border-right: 1px solid var(--border);

    overflow-x: hidden;
    overflow-y: auto;

    transition:
        width var(--transition),
        transform var(--transition);
}


/* Логотип Journal */

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;

    min-height: 58px;

    padding: 5px 8px;
}

.sidebar-brand img {
    width: 48px;
    height: 48px;

    flex-shrink: 0;

    object-fit: contain;
}

.sidebar-brand-text {
    min-width: 0;

    display: flex;
    flex-direction: column;

    white-space: nowrap;
}

.brand-name {
    color: var(--text);

    font-size: 23px;
    font-weight: 700;

    letter-spacing: -0.5px;
}

.brand-description {
    color: var(--text-muted);
    font-size: 11px;
}


/* Разделители */

.sidebar-divider {
    height: 1px;

    flex-shrink: 0;

    margin: 15px 4px;

    background: var(--border);
}


/* Основное меню */

.sidebar-menu {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-section-title {
    padding: 5px 10px 8px;

    color: var(--text-muted);

    font-size: 10px;
    font-weight: 600;

    letter-spacing: 0.9px;
    text-transform: uppercase;
    white-space: nowrap;
}


/* Элемент меню */

.sidebar-link {
    width: 100%;
    min-height: 44px;

    display: flex;
    align-items: center;
    gap: 12px;

    padding: 11px 12px;

    background: transparent;
    border: none;
    border-radius: var(--radius);

    color: var(--text-secondary);

    font-size: 14px;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;

    transition:
        background var(--transition),
        color var(--transition);
}

.sidebar-link .nav-icon {
    color: var(--text-muted);
}

.sidebar-link:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.sidebar-link.active {
    background: var(--accent-background);
    color: var(--accent-text);
}

.sidebar-link.active .nav-icon {
    color: var(--accent-text);
}


/* Нижняя часть меню */

.sidebar-bottom {
    margin-top: auto;

    display: flex;
    flex-direction: column;

    gap: 4px;

    padding-top: 20px;
}


/* Переключатель темы */

html[data-theme="dark"] .theme-icon-moon {
    display: none;
}

html[data-theme="light"] .theme-icon-sun {
    display: none;
}


/* Карточка пользователя */

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;

    padding: 10px;

    border-radius: var(--radius);

    transition: background var(--transition);
}

.sidebar-user:hover {
    background: var(--surface-hover);
}

.sidebar-user.active {
    background: var(--accent-background);
}

.user-avatar {
    width: 36px;
    height: 36px;

    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    background: var(--accent-background);
    color: var(--accent-text);

    border-radius: 50%;
}

.user-info {
    min-width: 0;

    display: flex;
    flex-direction: column;

    gap: 2px;
}

.user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    color: var(--text);

    font-size: 13px;
    font-weight: 600;
}

.user-role {
    color: var(--text-muted);
    font-size: 11px;

    overflow-wrap: anywhere;
}


/* Кнопка выхода */

.logout-button:hover {
    color: var(--danger);
    background: var(--danger-background);
}

.logout-button:hover .nav-icon {
    color: var(--danger);
}


/* Основной бренд XR */

.sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: center;

    gap: 8px;

    padding: 8px 0;
}

.sidebar-footer span {
    color: var(--text-muted);

    font-size: 13px;
    font-weight: 400;
}

.sidebar-footer a {
    display: flex;
    align-items: center;
    justify-content: center;

    padding: 4px;

    border-radius: var(--radius-small);

    opacity: 0.8;

    transition: opacity var(--transition);
}

.sidebar-footer a:hover {
    opacity: 1;
}

.sidebar-footer img {
    width: 110px;
    height: auto;

    object-fit: contain;
}


/* ========================================
   Основная область
======================================== */

.workspace {
    min-width: 0;
    min-height: 100vh;

    margin-left: var(--sidebar-width);

    transition: margin-left var(--transition);
}


/* Верхняя панель */

.topbar {
    position: sticky;
    top: 0;

    z-index: 50;

    min-height: var(--topbar-height);

    display: flex;
    align-items: center;
    gap: 18px;

    padding: 12px 28px;

    background: var(--surface);

    border-bottom: 1px solid var(--border);
}

.icon-button {
    width: 38px;
    height: 38px;

    flex-shrink: 0;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    background: transparent;

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text-secondary);

    transition: background var(--transition);
}

.icon-button:hover {
    background: var(--surface-hover);
    color: var(--text);
}


/* Навигационная цепочка */

.breadcrumbs {
    min-width: 0;

    display: flex;
    align-items: center;
    gap: 10px;

    color: var(--text-muted);

    font-size: 13px;
}

.breadcrumbs a:hover {
    color: var(--accent);
}

.breadcrumbs span:last-child {
    color: var(--text);

    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.breadcrumb-separator {
    color: var(--text-muted);
}

.topbar-right {
    margin-left: auto;

    display: flex;
    align-items: center;
    gap: 12px;
}


/* Содержимое страницы */

.main-content {
    min-width: 0;

    padding: 30px;
}


/* ========================================
   Общие элементы страниц
======================================== */

/* Заголовки страниц */

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    flex-wrap: wrap;
    gap: 16px;

    margin-bottom: 28px;
}

.page-header h1 {
    margin: 0 0 6px;

    font-size: 28px;
    font-weight: 700;

    letter-spacing: -0.5px;
}

.page-header p {
    margin: 0;

    color: var(--text-muted);
    font-size: 14px;
}

.page-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}


/* Карточки */

.card {
    min-width: 0;

    padding: 22px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius-large);

    box-shadow: var(--shadow);
}

.card h2 {
    margin: 0 0 16px;

    font-size: 18px;
    font-weight: 600;
}

.card-grid {
    display: grid;

    grid-template-columns:
        repeat(auto-fit, minmax(min(240px, 100%), 1fr));

    gap: 18px;
}


/* ========================================
   Кнопки
======================================== */

.button {
    min-height: 40px;

    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;

    padding: 9px 16px;

    border: 1px solid transparent;
    border-radius: var(--radius-small);

    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;

    transition:
        background var(--transition),
        border-color var(--transition);
}

.button-primary {
    background: var(--accent-solid);
    color: #ffffff;
}

.button-primary:hover:not(:disabled) {
    background: var(--accent-hover);
}

.button-secondary {
    background: var(--surface-secondary);
    border-color: var(--border);
    color: var(--text);
}

.button-secondary:hover:not(:disabled) {
    background: var(--surface-hover);
}

.button-danger {
    background: var(--danger-background);
    color: var(--danger);
}

.button-danger:hover:not(:disabled) {
    border-color: var(--danger);
}


/* ========================================
   Формы
======================================== */

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;

    margin-bottom: 18px;
}

.form-group label {
    color: var(--text-secondary);

    font-size: 13px;
    font-weight: 500;
}

.form-control {
    width: 100%;
    min-height: 42px;

    padding: 10px 12px;

    background: var(--background);

    border: 1px solid var(--border);
    border-radius: var(--radius-small);

    color: var(--text);

    outline: none;

    transition: border-color var(--transition);
}

.form-control:focus {
    border-color: var(--accent);
    outline: 1px solid var(--accent);
    outline-offset: 0;
}

.form-control::placeholder {
    color: var(--text-muted);
}

textarea.form-control {
    min-height: 100px;
    resize: vertical;
}

.form-hint {
    color: var(--text-muted);
    font-size: 12px;
}


/* ========================================
   Таблицы
======================================== */

.table-wrapper {
    width: 100%;

    overflow-x: auto;

    background: var(--surface);

    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.data-table {
    width: 100%;

    border-collapse: separate;
    border-spacing: 0;

    font-size: 13px;
}

.data-table th,
.data-table td {
    padding: 12px 16px;

    border-bottom: 1px solid var(--border);

    text-align: left;
    vertical-align: middle;
}

.data-table th {
    background: var(--surface-secondary);
    color: var(--text-muted);

    font-size: 12px;
    font-weight: 600;

    white-space: nowrap;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover td {
    background: var(--surface-hover);
}


/* ========================================
   Статусы
======================================== */

.status {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    padding: 4px 9px;

    border-radius: var(--radius-small);

    font-size: 12px;
    font-weight: 500;
}

.status-success {
    background: var(--success-background);
    color: var(--success);
}

.status-warning {
    background: var(--warning-background);
    color: var(--warning);
}

.status-danger {
    background: var(--danger-background);
    color: var(--danger);
}

.status-info {
    background: var(--info-background);
    color: var(--info);
}

.status-neutral {
    background: var(--surface-hover);
    color: var(--text-secondary);
}


/* ========================================
   Системные уведомления
======================================== */

.notification-container {
    position: fixed;

    right: 24px;
    bottom: 24px;

    z-index: 500;

    width: 360px;
    max-width: calc(100vw - 48px);

    display: flex;
    flex-direction: column;
    gap: 10px;
}

.notification {
    padding: 14px 16px;

    background: var(--surface);

    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    border-radius: var(--radius);

    color: var(--text);

    box-shadow: var(--shadow);

    overflow-wrap: anywhere;
}

.notification-success {
    border-left-color: var(--success);
}

.notification-error {
    border-left-color: var(--danger);
}

.notification-warning {
    border-left-color: var(--warning);
}

.notification-info {
    border-left-color: var(--info);
}


/* ========================================
   Свёрнутое боковое меню
======================================== */

html.sidebar-collapsed .sidebar {
    width: var(--sidebar-collapsed-width);

    padding-left: 10px;
    padding-right: 10px;
}

html.sidebar-collapsed .workspace {
    margin-left: var(--sidebar-collapsed-width);
}

html.sidebar-collapsed .sidebar-brand-text,
html.sidebar-collapsed .sidebar-section-title,
html.sidebar-collapsed .sidebar-link span,
html.sidebar-collapsed .user-info,
html.sidebar-collapsed .sidebar-footer span {
    display: none;
}

html.sidebar-collapsed .sidebar-brand {
    justify-content: center;

    padding-left: 0;
    padding-right: 0;
}

html.sidebar-collapsed .sidebar-brand img {
    width: 42px;
    height: 42px;
}

html.sidebar-collapsed .sidebar-link {
    justify-content: center;

    padding-left: 0;
    padding-right: 0;
}

html.sidebar-collapsed .sidebar-user {
    justify-content: center;

    padding-left: 0;
    padding-right: 0;
}

html.sidebar-collapsed .sidebar-footer img {
    width: 110px;
    height: auto;
}


/* ========================================
   Мобильное меню
======================================== */

.sidebar-overlay {
    display: none;
}

@media (max-width: 768px) {

    .sidebar,
    html.sidebar-collapsed .sidebar {
        width: var(--sidebar-width);

        padding: 18px 14px;

        transform: translateX(-100%);

        visibility: hidden;
    }

    .workspace,
    html.sidebar-collapsed .workspace {
        margin-left: 0;
    }

    html.mobile-menu-open .sidebar {
        transform: translateX(0);

        visibility: visible;
    }

    html.mobile-menu-open .sidebar-overlay {
        position: fixed;
        inset: 0;

        z-index: 90;

        display: block;

        width: 100%;
        height: 100%;

        background: rgba(0, 0, 0, 0.55);
        border: none;
    }

    html.mobile-menu-open body {
        overflow: hidden;
    }

    html.sidebar-collapsed .sidebar-brand-text,
    html.sidebar-collapsed .user-info {
        display: flex;
    }

    html.sidebar-collapsed .sidebar-link span,
    html.sidebar-collapsed .sidebar-section-title,
    html.sidebar-collapsed .sidebar-footer span {
        display: block;
    }

    html.sidebar-collapsed .sidebar-brand {
        justify-content: flex-start;

        padding: 5px 8px;
    }

    html.sidebar-collapsed .sidebar-brand img {
        width: 48px;
        height: 48px;
    }

    html.sidebar-collapsed .sidebar-link {
        justify-content: flex-start;

        padding: 11px 12px;
    }

    html.sidebar-collapsed .sidebar-user {
        justify-content: flex-start;

        padding: 10px;
    }

    html.sidebar-collapsed .sidebar-footer img {
        width: 80px;
        height: 46px;
    }

    .topbar {
        padding: 12px 16px;
        gap: 12px;
    }

    .main-content {
        padding: 20px 16px;
    }

    .page-header h1 {
        font-size: 24px;
    }

    .card {
        padding: 16px;
    }

    .data-table th,
    .data-table td {
        padding: 10px 12px;
    }

    .notification-container {
        right: 12px;
        bottom: 12px;

        max-width: calc(100vw - 24px);
    }
}


/* ========================================
   Уменьшение анимаций
======================================== */

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
        scroll-behavior: auto !important;
    }
}