/*
 * IMPACCT 2.0 — Base Layout
 * Sidebar (collapsible + resizable), topbar, content area, responsive.
 * All colors use theme CSS variables from theme.css.
 *
 * Sidebar behavior:
 * - User can collapse/expand via toggle button (hamburger ☰ / ✕)
 * - User can drag the right edge to resize between 180px–400px
 * - Collapsed state shows only icons (56px wide)
 * - Width and collapsed state persist in localStorage
 * - Main content margin adjusts dynamically via --sidebar-width
 */

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    /* Default sidebar width — overridden by JS from localStorage */
    --sidebar-width: 240px;
    --sidebar-collapsed-width: 56px;
    --header-height: 48px;
}

a {
    color: var(--accent-primary);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
    color: var(--accent-hover);
}

/* ══════════════════════════════════════
   SIDEBAR
   ══════════════════════════════════════ */
.sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-primary);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transition: width 0.2s ease;
    overflow: hidden;
}

/* ── Sidebar Header ── */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    height: var(--header-height);
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.brand-name {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-primary);
    letter-spacing: 0.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Collapse Toggle Button ── */
.sidebar-toggle {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}

.sidebar-toggle:hover {
    color: var(--text-primary);
    background: var(--sidebar-hover);
}

/* ── Sidebar Navigation ── */
.sidebar-nav {
    flex: 1;
    padding: 8px 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Upper section takes user-controlled flex proportion */
.sidebar-upper {
    flex: var(--sidebar-upper-flex, 3);
    min-height: 80px;
}

/* Lower section takes remaining space */
.sidebar-lower {
    flex: var(--sidebar-lower-flex, 1);
    min-height: 40px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--sidebar-text);
    font-size: 0.88rem;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    color: var(--sidebar-active);
    background: var(--sidebar-hover);
    font-weight: 600;
}

/* ── Section Header (non-clickable label above child links) ── */
.nav-section-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    user-select: none;
    cursor: default;
    white-space: nowrap;
    overflow: hidden;
}

.nav-section-header .nav-icon {
    font-size: 0.85rem;
}

/* When collapsed, hide section header label but keep icon */
.sidebar.collapsed .nav-section-header {
    justify-content: center;
    padding: 8px 0 6px;
}

/* Nav item icon (shown always, text hides on collapse) */
.nav-icon {
    font-size: 1.05rem;
    width: 22px;
    text-align: center;
    flex-shrink: 0;
}

.nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity 0.2s;
}

.nav-premium .nav-label::after {
    content: 'PRO';
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 4px;
    margin-left: 6px;
    border-radius: 3px;
    background: var(--accent-secondary);
    color: var(--btn-primary-text);
    vertical-align: middle;
}

/* ── Sidebar Footer ── */
.sidebar-footer {
    padding: 8px 0;
    border-top: 1px solid var(--border-primary);
}

.nav-logout {
    color: var(--color-danger) !important;
}

.nav-admin {
    color: var(--color-warning) !important;
    font-weight: 600;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-primary);
    margin: 4px 12px;
}

/* ── Brand Block ── */
.brand-block {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.brand-subtitle {
    font-size: 0.55rem;
    color: var(--text-muted);
    letter-spacing: 1.2px;
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1;
    margin-top: -2px;
}

.sidebar.collapsed .brand-subtitle {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* ── Sidebar Section Labels (V3) ── */
.sidebar-section-label {
    font-size: 9px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.7px;
    padding: 14px 16px 5px;
    user-select: none;
    cursor: default;
    white-space: nowrap;
    overflow: hidden;
}

.sidebar.collapsed .sidebar-section-label {
    font-size: 0;
    padding: 8px 0;
    text-align: center;
}

.sidebar.collapsed .sidebar-section-label::before {
    content: '—';
    font-size: 9px;
    display: block;
    text-align: center;
    color: var(--text-muted);
}

/* ── Nav Badges (V3) ── */
.nav-badge {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 700;
    display: inline-block;
    vertical-align: middle;
    margin-left: 4px;
}

.nav-badge-live {
    background: rgba(16, 185, 129, 0.15);
    color: var(--color-success, #10b981);
}

.nav-badge-pro {
    background: rgba(99, 102, 241, 0.15);
    color: var(--accent-primary, #6366f1);
}

.nav-badge-new {
    background: rgba(245, 158, 11, 0.18);
    color: var(--color-warning, #f59e0b);
}

.sidebar.collapsed .nav-badge {
    display: none;
}

/* ── Persona Switcher (V3) ── */
.persona-switcher {
    padding: 4px 8px;
    margin-bottom: 4px;
}

.persona-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-hover, rgba(255,255,255,0.05));
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm, 6px);
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

.persona-toggle:hover {
    background: var(--sidebar-hover);
}

.persona-current-icon {
    font-size: 1rem;
}

.persona-current-label {
    flex: 1;
    text-align: left;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.persona-chevron {
    flex-shrink: 0;
    transition: transform 0.2s;
}

.persona-options {
    margin-top: 4px;
    background: var(--bg-card, var(--bg-secondary));
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm, 6px);
    overflow: hidden;
}

.persona-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.1s, color 0.1s;
}

.persona-option:hover {
    background: var(--sidebar-hover);
    color: var(--text-primary);
}

.persona-option-active {
    color: var(--accent-primary);
    font-weight: 600;
}

.sidebar.collapsed .persona-switcher {
    padding: 4px 2px;
}

.sidebar.collapsed .persona-current-label,
.sidebar.collapsed .persona-chevron {
    display: none;
}

.sidebar.collapsed .persona-toggle {
    justify-content: center;
    padding: 8px 4px;
}

.sidebar.collapsed .persona-options {
    position: absolute;
    left: 100%;
    bottom: 40px;
    width: 160px;
    z-index: 200;
}

/* ── Resize Handle (right edge of sidebar) ── */
.sidebar-resize-handle {
    position: absolute;
    right: -3px;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 101;
    background: transparent;
    transition: background 0.15s;
}

.sidebar-resize-handle:hover,
.sidebar-resize-handle.dragging {
    background: var(--accent-primary);
    opacity: 0.5;
}

/* ── Section Splitter (draggable divider between main nav and admin) ── */
.sidebar-splitter {
    height: 6px;
    margin: 0 8px;
    cursor: row-resize;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    border-radius: 3px;
    position: relative;
}

.sidebar-splitter::after {
    content: '';
    width: 30px;
    height: 2px;
    background: var(--border-secondary);
    border-radius: 1px;
    transition: background 0.15s, width 0.15s;
}

.sidebar-splitter:hover::after,
.sidebar-splitter.dragging::after {
    background: var(--accent-primary);
    width: 40px;
}

.sidebar-splitter:hover {
    background: var(--bg-hover);
}

/* ══════════════════════════════════════
   COLLAPSED STATE
   ══════════════════════════════════════ */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Hide text labels when collapsed */
.sidebar.collapsed .brand-name,
.sidebar.collapsed .nav-label {
    opacity: 0;
    width: 0;
    pointer-events: none;
}

/* Center icons when collapsed */
.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 10px 0;
}

/* Keep resize handle visible when collapsed — user can drag to expand */
/* (No display:none here — intentionally kept visible) */

/* Hide premium badge in collapsed state */
.sidebar.collapsed .nav-premium .nav-label::after {
    display: none;
}

/* Minimise splitter when collapsed */
.sidebar.collapsed .sidebar-splitter {
    margin: 0 4px;
}

/* Adjust main content when collapsed */
.sidebar.collapsed ~ .main-content {
    margin-left: var(--sidebar-collapsed-width);
}

/* ══════════════════════════════════════
   MAIN CONTENT
   ══════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.2s ease;
}

.main-content-full {
    margin-left: 0 !important;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-primary);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-greeting {
    font-size: 0.95rem;
    color: var(--text-primary);
    font-weight: 500;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-persona {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: capitalize;
}

/* ── Topbar Page Title (V3) ── */
.topbar-page-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    margin: 0;
}

/* ── Persona Pill (V3 topbar) ── */
.persona-pill {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* ── Search Bar Enhancements (V3) ── */
.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.global-search-wrap {
    position: relative;
}

.global-search-wrap .global-search-input {
    padding-left: 30px;
    padding-right: 40px;
}

.search-shortcut {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-primary, rgba(0,0,0,0.1));
    padding: 1px 5px;
    border-radius: 3px;
    border: 1px solid var(--border-primary);
    pointer-events: none;
    font-family: monospace;
}

/* ── Notification Dot (V3) ── */
.notif-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-danger, #ef4444);
}

/* ── User Avatar (V3) ── */
.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    border: 2px solid;
    background: var(--bg-hover, rgba(255,255,255,0.05));
    color: var(--text-primary);
    flex-shrink: 0;
}

/* ── Notification Bell ── */
.notif-bell-wrap {
    position: relative;
}

.notif-bell-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    position: relative;
    padding: 4px 6px;
    border-radius: 6px;
    transition: background 0.12s;
}

.notif-bell-btn:hover {
    background: var(--bg-hover);
}

.notif-bell-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    background: var(--color-danger);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

.notif-panel {
    position: absolute;
    top: 100%;
    right: 0;
    width: 340px;
    max-height: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-lg);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    z-index: 200;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-top: 6px;
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-primary);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-primary);
}

.notif-mark-all {
    background: none;
    border: none;
    color: var(--accent-primary);
    font-size: 0.75rem;
    cursor: pointer;
    font-family: inherit;
}

.notif-panel-body {
    flex: 1;
    overflow-y: auto;
    max-height: 300px;
}

.notif-item {
    display: flex;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-primary);
    cursor: pointer;
    transition: background 0.1s;
}

.notif-item:hover {
    background: var(--bg-hover);
}

.notif-item.notif-unread {
    background: rgba(59, 130, 246, 0.04);
    border-left: 3px solid var(--accent-primary);
}

.notif-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-primary);
    flex-shrink: 0;
    margin-top: 5px;
}

.notif-item.notif-unread .notif-item-dot {
    background: var(--accent-primary);
}

.notif-item:not(.notif-unread) .notif-item-dot {
    background: transparent;
}

.notif-item-content {
    flex: 1;
    min-width: 0;
}

.notif-item-title {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-item-time {
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.notif-panel-footer {
    display: block;
    text-align: center;
    padding: 10px;
    font-size: 0.78rem;
    color: var(--accent-primary);
    text-decoration: none;
    border-top: 1px solid var(--border-primary);
}

.notif-panel-footer:hover {
    background: var(--bg-hover);
}

.notif-unread {
    border-left: 3px solid var(--accent-primary) !important;
    background: rgba(59, 130, 246, 0.04);
}

.notif-empty {
    padding: 30px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.82rem;
}

.content-area {
    flex: 1;
    padding: 24px;
}

/* ── Global: filter dropdowns always float above content ── */
.filter-bar,
.filter-row {
    position: relative;
    z-index: 100;
}

.ms-filter-dropdown {
    z-index: 9000 !important;
}

/* Active filter button state (for toggle-style filters like Verified) */
.ms-filter-btn-active {
    background: var(--accent-primary) !important;
    color: #fff !important;
    border-color: var(--accent-primary) !important;
}

/* ── Pipeline chips (project list pages) ── */
.pipeline-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 16px;
}

.pipe-chip {
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    transition: all 0.15s;
}

.pipe-chip:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.pipe-chip-active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.pipe-count {
    font-size: 10px;
    font-weight: 700;
    opacity: 0.85;
    margin-left: 4px;
}

.pipe-chip-active .pipe-count {
    opacity: 1;
}

/* ── Table Actions — inline with filter bar ── */
.table-actions-inline {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* Legacy standalone (fallback) */
.table-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    padding: 8px 0;
}

/* ── Page Header ── */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.page-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.persona-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: var(--radius-sm);
    background: var(--accent-primary);
    color: var(--btn-primary-text);
    font-weight: 600;
}

/* ── Responsive ── */
/* ── Sidebar backdrop (mobile overlay) ── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 89;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-backdrop.active {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    body {
        --sidebar-width: 0px;
    }
    .sidebar {
        transform: translateX(-100%);
        width: 240px !important;
        transition: transform 0.3s;
        z-index: 90;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
    }
    .sidebar.mobile-open ~ .sidebar-backdrop,
    .sidebar-backdrop.active {
        display: block;
        opacity: 1;
    }
    .main-content {
        margin-left: 0 !important;
    }
    .topbar-mobile-toggle {
        display: inline-flex;
    }

    /* Notification panel — full width on mobile */
    .notif-panel {
        position: fixed;
        top: 48px;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 80vh;
        border-radius: 0 0 var(--radius-lg) var(--radius-lg);
        margin-top: 0;
    }

    /* Content area less padding */
    .content-area {
        padding: 16px 12px;
    }

    /* Topbar right section */
    .topbar-right { gap: 8px; }
    .topbar-persona { display: none; }
    .persona-pill { display: none; }
    .search-shortcut { display: none; }
    .topbar-page-title { font-size: 0.88rem; }
}

@media (min-width: 769px) {
    .topbar-mobile-toggle {
        display: none;
    }
    .sidebar-backdrop {
        display: none !important;
    }
}
