/* assets/css/components/sidebar-v2.css — sidebar-v2 accordion shell
   (<x-sidebar-section> partial + Help & Legal section + collapse toggle).
   Linked from includes/header.php ONLY while the sidebar-v2 flag is on:
   its .sidebar-* selectors are the same class names used by the legacy
   sidebar (styled by layouts/sidebar.css, which loads BEFORE this sheet, so
   equal-specificity rules here win the cascade). Never load it standalone. */

/* ── CAMS2-exact section anatomy (2026-11-16 spacing pass) ────────────────
   CAMS2 sidebar spec (Sidebar.tsx): group labels are text-xs font-semibold
   UPPERCASE tracking-wider gray-400 (brand when the group holds the active
   route), separated by WHITESPACE (mt-4/mt-5) — no border separators;
   nav rows are flush-left px-3 py-2.5 ≈ 40px, text-sm font-medium, gap-3,
   20px icons, rounded-lg hovers, active = brand/10 wash + brand text,
   items 2px apart, chevron points right when closed / down when open.
   Compact density shrinks to 34/32px. Show/hide still runs through
   layouts/sidebar.css's max-height body mechanic. */

/* Whitespace rhythm between groups replaces the legacy border separators.
   8px — CMD runs 12 sections (vs CAMS2's ~8); the airy CAMS2 mt-5 made the
   menu measurably taller (regression, 2026-11-16). */
.sidebar-section + .sidebar-section {
    margin-top: 0.5rem;
}
.sidebar-section:first-of-type .sidebar-section-title {
    border-top: none;
}

.sidebar-section-title {
    min-height: 32px;
    padding: var(--spacing-2, 0.5rem) 14px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    gap: var(--spacing-3, 0.75rem);
    border-top: none;
    border-radius: var(--radius-md, 0.5rem);
    transition: background 200ms ease, color 200ms ease;
}
.sidebar-section-title:hover {
    background: var(--bg-tertiary);
    color: var(--text-secondary); /* neutral hover; brand only when open */
}
.sidebar-section-title > i:first-child {
    width: 20px;
    font-size: 15px;
    text-align: center;
}
.sidebar-section-title > svg.ci-lucide:first-child {
    width: 20px;
    height: 20px;
}
/* Chevron: right when closed, down when open (CAMS2 idiom); stays neutral —
   the group-active signal is the brand label, not a brand chevron. */
.sidebar-section-chevron {
    transform: rotate(-90deg);
    transition: transform 200ms ease;
    color: var(--text-tertiary);
}
.sidebar-section.open .sidebar-section-chevron {
    transform: rotate(0deg);
    color: var(--text-tertiary);
}
.sidebar-section-title:hover .sidebar-section-chevron {
    color: var(--text-secondary);
}

/* No left accent border; active is the brand/10 wash + brand text.
   Items carry font-medium (500) per CAMS2 nav rows. */
.sidebar-section-title,
.sidebar-link {
    border-left: none;
}
.sidebar-section-title {
    font-weight: 600;
}
.sidebar-link {
    font-weight: 500;
}

/* The group containing the active route is auto-opened server-side (the
   section renders with class "open"); its title reads as brand-coloured. */
.sidebar-section.open .sidebar-section-title {
    color: var(--color-brand-dark);
}
.dark .sidebar-section.open .sidebar-section-title {
    color: var(--color-brand-100);
}

.sidebar-link {
    min-height: 40px;
    padding: var(--spacing-2, 0.5rem) 14px;
    font-size: 13px;
    gap: var(--spacing-3, 0.75rem);
    border-radius: var(--radius-md, 0.5rem);
    transition: background 200ms ease, color 200ms ease;
}
/* CAMS2 space-y-0.5 between items inside a group. */
.sidebar-section-body .sidebar-link + .sidebar-link {
    margin-top: 2px;
}
.sidebar-link > i {
    width: 20px;
    font-size: 15px;
    text-align: center;
}
.sidebar-link > svg.ci-lucide {
    width: 20px;
    height: 20px;
}
/* Accordion chevron (Lucide svg variant of .sidebar-section-chevron). */
.sidebar-section-chevron.ci-lucide {
    width: 16px;
    height: 16px;
}

/* Active child = brand tint bg + brand-dark text (existing tokens). Same pair
   layouts/sidebar.css uses; repeated here so the v2 contract holds even if
   the base sheet's values move. brand-dark, not brand: brand text on the 10%
   tint measures 4.03:1 (below AA 4.5:1 for 13px text). */
.sidebar-link.active {
    color: var(--color-brand-dark);
    background: color-mix(in srgb, var(--color-brand) 10%, transparent);
}

/* ── Desktop collapse toggle (>=1280px) ────────────────────────────────────
   #sidebarCollapseToggle (sidebar footer) flips .sidebar--collapsed on the
   sidebar root and .cmd-sidebar-collapsed on <html>. Persisted in
   localStorage "cmd_sidebar_collapsed"; the head boot script applies the
   <html> class before first paint, so every rule below keys off it —
   flash-free, same pattern as the theme boot. The .sidebar--collapsed root
   class is JS state and mirrors the <html> class 1:1 (sidebar.js keeps them
   in sync). Below 1280px the button is hidden and the class has no effect
   (the mobile drawer keeps full labels). */
.sidebar-collapse-toggle {
    display: none;
}

@media (min-width: 1280px) {
    .sidebar-collapse-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--spacing-2, 0.5rem);
        width: calc(100% - 1rem);
        margin: var(--spacing-2, 0.5rem) auto;
        padding: var(--spacing-2, 0.5rem) 0;
        border: 1px solid var(--border-subtle);
        border-radius: var(--radius-md, 0.5rem);
        background: transparent;
        color: var(--text-secondary);
        cursor: pointer;
        font-size: 0.8rem;
        transition: all var(--transition-fast, 150ms);
    }

    .sidebar-collapse-toggle i,
    .sidebar-collapse-toggle svg.ci-lucide {
        transition: transform var(--transition-fast, 150ms);
    }

    .sidebar-collapse-toggle:hover {
        background: var(--bg-tertiary);
        color: var(--color-brand);
    }

    html.cmd-sidebar-collapsed .sidebar-collapse-toggle i {
        transform: rotate(180deg);
    }

    /* 72px icon rail — same variable the 1024-1280 auto-rail repoints, so
       .sidebar, .content-wrapper and .topbar all follow it. */
    html.cmd-sidebar-collapsed {
        --sidebar-width: var(--sidebar-collapsed-width, 4.5rem);
    }

    /* Section titles become icon-only (label + chevron hidden, children hidden). */
    html.cmd-sidebar-collapsed .sidebar-section-title span,
    html.cmd-sidebar-collapsed .sidebar-section-chevron {
        display: none;
    }

    html.cmd-sidebar-collapsed .sidebar-section-title {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    html.cmd-sidebar-collapsed .sidebar-section-title > i:first-child,
    html.cmd-sidebar-collapsed .sidebar-section-title > svg.ci-lucide:first-child {
        margin: 0;
    }

    html.cmd-sidebar-collapsed .sidebar-section-body {
        display: none;
    }

    html.cmd-sidebar-collapsed .sidebar-band-title {
        display: none;
    }

    /* Rest of the chrome follows the auto-rail treatment (reused, not
       duplicated: identical rules to the 1024-1279.98px block). */
    html.cmd-sidebar-collapsed .sidebar-search {
        display: none;
    }

    html.cmd-sidebar-collapsed .sidebar-header {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    html.cmd-sidebar-collapsed .sidebar-logo {
        height: 1.75rem;
        max-width: 3rem;
        object-fit: contain;
    }

    html.cmd-sidebar-collapsed .sidebar-close {
        display: none;
    }

    html.cmd-sidebar-collapsed .sidebar-user-card {
        justify-content: center;
    }

    html.cmd-sidebar-collapsed .sidebar-user-card__info,
    html.cmd-sidebar-collapsed .sidebar-user-card__theme {
        display: none;
    }

    html.cmd-sidebar-collapsed .sidebar-link {
        justify-content: center;
        padding-left: 0;
        padding-right: 0;
    }

    html.cmd-sidebar-collapsed .sidebar-link span {
        display: none;
    }
}

/* Sidebar quick-create in rail (icon-only) mode — button centered, label
   hidden, menu fixed-width so it doesn't squeeze to the 72px rail. */
@media (min-width: 1280px) {
    html.cmd-sidebar-collapsed .sidebar-create { margin: 10px 8px 4px; }
    html.cmd-sidebar-collapsed .sidebar-create__btn span { display: none; }
    html.cmd-sidebar-collapsed .sidebar-create__menu { right: auto; width: 200px; }
}


/* CAMS2 compact density: sidebar rows shrink to 34px (links) / 32px
   (titles) and the icon column drops to 18px. */
[data-density="compact"] .sidebar-section-title { min-height: 28px; }
[data-density="compact"] .sidebar-link { min-height: 34px; }
[data-density="compact"] .sidebar-link > i,
[data-density="compact"] .sidebar-section-title > i:first-child { width: 18px; font-size: 14px; }
[data-density="compact"] .sidebar-link > svg.ci-lucide,
[data-density="compact"] .sidebar-section-title > svg.ci-lucide:first-child { width: 18px; height: 18px; }

/* ── Category color coding (2026-10-13) ──────────────────────────────
   One hue per nav section — visual wayfinding through the menu maze.
   The section key IS the category: .navcat-{key} sets --navc, .navcat
   applies it. Applied ONLY to icons and picker chips; text stays neutral.
   Hue anchors: home = brand orange; the rest sit on the Tailwind-600
   scale (light) / 300–400 scale (dark), spread around the wheel so no
   two neighbours read alike. Manage cluster stays quiet slate. */
.navcat-home           { --navc: var(--color-brand); }
.navcat-dashboard      { --navc: var(--color-nav-dashboard); } /* pink-600   */
.navcat-mix-design     { --navc: var(--color-nav-mix-design); } /* violet-600 */
.navcat-materials      { --navc: var(--color-nav-materials); } /* cyan-600   */
.navcat-production     { --navc: var(--color-nav-production); } /* blue-600   */
.navcat-quality        { --navc: var(--color-nav-quality); } /* emerald-600*/
.navcat-reports        { --navc: var(--color-nav-reports); } /* amber-600  */
.navcat-analysis       { --navc: var(--color-nav-analysis); } /* teal-600   */
.navcat-calibration    { --navc: var(--color-nav-calibration); } /* lime-600   */
.navcat-setup          { --navc: var(--color-nav-setup); } /* slate-500  */
.navcat-administration { --navc: var(--color-nav-setup); }
.navcat-account        { --navc: var(--color-nav-setup); }
html.dark .navcat-dashboard      { --navc: var(--color-nav-dashboard); } /* pink-400   */
html.dark .navcat-mix-design     { --navc: var(--color-nav-mix-design); } /* violet-400 */
html.dark .navcat-materials      { --navc: var(--color-nav-materials); } /* cyan-400   */
html.dark .navcat-production     { --navc: var(--color-nav-production); } /* blue-400   */
html.dark .navcat-quality        { --navc: var(--color-nav-quality); } /* emerald-400*/
html.dark .navcat-reports        { --navc: var(--color-nav-reports); } /* amber-400  */
html.dark .navcat-analysis       { --navc: var(--color-nav-analysis); } /* teal-400   */
html.dark .navcat-calibration    { --navc: var(--color-nav-calibration); } /* lime-400   */
html.dark .navcat-setup          { --navc: var(--color-nav-setup); } /* slate-400  */
html.dark .navcat-administration { --navc: var(--color-nav-setup); }
html.dark .navcat-account        { --navc: var(--color-nav-setup); }
/* !important + element selector: beats any inherited/direct color rule in
   any stylesheet — the category hue is non-negotiable wayfinding. */
i.navcat, .navcat { color: var(--navc, inherit) !important; }

/* ── N4 sidebar bands + sub-headings ───────────────────────────────────────
   Band headings (Daily / Lifecycle / Manage) are plain non-interactive text:
   small uppercase muted labels that separate the three groups of sections.
   Sub-headings label runs of links inside one long section; their left inset
   lines up with the link text (14px row padding + 20px icon + 12px gap). */
.sidebar-band + .sidebar-band,
.sidebar-band + .sidebar-section {
    margin-top: var(--spacing-4, 1rem);
}
.sidebar-band-title {
    padding: var(--spacing-1, 0.25rem) 14px var(--spacing-1, 0.25rem);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    user-select: none;
}
.sidebar-subheading {
    padding: var(--spacing-2, 0.5rem) 14px 2px calc(14px + 20px + var(--spacing-3, 0.75rem));
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-tertiary);
    user-select: none;
}

/* Single-link section (Home, Dashboard): the row reads like a section title
   (same height, type and icon column) but is a plain link — no chevron, no
   body. .sidebar-link.sidebar-section-link beats the generic link rules. */
.sidebar-link.sidebar-section-link {
    min-height: 32px;
    padding: var(--spacing-2, 0.5rem) 14px 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    gap: var(--spacing-3, 0.75rem);
    color: var(--text-secondary);
}
.sidebar-link.sidebar-section-link:hover {
    background: var(--bg-tertiary);
}
.sidebar-link.sidebar-section-link.active {
    color: var(--color-brand-dark);
}
.dark .sidebar-link.sidebar-section-link.active {
    color: var(--color-brand-100);
}
html.cmd-sidebar-collapsed .sidebar-link.sidebar-section-link > span {
    display: none;
}
