/* Compact sidebar rail with hover/focus flyout submenus. */

.sidebar {
    --sidebar-top-nav-gap: 0.75rem;
    --sidebar-flyout-bg: color-mix(in srgb, var(--sidebar-bg) 82%, var(--sidebar-hover-bg) 18%);
    --sidebar-flyout-gap: 6px;
    /* Lucide chevron-right — used as a mask on flyout section triggers. */
    --sidebar-flyout-chevron-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m9 18 6-6-6-6'/%3E%3C/svg%3E");

    position: fixed;
    top: 0;
    left: 0;
    z-index: 999;
    width: var(--sidebar-width);
    height: 100vh; /* full viewport — no top banner */
    background: var(--sidebar-bg);
    color: var(--sidebar-fg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    /* Flyouts use position:fixed — do not clip with overflow here. */
    overflow: visible;
}

.sidebar__fill {
    flex: 1 1 auto;
    min-height: 0;
}

/* Wordmark at top of rail. */
.sidebar__brand {
    flex-shrink: 0;
    padding: 0.75rem 0.25rem 0;
}

.sidebar__dev-badge {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    margin: 0.15rem 0.35rem 0;
    padding: 0.15rem 0.25rem 0.05rem;
    color: var(--color-red-500);
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    text-align: center;
    pointer-events: none;
    user-select: none;
}

.sidebar__dev-badge-line {
    display: block;
}

.sidebar__brand-mark {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    color: var(--sidebar-fg);
    pointer-events: none;
    user-select: none;
}

.sidebar__brand-logo {
    width: 28px;
    height: 28px;
    display: block;
    object-fit: contain;
}

.sidebar__brand-title {
    display: block;
    max-width: 100%;
    font-size: 0.775rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.15;
    text-align: center;
    color: var(--sidebar-fg);
    overflow-wrap: normal;
    word-break: normal;
}

.sidebar__menu {
    flex: 0 0 auto;
    padding-bottom: 0.75rem;
}

.sidebar__sections {
    list-style: none;
    margin: 0;
    /* Matches .sidebar__flyout-nav's side padding (0.35rem 0.5rem) so a
       hovered item's rounded background sits inset from the rail's edges,
       same as sub-nav items sit inset from the flyout panel's edges. */
    padding: 0.35rem 0.5rem;
    display: flex;
    flex-direction: column;
    /* No flex gap — .sidebar__flyout-nav is a plain block list with no
       gap either; item spacing comes solely from each trigger's own
       margin (see .sidebar__section-trigger) to match it exactly. */
}

.sidebar__separator {
    /* Matches .sidebar__flyout-separator's own margin exactly. */
    margin: 0.35rem 0;
    padding: 0;
    width: 100%;
    height: 1px;
    border: none;
    /* Solid color, matching .sidebar__flyout-separator (sub-nav) rather
       than the old gradient. */
    background: var(--color-blue-brand);
    box-sizing: border-box;
}

/* Inset gray rail dividers (logo → dev badge → nav) — not flyout blue. */
.sidebar__brand + .sidebar__separator,
.sidebar__dev-badge + .sidebar__separator {
    width: auto;
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    background: color-mix(in srgb, var(--sidebar-hover-bg) 85%, white);
}

.sidebar__brand + .sidebar__separator {
    margin-top: 0.75rem;
    margin-bottom: 0.35rem;
}

.sidebar__dev-badge + .sidebar__separator {
    margin-top: 0.45rem;
    margin-bottom: 0.35rem;
}

.sidebar__category {
    margin: 0.85rem 0 0.2rem;
    padding: 0 0.65rem;
    list-style: none;
    pointer-events: none;
    user-select: none;
}

/* First category in a flyout sits at the panel top (e.g. Database → Maintenance). */
.sidebar__flyout-nav > .sidebar__category:first-child {
    margin-top: 0.2rem;
}

.sidebar__category-label {
    display: block;
    font-size: 0.625rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    line-height: 1.2;
    text-align: left;
    color: var(--color-blue-400);
}

/* ---- Sidebar links (flyout panel) — beat browser default purple/underline ---- */

.sidebar__flyout-nav li a {
    color: var(--sidebar-fg);
    text-decoration: none;
    font-family: inherit;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.sidebar__flyout-nav li a:visited {
    color: var(--sidebar-fg);
}

.sidebar__label {
    display: block;
    max-width: 100%;
    overflow-wrap: normal;
    word-break: normal;
}

/* ---- Section triggers (Queue, CV5, …) ---- */

.sidebar__section {
    position: relative;
}

.sidebar__section-trigger {
    /* Row layout matching .sidebar__flyout-nav li a (icon left, label
       right) — the primary rail used to be a narrow icon-on-top/
       label-below column; this aligns it with the sub-nav's look. */
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    /* Matches .sidebar__flyout-nav li a's own margin exactly (the flyout
       list has no flex gap of its own — item spacing is purely this). */
    margin: 0.1rem 0;
    padding: 0.45rem 0.65rem;
    border: none;
    background: transparent;
    color: var(--sidebar-fg);
    text-decoration: none;
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    border-radius: 6px;
    transition: background 0.12s ease, color 0.12s ease;
}

/* Submenu-only triggers (CVCP, Superuser, Account) have no
   destination of their own — a pointer cursor would misleadingly imply
   they navigate somewhere. */
button.sidebar__section-trigger {
    cursor: default;
}

/* Flyout sections only — direct links (Dashboard, Requests, …) have no
   sibling .sidebar__flyout, so they stay chevron-free. Link+flyout items
   (Emails, Tracking) still get the marker even though they navigate
   on click. Chevron is absolutely positioned so labels can use the full row
   width and may run underneath it. */
.sidebar__section:has(> .sidebar__flyout) > .sidebar__section-trigger,
.sidebar-account-menu > .sidebar-account__trigger {
    position: relative;
}

.sidebar__section:has(> .sidebar__flyout) > .sidebar__section-trigger::after,
.sidebar-account-menu > .sidebar-account__trigger::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 0.35rem;
    z-index: 1;
    flex-shrink: 0;
    width: 0.875rem;
    height: 0.875rem;
    opacity: 0.45;
    pointer-events: none;
    background-color: currentColor;
    transform: translateY(-50%);
    -webkit-mask: var(--sidebar-flyout-chevron-mask) no-repeat center / contain;
    mask: var(--sidebar-flyout-chevron-mask) no-repeat center / contain;
}

.sidebar__section:has(> .sidebar__flyout):hover > .sidebar__section-trigger::after,
.sidebar__section:has(> .sidebar__flyout).is-open > .sidebar__section-trigger::after,
.sidebar-account-menu:hover > .sidebar-account__trigger::after,
.sidebar-account-menu.is-open > .sidebar-account__trigger::after {
    opacity: 0.75;
}

/* Hover / flyout open — not when this rail item is already active. */
.sidebar__section:not(:has(.sidebar__flyout-nav a.is-active)) .sidebar__section-trigger:hover:not(.is-active),
.sidebar__section.is-open:not(:has(.sidebar__flyout-nav a.is-active)) .sidebar__section-trigger:not(.is-active) {
    background: var(--sidebar-hover-bg);
    outline: none;
}

/* Direct link active (Dashboard) — same as section-with-active-child below. */
.sidebar__section-trigger.is-active,
.sidebar__section-trigger.is-active:hover,
.sidebar__section:has(.sidebar__flyout-nav a.is-active) .sidebar__section-trigger,
.sidebar__section:has(.sidebar__flyout-nav a.is-active) .sidebar__section-trigger:hover,
.sidebar__section.is-open:has(.sidebar__flyout-nav a.is-active) .sidebar__section-trigger {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-fg);
}

/* ---- Flyout panel ---- */

.sidebar__flyout {
    position: fixed;
    left: calc(var(--sidebar-width) + var(--sidebar-flyout-gap));
    top: 0;
    z-index: 1100;
    min-width: var(--sidebar-flyout-width);
    overflow: visible;
    padding: 0.35rem 0;
    background: var(--sidebar-flyout-bg);
    border: 1px solid color-mix(in srgb, var(--sidebar-border) 65%, transparent);
    border-radius: 8px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-10px);
    transition: none;
}

/* Invisible bridge so the pointer can move into the flyout without closing. */
.sidebar__flyout::before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    width: 10px;
    height: 100%;
}

.sidebar__section.is-open .sidebar__flyout {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
    transition:
        transform 0.25s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {

    .sidebar__flyout,
    .sidebar__section.is-open .sidebar__flyout {
        transition: none;
        transform: none;
    }
}

.sidebar__flyout-nav {
    list-style: none;
    margin: 0;
    padding: 0.35rem 0.5rem;
}

/* Brand-blue rule between flyout groups (e.g. Email Generator vs admin lists). */
.sidebar__flyout-separator {
    margin: 0.35rem 0;
    padding: 0;
    height: 1px;
    background: var(--color-blue-brand);
}

.sidebar__flyout-nav li a {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    margin: 0.1rem 0;
    padding: 0.45rem 0.65rem;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    white-space: nowrap;
    border-radius: 6px;
}

.sidebar__flyout-nav li a:hover:not(.is-active) {
    background: var(--sidebar-hover-bg);
}

.sidebar__flyout-nav li a.is-active,
.sidebar__flyout-nav li a.is-active:hover {
    background: color-mix(in srgb, var(--sidebar-active-bg) 70%, var(--sidebar-hover-bg) 30%);
    font-weight: 600;
}

/* ---- Nested flyout submenus (e.g. Database reference groups) ---- */

.sidebar__flyout-submenu {
    position: static;
    list-style: none;
}

.sidebar__flyout-submenu:not(:has(.sidebar__flyout-nav a.is-active))
    > .sidebar__flyout-submenu-trigger:hover:not(.is-active) .sidebar__icon,
.sidebar__flyout-submenu.is-open:not(:has(.sidebar__flyout-nav a.is-active))
    > .sidebar__flyout-submenu-trigger:not(.is-active) .sidebar__icon {
    color: var(--color-sidebar-icon);
}

.sidebar__flyout-submenu:has(.sidebar__flyout-nav a.is-active)
    > .sidebar__flyout-submenu-trigger .sidebar__icon {
    color: var(--color-sidebar-icon);
}

.sidebar__flyout-submenu-trigger {
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    margin: 0.1rem 0;
    padding: 0.45rem 1.5rem 0.45rem 0.65rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--sidebar-fg);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    white-space: nowrap;
    cursor: default;
    box-sizing: border-box;
    transition: background 0.12s ease, color 0.12s ease;
}

.sidebar__flyout-submenu-trigger::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 0.35rem;
    z-index: 1;
    width: 0.875rem;
    height: 0.875rem;
    opacity: 0.45;
    pointer-events: none;
    background-color: currentColor;
    transform: translateY(-50%);
    -webkit-mask: var(--sidebar-flyout-chevron-mask) no-repeat center / contain;
    mask: var(--sidebar-flyout-chevron-mask) no-repeat center / contain;
}

.sidebar__flyout-submenu:hover > .sidebar__flyout-submenu-trigger::after,
.sidebar__flyout-submenu.is-open > .sidebar__flyout-submenu-trigger::after {
    opacity: 0.75;
}

.sidebar__flyout-submenu:not(:has(.sidebar__flyout-nav a.is-active))
    > .sidebar__flyout-submenu-trigger:hover:not(.is-active),
.sidebar__flyout-submenu.is-open:not(:has(.sidebar__flyout-nav a.is-active))
    > .sidebar__flyout-submenu-trigger:not(.is-active) {
    background: var(--sidebar-hover-bg);
    outline: none;
}

.sidebar__flyout-submenu:has(.sidebar__flyout-nav a.is-active) > .sidebar__flyout-submenu-trigger,
.sidebar__flyout-submenu:has(.sidebar__flyout-nav a.is-active)
    > .sidebar__flyout-submenu-trigger:hover {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-fg);
    font-weight: 600;
}

.sidebar__flyout-submenu-panel {
    position: absolute;
    top: 0;
    left: calc(100% + var(--sidebar-flyout-gap));
    z-index: 1101;
    min-width: var(--sidebar-flyout-width);
    overflow: visible;
    padding: 0.35rem 0;
    background: var(--sidebar-flyout-bg);
    border: 1px solid color-mix(in srgb, var(--sidebar-border) 65%, transparent);
    border-radius: 8px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-10px);
    transition: none;
}

.sidebar__flyout-submenu-panel::before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    width: 10px;
    height: 100%;
}

.sidebar__flyout-submenu.is-open > .sidebar__flyout-submenu-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
    transition:
        transform 0.2s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.16s ease;
}

@media (prefers-reduced-motion: reduce) {

    .sidebar__flyout-submenu-panel,
    .sidebar__flyout-submenu.is-open > .sidebar__flyout-submenu-panel {
        transition: none;
        transform: none;
    }
}

/* ---- Shared icon styles ---- */

.sidebar__icon {
    width: 14px;
    height: 14px;
    color: var(--color-sidebar-icon);
    flex-shrink: 0;
    display: block;
}

.sidebar__icon--flip-x {
    transform: scaleX(-1);
}

.sidebar__external {
    width: 12px;
    height: 12px;
    margin-left: auto;
    color: var(--sidebar-fg-muted);
    flex-shrink: 0;
}

.sidebar .sidebar__icon svg path,
.sidebar .sidebar__icon svg line,
.sidebar .sidebar__icon svg circle,
.sidebar .sidebar__icon svg polyline,
.sidebar .sidebar__icon svg rect {
    stroke-width: 2.5 !important;
}

.sidebar__section-trigger:hover:not(.is-active) .sidebar__icon,
.sidebar__section.is-open .sidebar__section-trigger:not(.is-active) .sidebar__icon,
.sidebar__section:has(.sidebar__flyout-nav a.is-active) .sidebar__section-trigger .sidebar__icon,
.sidebar__section-trigger.is-active .sidebar__icon,
.sidebar__flyout-nav li a:hover:not(.is-active) .sidebar__icon {
    color: var(--color-sidebar-icon);
}

.sidebar__flyout-nav li a.is-active .sidebar__icon,
.sidebar__flyout-nav li a.is-active:hover .sidebar__icon {
    color: var(--sidebar-fg);
}

/* ---- Footer rail (superuser + account) ---- */

.sidebar__footer {
    flex-shrink: 0;
    /* Matches .sidebar__sections side padding so the account trigger lines up. */
    padding: 0 0.5rem 0.75rem;
}

.sidebar__footer-account {
    position: relative;
}

.sidebar-account-menu {
    position: relative;
}

.sidebar-account-menu .sidebar__section-trigger:hover:not(.is-active),
.sidebar-account-menu.is-open .sidebar__section-trigger:not(.is-active) {
    background: var(--sidebar-hover-bg);
    outline: none;
}

.sidebar-account__trigger.is-active,
.sidebar-account__trigger.is-active:hover,
.sidebar-account-menu:has(.sidebar-account__dropdown-link.is-active) .sidebar-account__trigger,
.sidebar-account-menu:has(.sidebar-account__dropdown-link.is-active) .sidebar-account__trigger:hover,
.sidebar-account-menu.is-open:has(.sidebar-account__dropdown-link.is-active) .sidebar-account__trigger {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-fg);
}

.sidebar-account-menu:has(.sidebar-account__dropdown-link.is-active) .sidebar-account__trigger .sidebar__icon,
.sidebar-account__trigger.is-active .sidebar__icon {
    color: var(--sidebar-fg);
}


.sidebar-account__trigger:focus-visible {
    outline: 2px solid var(--outline-focus-light);
    outline-offset: 2px;
}

.sidebar-account__dropdown {
    position: fixed;
    left: calc(var(--sidebar-width) + var(--sidebar-flyout-gap));
    z-index: 1100;
    min-width: var(--sidebar-flyout-width);
    padding: 0.35rem 0;
    background: var(--sidebar-flyout-bg);
    border: 1px solid color-mix(in srgb, var(--sidebar-border) 65%, transparent);
    border-radius: 8px;
    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-10px);
    transition: none;
}

.sidebar-account__dropdown::before {
    content: "";
    position: absolute;
    top: 0;
    left: -10px;
    width: 10px;
    height: 100%;
}

.sidebar-account-menu.is-open .sidebar-account__dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
    transition:
        transform 0.25s cubic-bezier(0.22, 1, 0.36, 1),
        opacity 0.2s ease;
}

@media (prefers-reduced-motion: reduce) {
    .sidebar-account__dropdown,
    .sidebar-account-menu.is-open .sidebar-account__dropdown {
        transition: none;
        transform: none;
    }
}

.sidebar-account__dropdown-nav {
    list-style: none;
    margin: 0;
    padding: 0.35rem 0.5rem;
}

.sidebar-account__dropdown-nav li {
    margin: 0;
    padding: 0;
}

.sidebar-account__dropdown-form {
    margin: 0;
    padding: 0;
}

.sidebar-account__dropdown-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    margin: 0.1rem 0;
    padding: 0.45rem 0.65rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--sidebar-fg);
    font-family: inherit;
    font-size: 0.84rem;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    box-sizing: border-box;
    transition: background 0.12s ease;
}

.sidebar-account__dropdown-link:hover:not(.is-active),
.sidebar-account__dropdown-link:focus-visible {
    background: var(--sidebar-hover-bg);
    outline: none;
}

.sidebar-account__dropdown-link.is-active {
    background: color-mix(in srgb, var(--sidebar-active-bg) 70%, var(--sidebar-hover-bg) 30%);
    font-weight: 600;
}

.sidebar-account__dropdown-icon {
    width: 14px;
    height: 14px;
    color: var(--color-sidebar-icon);
    flex-shrink: 0;
    display: block;
    pointer-events: none;
}

.sidebar-account__dropdown-link.is-active .sidebar-account__dropdown-icon {
    color: var(--sidebar-fg);
}

.sidebar .sidebar-account__dropdown-icon svg path,
.sidebar .sidebar-account__dropdown-icon svg line,
.sidebar .sidebar-account__dropdown-icon svg circle,
.sidebar .sidebar-account__dropdown-icon svg polyline,
.sidebar .sidebar-account__dropdown-icon svg rect {
    stroke-width: 2.5 !important;
}