/* ============================================================
   Ziqsy CMS — Persistent role-aware left sidebar
   Additive layer. Loaded after the design system so it wins.
   Integrates with the existing shell:
     .top-header  fixed, 64px, full width (unified bar; carries the nav toggle)
   ============================================================ */

:root {
    --zq-sidebar-w: 268px;
    --zq-sidebar-w-collapsed: 76px;
    --zq-header-h: 64px;
    --zq-sidebar-bg: #ffffff;
    --zq-sidebar-fg: #475569;
    --zq-sidebar-muted: #5b6b7f;              /* WCAG AA 5.4:1 on white (was #94a3b8 = 2.56:1) */
    --zq-sidebar-active: #00aeef;             /* bright azure: decorative accent bar + badge bg only */
    --zq-sidebar-active-ink: #00719e;         /* azure TEXT on the active pill (5.1:1 on #e6f7fd) */
    --zq-sidebar-active-soft: rgba(0, 174, 239, .10);
    --zq-sidebar-border: #e8edf3;
    --zq-sidebar-ink: #0f172a;
}

/* ---- Shell adjustments when a sidebar is present (authenticated) ---- */
@media (min-width: 992px) {
    body.has-sidebar > .container-fluid {
        margin-left: var(--zq-sidebar-w);
        transition: margin-left .22s cubic-bezier(.4, 0, .2, 1);
    }
    /* Collapsed (rail) mode */
    body.has-sidebar.zq-rail > .container-fluid { margin-left: var(--zq-sidebar-w-collapsed); }
}

/* ---- The sidebar ---- */
.app-sidebar {
    position: fixed;
    top: var(--zq-header-h);
    left: 0;
    bottom: 0;
    width: var(--zq-sidebar-w);
    background: var(--zq-sidebar-bg);
    border-right: 1px solid var(--zq-sidebar-border);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform .25s cubic-bezier(.4, 0, .2, 1), width .22s cubic-bezier(.4, 0, .2, 1);
    font-family: var(--zq-font-body, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
}

.app-sidebar__scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 14px 14px 8px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}
.app-sidebar__scroll::-webkit-scrollbar { width: 8px; }
.app-sidebar__scroll::-webkit-scrollbar-thumb { background: #d8e0ea; border-radius: 8px; border: 2px solid #fff; }
.app-sidebar__scroll::-webkit-scrollbar-thumb:hover { background: #c2cedb; }

/* Section grouping */
.app-nav-section { margin-bottom: 6px; }
.app-nav-section + .app-nav-section { margin-top: 10px; }

.app-nav-section__label {
    font-family: var(--zq-font-display, 'Plus Jakarta Sans', sans-serif);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--zq-sidebar-muted);
    padding: 10px 12px 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Nav items */
.app-nav-link {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    margin: 2px 0;
    border-radius: 10px;
    color: var(--zq-sidebar-fg);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease, transform .12s ease;
}
.app-nav-link i {
    font-size: 18px;
    width: 22px;
    text-align: center;
    flex: 0 0 22px;
    color: var(--zq-sidebar-muted);
    transition: color .15s ease;
}
.app-nav-link span { overflow: hidden; text-overflow: ellipsis; }

.app-nav-link:hover {
    background: #f1f5f9;
    color: var(--zq-sidebar-ink);
}
.app-nav-link:hover i { color: var(--zq-sidebar-ink); }

.app-nav-link.is-active {
    background: var(--zq-sidebar-active-soft);
    color: var(--zq-sidebar-active-ink);
    font-weight: 600;
}
.app-nav-link.is-active i { color: var(--zq-sidebar-active-ink); }
.app-nav-link.is-active::before {
    content: "";
    position: absolute;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
    height: 22px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--zq-sidebar-active);
}

/* Optional small count/badge on a link */
.app-nav-link .app-nav-badge {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    background: var(--zq-sidebar-active);
    color: #fff;
    border-radius: 999px;
    padding: 1px 7px;
    line-height: 1.5;
}

/* ---- Footer: compact user card ---- */
.app-sidebar__footer {
    flex: 0 0 auto;
    border-top: 1px solid var(--zq-sidebar-border);
    padding: 10px 12px;
    background: #fbfdff;
}
.app-usercard {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px;
    border-radius: 12px;
    text-decoration: none;
    transition: background .15s ease;
}
.app-usercard:hover { background: #eef6fb; }
.app-usercard__avatar {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
}
.app-usercard__avatar-fallback {
    flex: 0 0 38px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    font-family: var(--zq-font-display, 'Plus Jakarta Sans', sans-serif);
}
.app-usercard__meta { min-width: 0; flex: 1 1 auto; }
.app-usercard__name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--zq-sidebar-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-usercard__role {
    font-size: 11.5px;
    color: var(--zq-sidebar-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.app-sidebar__logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    border: 1px solid var(--zq-sidebar-border);
    border-radius: 10px;
    background: #fff;
    color: #64748b;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.app-sidebar__logout:hover { background: #fff1f2; color: #e11d48; border-color: #fecdd3; }

/* ---- Rail (collapsed) behaviour on desktop ---- */
@media (min-width: 992px) {
    body.zq-rail .app-sidebar { width: var(--zq-sidebar-w-collapsed); }
    body.zq-rail .app-sidebar .app-nav-link span,
    body.zq-rail .app-sidebar .app-nav-section__label,
    body.zq-rail .app-sidebar .app-usercard__meta,
    body.zq-rail .app-sidebar .app-nav-badge,
    body.zq-rail .app-sidebar .app-sidebar__logout span { display: none; }
    body.zq-rail .app-sidebar .app-nav-link { justify-content: center; padding: 10px; }
    body.zq-rail .app-sidebar .app-nav-link.is-active::before { left: -10px; }
    body.zq-rail .app-sidebar .app-nav-section__label {
        display: block; height: 1px; padding: 0; margin: 8px 8px;
        background: var(--zq-sidebar-border); text-indent: -9999px; overflow: hidden;
    }
    body.zq-rail .app-sidebar .app-usercard { justify-content: center; }
}

/* ---- Mobile: off-canvas drawer ---- */
.zq-sidebar-backdrop {
    position: fixed;
    inset: var(--zq-header-h) 0 0 0;
    background: rgba(15, 23, 42, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .22s ease, visibility .22s ease;
    z-index: 999;
}
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        box-shadow: 0 18px 50px rgba(15, 23, 42, .22);
        width: min(86vw, var(--zq-sidebar-w));
    }
    body.zq-drawer-open .app-sidebar { transform: translateX(0); }
    body.zq-drawer-open .zq-sidebar-backdrop { opacity: 1; visibility: visible; }
    body.has-sidebar > .container-fluid { margin-left: 0; }
}

/* ---- Toggle button (in the context bar) ---- */
.zq-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--zq-sidebar-border);
    border-radius: 10px;
    background: #fff;
    color: #475569;
    font-size: 19px;
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.zq-nav-toggle:hover { background: #f1f5f9; color: var(--zq-sidebar-active); border-color: #cfe9f7; }
