/* =========================================================
   Каркас страницы: сайдбар, шапка, модалки, уведомления
   ========================================================= */

:root {
    --sidebar-w: 17rem;
    --sidebar-w-collapsed: 4.75rem;
    /* Высота липкой шапки — её используют sticky-элементы (напр. панель недели) */
    --topbar-h: 4.75rem;
}

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

/* --- Сайдбар --- */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 50;
    display: flex; flex-direction: column; width: var(--sidebar-w); padding: 1.5rem;
    background: var(--c-surface); border-right: 1px solid var(--c-border);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), width 0.25s; 
    overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }

.sidebar-brand {
    display: flex; align-items: center; gap: 0.75rem;
    margin-bottom: 2rem; text-decoration: none; color: var(--c-text);
}
.sidebar-brand-mark {
    display: flex; align-items: center; justify-content: center;
    width: 2.5rem; height: 2.5rem; border-radius: var(--r-sm);
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet));
    color: #fff;
}
.sidebar-brand-name { font-size: 1rem; font-weight: 800; letter-spacing: -0.01em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar-section { margin: 1.5rem 0 0.5rem; padding: 0 1rem; }

.sidebar-link {
    display: flex; align-items: center; gap: 0.875rem;
    padding: 0.875rem 1rem; border-radius: var(--r-md);
    font-size: 0.875rem; font-weight: 700; color: var(--c-text-muted);
    text-decoration: none; transition: background-color 0.15s, color 0.15s, transform 0.1s;
}
.sidebar-link .icon { width: 1.125rem; height: 1.125rem; }
.sidebar-link:hover { background: var(--c-bg-subtle); color: var(--c-text); transform: translateX(2px); }
.sidebar-link.active { background: var(--c-primary-soft); color: var(--c-primary); }

.sidebar-footer { margin-top: auto; padding-top: 1.5rem; }
.sidebar-user {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.875rem; margin-bottom: 0.5rem;
    background: var(--c-bg-subtle); border: 1px solid var(--c-border); border-radius: var(--r-md);
}
.sidebar-avatar {
    display: flex; align-items: center; justify-content: center;
    width: 2.25rem; height: 2.25rem; flex-shrink: 0;
    background: linear-gradient(135deg, var(--c-primary), var(--c-violet)); color: #fff;
    border-radius: 0.625rem; font-size: 0.875rem; font-weight: 800;
    text-transform: uppercase; text-decoration: none;
    transition: transform 0.15s, box-shadow 0.15s;
}
a.sidebar-avatar:hover { color: #fff; transform: scale(1.05); box-shadow: var(--shadow-primary); }
.sidebar-username {
    font-size: 0.8125rem; font-weight: 700; color: var(--c-text);
    text-decoration: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
a.sidebar-username:hover { color: var(--c-primary); }

.sidebar-collapse {
    display: flex; align-items: center; justify-content: center;
    width: 100%; margin-top: 0.75rem; padding: 0.75rem 1rem;
    background: var(--c-bg-subtle); color: var(--c-text-muted);
    border: 1px solid var(--c-border); border-radius: var(--r-md); cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.sidebar-collapse:hover { color: var(--c-primary); border-color: var(--c-primary); background: var(--c-selected-bg); }
.sidebar-collapse svg { transition: transform 0.25s; }

.sidebar-overlay {
    position: fixed; inset: 0; z-index: 45;
    background: var(--c-overlay); backdrop-filter: blur(2px);
    display: none;
}
.sidebar-overlay.open { display: block; }

/* --- Основная область --- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    position: sticky; top: 0; z-index: 40;
    display: flex; align-items: center; gap: 1rem;
    min-height: var(--topbar-h); height: auto;
    padding: 0.625rem var(--sp-page);
    background: var(--c-topbar-bg); backdrop-filter: blur(14px);
    border-bottom: 1px solid transparent; transition: border-color 0.2s;
}
.topbar.scrolled { border-bottom-color: var(--c-border-strong); }
.topbar-title { font-size: 1rem; font-weight: 800; }
.topbar-actions { display: flex; align-items: center; gap: 0.625rem; margin-left: auto; }

/* Группа действий шапки: на десктопе кнопки в ряд, на мобильных — меню «Ещё» */
.topbar-actions-group { position: relative; display: flex; align-items: center; }
.topbar-actions-row { display: flex; align-items: center; gap: 0.625rem; }
.more-toggle { display: none; }

.nav-toggle {
    display: flex; align-items: center; justify-content: center;
    width: 2.75rem; height: 2.75rem; flex-shrink: 0;
    background: var(--c-surface); color: var(--c-text-soft);
    border: 1px solid var(--c-border-strong); border-radius: var(--r-sm);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.nav-toggle:hover { color: var(--c-primary); border-color: var(--c-primary); background: var(--c-selected-bg); }

.content { flex: 1; padding: 1.5rem var(--sp-page) 4rem; }
.content-narrow { max-width: 60rem; margin: 0 auto; }

.page-head {
    display: flex; flex-wrap: wrap; align-items: flex-end; gap: 1rem;
    margin-bottom: 2rem;
}
.page-head-actions { display: flex; flex-wrap: wrap; gap: 0.625rem; margin-left: auto; }

/* На больших экранах сайдбар всегда виден */
@media (min-width: 1024px) {
    .sidebar { transform: translateX(0); }
    .main { margin-left: var(--sidebar-w); }
    .nav-toggle { display: none; }
    .sidebar-overlay { display: none !important; }
}

/* На планшетах/мобильных сайдбар — выдвижная панель: по высоте весь экран,
   по ширине половина (остальное — оверлей, тап по нему закрывает меню) */
@media (max-width: 1023px) {
    .sidebar {
        width: 50%; padding: 1.25rem;
    }
    .sidebar-brand { margin-bottom: 1.5rem; }
    .sidebar-collapse { display: none; }
}

/* --- Сворачивание сайдбара до иконок (только на десктопе) --- */
@media (min-width: 1024px) {
    .main { transition: margin-left 0.25s; }

    html.sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); padding-left: 0.75rem; padding-right: 0.75rem; }
    html.sb-collapsed .main { margin-left: var(--sidebar-w-collapsed); }

    html.sb-collapsed .sidebar-brand { justify-content: center; gap: 0; }
    html.sb-collapsed .sidebar-brand-name { display: none; }

    html.sb-collapsed .sidebar-link { justify-content: center; padding: 0.875rem 0.5rem; }
    html.sb-collapsed .sidebar-link-text { display: none; }
    html.sb-collapsed .sidebar-link .icon { width: 1.25rem; height: 1.25rem; }
    html.sb-collapsed .sidebar-link:hover { transform: none; }

    html.sb-collapsed .sidebar-user { justify-content: center; padding: 0.5rem; background: none; border: none; margin-bottom: 0.75rem; }
    html.sb-collapsed .sidebar-username { display: none; }

    html.sb-collapsed .sidebar-footer .btn { width: 100%; justify-content: center; padding: 0.625rem; }
    html.sb-collapsed .sidebar-collapse svg { transform: rotate(180deg); }
    html.sb-collapsed .sidebar-collapse { padding: 0.75rem; }
}

/* --- Модальные окна --- */
.modal {
    position: fixed; inset: 0; z-index: 200;
    display: none; align-items: center; justify-content: center;
    padding: 1rem; background: var(--c-modal-scrim); backdrop-filter: blur(6px);
}
.modal.open { display: flex; }
.modal-panel {
    width: 100%; max-width: 30rem; max-height: 90vh; overflow-y: auto;
    padding: 1.75rem; background: var(--c-surface);
    border-radius: var(--r-xl); box-shadow: var(--shadow-pop);
}
.modal-panel-wide { max-width: 44rem; }
.modal-confirm { max-width: 24rem; text-align: center; }
.modal-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.5rem; }
.modal-title { margin: 0; font-size: 1.25rem; font-weight: 800; }
.modal-close {
    display: flex; align-items: center; justify-content: center;
    margin-left: auto; width: 2.25rem; height: 2.25rem; flex-shrink: 0;
    background: var(--c-bg-subtle); color: var(--c-text-muted);
    border: none; border-radius: 0.625rem; cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--c-border); color: var(--c-text); }
.modal-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.modal-actions .btn { flex: 1; }

/* --- Уведомления --- */
#toast-container {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 600;
    display: flex; flex-direction: column-reverse; gap: 0.625rem;
    pointer-events: none;
}
.toast {
    display: flex; align-items: center; gap: 0.75rem;
    min-width: 16rem; max-width: 22rem; padding: 0.9375rem 1.25rem;
    border-radius: var(--r-md); color: var(--c-toast-text);
    font-size: 0.8125rem; font-weight: 700; line-height: 1.4;
    background: var(--c-toast-bg); box-shadow: var(--shadow-pop);
    transform: translateX(120%); opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast .icon { color: #4ade80; width: 1.25rem; height: 1.25rem; }
.toast-error { background: var(--c-danger); }
.toast-error .icon { color: #fff; }
.toast-info .icon { color: #818cf8; }

/* --- Кнопка «наверх» --- */
#back-to-top {
    position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 100;
    width: 3rem; height: 3rem; display: none;
    align-items: center; justify-content: center;
    background: var(--c-surface); color: var(--c-primary);
    border: 1px solid var(--c-border-strong); border-radius: var(--r-md);
    box-shadow: var(--shadow-card); cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
#back-to-top.visible { display: flex; }
#back-to-top:hover { background: linear-gradient(135deg, var(--c-primary), var(--c-violet)); color: #fff; border-color: transparent; }

/* --- Страница входа, регистрации и ошибок --- */
.centered-page {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: 1.5rem;
    background:
        radial-gradient(720px 460px at 100% 0%, var(--c-violet-soft), transparent 55%),
        radial-gradient(640px 420px at 0% 100%, var(--c-sky-soft), transparent 55%),
        var(--c-bg);
}
.centered-back {
    position: absolute; top: 1.25rem; left: 1.25rem;
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.625rem 1rem; border-radius: var(--r-md);
    color: var(--c-text-muted); font-size: 0.8125rem; font-weight: 700;
    text-decoration: none; transition: color 0.15s, background-color 0.15s;
}
.centered-back:hover { color: var(--c-primary); background: var(--c-selected-bg); }
.centered-card {
    position: relative;
    width: 100%; max-width: 26rem; padding: 2.5rem;
    background: var(--c-surface); border: 1px solid var(--c-border);
    border-radius: var(--r-xl); box-shadow: var(--shadow-pop); text-align: center;
}
.centered-card .field, .centered-card .field-label { text-align: left; }
.centered-head { text-align: center; margin-bottom: 1.75rem; }
.centered-mark {
    display: flex; align-items: center; justify-content: center;
    width: 3.5rem; height: 3.5rem; margin: 0 auto 1rem;
    background: var(--c-primary-soft); color: var(--c-primary);
    border-radius: var(--r-md);
}
.centered-mark-danger { background: var(--c-danger-soft); color: var(--c-danger); margin-bottom: 1.25rem; }
.centered-title { margin: 0; font-size: 1.375rem; font-weight: 800; letter-spacing: -0.01em; }
.centered-sub { margin: 0.375rem 0 0; font-size: 0.875rem; font-weight: 600; color: var(--c-text-muted); }
.centered-switch { margin-top: 1.5rem; font-size: 0.8125rem; font-weight: 600; color: var(--c-text-muted); }
.centered-switch a {
    color: var(--c-primary); text-decoration: none; font-weight: 700;
    transition: color 0.15s, text-decoration-color 0.15s;
    text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px;
}
.centered-switch a:hover { color: var(--c-primary-hover); text-decoration-color: currentColor; }
.centered-foot { margin-top: 1.75rem; display: flex; justify-content: center; }
.error-code { font-size: 3.5rem; font-weight: 800; line-height: 1; color: var(--c-primary); letter-spacing: -0.03em; }

/* --- Загрузка содержимого --- */
.page-loading { display: flex; justify-content: center; padding: 4rem 0; }

@media (max-width: 640px) {
    .centered-card { padding: 1.75rem; }

    /* Шапка: сворачиваем действия страницы в меню «Ещё» */
    .topbar { flex-wrap: wrap; row-gap: 0.5rem; }
    .topbar-actions { flex-wrap: wrap; }
    .more-toggle { display: inline-flex; }
    .topbar-actions-drop {
        position: absolute; top: calc(100% + 0.5rem); right: 0; z-index: 80;
        display: none; min-width: 12.5rem; padding: 0.5rem;
        background: var(--c-surface); border: 1px solid var(--c-border);
        border-radius: var(--r-lg); box-shadow: var(--shadow-pop);
    }
    .topbar-actions-drop.open { display: block; }
    .topbar-actions-row { flex-direction: column; align-items: stretch; gap: 0.375rem; }
    .topbar-actions-row .btn { width: 100%; justify-content: flex-start; }

    /* Заголовок страницы и все действия — строго в колонку */
    .page-head { flex-direction: column; align-items: stretch; gap: 1rem; }
    .page-head-actions { margin-left: 0; }
    .page-head-actions .btn { flex: 1; }
}