/* ==========================================================================
   layout/topbar.css — fixed application header
   Rendered once by the layout; offsets follow the sidebar state.
   ========================================================================== */

.app-topbar {
    position: fixed;
    top: 0;
    left: var(--crm-sidebar-width);
    right: 0;
    height: var(--crm-topbar-height);
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0 1.25rem;
    background: rgba(255, 255, 255, 0.86);
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--crm-border);
    transition: left var(--crm-normal) var(--crm-ease);
}
body.sidebar-collapsed .app-topbar { left: var(--crm-sidebar-width-collapsed); }

.topbar-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--crm-radius-sm);
    background: transparent;
    color: var(--crm-text-muted);
    font-size: 0.875rem;
    transition: background-color var(--crm-fast) var(--crm-ease), color var(--crm-fast) var(--crm-ease);
}
.topbar-icon-btn:hover { background: var(--crm-surface-sunken); color: var(--crm-ink); }

.topbar-context {
    font-size: var(--crm-fs-sm);
    color: var(--crm-text-muted);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}
.topbar-context .context-app {
    color: var(--crm-ink);
    font-weight: 550;
    letter-spacing: -0.01em;
}
.topbar-context .context-sep { color: var(--crm-border-strong); }

.topbar-spacer { flex: 1 1 auto; }

.topbar-action {
    font-size: var(--crm-fs-sm);
}

/* User menu */
.topbar-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border: 0;
    background: transparent;
    padding: 0.25rem 0.375rem;
    border-radius: var(--crm-radius-sm);
    transition: background-color var(--crm-fast) var(--crm-ease);
}
.topbar-user-btn:hover { background: var(--crm-surface-sunken); }
.topbar-user-btn .user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--crm-primary-soft);
    color: var(--crm-primary-ink);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 600;
}
.topbar-user-btn .user-name {
    font-size: var(--crm-fs-sm);
    font-weight: 500;
    color: var(--crm-text);
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-user-btn .fa-chevron-down { font-size: 0.5625rem; color: var(--crm-text-faint); }

.topbar-user-menu {
    min-width: 200px;
}
.topbar-user-menu .menu-identity {
    padding: 0.5rem 0.875rem 0.4375rem;
}
.topbar-user-menu .menu-identity .identity-name {
    font-size: var(--crm-fs-sm);
    font-weight: 550;
    color: var(--crm-ink);
}
.topbar-user-menu .menu-identity .identity-role {
    font-size: var(--crm-fs-xs);
    color: var(--crm-text-muted);
}

/* ---- Notification bell ---- */
.topbar-notify { position: relative; }

.topbar-notify-btn { position: relative; }

.topbar-notify-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #dc3545;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 16px;
    text-align: center;
}

.topbar-notify-menu {
    width: min(360px, calc(100vw - 1.5rem));
    padding: 0;
    border: 1px solid var(--crm-border);
    border-radius: 0.75rem;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
    overflow: hidden;
}

.topbar-notify-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--crm-border);
    background: var(--crm-surface-alt, #f8f9fa);
}

.topbar-notify-list {
    max-height: 360px;
    overflow-y: auto;
}

.topbar-notify-item {
    display: block;
    width: 100%;
    text-align: left;
    border: 0;
    border-bottom: 1px solid var(--crm-border);
    background: #fff;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: inherit;
    transition: background-color 120ms ease;
}
.topbar-notify-item:hover { background: var(--crm-surface-sunken, #f1f3f5); }
.topbar-notify-item.is-unread { background: rgba(13, 110, 253, 0.06); }
.topbar-notify-item .notify-title {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.15rem;
}
.topbar-notify-item .notify-body {
    font-size: 0.8125rem;
    color: var(--crm-text-muted, #6c757d);
    margin-bottom: 0.2rem;
}
.topbar-notify-item .notify-meta {
    font-size: 0.75rem;
    color: var(--crm-text-muted, #6c757d);
}

.crm-toast-stack {
    position: fixed;
    top: calc(var(--crm-topbar-height, 56px) + 12px);
    right: 16px;
    z-index: 1080;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: min(360px, calc(100vw - 24px));
    pointer-events: none;
}
.crm-toast-stack .toast {
    pointer-events: auto;
    border: 0;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
}

@media (max-width: 767.98px) {
    .app-topbar { left: 0 !important; padding: 0 0.875rem; }
    .topbar-user-btn .user-name { display: none; }
    .topbar-context .context-page { display: none; }
}
