/* =====================================================
   TOIR Base Styles
   ===================================================== */

/* =====================================================
   Skip-to-content link (a11y)
   ===================================================== */

.skip-link {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 2000;
    background: var(--p-500);
    color: #fff;
    padding: 0.5rem 1rem;
    border-radius: var(--r-md);
    font-weight: 500;
    text-decoration: none;
}

.skip-link:focus,
.skip-link:focus-visible {
    color: #fff;
    outline: 3px solid #fff;
    outline-offset: 2px;
}

/* Don't add focus ring to main when it's used as skip-link target */
#main-content:focus {
    outline: none;
}

/* =====================================================
   Focus-visible — keyboard navigation
   ===================================================== */

/* Убираем outline при клике мышью, оставляем только при keyboard */
:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

/* Bootstrap кнопки — переопределяем их box-shadow focus */
.btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    box-shadow: none;
}

/* Nav-ссылки в сайдбаре */
.sidebar .nav-link:focus-visible,
.offcanvas-body .nav-link:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

/* Поля ввода — двойное кольцо фокуса (§5, DESIGN_SYSTEM.md) */
.form-control:focus,
.form-select:focus {
    border-color: var(--p-400);
    box-shadow: var(--sh-focus);
    outline: none;
}

/* =====================================================
   Root & base helpers
   ===================================================== */

:root {
    /* Layout */
    --sidebar-width: 270px;

    /* Backgrounds — роли Industrial Swiss (marketing/tokens.css) */
    --bg-body: var(--bg-sunken);
    --bg-sidebar: var(--surface);
    --bg-muted: var(--n-50);
    --bg-hover: var(--n-50);
    --bg-card: var(--surface);

    /* Text.
       ВНИМАНИЕ: --text-muted и --font-mono здесь НЕ определять —
       эти имена принадлежат ролям из marketing/tokens.css, локальное
       переопределение перебивает их по всему приложению. */
    --text-primary: var(--text);
    --text-secondary: var(--n-600);

    /* Borders */
    --border-color: var(--border);
    --border-color-light: var(--border-faint);
    --border-radius-sm: var(--r-sm);
    --border-radius-md: var(--r-md);
    --border-radius-lg: var(--r-lg);

    /* Shadows: линия и подъём вместо размытия (§5) */
    --shadow-sm: var(--sh-hair);
    --shadow-md: var(--sh-raise);

    /* Transitions: механизм, а не желе (§6) */
    --transition-fast: background var(--d-fast) var(--e-out), color var(--d-fast) var(--e-out), border-color var(--d-fast) var(--e-out);
    --transition-input: border-color var(--d-fast) var(--e-out), box-shadow var(--d-fast) var(--e-out);
    --transition-lift: transform var(--d-base) var(--e-out), box-shadow var(--d-base) var(--e-out);
    --transition-sidebar: margin-left var(--d-slow) var(--e-out);

    /* Typography */
    --font-body: var(--font-sans);

    /* Brand / Primary — сталь */
    --color-primary: var(--p-500);
    --color-primary-hover: var(--p-50);
    --color-primary-subtle: rgba(31, 80, 117, 0.25);
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-body);
    font-family: var(--font-body);
}

code, pre, kbd, .font-monospace {
    font-family: var(--font-mono);
}

.input-group {
    display: flex;
    align-items: center;
    position: relative;
    z-index: 10;
}

.dropdown-menu {
    z-index: 1050 !important;
}

/* =====================================================
   Layout
   ===================================================== */

.topbar {
    height: 56px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1030;
    background-color: var(--bg-sidebar);
}

.layout {
    flex: 1 1 auto;
    min-height: calc(100vh - 56px);
}

.sidebar {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border-color-light);
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 1020;
    background: var(--bg-sunken);
}

/* Thin, unobtrusive scrollbar for the nav surface */
.sidebar {
    scrollbar-width: thin;
    scrollbar-color: var(--n-200) transparent;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb {
    background-color: var(--n-200);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
.sidebar::-webkit-scrollbar-thumb:hover { background-color: var(--n-300); }

/* ── Shared nav styles: sidebar + offcanvas ─────────────── */

.sidebar .brand,
.offcanvas-body .brand {
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-size: 1.1rem;
    color: var(--text-primary);
}

/* Brand mark: icon rendered as a rounded gradient tile */
.sidebar .brand > i:first-child,
.offcanvas-body .brand > i:first-child {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--r-md);
    font-size: 1.1rem;
    color: var(--n-0);
    background: var(--p-500);
}

.sidebar .section-title,
.offcanvas-body .section-title {
    font-size: .75rem;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin: 1.35rem .25rem .35rem;
}

.sidebar .nav-link,
.offcanvas-body .nav-link {
    position: relative;
    border-radius: var(--border-radius-md);
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .5rem .7rem;
    margin-bottom: 1px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: var(--transition-fast);
}

/* Consistent icon column so all labels align */
.sidebar .nav-link > i:first-child,
.offcanvas-body .nav-link > i:first-child {
    flex-shrink: 0;
    width: 1.3rem;
    margin: 0 !important;
    text-align: center;
    font-size: 1.05rem;
    color: var(--text-faint);
    transition: color var(--d-fast) var(--e-out);
}

.sidebar .nav-link:hover,
.offcanvas-body .nav-link:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}
.sidebar .nav-link:hover > i:first-child,
.offcanvas-body .nav-link:hover > i:first-child {
    color: var(--text-secondary);
}

.sidebar .nav-link.active,
.offcanvas-body .nav-link.active {
    background: var(--p-50);
    color: var(--p-500);
    font-weight: 600;
}
.sidebar .nav-link.active > i:first-child,
.offcanvas-body .nav-link.active > i:first-child {
    color: var(--p-500);
}
/* Square signal bar on the active item — щит, не пилюля (DS §1.1) */
.sidebar .nav-link.active::before,
.offcanvas-body .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 1.1rem;
    background: var(--p-500);
}

/* Заблокированный тарифом пункт меню — виден, но приглушён, ведёт на тарифы */
.sidebar .nav-link--locked,
.offcanvas-body .nav-link--locked {
    color: var(--text-muted);
}
.sidebar .nav-link--locked > i:first-child,
.offcanvas-body .nav-link--locked > i:first-child {
    opacity: .5;
}
.sidebar .nav-link--locked .nav-locked-label,
.offcanvas-body .nav-link--locked .nav-locked-label {
    opacity: .8;
}
.nav-lock-chip {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 50%;
    background: var(--bg-hover);
    color: var(--text-muted);
    font-size: .68rem;
    transition: var(--transition-fast);
}
.sidebar .nav-link--locked:hover,
.offcanvas-body .nav-link--locked:hover {
    background-color: var(--p-50);
    color: var(--p-500);
}
.sidebar .nav-link--locked:hover > i:first-child,
.sidebar .nav-link--locked:hover .nav-locked-label,
.offcanvas-body .nav-link--locked:hover > i:first-child,
.offcanvas-body .nav-link--locked:hover .nav-locked-label {
    opacity: 1;
}
.sidebar .nav-link--locked:hover .nav-lock-chip,
.offcanvas-body .nav-link--locked:hover .nav-lock-chip {
    background: var(--p-500);
    color: var(--n-0);
}

/* Content shifts when sidebar is present */
.content-with-sidebar {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    transition: var(--transition-sidebar);
}

/* Read-only demo-mode banner */
.demo-banner {
    display: flex;
    align-items: center;
    gap: var(--s-3);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--r-md);
    padding: .7rem .9rem;
    margin-bottom: var(--s-4);
}
.demo-banner-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--a-500);
    box-shadow: 0 0 0 3px rgba(var(--a-500-rgb), .25);
    flex: 0 0 auto;
}
.demo-banner-txt {
    font-size: var(--t-sm);
}
.demo-banner-sub {
    display: block;
    font-family: var(--font-mono);
    font-size: .5625rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 1px;
}
.demo-banner-back {
    margin-left: auto;
    background: var(--a-500);
    color: var(--n-950);
    font-weight: var(--fw-semibold);
    font-size: var(--t-sm);
    border-radius: var(--r-md);
    padding: .45rem .8rem;
    text-decoration: none;
    white-space: nowrap;
}

/* One-time demo hint card on the dashboard — steel plate, no ochre on light */
.demo-hint { border: 1px solid var(--border); border-radius: var(--r-md);
    background: var(--surface); margin-bottom: var(--s-5); }
.demo-hint-top { display: flex; gap: var(--s-4); padding: var(--s-5); }
.demo-hint-plate { width: 44px; height: 44px; flex: 0 0 auto; border-radius: var(--r-md);
    background: var(--p-50); color: var(--p-500); display: grid; place-items: center; font-size: 1.25rem; }
.demo-hint-h { font-size: var(--t-h3); font-weight: var(--fw-black); letter-spacing: var(--tr-head); margin: 0 0 .3rem; }
.demo-hint-p { font-size: var(--t-sm); color: var(--text-muted); line-height: var(--lh-body); margin: 0; }
.demo-hint-acts { display: flex; gap: var(--s-3); padding: 0 var(--s-5) var(--s-5); }

/* Hub tab strip — one sidebar entry → sub-sections as tabs */
.tab-strip { display: flex; gap: var(--s-4); border-bottom: 1px solid var(--border); margin-bottom: var(--s-5); }
.tab-strip-item { padding: .6rem 0; text-decoration: none; color: var(--text-muted);
    font-weight: var(--fw-semibold); font-size: var(--t-sm); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-strip-item:hover { color: var(--text); }
.tab-strip-item.active { color: var(--p-500); border-bottom-color: var(--p-500); }

/* Sidebar footer (secondary links) + profile chip + nav counters */
.sidebar-foot { margin-top: var(--s-4); padding-top: var(--s-2); border-top: 1px solid var(--border-faint); }
.sidebar-profile { margin-top: var(--s-2); padding-top: var(--s-2); border-top: 1px solid var(--border-faint); }
.sidebar-profile-btn { display: flex; align-items: center; gap: var(--s-2); width: 100%;
    background: none; border: 0; padding: .5rem .35rem; color: var(--text); text-align: left; }
.sidebar-avatar { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 50%;
    background: var(--p-50); color: var(--p-600); display: grid; place-items: center;
    font-weight: var(--fw-bold); font-size: .8rem; }
.sidebar-profile-nm { min-width: 0; flex: 1; font-size: var(--t-sm); font-weight: var(--fw-semibold); line-height: 1.15; }
.sidebar-profile-nm small { display: block; font-family: var(--font-mono); font-size: .5rem;
    letter-spacing: .08em; text-transform: uppercase; color: var(--text-faint); font-weight: 400; }
.sidebar-profile-more { color: var(--text-faint); }
.nav-count { margin-left: auto; font-family: var(--font-mono); font-variant-numeric: tabular-nums;
    font-size: .625rem; color: var(--text-muted); }
.nav-count--alert { background: var(--stop); color: var(--n-0); border-radius: var(--r-sm);
    min-width: 16px; height: 16px; display: inline-grid; place-items: center; padding: 0 4px;
    font-weight: var(--fw-bold); font-size: .625rem; }

/* Tablet and below: hide sidebar, show topbar */
@media (max-width: 1199.98px) {
    .sidebar {
        display: none;
    }
    .content-with-sidebar {
        margin-left: 0;
        width: 100%;
    }
    .topbar {
        display: flex !important;
    }
}

/* Mobile */
@media (max-width: 991.98px) {
    .topbar {
        display: flex !important;
    }
}

/* Desktop: show sidebar, hide topbar */
@media (min-width: 1200px) {
    .sidebar {
        display: block !important;
    }
    .topbar {
        display: none !important;
    }
}

/* =====================================================
   Tables
   ===================================================== */

.table td,
.table th {
    vertical-align: middle;
}

/* =====================================================
   Forms & required fields
   ===================================================== */

.form-check-input[type="radio"] {
    width: 1.25em;
    height: 1.25em;
    margin-right: .5em;
}

.form-check-label {
    font-weight: 500;
    cursor: pointer;
}

.form-label.required::after {
    content: " *";
    color: var(--stop);
    font-weight: 600;
}

.form-control:required,
.form-select:required {
    border-left: 3px solid var(--stop);
    padding-left: calc(.75rem - 3px);
}

/* =====================================================
   Form sections
   ===================================================== */

.form-section {
    padding: 1rem 1.25rem;
    border-radius: var(--border-radius-lg);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    margin-bottom: 1.5rem;
}

.form-section-header {
    font-size: .75rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

/* =====================================================
   Detail view helpers
   ===================================================== */

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
}

.detail-item {
    padding: .75rem .9rem;
    border-radius: var(--border-radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
}

.detail-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

.detail-value {
    font-weight: 600;
}

/* =====================================================
   Skeleton loading
   ===================================================== */

@keyframes skeleton-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}

.skeleton {
    background: linear-gradient(
        90deg,
        var(--n-100) 25%,
        var(--n-50) 50%,
        var(--n-100) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--border-radius-sm);
    color: transparent !important;
    pointer-events: none;
    user-select: none;
}

.skeleton-text  { height: 1em;    margin-bottom: .4em; }
.skeleton-title { height: 1.5em;  width: 55%; margin-bottom: .75em; }
.skeleton-badge { height: 1.4em;  width: 4rem; display: inline-block; }
.skeleton-btn   { height: 2.1rem; width: 6rem; display: inline-block; border-radius: var(--border-radius-md); }

@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; background: var(--n-100); }
}

/* =====================================================
   Select2 — Bootstrap-like (Single & Multiple)
   ===================================================== */

.select2-container {
    width: 100% !important;
    font-size: 1rem;
}

/* ---------- Single ---------- */

.select2-container--default .select2-selection--single {
    height: calc(2.375rem + 2px);
    padding: .375rem .75rem;
    padding-right: 2.25rem;
    border-radius: var(--r-md);
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    display: flex;
    align-items: center;
    position: relative;
    transition: var(--transition-input);
}

.select2-selection__rendered {
    padding: 0;
    color: var(--text);
}

.select2-selection__placeholder {
    color: var(--text-muted);
}

.select2-selection__arrow {
    position: absolute;
    right: .75rem;
    inset-block: 0;
    display: flex;
    align-items: center;
    pointer-events: none;
}

.select2-selection__arrow b {
    border-width: 5px 5px 0;
    border-style: solid;
    border-color: var(--text-muted) transparent transparent;
    opacity: .6;
}

.select2-container--focus .select2-selection--single {
    border-color: var(--p-400);
    box-shadow: var(--sh-focus);
}

.select2-container--disabled .select2-selection--single {
    background-color: var(--n-100);
    opacity: .65;
    cursor: not-allowed;
}

/* ---------- Multiple ---------- */

.select2-container--default .select2-selection--multiple {
    min-height: calc(2.375rem + 2px);
    padding: .25rem .5rem;
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    display: flex;
    flex-wrap: wrap;
    gap: .35rem;
    transition: var(--transition-input);
}

.select2-container--focus .select2-selection--multiple {
    border-color: var(--p-400);
    box-shadow: var(--sh-focus);
}

.select2-container--disabled .select2-selection--multiple {
    background-color: var(--n-100);
    opacity: .65;
    cursor: not-allowed;
}

/* Chips */

.select2-selection__choice {
    position: relative;
    display: inline-flex;
    align-items: center;
    padding: .3rem .6rem .3rem 1.6rem;
    background-color: var(--n-100);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    font-size: .9rem;
}

.select2-selection__choice__display {
    padding: 0;
    white-space: nowrap;
}

.select2-selection__choice__remove {
    position: absolute;
    left: .4rem;
    top: 50%;
    transform: translateY(-50%);
    width: 1.1rem;
    height: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: .25rem;
    color: var(--text-muted);
    cursor: pointer;
}

.select2-selection__choice__remove:hover {
    background-color: var(--stop-bg);
    color: var(--stop-ink);
}

/* =====================================================
   Select2 Dropdown
   ===================================================== */

.select2-dropdown {
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--r-md);
    box-shadow: var(--sh-pop);
    overflow: hidden;
}

.select2-search--dropdown {
    padding: .5rem;
    border-bottom: 1px solid var(--border);
}

.select2-search__field {
    height: calc(2.375rem + 2px);
    padding: .375rem .75rem;
    border-radius: var(--r-md);
    border: 1px solid var(--border-strong);
    background-color: var(--surface);
    color: var(--text);
}

.select2-search__field:focus {
    border-color: var(--p-400);
    box-shadow: var(--sh-focus);
    outline: none;
}

.select2-results__option {
    padding: .5rem .75rem;
    font-size: .95rem;
    cursor: pointer;
}

.select2-results__option--highlighted {
    background-color: var(--color-primary-hover);
}

/* ===== Selected ALWAYS wins (hard fix) ===== */

.select2-results__option[aria-selected="true"] {
    background-color: var(--n-100) !important;
    color: var(--text) !important;
    font-weight: 600;
}

/* =====================================================
   jsTree — TOIR UI
   ===================================================== */

#locations-tree {
    font-size: 1.1rem;
}

#locations-tree .jstree-anchor {
    width: 100%;
    margin: .1rem 0;
    border-radius: var(--r-md);
    color: var(--text);
}

#locations-tree .jstree-wholerow-hovered {
    background: var(--n-50);
    border-radius: var(--r-md);
}

#locations-tree .jstree-wholerow-clicked {
    background: var(--color-primary-hover);
    border-radius: var(--r-md);
}

.tree-row-ui {
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.tree-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-meta {
    font-size: .75rem;
    color: var(--text-muted);
}

/* =====================================================
   Utilities
   ===================================================== */

.file-row.is-removed {
    opacity: .45;
    background-color: var(--n-50);
}

.file-row.is-removed a {
    text-decoration: line-through;
}

.table-row-link {
    cursor: pointer;
}

.table-row-link:hover {
    background-color: var(--bg-hover);
}

.hover-shadow:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

/* Stat card icon circle */
.stat-card-icon {
    width: 2.75rem;
    height: 2.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}

/* Clickable stat cards */
.stat-card-link {
    transition: var(--transition-lift);
    cursor: pointer;
}
.stat-card-link:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* =====================================================
   Select2 MULTIPLE — caret / cursor alignment fix
   ===================================================== */

.select2-container--default
.select2-selection--multiple
.select2-search {
    display: inline-flex;
    align-items: center;
    margin: 0;
}

/* Input field (cursor) */
.select2-container--default
.select2-selection--multiple
.select2-search__field {
    margin: 0;
    padding: 0;
    min-width: 1ch;
    width: auto;
    height: 1.6em;
    line-height: 1.6;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
}

/* Offcanvas for mobile menu - nav styles shared above with sidebar */
.offcanvas-start {
    width: var(--sidebar-width);
    border-right: 1px solid var(--border-color);
}

.offcanvas-body {
    padding: 1rem;
    background-color: var(--bg-sidebar);
}

/* =====================================================
   AI Reports nav item
   ===================================================== */

/* ── AI group block ─────────────────────────────────────── */
.nav-ai-group {
    margin-top: .85rem;
    border-radius: var(--r-md);
    overflow: hidden;
    border: 1px solid var(--border);
}

.nav-ai-header {
    display: flex;
    align-items: center;
    gap: .45rem;
    padding: .5rem .75rem .45rem;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--bg-sunken);
    border-bottom: 1px solid var(--border-faint);
    user-select: none;
    white-space: nowrap;
}

.nav-ai-header .ai-header-icon {
    font-size: .9rem;
    color: var(--p-500);
    flex-shrink: 0;
}

.nav-ai-header .ai-header-text {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.nav-ai-header .ai-header-badge {
    margin-left: auto;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: .55rem;
    font-weight: 600;
    letter-spacing: .08em;
    padding: 1px 5px;
    border-radius: var(--r-sm);
    color: var(--text-faint);
    border: 1px solid var(--border);
}

.nav-ai-links {
    padding: .35rem .4rem .4rem;
    display: flex;
    flex-direction: column;
    gap: .1rem;
}

/* Ссылки внутри AI-группы */
.sidebar .nav-link--ai,
.offcanvas-body .nav-link--ai {
    position: relative;
    border-radius: var(--r-md);
    padding: .45rem .65rem;
    font-size: .92rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin: 0;
    transition: var(--transition-fast);
}
.sidebar .nav-link--ai > i:first-child,
.offcanvas-body .nav-link--ai > i:first-child {
    color: var(--text-faint);
    width: 1.15rem;
}

.sidebar .nav-link--ai:hover,
.offcanvas-body .nav-link--ai:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar .nav-link--ai.active,
.offcanvas-body .nav-link--ai.active {
    background: var(--p-50);
    color: var(--p-500);
    font-weight: 600;
}
.sidebar .nav-link--ai.active > i:first-child,
.offcanvas-body .nav-link--ai.active > i:first-child {
    color: var(--p-500);
}
/* AI links live in their own group — suppress the generic active pill/left accent */
.sidebar .nav-link--ai.active::before,
.offcanvas-body .nav-link--ai.active::before {
    content: none;
}

.nav-link--ai-badge {
    margin-left: auto;
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: .58rem;
    font-weight: 600;
    letter-spacing: .08em;
    padding: 1px 5px;
    border-radius: var(--r-sm);
    color: var(--text-faint);
    border: 1px solid var(--border);
}

.sidebar .nav-link--ai.active .nav-link--ai-badge,
.offcanvas-body .nav-link--ai.active .nav-link--ai-badge {
    color: var(--p-500);
    border-color: var(--p-300);
}

/* User info */
.user-info {
    background-color: var(--surface);
    border-radius: var(--r-md);
    padding: .6rem .75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.user-info > div:first-child i.bi-person-circle {
    font-size: 1.5rem;
    color: var(--p-500);
}

/* Секция «Организация» в футере — отбивка от базы знаний */
.section-title--org { padding-top: var(--s-3); border-top: 1px solid var(--border-faint); }

/* Дропдаун профиля: аккаунт + список организаций */
.sidebar-profile .org-current { color: var(--text-muted); }
.sidebar-profile .switch-sect { font-family: var(--font-mono); font-size: .5625rem;
    letter-spacing: .14em; text-transform: uppercase; color: var(--text-faint); padding: .35rem .75rem 0; }

/* Верх сайдбара: тумблер демо-режима + тур */
.demo-toggle { display: flex; align-items: center; width: 100%; padding: .3rem .25rem;
    background: none; border: 0; text-align: left; text-decoration: none;
    color: var(--text-muted); font-size: var(--t-sm); }
.demo-toggle:hover { color: var(--text); }
.demo-toggle.is-on { color: var(--a-700); font-weight: var(--fw-semibold); }
.demo-toggle-track { margin-left: auto; flex: 0 0 auto; width: 30px; height: 17px; border-radius: 9px;
    background: var(--n-200); position: relative; transition: background .15s; }
.demo-toggle-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
    border-radius: 50%; background: var(--n-0); transition: transform .15s; }
.demo-toggle.is-on .demo-toggle-track { background: var(--a-500); }
.demo-toggle.is-on .demo-toggle-track::after { transform: translateX(13px); }
.quick-tour { display: flex; align-items: center; gap: .4rem; width: 100%; margin-bottom: var(--s-3);
    padding: .3rem .25rem; background: none; border: 0; text-align: left;
    color: var(--text-muted); font-size: var(--t-sm); }
.quick-tour:hover { color: var(--p-600); }

