/**
 * App shell: sidebar, content, topbar, collapsed / mobile.
 * Источник: backend/resources/css/app.css (.sidebar-*, .content-shell, .topbar*)
 * Зависимости: CSS-переменные из tokens.css (--color-*, --shadow-elevated, --color-violet).
 * Brand mark: .brand-mark из tokens.css.
 *
 * Разметка-ориентир: layouts/app.blade.php
 * Полный topbar-search (expand / dropdown) в трекере объёмнее — сюда ядро шапки.
 */

/* —— Sidebar —— */
.sidebar-shell {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    display: flex;
    height: 100%;
    flex-direction: column;
    width: 264px;
    border-right: 1px solid var(--color-line);
    background: rgb(var(--glass-rgb) / 0.8);
    backdrop-filter: blur(20px) saturate(1.4);
    transition: width 0.3s ease, transform 0.3s ease;
}

.sidebar-head {
    display: flex;
    height: 64px;
    flex-shrink: 0;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-inline: 1rem;
    border-bottom: 1px solid var(--color-line);
}

.sidebar-brand {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 0.75rem;
    border-radius: 12px;
    text-decoration: none;
}

.sidebar-brand-logo {
    display: block;
    width: auto;
    height: 32px;
    max-width: 140px;
}

/* Тёмный текст логотипа не виден на тёмном фоне — в тёмной теме инверсная версия. */
.sidebar-brand-logo--dark,
:root[data-theme="dark"] .sidebar-brand-logo--light {
    display: none;
}

:root[data-theme="dark"] .sidebar-brand-logo--dark {
    display: block;
}

.sidebar-brand-mark {
    display: none;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
}

.sidebar-brand-mark--text {
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--accent-soft, color-mix(in srgb, var(--color-accent, var(--tw-blue-600)) 14%, transparent));
    color: var(--color-accent, var(--tw-blue-600-text));
    font-size: 11px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
}

.sidebar-brand .brand-mark {
    width: 36px;
    height: 36px;
}

.sidebar-nav {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 1.1rem;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-group-title {
    margin: 0 0 0.35rem;
    padding-inline: 0.75rem;
    color: var(--color-muted-2);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    white-space: nowrap;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 42px;
    padding: 5px 8px;
    border-radius: 12px;
    color: var(--tw-slate-600-text);
    font-size: 14px;
    font-weight: 700;
    letter-spacing: 0;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-link-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--color-surface-3);
    color: var(--color-muted);
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease, transform 0.3s ease;
}

.sidebar-link-icon svg {
    width: 18px;
    height: 18px;
}

.sidebar-link:hover {
    background: rgba(37, 99, 235, 0.06);
    color: var(--color-accent-2);
}

.sidebar-link:hover .sidebar-link-icon {
    background: var(--color-surface);
    color: var(--color-accent);
    box-shadow: 0 2px 8px rgb(var(--ink-rgb) / 0.08);
}

.sidebar-link.is-active {
    background: linear-gradient(90deg, rgba(37, 99, 235, 0.11), rgba(124, 58, 237, 0.05));
    color: var(--color-accent-2);
}

.sidebar-link.is-active .sidebar-link-icon {
    background: linear-gradient(135deg, var(--color-accent), var(--color-violet));
    color: #fff;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.28);
}

.sidebar-link:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* В тёмной теме светлые подсветки сливаются с фоном: плотнее заливка, иконка не темнеет. */
:root[data-theme="dark"] .sidebar-link:hover {
    background: rgb(59 130 246 / 0.12);
    color: var(--color-text);
}

:root[data-theme="dark"] .sidebar-link:hover .sidebar-link-icon {
    background: rgb(59 130 246 / 0.2);
    color: var(--color-accent-2);
    box-shadow: none;
}

:root[data-theme="dark"] .sidebar-link.is-active {
    background: linear-gradient(90deg, rgb(59 130 246 / 0.2), rgb(139 92 246 / 0.1));
    color: #93c5fd;
}

.sidebar-foot {
    flex-shrink: 0;
    padding: 0.75rem;
    border-top: 1px solid var(--color-line);
}

/* —— Content —— */
.content-shell {
    margin-left: 264px;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* Collapsed — desktop only */
@media (min-width: 1024px) {
    .sidebar-shell.is-collapsed {
        width: 76px;
    }

    .sidebar-shell.is-collapsed .sidebar-head {
        justify-content: center;
        padding-inline: 0;
    }

    .sidebar-shell.is-collapsed .sidebar-head-main {
        justify-content: center;
    }

    .sidebar-shell.is-collapsed .sidebar-brand-logo,
    .sidebar-shell.is-collapsed .sidebar-brand-text {
        display: none;
    }

    .sidebar-shell.is-collapsed .sidebar-brand-mark {
        display: block;
    }

    .sidebar-shell.is-collapsed .sidebar-brand-mark--text {
        display: inline-flex;
    }

    .sidebar-shell.is-collapsed .sidebar-label {
        display: none;
    }

    .sidebar-shell.is-collapsed .sidebar-link {
        justify-content: center;
    }

    .sidebar-shell.is-collapsed .sidebar-group-title {
        height: 1px;
        margin: 0 0.75rem 0.5rem;
        padding: 0;
        overflow: hidden;
        background: var(--color-line);
        font-size: 0;
    }

    .sidebar-shell.is-collapsed .sidebar-collapse-icon {
        transform: rotate(180deg);
    }

    /* Service switcher lives in sidebar-head; hide when icons-only */
    .sidebar-shell.is-collapsed .service-switcher {
        display: none;
    }

    .content-shell.is-collapsed {
        margin-left: 76px;
    }
}

/* Mobile — off-canvas */
@media (max-width: 1023px) {
    .sidebar-shell {
        width: min(300px, 86vw);
        padding-bottom: env(safe-area-inset-bottom);
        background: rgb(var(--glass-rgb) / 0.96);
        transform: translateX(-100%);
    }

    .sidebar-shell.is-mobile-open {
        transform: translateX(0);
        box-shadow: var(--shadow-elevated);
    }

    .content-shell {
        margin-left: 0;
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 35;
        background: rgb(var(--ink-rgb) / 0.35);
        backdrop-filter: blur(2px);
    }
}

/* —— Topbar —— */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    height: 64px;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-inline: 1rem;
    background: linear-gradient(180deg, rgb(var(--glass-rgb) / 0.62), rgb(var(--glass-rgb) / 0.42));
    backdrop-filter: blur(24px) saturate(1.9) brightness(1.04);
    border-bottom: 1px solid rgb(var(--glass-rgb) / 0.55);
    box-shadow:
        inset 0 1px 0 rgb(var(--glass-rgb) / 0.8),
        0 1px 0 rgb(var(--ink-rgb) / 0.06),
        0 10px 30px -18px rgb(var(--ink-rgb) / 0.25);
}

@media (min-width: 640px) {
    .topbar {
        padding-inline: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .topbar {
        padding-inline: 2rem;
    }
}

.topbar-section-icon {
    display: inline-flex;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--color-blue-soft), var(--tw-violet-100));
    color: var(--color-accent-2);
    box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.1);
}

.topbar-section-icon svg {
    width: 18px;
    height: 18px;
}

.topbar-section {
    color: var(--color-text);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: 0;
}

.topbar-meta {
    margin-top: 1px;
    font-size: 12px;
    font-weight: 700;
    color: var(--color-muted);
}

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

.topbar-titles {
    min-width: 0;
    line-height: 1.2;
}

.topbar-section {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-head-main {
    display: flex;
    min-width: 0;
    flex: 1;
    align-items: center;
    gap: 0.35rem;
}

.sidebar-brand-text {
    display: flex;
    min-width: 0;
    flex-direction: column;
}

.sidebar-brand-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
    font-size: 15px;
    font-weight: 900;
    letter-spacing: -0.02em;
}

.sidebar-brand-tag {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-muted);
    font-size: 12px;
    font-weight: 700;
}

.sidebar-collapse-btn {
    width: 100%;
    border: 0;
    background: transparent;
    font: inherit;
}

button.sidebar-link {
    font-family: inherit;
}

/* Visibility helpers (no Tailwind in Dewibe) */
.shell-desktop-only {
    display: none;
}

.shell-mobile-only {
    display: inline-flex;
}

.shell-tablet-menu {
    display: none;
}

.shell-hide-xs {
    display: none;
}

@media (min-width: 640px) {
    .shell-hide-xs {
        display: inline-flex;
    }
}

@media (min-width: 768px) and (max-width: 1023px) {
    .shell-tablet-menu {
        display: inline-flex;
    }
}

@media (min-width: 1024px) {
    .shell-desktop-only {
        display: block;
    }

    .shell-mobile-only,
    .shell-tablet-menu {
        display: none !important;
    }
}

/* —— User menu —— */
.user-menu-wrap {
    position: relative;
}

.user-menu-btn {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 2px;
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

@media (min-width: 768px) {
    .user-menu-btn {
        padding: 3px 10px 3px 3px;
    }
}

.user-menu-btn:hover,
.user-menu-btn.is-open {
    border-color: var(--color-line);
    background: var(--color-surface);
    box-shadow: 0 2px 8px rgb(var(--ink-rgb) / 0.06);
}

.user-menu-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.avatar {
    display: inline-flex;
    height: 40px;
    width: 40px;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-violet));
    color: #fff;
    font-size: 13px;
    font-weight: 900;
}

.user-menu-avatar {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    font-size: 12px;
}

.user-menu-meta {
    display: none;
    min-width: 0;
    text-align: left;
    line-height: 1.2;
}

@media (min-width: 768px) {
    .user-menu-meta {
        display: block;
    }

    .user-menu-chevron {
        display: block;
    }
}

.user-menu-chevron {
    display: none;
    flex-shrink: 0;
    color: var(--color-muted-2);
    transition: transform 0.2s ease;
}

.user-menu-btn.is-open .user-menu-chevron {
    transform: rotate(180deg);
}

.user-menu-name {
    display: block;
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
    font-size: 13px;
    font-weight: 900;
}

.user-menu-role {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
    color: var(--color-accent-2);
    font-size: 11.5px;
    font-weight: 800;
    white-space: nowrap;
}

.user-menu-role::before {
    content: "";
    width: 6px;
    height: 6px;
    flex-shrink: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--color-accent), var(--color-violet));
}

.user-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 0.5rem);
    z-index: 40;
    width: min(18rem, calc(100vw - 2rem));
    padding: 6px;
    border: 1px solid var(--color-line);
    border-radius: 16px;
    background: var(--color-surface);
    box-shadow: 0 18px 40px rgb(var(--ink-rgb) / 0.14);
}

.user-menu-head {
    margin-bottom: 6px;
    padding: 12px;
    border-radius: 11px;
    background: linear-gradient(135deg, rgba(219, 234, 254, 0.7), rgba(237, 233, 254, 0.7));
}

:root[data-theme="dark"] .user-menu-head {
    background: linear-gradient(135deg, rgb(59 130 246 / 0.16), rgb(139 92 246 / 0.14));
}

.user-menu-head-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
    font-size: 14px;
    font-weight: 900;
}

.user-menu-head-email {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-muted);
    font-size: 12px;
    font-weight: 700;
}

.user-menu-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-top: 0.65rem;
}

.role-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 9px;
    border: 1px solid var(--c-c7d7fb);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-accent-2);
    font-size: 11.5px;
    font-weight: 800;
}

.user-menu-item {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.65rem;
    padding: 9px 10px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--color-text);
    font-size: 13.5px;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.user-menu-item svg {
    width: 18px;
    height: 18px;
    color: var(--color-muted);
}

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

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

.user-menu-item.is-danger:hover svg {
    background: transparent;
}

.user-menu-theme {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 8px 10px;
    margin-bottom: 4px;
}

.user-menu-theme-label {
    color: var(--color-muted);
    font-size: 13px;
    font-weight: 700;
}

.user-menu-theme-options {
    position: relative;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--color-line);
    border-radius: 10px;
    background: var(--color-surface-3);
}

.user-menu-theme-indicator {
    position: absolute;
    top: 3px;
    bottom: 3px;
    left: 0;
    width: 0;
    border-radius: 7px;
    background: var(--color-surface);
    box-shadow: 0 1px 3px rgb(var(--ink-rgb) / 0.12);
    pointer-events: none;
}

.user-menu-theme-indicator.is-animated {
    transition:
        transform 0.28s cubic-bezier(0.2, 0, 0, 1),
        width 0.28s cubic-bezier(0.2, 0, 0, 1);
}

@media (prefers-reduced-motion: reduce) {
    .user-menu-theme-indicator.is-animated {
        transition: none;
    }
}

.user-menu-theme-option {
    position: relative;
    z-index: 1;
    padding: 0.25rem 0.6rem;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: var(--color-muted);
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
}

.user-menu-theme-option:hover {
    color: var(--color-text);
}

.user-menu-theme-option:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.user-menu-theme-option.is-active {
    color: var(--color-text);
}

/* —— Mobile tabbar —— */
.mobile-tabbar {
    display: none;
}

@media (max-width: 767px) {
    .content-shell {
        padding-bottom: calc(60px + env(safe-area-inset-bottom) + 16px);
    }

    .topbar {
        height: 56px;
        padding-inline: 12px;
    }

    .topbar-section {
        font-size: 17px;
    }

    .mobile-tabbar {
        position: fixed;
        inset-inline: 0;
        bottom: 0;
        z-index: 34;
        display: grid;
        grid-auto-columns: minmax(0, 1fr);
        grid-auto-flow: column;
        height: calc(60px + env(safe-area-inset-bottom));
        padding: 4px 6px env(safe-area-inset-bottom);
        background: linear-gradient(180deg, rgb(var(--glass-rgb) / 0.95), rgb(var(--glass-rgb) / 0.98));
        backdrop-filter: blur(24px) saturate(1.8);
        -webkit-backdrop-filter: blur(24px) saturate(1.8);
        border-top: 1px solid rgb(var(--ink-rgb) / 0.07);
        box-shadow: 0 -10px 30px -20px rgb(var(--ink-rgb) / 0.35), inset 0 1px 0 rgb(var(--glass-rgb) / 0.9);
    }

    .mobile-tab {
        position: relative;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-width: 0;
        height: 60px;
        margin-top: -4px;
        padding: 0 2px;
        border: 0;
        border-radius: 14px;
        background: transparent;
        color: var(--tw-slate-500-text);
        font-size: 10.5px;
        font-weight: 800;
        letter-spacing: 0;
        line-height: 1;
        text-decoration: none;
        cursor: pointer;
    }

    .mobile-tab-icon {
        display: grid;
        width: 44px;
        height: 30px;
        place-items: center;
        border-radius: 999px;
    }

    .mobile-tab-icon svg {
        width: 22px;
        height: 22px;
    }

    .mobile-tab-label {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-tab.is-active {
        color: var(--color-accent-2);
    }

    .mobile-tab.is-active .mobile-tab-icon {
        background: linear-gradient(135deg, rgba(37, 99, 235, 0.14), rgba(124, 58, 237, 0.12));
    }

    .mobile-tab:focus-visible {
        outline: 2px solid var(--color-accent);
        outline-offset: -2px;
    }
}

/* Main inside content-shell */
.content-shell > .iac-main {
    max-width: 80rem; /* max-w-7xl */
    margin-left: auto;
    margin-right: auto;
    padding: 1.25rem 1.25rem 4rem;
    position: relative;
    z-index: 2;
}

@media (min-width: 640px) {
    .content-shell > .iac-main {
        padding: 1.5rem 1.5rem 4rem;
    }
}

@media (min-width: 1024px) {
    .content-shell > .iac-main {
        padding: 2rem 2rem 5rem;
    }
}

.page-appear {
    animation: page-appear 0.35s ease both;
}

/* Laravel Debugbar — не трогать position (atmosphere только на .app-shell) */
@media (min-width: 1024px) {
    div.phpdebugbar:not(.phpdebugbar-closed) {
        left: 264px;
        width: calc(100% - 264px);
    }

    body:has(.sidebar-shell.is-collapsed) div.phpdebugbar:not(.phpdebugbar-closed) {
        left: 76px;
        width: calc(100% - 76px);
    }
}

@keyframes page-appear {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar-shell,
    .content-shell {
        transition: none !important;
    }

    .page-appear {
        animation: none;
    }
}

/* —— Notifications bell —— */
.notif-wrap {
    position: relative;
}

.notif-btn {
    position: relative;
    display: inline-flex;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--color-muted, currentColor);
    cursor: pointer;
}

.notif-btn:hover,
.notif-btn[aria-expanded="true"] {
    border-color: var(--color-line);
    background: var(--color-surface);
}

.notif-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

.notif-badge {
    position: absolute;
    top: 3px;
    right: 3px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--color-danger, #dc2626);
    color: #fff;
    font-size: 10px;
    font-weight: 800;
    line-height: 17px;
    text-align: center;
}

.notif-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 60;
    width: min(380px, calc(100vw - 32px));
    max-height: 70vh;
    overflow: auto;
    border: 1px solid var(--color-line);
    border-radius: 14px;
    background: var(--color-surface);
    box-shadow: 0 12px 32px rgb(var(--ink-rgb) / 0.14);
}

.notif-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-line);
    font-weight: 700;
}

.notif-readall {
    border: 0;
    background: none;
    color: var(--color-accent);
    font-size: 12px;
    cursor: pointer;
}

.notif-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.notif-empty {
    padding: 16px 14px;
    color: var(--color-muted, inherit);
    font-size: 13px;
}

.notif-item a {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-line);
    color: inherit;
    font-size: 13px;
    text-decoration: none;
}

.notif-item a:hover {
    background: rgb(var(--ink-rgb) / 0.04);
}

.notif-item.is-unread .notif-title {
    font-weight: 700;
}

.notif-line {
    overflow: hidden;
    color: var(--color-muted, inherit);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-time {
    color: var(--color-muted, inherit);
    font-size: 11px;
}
