/* JennSentry Sidebar — Phase B shell (B1)
 * Uses only design tokens from sentry.css :root.
 * Dark mode inherits automatically via [data-theme="dark"] overrides.
 */

:root {
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 56px;
}

/* ── Sidebar shell ─────────────────────────────────────────────── */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: width var(--transition-normal);
    overflow: hidden;
}

.sidebar[data-collapsed="true"] {
    width: var(--sidebar-collapsed-width);
}

/* ── Header ────────────────────────────────────────────────────── */

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    min-height: 52px;
    flex-shrink: 0;
}

.sidebar-header img {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.sidebar-header span {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Action List header badge ─────────────────────────────────── */

.sidebar-header .action-list-badge {
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--error);
    color: var(--surface);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    flex-shrink: 0;
    /* Override .sidebar-header span inherited overflow rules — pill must not clip */
    overflow: visible;
    text-overflow: clip;
}

/* ── Navigation scroll container ───────────────────────────────── */

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: var(--radius-pill);
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

/* ── Section (collapsible group) ───────────────────────────────── */

.sidebar-section {
    margin-bottom: 4px;
}

.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 14px;
    cursor: pointer;
    user-select: none;
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.sidebar-section-header:hover {
    color: var(--text);
}

.sidebar-section-header .chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}

.sidebar-section[data-expanded="false"] .sidebar-section-header .chevron {
    transform: rotate(-90deg);
}

/* Hide items when section is collapsed */
.sidebar-section[data-expanded="false"] .sidebar-item {
    display: none;
}

/* ── Navigation item ───────────────────────────────────────────── */

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    margin: 1px 6px;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
    overflow: hidden;
    border-left: 3px solid transparent;
}

.sidebar-item .icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    line-height: 1;
}

.sidebar-item:hover {
    background: var(--surface-2);
}

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

/* Active state — teal left border + tinted background */
.sidebar-item.active {
    border-left-color: var(--primary);
    background: rgba(var(--primary-rgb), 0.08);
    color: var(--primary);
    font-weight: 600;
}

.sidebar-item.active:hover {
    background: rgba(var(--primary-rgb), 0.12);
}

/* Badge (notification count, etc.) */
.sidebar-item .badge {
    margin-left: auto;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: var(--radius-pill);
    background: var(--error);
    color: var(--surface);
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    line-height: 18px;
    text-align: center;
    flex-shrink: 0;
}

/* ── Pinned items ──────────────────────────────────────────────── */

.sidebar-item-pinned {
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    margin-top: 4px;
    margin-bottom: 4px;
    padding-top: 4px;
    padding-bottom: 4px;
}

.sidebar-item-pinned .sidebar-item {
    margin-top: 0;
    margin-bottom: 0;
}

/* ── Tier counts (tiny inline widget: now / watch / improve) ──── */

.sidebar-tier-counts {
    display: inline-flex;
    gap: 6px;
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 10px;
    line-height: 1;
    flex-shrink: 0;
}

.sidebar-tier-counts span {
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    font-weight: 400;
}

.sidebar-tier-counts .now {
    background: var(--error-bg);
    color: var(--error);
}

.sidebar-tier-counts .watch {
    background: var(--warning-bg);
    color: var(--warning);
}

.sidebar-tier-counts .improve {
    background: var(--info-bg);
    color: var(--info);
}

/* ── Footer ────────────────────────────────────────────────────── */

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    font-family: var(--font-body);
    font-size: 12px;
    color: var(--text-muted);
}

.sidebar-footer .node-info {
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .node-role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 1px 6px;
    border-radius: var(--radius-pill);
    background: rgba(var(--primary-rgb), 0.10);
    color: var(--primary);
}

.sidebar-footer .theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-footer .theme-toggle:hover {
    background: var(--border);
    color: var(--text);
}

/* ── Collapse toggle ───────────────────────────────────────────── */

.sidebar-collapse {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    margin-left: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast),
                transform var(--transition-fast);
}

.sidebar-collapse:hover {
    background: var(--border);
    color: var(--text);
}

.sidebar[data-collapsed="true"] .sidebar-collapse {
    transform: rotate(180deg);
}

/* ── Collapsed state — hide labels, keep icons ─────────────────── */

.sidebar[data-collapsed="true"] .sidebar-item span:not(.icon):not(.badge) {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-header span:not(.action-list-badge) {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-section-header {
    justify-content: center;
    padding: 6px 0;
}

.sidebar[data-collapsed="true"] .sidebar-section-header span {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-section-header .chevron {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-item {
    justify-content: center;
    padding: 8px 0;
    margin: 1px 4px;
    border-left-width: 0;
}

.sidebar[data-collapsed="true"] .sidebar-item.active {
    /* Use bottom border instead of left border in collapsed mode */
    border-left-width: 0;
    background: rgba(var(--primary-rgb), 0.08);
}

.sidebar[data-collapsed="true"] .sidebar-tier-counts {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-footer .node-info span:not(.node-role) {
    display: none;
}

.sidebar[data-collapsed="true"] .sidebar-footer {
    align-items: center;
    padding: 10px 4px;
}

.sidebar[data-collapsed="true"] .sidebar-header {
    justify-content: center;
    padding: 12px 4px;
}

/* ── Responsive: auto-collapse to icon rail ────────────────────── */

@media (max-width: 1199px) {
    .sidebar {
        width: var(--sidebar-collapsed-width);
    }

    .sidebar .sidebar-item span:not(.icon):not(.badge) {
        display: none;
    }

    .sidebar .sidebar-header span:not(.action-list-badge) {
        display: none;
    }

    .sidebar .sidebar-section-header span {
        display: none;
    }

    .sidebar .sidebar-section-header .chevron {
        display: none;
    }

    .sidebar .sidebar-section-header {
        justify-content: center;
        padding: 6px 0;
    }

    .sidebar .sidebar-item {
        justify-content: center;
        padding: 8px 0;
        margin: 1px 4px;
        border-left-width: 0;
    }

    .sidebar .sidebar-tier-counts {
        display: none;
    }

    .sidebar .sidebar-footer .node-info span:not(.node-role) {
        display: none;
    }

    .sidebar .sidebar-footer {
        align-items: center;
        padding: 10px 4px;
    }

    .sidebar .sidebar-header {
        justify-content: center;
        padding: 12px 4px;
    }

    .sidebar .sidebar-collapse {
        transform: rotate(180deg);
    }
}

/* ── Responsive: off-canvas drawer with backdrop ───────────────── */

@media (max-width: 767px) {
    .sidebar {
        width: var(--sidebar-width);
        transform: translateX(-100%);
        transition: transform var(--transition-normal), width var(--transition-normal);
        box-shadow: var(--shadow-lg);
    }

    .sidebar[data-collapsed="true"] {
        width: var(--sidebar-width);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Reset collapsed-mode overrides for mobile drawer (show full labels) */
    .sidebar .sidebar-item span:not(.icon):not(.badge) {
        display: inline;
    }

    .sidebar .sidebar-header span:not(.action-list-badge) {
        display: inline;
    }

    .sidebar .sidebar-section-header span {
        display: inline;
    }

    .sidebar .sidebar-section-header .chevron {
        display: inline;
    }

    .sidebar .sidebar-section-header {
        justify-content: space-between;
        padding: 6px 14px;
    }

    .sidebar .sidebar-item {
        justify-content: flex-start;
        padding: 8px 14px;
        margin: 1px 6px;
        border-left-width: 3px;
    }

    .sidebar .sidebar-tier-counts {
        display: inline-flex;
    }

    .sidebar .sidebar-footer .node-info span:not(.node-role) {
        display: inline;
    }

    .sidebar .sidebar-footer {
        align-items: stretch;
        padding: 10px 14px;
    }

    .sidebar .sidebar-header {
        justify-content: flex-start;
        padding: 12px 14px;
    }

    .sidebar .sidebar-collapse {
        transform: none;
    }

    /* Backdrop overlay */
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 99;
        background: rgba(0, 0, 0, 0.4);
        transition: opacity var(--transition-normal);
        opacity: 0;
    }

    .sidebar-backdrop.visible {
        display: block;
        opacity: 1;
    }
}

/* Backdrop is hidden by default on larger screens */
@media (min-width: 768px) {
    .sidebar-backdrop {
        display: none;
    }
}

/* ── Teams-embedded mode ───────────────────────────────────────── */

body.teams-embedded .sidebar-header {
    /* Teams provides its own app icon in the tab frame */
    display: none;
}

body.teams-embedded .sidebar {
    /* Offset for missing header */
    padding-top: 4px;
}

/* ── Main offset (B4) ──────────────────────────────────────────── */
/* sidebar.js sets body.has-sidebar on init. Push <main> rightward
 * to make room for the fixed-position sidebar.
 */

body.has-sidebar .dashboard-main {
    margin-left: var(--sidebar-width);
    transition: margin-left var(--transition-normal);
}

/* When the sidebar is user-collapsed (rail), shrink the offset to match. */
body.has-sidebar .sidebar[data-collapsed="true"] ~ .dashboard-main,
body.has-sidebar:has(.sidebar[data-collapsed="true"]) .dashboard-main {
    margin-left: var(--sidebar-collapsed-width);
}

/* Responsive: at icon-rail breakpoint, main offset matches collapsed width. */
@media (max-width: 1199px) {
    body.has-sidebar .dashboard-main {
        margin-left: var(--sidebar-collapsed-width);
    }
}

/* Mobile: sidebar becomes off-canvas drawer; main reclaims full width. */
@media (max-width: 767px) {
    body.has-sidebar .dashboard-main {
        margin-left: 0;
    }
}
