/* =========================================================
   Каркас панели: закреплённая боковая панель + рабочая область
   на всю ширину. Переменные темы и размеры — в tokens.css.
   ========================================================= */

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-main);
    font-weight: 500;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    color: inherit;
}

.app-shell,
.layout {
    min-height: 100vh;
    display: flex;
}

/* ---------- Боковая панель (всегда закреплена) ---------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: var(--sidebar-width);
    height: 100vh;
    padding: 16px 12px 12px;
    display: flex;
    flex-direction: column;
    color: var(--sidebar-ink);
    background: var(--sidebar-bg), var(--sidebar-base);
    border-right: 1px solid var(--sidebar-line);
}

.sidebar-brand {
    flex: 0 0 auto;
    margin-bottom: 14px;
}

.brand-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 6px;
    text-decoration: none;
}

.brand-mark {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border-radius: 11px;
    display: inline-grid;
    place-items: center;
    color: #ffffff;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: var(--brand-mark);
}

.brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    line-height: 1.1;
}

.brand-text b {
    color: #ffffff;
    font-size: 15px;
    font-weight: 800;
}

.brand-text small {
    color: var(--sidebar-ink-2);
    font-size: 11px;
    font-weight: 500;
}

.sidebar-search-wrap {
    flex: 0 0 auto;
    padding-bottom: 12px;
}

.sidebar-search {
    width: 100%;
    height: 40px;
    padding: 0 12px 0 38px;
    color: var(--sidebar-ink);
    border: 1px solid var(--sidebar-line);
    border-radius: var(--radius-md);
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='17' height='17' viewBox='0 0 24 24' fill='none' stroke='%239aa3b5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") no-repeat 13px center,
        var(--sidebar-field);
    font-family: inherit;
    font-size: 13px;
    outline: none;
}

.sidebar-search::placeholder {
    color: var(--sidebar-ink-2);
}

.sidebar-search:focus {
    border-color: var(--accent);
    box-shadow: var(--focus-ring);
}

.sidebar-nav {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: 0 -4px;
    padding: 0 4px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.35) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.35);
    border-radius: var(--radius-pill);
}

/* Группа меню */

.nav-group-title {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--sidebar-ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
    transition: background var(--ease), color var(--ease);
}

.nav-group-title:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.06);
}

.nav-group.active > .nav-group-title {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.nav-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-icon {
    flex: 0 0 20px;
    width: 20px;
    height: 20px;
    display: inline-grid;
    place-items: center;
    color: var(--sidebar-icon);
}

.nav-group.active > .nav-group-title .nav-icon {
    color: #ffffff;
}

.nav-caret {
    flex: 0 0 7px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--sidebar-ink-2);
    border-bottom: 1.5px solid var(--sidebar-ink-2);
    transform: rotate(45deg) translateY(-2px);
    transition: transform var(--ease);
}

.nav-group.open .nav-caret {
    transform: rotate(225deg) translateY(-1px);
}

/* Подменю */

.nav-submenu {
    display: none;
    margin: 2px 0 6px 20px;
    padding-left: 12px;
    border-left: 1px solid var(--sidebar-line);
}

.nav-group.open .nav-submenu,
.nav-group.search-open .nav-submenu {
    display: block;
}

.nav-sub-link {
    display: block;
    padding: 7px 10px;
    margin: 1px 0;
    border-radius: var(--radius-sm);
    color: var(--sidebar-ink-2);
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
    transition: background var(--ease), color var(--ease);
}

.nav-sub-link:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.06);
}

.nav-sub-link.active {
    color: #ffffff;
    background: var(--accent);
}

/* ---------- Рабочая область на всю ширину ---------- */

.workspace {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: var(--sidebar-width);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 45;
    height: var(--topbar-height);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.topbar-left,
.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: inline-grid;
    place-items: center;
    font-weight: 800;
    text-transform: uppercase;
    background: var(--accent-soft);
    color: var(--accent-ink);
}

.user-name {
    max-width: 260px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    cursor: pointer;
    transition: background var(--ease), border-color var(--ease);
}

/* Кнопка меню — только на узких экранах */
.sidebar-toggle {
    display: none;
    place-items: center;
    align-content: center;
    gap: 4px;
    padding: 10px;
}

.sidebar-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    border-radius: var(--radius-pill);
    background: currentColor;
}

.content {
    min-height: calc(100vh - var(--topbar-height));
    padding: var(--page-pad-top) var(--page-pad-x) 48px;
}

.content-inner {
    width: 100%;
}

.page {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* Шапка страницы: заголовок слева, действия справа (как PageLayout в AdminLTE) */
.top,
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px 16px;
    margin-bottom: 20px;
}

.top h1,
.page-header h1,
.detail-header h1,
.hero-panel h1 {
    margin: 0;
    color: var(--ink);
    font-size: clamp(22px, 1.8vw, 28px);
    line-height: 1.2;
    letter-spacing: -0.02em;
    font-weight: 800;
}

.filter-form {
    flex: 0 0 auto;
}

/* ---------- Шапка страницы ----------
   Заголовок с действиями закреплён под верхней панелью и вместе с ней
   образует одну шапку: сверху цепочка разделов и профиль, ниже —
   название страницы, статус записи и кнопки. При прокрутке длинной
   формы «Сохранить» и статус всегда на виду. */
.content:has(> .content-inner > .page > .top),
.content:has(> .content-inner > .page > form > .top),
.content:has(> .content-inner > .page > .page-header) {
    padding-top: 0;
}

.workspace:has(.page > .top, .page > form > .top, .page > .page-header) .topbar {
    border-bottom-color: transparent;
}

.page > .top,
.page > form > .top,
.page > .page-header {
    position: sticky;
    top: var(--topbar-height);
    z-index: 40;
    min-height: 56px;
    margin: 0 calc(-1 * var(--page-pad-x)) 20px;
    padding: 0 var(--page-pad-x) 14px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.page > .top h1,
.page > form > .top h1,
.page > .page-header h1 {
    font-size: clamp(20px, 1.5vw, 24px);
}

/* Заголовок и статус записи («Сохранено», «Изменён», «Новая») рядом */
.page-title {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    min-width: 0;
}

.page-title #formStatus {
    padding: 4px 10px;
    font-size: 12px;
    box-shadow: none;
}

/* ---------- Меню «⋯» с редкими и опасными действиями ---------- */

.more-menu {
    position: relative;
}

.more-menu > summary {
    list-style: none;
    cursor: pointer;
}

.more-menu > summary::-webkit-details-marker {
    display: none;
}

.more-menu-toggle {
    padding-left: 11px;
    padding-right: 11px;
}

.more-menu-panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 70;
    min-width: 230px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

/* ---------- Вкладки внутри страницы ---------- */

.page-tabs {
    display: flex;
    gap: 4px;
    margin: 0 0 18px;
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
}

.page-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 0;
    background: transparent;
    color: var(--ink-2);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.page-tab:hover {
    color: var(--ink);
}

.page-tab[aria-selected="true"] {
    color: var(--accent-ink);
}

.page-tab[aria-selected="true"]::after {
    content: "";
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: -1px;
    height: 2px;
    border-radius: 2px;
    background: var(--accent);
}

.page-tab-count {
    min-width: 22px;
    padding: 1px 7px;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    color: var(--ink-2);
    font-size: 12px;
    text-align: center;
}

[data-tab-panel][hidden] {
    display: none !important;
}

/* На телефоне кнопки шапки — в одну строку, чтобы закреплённая шапка
   не занимала пол-экрана (обычные .btn там растягиваются на всю ширину). */
@media (max-width: 640px) {
    .page > .top,
    .page > form > .top,
    .page > .page-header {
        padding-bottom: 10px;
    }

    .page .top .actions-row,
    .page .page-header .actions-row {
        flex-wrap: nowrap;
    }

    .page .top .actions-row > .btn,
    .page .page-header .actions-row > .btn {
        flex: 1 1 0;
        width: auto;
        min-width: 0;
    }

    .actions-row .more-menu-toggle {
        width: auto;
    }
}

.sidebar-backdrop {
    display: none;
}

/* ---------- Разделы меню (как подписи групп в AdminLTE) ---------- */

.nav-section + .nav-section {
    margin-top: 10px;
}

.nav-section-title {
    padding: 8px 10px 6px;
    color: var(--sidebar-ink-2);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .1em;
    opacity: .8;
}

/* ---------- Хлебные крошки в шапке ---------- */

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    color: var(--ink-2);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
}

.crumb-home {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    display: inline-grid;
    place-items: center;
    border-radius: var(--radius-sm);
    color: var(--ink-2);
    transition: background var(--ease), color var(--ease);
}

.crumb-home:hover {
    color: var(--accent-ink);
    background: var(--accent-soft);
}

.crumb {
    color: var(--ink-2);
    text-decoration: none;
}

.crumb:hover {
    color: var(--accent-ink);
}

.crumb-sep {
    width: 6px;
    height: 6px;
    flex: 0 0 6px;
    border-top: 1.5px solid var(--ink-3);
    border-right: 1.5px solid var(--ink-3);
    transform: rotate(45deg);
}

.crumb-current {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--ink);
    font-weight: 700;
}

/* ---------- Меню пользователя (выпадающее, без JS — <details>) ---------- */

.user-menu {
    position: relative;
}

.user-menu-toggle {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 3px 10px 3px 3px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    list-style: none;
    transition: background var(--ease), border-color var(--ease);
}

.user-menu-toggle::-webkit-details-marker {
    display: none;
}

.user-menu-toggle:hover,
.user-menu[open] .user-menu-toggle {
    background: var(--surface);
    border-color: var(--line);
}

.user-menu-caret {
    color: var(--ink-3);
    transition: transform var(--ease);
}

.user-menu[open] .user-menu-caret {
    transform: rotate(180deg);
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 70;
    width: 260px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-pop);
}

.user-menu-head {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 10px 12px;
    margin-bottom: 6px;
    border-bottom: 1px solid var(--line);
}

.user-menu-head b {
    color: var(--ink);
    font-size: 14px;
    font-weight: 700;
}

.user-menu-head small {
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 500;
}

.user-menu-panel form {
    margin: 0;
}

.user-menu-item,
.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.user-menu-item:hover,
.menu-item:hover {
    background: var(--surface-2);
}

.user-menu-item.danger,
.menu-item.danger {
    color: var(--danger-ink);
}

.user-menu-item.danger:hover,
.menu-item.danger:hover {
    background: var(--danger-soft);
}

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

.theme-toggle {
    display: inline-grid;
    place-items: center;
}

.theme-toggle:hover {
    background: var(--surface-2);
}

/* В светлой теме предлагаем тёмную (луна), в тёмной — светлую (солнце) */
.theme-icon-sun,
[data-theme="dark"] .theme-icon-moon {
    display: none;
}

[data-theme="dark"] .theme-icon-sun {
    display: block;
}

/* ---------- Узкие экраны: панель выезжает по кнопке меню ---------- */

@media (max-width: 960px) {
    .sidebar {
        transform: translateX(-105%);
        transition: transform .22s ease;
        box-shadow: var(--shadow-sidebar);
    }

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

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 55;
        background: var(--overlay);
        backdrop-filter: blur(4px);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .workspace {
        margin-left: 0;
    }

    .sidebar-toggle {
        display: inline-grid;
    }

    .topbar {
        padding: 0 16px;
    }

    :root {
        --page-pad-x: 16px;
        --page-pad-top: 20px;
    }

    .content {
        padding-bottom: 40px;
    }

    .user-name,
    .user-menu-caret,
    .breadcrumbs .crumb,
    .breadcrumbs .crumb + .crumb-sep {
        display: none;
    }
}

