/* ═══════════════════════════════════════════════
   WB STAT — Beautiful Persistent Sidebar (RIGHT)
   ═══════════════════════════════════════════════ */

/* ── Layout: push content away from right sidebar ── */
body.has-icon-nav {
    padding-right: 256px; /* 240px sidebar + 8px gap + 8px clearance */
    padding-left: 0;
}

/* Fullscreen map pages (map_tasks, cluster_assign, task_detail) используют
   body{overflow:hidden; height:100vh} — padding на body не работает.
   Вместо этого сжимаем inner layout-контейнеры. */
body.has-icon-nav.map-page {
    padding-right: 0;
}
body.has-icon-nav.map-page nav.top-nav,
body.has-icon-nav.map-page .top-nav {
    padding-right: 264px; /* 20px штатный + 244px под сайдбар */
}
body.has-icon-nav .page-layout,
body.has-icon-nav .task-layout {
    padding-right: 256px;
}

/* Map pages: sidebar floats over the map, no padding needed */
body.has-icon-nav.map-page .map-layout,
body.has-icon-nav.map-page .task-layout,
body.has-icon-nav.map-page .page-layout {
    padding-right: 0;
}

/* ────────────────────────────────────────────────
   Sidebar — floating, rounded, liquid glass
   ──────────────────────────────────────────────── */
.sidebar-nav {
    position: fixed;
    right: 8px;
    top: 8px;
    bottom: 8px;
    width: 240px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.025) 42%, rgba(255, 255, 255, 0.04)),
        rgba(18, 17, 24, 0.84);
    backdrop-filter: blur(28px) saturate(170%);
    -webkit-backdrop-filter: blur(28px) saturate(170%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.60),
        0 1px 0 rgba(255, 255, 255, 0.12) inset,
        0 -1px 0 rgba(0, 0, 0, 0.30) inset;
    display: flex;
    flex-direction: column;
    z-index: 1100;
    overflow: hidden;
}

[data-theme="light"] .sidebar-nav {
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.42)),
        rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(255, 255, 255, 0.72);
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.15),
        0 1px 0 rgba(255, 255, 255, 0.9) inset;
}

/* ── Logo / Header ── */
.sidebar-nav__header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px 16px 16px;
    flex-shrink: 0;
}
.sidebar-nav__logo {
    width: 44px;
    height: 44px;
    background: none;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-card);
    font-family: 'Space Mono', monospace;
    font-size: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-align: center;
    line-height: 1.2;
    text-decoration: none;
    flex-shrink: 0;
    transition: filter 0.2s;
}
.sidebar-nav__logo:hover {
    filter: drop-shadow(0 0 10px var(--wb-purple-glow));
}
.sidebar-nav__title {
    font-family: 'Geologica', sans-serif;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    line-height: 1;
    white-space: nowrap;
}

/* ── Search ── */
.sidebar-nav__search {
    padding: 0 12px 12px;
    flex-shrink: 0;
}
.sidebar-nav__search-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.045);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 10px;
    padding: 7px 10px;
    transition: border-color 0.15s, background 0.15s;
}
.sidebar-nav__search-inner:focus-within {
    border-color: rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.07);
}
.sidebar-nav__search-icon {
    color: var(--text-dim);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}
.sidebar-nav__search-input {
    background: none;
    border: none;
    outline: none;
    color: var(--text);
    font-family: 'Geologica', sans-serif;
    font-size: 0.82rem;
    width: 100%;
}
.sidebar-nav__search-input::placeholder {
    color: var(--text-dim);
}

/* ── Nav body ── */
.sidebar-nav__body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 10px 8px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}
.sidebar-nav__body::-webkit-scrollbar { width: 3px; }
.sidebar-nav__body::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav__body::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Group labels */
.snav-group-label {
    font-family: 'Geologica', sans-serif;
    font-size: 0.58rem;
    font-weight: 700;
    letter-spacing: 0.13em;
    text-transform: uppercase;
    color: var(--text-dim);
    opacity: 0.55;
    padding: 10px 8px 4px;
    pointer-events: none;
    user-select: none;
}

/* Separator */
.snav-sep {
    height: 1px;
    background: rgba(255, 255, 255, 0.09);
    margin: 6px 4px;
    opacity: 1;
}

/* Nav links */
.snav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    color: var(--text-mid);
    text-decoration: none;
    font-family: 'Geologica', sans-serif;
    font-size: 0.855rem;
    font-weight: 500;
    transition: background 0.14s, color 0.14s;
    white-space: nowrap;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
}
.snav-link:hover {
    background: rgba(255, 255, 255, 0.07);
    color: var(--text);
}
.snav-link.active {
    background: var(--wb-purple);
    color: var(--bg-card);
}
[data-theme="light"] .snav-link.active {
    background: var(--wb-purple);
    color: var(--bg-card);
}
.snav-link__icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0.75;
}
.snav-link.active .snav-link__icon {
    opacity: 1;
}
.snav-link__icon svg {
    width: 16px;
    height: 16px;
}
.snav-link__label { flex: 1; }

/* Logout hover */
.snav-link--logout:hover {
    background: var(--red-dim);
    color: var(--red);
}

/* ── Footer: theme toggle + user ── */
.sidebar-nav__footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

/* Theme toggle row */
.snav-theme-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 10px;
    color: var(--text-mid);
    font-family: 'Geologica', sans-serif;
    font-size: 0.855rem;
    font-weight: 500;
}
.snav-theme-row__icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0.7;
}
.snav-theme-row__label { flex: 1; }

/* iOS-style toggle */
.theme-ios-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    cursor: pointer;
    margin-left: auto;
}
.theme-ios-toggle__input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.theme-ios-toggle__input:focus { outline: none; }
.theme-ios-toggle__track {
    display: block;
    width: 34px;
    height: 20px;
    border-radius: 10px;
    background: var(--border-bright);
    transition: background 0.2s ease;
    position: relative;
}
.theme-ios-toggle__track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}
.theme-ios-toggle__input:checked + .theme-ios-toggle__track {
    background: var(--wb-purple);
}
.theme-ios-toggle__input:checked + .theme-ios-toggle__track::after {
    transform: translateX(14px);
}

/* User block */
.sidebar-nav__user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 4px;
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    margin-top: 4px;
}
.sidebar-nav__avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--wb-purple-dim);
    border: 1.5px solid var(--wb-purple-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--purple-text);
    font-family: 'Geologica', sans-serif;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.sidebar-nav__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.sidebar-nav__user-info { flex: 1; min-width: 0; }
.sidebar-nav__user-name {
    font-family: 'Geologica', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-nav__user-role {
    font-family: 'Geologica', sans-serif;
    font-size: 0.65rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 3px;
}
.sidebar-nav__user-role svg {
    display: inline;
    vertical-align: middle;
}

/* ── Legacy icon-nav compat: hide old nav ── */
.icon-nav { display: none !important; }
.icon-nav__flyout { display: none !important; }

/* ────────────────────────────────────────────────
   Mobile: bottom sheet
   ──────────────────────────────────────────────── */
@media (max-width: 640px) {
    body.has-icon-nav {
        padding-right: 0;
        padding-bottom: 56px;
    }
    body.has-icon-nav.map-page nav.top-nav,
    body.has-icon-nav.map-page .top-nav {
        padding-right: 20px; /* сбрасываем до штатного */
    }
    body.has-icon-nav .map-layout,
    body.has-icon-nav .page-layout,
    body.has-icon-nav .task-layout {
        padding-right: 0;
    }
    .sidebar-nav {
        /* Mobile: collapsed button at bottom-right */
        top: auto;
        bottom: 0;
        right: 0;
        width: 100%;
        height: auto;
        max-height: 85vh;
        border-left: none;
        border-top: 1px solid var(--border);
        border-radius: 18px 18px 0 0;
        transform: translateY(calc(100% - 56px));
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 -4px 40px rgba(0,0,0,0.4);
    }
    .sidebar-nav.mobile-open {
        transform: translateY(0);
    }
    .sidebar-nav__header {
        cursor: pointer;
        padding: 14px 16px 12px;
    }
    .sidebar-nav__header::after {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: var(--border-bright);
        border-radius: 2px;
        margin: 0 auto;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
    }
    .sidebar-nav__search { display: none; }
    .sidebar-nav.mobile-open .sidebar-nav__search { display: block; }
}
