:root {
    --sidebar-width: 220px;
    --shell-navy: #1a2636;
    --shell-coral: #F05A50;
    --app-header-h: 56px;
}

.scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(26, 38, 54, .45);
    z-index: 90;
}
.scrim.on { display: block; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--shell-navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 10px calc(12px + env(safe-area-inset-bottom, 0px));
}

.logo-section {
    padding: 10px 6px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: transparent;
}
.logo-img {
    width: auto;
    max-width: 100%;
    height: auto;
    max-height: 72px;
    object-fit: contain;
    display: block;
    background: transparent;
    border-radius: 0;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,.15));
}
.logo-brand {
    font-size: 15px;
    font-weight: 800;
    letter-spacing: .04em;
    color: #fff;
    line-height: 1.1;
    text-align: center;
}
.logo-company {
    max-width: 100%;
    margin-top: 2px;
    padding: 5px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,.12);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar .logo-section,
.sidebar .sidebar-menu {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
body.crm-shell-ready .sidebar .logo-section,
body.crm-shell-ready .sidebar .sidebar-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: opacity .18s ease;
}

.sidebar-menu { padding: 0 2px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.menu-item {
    display: flex;
    align-items: center;
    padding: 7px 10px;
    border-radius: 7px;
    color: rgba(255,255,255,.82);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
    min-height: 32px;
    box-sizing: border-box;
    transition: background .15s ease, color .15s ease;
}
.menu-item i { width: 15px; font-size: 12px; margin-right: 7px; text-align: center; }
.menu-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.menu-item.active { background: var(--shell-coral); color: #fff; }
.menu-item.active i { color: #fff; }
.menu-item.admin-only { display: none !important; }
body.crm-admin .menu-item.admin-only { display: flex !important; }
.menu-item.super-only { display: none !important; }
body.crm-super .menu-item.super-only { display: flex !important; }
.menu-group.super-only { display: none !important; }
body.crm-super .menu-group.super-only { display: flex !important; }
.menu-group { display: flex; flex-direction: column; gap: 1px; }
.menu-group > .menu-item,
.menu-group > .menu-toggle { justify-content: flex-start; }
.menu-group > .menu-toggle .chev { margin-left: auto; margin-right: 0; width: auto; font-size: 9px; opacity: .65; transition: transform .15s ease; }
.menu-group.open > .menu-toggle .chev { transform: rotate(90deg); }
.menu-toggle.section-on { color: #fff; background: rgba(255,255,255,.08); }
.menu-toggle.section-on i { color: var(--shell-coral); }
.menu-sub { display: none; flex-direction: column; gap: 1px; padding: 1px 0 3px 8px; border-left: 1px solid rgba(255,255,255,.08); margin: 0 0 2px 12px; }
.menu-group.open .menu-sub { display: flex; }
.menu-sub-label {
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: rgba(148, 163, 184, .9);
    padding: 7px 8px 2px;
}
.menu-sub .menu-item { min-height: 28px; padding: 5px 8px; font-size: 11px; font-weight: 600; color: rgba(255,255,255,.74); border-radius: 6px; }
.menu-sub .menu-item i { width: 12px; font-size: 10px; margin-right: 6px; opacity: .9; }
.menu-sub .menu-item.sub-on {
    background: rgba(240, 90, 80, .18);
    color: #fff;
    box-shadow: inset 2px 0 0 var(--shell-coral);
}
.menu-sub .menu-item.sub-on i { color: #ffb4ae; opacity: 1; }
.menu-sub .menu-item.active { background: transparent; }
.menu-sub .menu-item.admin-only { display: none !important; }
body.crm-admin .menu-sub .menu-item.admin-only { display: flex !important; }
.menu-sub .menu-item.super-only { display: none !important; }
body.crm-super .menu-sub .menu-item.super-only { display: flex !important; }
.sidebar-menu { gap: 2px; }
.logo-section { padding: 14px 12px 10px; }

.main,
.main-content {
    margin-left: var(--sidebar-width);
    background: #ffffff;
    /* room for fixed app header (sticky breaks with body overflow-x) */
    padding-top: calc(var(--app-header-h) + 10px) !important;
}

/* Fixed app header — stays put while page scrolls */
.main-content > .header,
.main > .top,
.app-header {
    position: fixed !important;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    z-index: 900;
    background: #fff;
    border-bottom: 1px solid #e8eaee;
    box-shadow: 0 2px 10px rgba(17, 24, 39, .06);
    margin: 0 !important;
    padding: 0 16px;
    min-height: var(--app-header-h);
    height: var(--app-header-h);
    width: auto;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1 1 auto;
}
.app-brand {
    font-size: 16px;
    font-weight: 800;
    letter-spacing: .03em;
    color: var(--shell-navy);
    white-space: nowrap;
    line-height: 1;
}

/* Page-specific title + actions below the common header */
.page-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px 0 10px;
    margin-bottom: 4px;
}
.page-bar .welcome-section h1,
.page-bar .titles h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    color: #111827;
    line-height: 1.2;
}
.page-bar .welcome-section p,
.page-bar .titles p {
    margin: 4px 0 0;
    font-size: 13px;
    color: #6b7280;
}
.page-bar .header-actions,
.page-bar .page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.header-user-block {
    margin-left: auto;
    flex: 0 0 auto;
}
.header-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 5px 4px 4px;
    background: #f8fafc;
    border: 1px solid #e8eaee;
    border-radius: 999px;
    max-width: min(320px, 58vw);
}
.user-avatar-wrap {
    position: relative;
    flex-shrink: 0;
    width: 34px;
    height: 34px;
}
.user-avatar-large {
    width: 34px;
    height: 34px;
    background: var(--shell-coral);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
}
.user-avatar-img {
    position: absolute;
    inset: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #e8eaee;
}
.user-details { min-width: 0; padding-right: 2px; }
.user-name {
    font-size: 13px;
    font-weight: 800;
    color: #111827;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-role {
    display: inline-block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 700;
    color: var(--shell-coral);
    background: #fff1f0;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    border: 0;
    border-radius: 999px;
    height: 32px;
    padding: 0 12px;
    background: var(--shell-navy);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: background .18s ease, transform .15s ease;
}
.logout-btn:hover { background: var(--shell-coral); }
.logout-btn i { font-size: 12px; }

#userEmail, #userCompany { display: none !important; }

/* Header bell — keep in shell.css so it never flashes before notifications.css */
.notif-bell-wrap { position: relative; flex-shrink: 0; }
.notif-bell-btn {
    position: relative;
    width: 40px; height: 40px; border-radius: 12px;
    border: 0; background: #f8fafc; color: #1a2636;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 15px;
}
.notif-bell-btn:hover { background: #fff1f0; color: #F05A50; }
.notif-badge {
    position: absolute; top: 4px; right: 4px;
    min-width: 16px; height: 16px; padding: 0 4px;
    border-radius: 999px; background: #F05A50; color: #fff;
    font-size: 9px; font-weight: 800; line-height: 16px; text-align: center;
    display: none;
}
.notif-badge.on { display: block; }
.notif-badge[hidden] { display: none !important; }
.notif-drop {
    display: none; position: absolute; right: 0; top: calc(100% + 8px);
    width: min(360px, 92vw); background: #fff; border: 1px solid #e8eaee;
    border-radius: 14px; box-shadow: 0 12px 32px rgba(17,24,39,.14);
    z-index: 1200; overflow: hidden;
}
.notif-drop.open { display: block; }

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-110%);
        transition: transform .22s ease;
        width: min(84vw, 260px);
        padding-left: calc(10px + env(safe-area-inset-left, 0px));
    }
    .sidebar.active { transform: none; }
    .main,
    .main-content { margin-left: 0; }
    .main-content > .header,
    .main > .top,
    .app-header {
        left: 0;
        margin: 0 !important;
    }
    .logout-btn span { display: none; }
    .logout-btn { width: 32px; padding: 0; justify-content: center; }
    .header-user { max-width: min(200px, 58vw); }
    .app-brand { font-size: 14px; }
    .page-bar { padding-top: 12px; }
    .page-bar .header-actions { width: 100%; margin-left: 0; }
}
