/* Каркас приложения: sidebar, topbar, bottom-tabs.
   Использует префикс .shell-* и понимает роль через атрибут [data-role] на body. */

/* ============== Sidebar ============== */
.shell-sidebar {
    position: sticky;
    top: 0;
    height: 100dvh;
    background: var(--color-bg-soft);
    border-right: 1px solid var(--color-line);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: var(--z-sidebar);
}

.shell-sidebar__brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) var(--space-5) var(--space-4);
    text-decoration: none;
    color: var(--color-text);
}

.shell-sidebar__brand-mark {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--accent);
    color: var(--accent-contrast);
    display: grid;
    place-items: center;
    font-weight: var(--fw-black);
    font-size: var(--fs-md);
    letter-spacing: -0.02em;
    flex-shrink: 0;
}

.shell-sidebar__brand-label {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    min-width: 0;
}
.shell-sidebar__brand-name {
    font-weight: var(--fw-black);
    font-size: var(--fs-md);
    letter-spacing: -0.01em;
}
.shell-sidebar__brand-meta {
    font-size: var(--fs-xs);
    color: var(--color-text-soft);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.shell-sidebar__nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--space-2) var(--space-3) var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.shell-sidebar__section-title {
    padding: var(--space-3) var(--space-3) var(--space-1);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-text-soft);
}

.shell-sidebar__item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 10px var(--space-3);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: var(--fw-semibold);
    font-size: var(--fs-sm);
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
}
.shell-sidebar__item:hover {
    background: var(--color-surface);
    color: var(--color-text);
}
.shell-sidebar__item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}
.shell-sidebar__item.is-active::before {
    content: "";
    position: absolute;
    left: -4px;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    border-radius: var(--radius-pill);
    background: var(--accent);
}

.shell-sidebar__item-icon {
    flex: 0 0 auto;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    font-size: 16px;
    line-height: 1;
}
.shell-sidebar__item-label { flex: 1 1 auto; min-width: 0; }
.shell-sidebar__item-note {
    font-size: var(--fs-xs);
    color: var(--color-text-soft);
    font-weight: var(--fw-regular);
    text-transform: none;
    letter-spacing: 0;
    margin-top: 2px;
}
.shell-sidebar__item-lock { font-size: var(--fs-xs); color: var(--color-warning); }
/* Бейдж «новых заданий» у пункта навбара (админ). Скрыт, когда счётчик 0 (не рендерится). */
.shell-sidebar__item-badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--color-danger, #e5484d);
    color: #fff;
    font-size: 11px;
    font-weight: var(--fw-bold, 700);
    line-height: 1;
}

.shell-sidebar__footer {
    padding: var(--space-3) var(--space-4) calc(var(--space-4) + var(--safe-bottom));
    border-top: 1px solid var(--color-line);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    background: var(--color-bg-soft);
}

/* Скрим оверлея — по умолчанию скрыт на всех экранах,
   на mobile показывается через body.is-sidebar-open (см. ниже). */
.shell-sidebar__scrim { display: none; }

.shell-sidebar__user {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2);
    border-radius: var(--radius-md);
}
.shell-sidebar__user-info { min-width: 0; line-height: 1.2; }
.shell-sidebar__user-name { font-weight: var(--fw-semibold); font-size: var(--fs-sm); color: var(--color-text); }
.shell-sidebar__user-meta { font-size: var(--fs-xs); color: var(--color-text-soft); }

/* ============== Topbar ============== */
.shell-topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: var(--topbar-height);
    padding: 0 var(--space-6);
    background: color-mix(in srgb, var(--color-bg) 85%, transparent);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--color-line);
}

.shell-topbar__title { font-weight: var(--fw-bold); font-size: var(--fs-md); color: var(--color-text); min-width: 0; }
.shell-topbar__actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

.shell-topbar__role-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 4px var(--space-3);
    border-radius: var(--radius-pill);
    background: var(--accent-soft);
    color: var(--accent);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ===== Переключатель темы — компактная иконка в строке аккаунта ===== */
.shell-sidebar__theme-btn {
    margin-left: auto;
    flex: none;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border: 1px solid var(--color-line);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.shell-sidebar__theme-btn:hover { background: var(--color-surface-2); border-color: var(--color-line-strong); }
.shell-sidebar__theme-btn:active { transform: scale(0.92); }
.shell-sidebar__theme-btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.shell-sidebar__theme-btn[hidden] { display: none; }
/* в свёрнутом сайдбаре (только аватар) компактную кнопку прячем */
body.ff-sidebar-collapsed .shell-sidebar__theme-btn,
body.aa-sidebar-collapsed .shell-sidebar__theme-btn,
body.ac-sidebar-collapsed .shell-sidebar__theme-btn { display: none; }

/* ===== Колокольчик уведомлений ===== */
.notif { position: relative; }
.notif__bell {
    position: relative; border: 0; background: transparent; cursor: pointer;
    font-size: 20px; line-height: 1; padding: 6px 8px; border-radius: var(--radius-md);
    transition: background var(--transition-fast);
}
.notif__bell:hover { background: var(--color-surface-2); }
.notif__badge {
    position: absolute; top: 0; right: 0;
    min-width: 17px; height: 17px; padding: 0 4px;
    background: var(--color-danger); color: #fff;
    border-radius: var(--radius-pill);
    font-size: 10px; font-weight: 800; line-height: 17px; text-align: center;
}
.notif__panel {
    position: absolute; top: calc(100% + 8px); right: 0;
    width: min(380px, calc(100vw - 24px));
    background: var(--color-surface);
    border: 1px solid var(--color-line-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 9000;
    overflow: hidden;
    animation: notif-in 140ms ease-out;
}
@keyframes notif-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.notif__head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--color-line);
}
.notif__readall {
    border: 0; background: transparent; color: var(--accent);
    font-size: 12px; font-weight: 600; cursor: pointer;
}
.notif__list { max-height: 60vh; overflow-y: auto; }
.notif__empty { padding: 28px 16px; text-align: center; color: var(--color-text-muted); font-size: var(--fs-sm); }
.notif__item {
    display: flex; gap: 10px; padding: 11px 14px;
    text-decoration: none; color: inherit;
    border-bottom: 1px solid var(--color-line);
    transition: background var(--transition-fast);
}
.notif__item:hover { background: var(--color-surface-2); }
.notif__item.is-unread { background: var(--accent-soft); }
.notif__item.is-unread:hover { background: color-mix(in srgb, var(--accent-soft) 80%, var(--accent) 10%); }
.notif__item-icon { font-size: 18px; line-height: 1.3; flex-shrink: 0; }
.notif__item-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.notif__item-title { font-weight: var(--fw-semibold); font-size: var(--fs-sm); }
.notif__item-text { font-size: 12px; color: var(--color-text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notif__item-time { font-size: 11px; color: var(--color-text-soft); }

.shell-topbar__menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-line);
    background: var(--color-surface);
    color: var(--color-text);
    align-items: center;
    justify-content: center;
}

/* ============== Bottom tabs (mobile) ============== */
.shell-bottom-tabs {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: var(--z-bottom-tabs);
    display: none;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3) calc(var(--space-2) + var(--safe-bottom));
    border-top: 1px solid var(--color-line);
    background: color-mix(in srgb, var(--color-bg) 92%, transparent);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    overflow-x: auto;
    scrollbar-width: none;
}
.shell-bottom-tabs::-webkit-scrollbar { display: none; }

.shell-bottom-tabs__item {
    flex: 0 0 auto;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 72px;
    min-height: 52px;
    padding: 6px var(--space-3);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 10px;
    font-weight: var(--fw-bold);
    line-height: 1.1;
    text-decoration: none;
    white-space: nowrap;
}
.shell-bottom-tabs__item-icon { font-size: 18px; line-height: 1; }
.shell-bottom-tabs__item.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-contrast);
}

/* Клиент: фиксированный набор из 5 важных вкладок — раскладываем равномерно на всю
   ширину экрана (без горизонтального скролла, чтобы «Поручения» не уезжали за край).
   Админ/бухгалтер оставляем на прокрутке — у них пунктов больше. */
body[data-role="user"] .shell-bottom-tabs {
    gap: 6px;
    padding-left: var(--space-2);
    padding-right: var(--space-2);
    overflow-x: hidden;
}
body[data-role="user"] .shell-bottom-tabs__item {
    flex: 1 1 0;
    min-width: 0;
    padding-left: 2px;
    padding-right: 2px;
    font-size: 9px;
    letter-spacing: -0.01em;
}
body[data-role="user"] .shell-bottom-tabs__item > span:last-child {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============== Auth shell ============== */
.shell-auth {
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: var(--space-5);
    background:
        radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent) 0%, transparent 60%),
        radial-gradient(800px 400px at 110% 110%, color-mix(in srgb, var(--accent) 12%, transparent) 0%, transparent 50%),
        var(--color-bg);
}

.shell-auth__panel {
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border: 1px solid var(--color-line);
    border-radius: var(--radius-xl);
    padding: var(--space-7) var(--space-6);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.shell-auth__brand {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    text-align: center;
}
.shell-auth__brand-mark {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-lg);
    background: var(--accent);
    color: var(--accent-contrast);
    display: grid;
    place-items: center;
    font-size: var(--fs-xl);
    font-weight: var(--fw-black);
    letter-spacing: -0.02em;
}
.shell-auth__title { font-size: var(--fs-2xl); font-weight: var(--fw-black); line-height: 1; color: var(--color-text); }
.shell-auth__subtitle { color: var(--color-text-muted); font-size: var(--fs-sm); }

.shell-auth__footer { color: var(--color-text-muted); text-align: center; font-size: var(--fs-sm); }

/* ============== Responsive ============== */
@media (max-width: 980px) {
    .shell-sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100dvh;
        width: min(86vw, 320px);
        transform: translateX(-100%);
        transition: transform var(--transition-md);
        box-shadow: var(--shadow-lg);
    }
    body.is-sidebar-open .shell-sidebar { transform: translateX(0); }

    .shell-sidebar__scrim {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: calc(var(--z-sidebar) - 1);
    }
    body.is-sidebar-open .shell-sidebar__scrim { display: block; }

    .shell-topbar { padding: 0 var(--space-3); }
    .shell-topbar__menu-btn { display: inline-flex; }

    .shell-bottom-tabs { display: flex; }
    body[data-role="auth"] .shell-bottom-tabs,
    body[data-role="public"] .shell-bottom-tabs { display: none; }

    .shell-auth__panel { padding: var(--space-5) var(--space-4); border-radius: var(--radius-lg); }
}

/* ============== Sidebar collapse toggle + compact mode (desktop) ============== */
.shell-sidebar__collapse {
    display: none;  /* hidden on mobile (sidebar is off-canvas there) */
    align-items: center; gap: 6px;
    width: 100%; padding: 8px 10px;
    margin: 6px 0;
    border: 1px solid var(--color-line); border-radius: var(--radius-sm);
    background: var(--color-surface); color: var(--color-text-muted);
    font-size: 12px; font-weight: var(--fw-semibold); cursor: pointer;
}
.shell-sidebar__collapse:hover { background: var(--color-bg-soft); color: var(--color-text); }
@media (min-width: 981px) {
    .shell-sidebar__collapse { display: inline-flex; }
}
/* ---- Compact mode: только иконки + brand mark; работает для любой роли (ff/aa/ac). ---- */
body.ff-sidebar-collapsed .shell-sidebar,
body.aa-sidebar-collapsed .shell-sidebar,
body.ac-sidebar-collapsed .shell-sidebar {
    width: var(--sidebar-collapsed-width, 72px);
    padding-left: 4px; padding-right: 4px;
}
body.ff-sidebar-collapsed .shell-sidebar__brand-label,
body.aa-sidebar-collapsed .shell-sidebar__brand-label,
body.ac-sidebar-collapsed .shell-sidebar__brand-label,
body.ff-sidebar-collapsed .shell-sidebar__item-label,
body.aa-sidebar-collapsed .shell-sidebar__item-label,
body.ac-sidebar-collapsed .shell-sidebar__item-label,
body.ff-sidebar-collapsed .shell-sidebar__section-title,
body.aa-sidebar-collapsed .shell-sidebar__section-title,
body.ac-sidebar-collapsed .shell-sidebar__section-title,
body.ff-sidebar-collapsed .shell-sidebar__user-info,
body.aa-sidebar-collapsed .shell-sidebar__user-info,
body.ac-sidebar-collapsed .shell-sidebar__user-info,
body.ff-sidebar-collapsed .shell-sidebar__collapse-label,
body.aa-sidebar-collapsed .shell-sidebar__collapse-label,
body.ac-sidebar-collapsed .shell-sidebar__collapse-label,
body.ff-sidebar-collapsed .shell-sidebar__item-note,
body.aa-sidebar-collapsed .shell-sidebar__item-note,
body.ac-sidebar-collapsed .shell-sidebar__item-note {
    display: none;
}
body.ff-sidebar-collapsed .shell-sidebar__item,
body.aa-sidebar-collapsed .shell-sidebar__item,
body.ac-sidebar-collapsed .shell-sidebar__item,
body.ff-sidebar-collapsed .shell-sidebar__brand,
body.aa-sidebar-collapsed .shell-sidebar__brand,
body.ac-sidebar-collapsed .shell-sidebar__brand,
body.ff-sidebar-collapsed .shell-sidebar__collapse,
body.aa-sidebar-collapsed .shell-sidebar__collapse,
body.ac-sidebar-collapsed .shell-sidebar__collapse,
body.ff-sidebar-collapsed .shell-sidebar__user,
body.aa-sidebar-collapsed .shell-sidebar__user,
body.ac-sidebar-collapsed .shell-sidebar__user {
    justify-content: center; gap: 0;
}
/* main content расширяется когда сайдбар свёрнут (если grid-template-columns у app-shell) */
body.ff-sidebar-collapsed .app-shell,
body.aa-sidebar-collapsed .app-shell,
body.ac-sidebar-collapsed .app-shell {
    grid-template-columns: var(--sidebar-collapsed-width, 72px) 1fr;
}

/* Подкрутка nav: иконки покрупнее (эмодзи читаются лучше), активный пункт
   получает мягкое выделение, секции — лёгкий разделитель сверху. */
.shell-sidebar__item { padding: 9px var(--space-3); }
.shell-sidebar__item-icon { font-size: 18px; line-height: 1; width: 22px; }
.shell-sidebar__item.is-active {
    background: linear-gradient(90deg, var(--accent-soft), transparent 120%);
    color: var(--accent);
    font-weight: var(--fw-bold);
}
.shell-sidebar__item.is-active .shell-sidebar__item-icon { transform: scale(1.08); }
.shell-sidebar__nav { gap: var(--space-3); }
.shell-sidebar__section-title { padding: var(--space-2) var(--space-3) 2px; }
.shell-sidebar__section-title + .stack { gap: 2px; }
.shell-sidebar__item-lock { margin-left: auto; }
/* Свёрнуть/развернуть — сделать сдержаннее (не «кнопка-кирпич»). */
.shell-sidebar__collapse {
    border: 0; background: transparent; padding: 6px 10px;
    margin: 0 var(--space-3) var(--space-2);
    color: var(--color-text-soft); font-size: 11px;
    border-top: 1px solid var(--color-line); border-radius: 0;
    padding-top: 10px; justify-content: flex-start;
}
.shell-sidebar__collapse:hover { background: transparent; color: var(--accent); }

/* ===== Переключатель разделов каталога (Остатки/Браки/Комплекты) — общий для
   /products и /products/kits, чтобы переход между разделами не «прыгал». ===== */
.cat-seg { display: inline-flex; background: var(--color-surface-2); border: 1px solid var(--color-line); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.cat-seg__btn { border: 0; background: transparent; color: var(--color-text-muted); font-family: inherit; font-size: var(--fs-sm);
    font-weight: var(--fw-semibold); padding: 7px 16px; border-radius: var(--radius-pill); cursor: pointer; display: inline-flex; align-items: center; text-decoration: none; transition: var(--transition-fast); }
.cat-seg__btn.is-active { background: var(--color-surface); color: var(--color-text); box-shadow: var(--shadow-sm); }
