/* ============================================================
   GILGAMEZ — ADMIN PANEL HEADER / TOPBAR (SECTION A)
   Standardized Header Shell Component (Rule #18)
   ============================================================ */

/* --- 1. Header Container ------------------------------------- */
#admin-header, .admin-header {
    height: 60px;
    z-index: 500;
    background: var(--theme-header-bg, var(--bg-surface, rgba(13, 15, 20, 0.75)));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--theme-header-border, var(--border, rgba(255, 255, 255, 0.06)));
}

#navbar-container {
    position: relative;
    z-index: 500;
    flex-shrink: 0;
    height: 100%;
}

.topbar {
    position: relative;
    z-index: 500;
    height: 60px;
    flex-shrink: 0;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* --- 2. Header Brand Group, Title & Navigation ---------------- */
.topbar-brand-group {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
    flex: 1 1 auto;
    overflow: hidden;
}

.topbar-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-primary, #f8fafc);
    margin: 0;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

/* --- 3. Header Action Buttons -------------------------------- */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

#admin-language-switcher-slot {
    display: inline-flex;
    align-items: center;
    position: relative;
    z-index: 600;
}

#admin-language-switcher-slot .btn-lang-switcher {
    height: 34px;
    min-height: 34px;
    padding: 0 10px;
    font-size: 12.5px;
    border-radius: 8px;
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
}

#admin-language-switcher-slot .btn-lang-switcher:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(99, 102, 241, 0.4);
}

#admin-language-switcher-slot .lang-dropdown-menu {
    top: calc(100% + 6px);
    right: 0;
    z-index: 1100;
}

.topbar-view-store {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    background: var(--bg-hover, rgba(255, 255, 255, 0.05));
    color: var(--text-secondary, #cbd5e1);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s ease;
}

.topbar-view-store:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #f8fafc);
    border-color: var(--border, rgba(255, 255, 255, 0.2));
}

.topbar-doc-trigger-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 8px;
    border: 1px solid var(--primary-glow, rgba(99, 102, 241, 0.2));
    background: var(--primary-glow, rgba(99, 102, 241, 0.08));
    color: var(--primary-light, #818cf8);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.topbar-doc-trigger-btn:hover {
    background: var(--primary-glow, rgba(99, 102, 241, 0.16));
    border-color: var(--primary-light, rgba(99, 102, 241, 0.4));
    color: var(--text-primary, #fff);
}

/* Mobile Hamburger Toggle (hidden on desktop) */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary, #cbd5e1);
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.08));
    color: var(--text-primary, #f8fafc);
}

/* --- 4. Notification Bell & Panel ---------------------------- */
#notif-bell-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.notif-bell-btn {
    position: relative;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--bg-hover, rgba(255, 255, 255, 0.05));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
    color: var(--text-muted, #94a3b8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.notif-bell-btn:hover {
    background: var(--bg-hover, rgba(255, 255, 255, 0.1));
    color: var(--text-primary, #f8fafc);
    border-color: var(--border, rgba(255, 255, 255, 0.15));
}

.notif-bell-btn.has-unread {
    color: var(--primary-light, #818cf8);
    border-color: var(--primary-glow, rgba(99, 102, 241, 0.3));
    background: var(--primary-glow, rgba(99, 102, 241, 0.08));
    animation: bell-ring 0.4s ease 0s 1;
}

@keyframes bell-ring {
    0%   { transform: rotate(0); }
    20%  { transform: rotate(-15deg); }
    40%  { transform: rotate(15deg); }
    60%  { transform: rotate(-8deg); }
    80%  { transform: rotate(8deg); }
    100% { transform: rotate(0); }
}

.notif-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--danger, #ef4444);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--bg-base, #0a0c10);
    font-family: 'Inter', sans-serif;
    line-height: 1;
}

.notif-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 360px;
    max-height: 480px;
    background: var(--theme-modal-bg, var(--theme-bg-card, rgba(18, 20, 30, 0.98)));
    border: 1px solid var(--border, rgba(255, 255, 255, 0.1));
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65), 0 0 0 1px var(--border, rgba(255, 255, 255, 0.05));
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    z-index: 1500;
    flex-direction: column;
    overflow: hidden;
}

.notif-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border, rgba(255, 255, 255, 0.06));
    flex-shrink: 0;
}

.notif-panel-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary, #f8fafc);
}

.notif-mark-all-btn {
    background: none;
    border: none;
    color: var(--primary-light, #818cf8);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    font-family: 'Inter', sans-serif;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s;
}

.notif-mark-all-btn:hover {
    background: var(--primary-glow, rgba(99, 102, 241, 0.1));
}

.notif-list {
    overflow-y: auto;
    flex: 1;
    max-height: 400px;
}

.notif-list::-webkit-scrollbar { width: 4px; }
.notif-list::-webkit-scrollbar-track { background: transparent; }
.notif-list::-webkit-scrollbar-thumb { background: var(--border, rgba(255, 255, 255, 0.1)); border-radius: 2px; }

.notif-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted, #94a3b8);
    font-size: 14px;
}

.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.04));
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: rgba(255, 255, 255, 0.03); }

.notif-item--unread {
    background: rgba(99, 102, 241, 0.04);
}
.notif-item--unread:hover {
    background: rgba(99, 102, 241, 0.07);
}

.notif-item-icon {
    font-size: 18px;
    flex-shrink: 0;
    margin-top: 1px;
    line-height: 1;
}

.notif-item-body {
    flex: 1;
    min-width: 0;
}

.notif-item-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #f8fafc);
    margin-bottom: 3px;
    line-height: 1.3;
}

.notif-item-msg {
    font-size: 12px;
    color: var(--text-muted, #94a3b8);
    line-height: 1.5;
    word-break: break-word;
}

.notif-item-time {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.25);
    margin-top: 5px;
}

.notif-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary, #6366f1);
    flex-shrink: 0;
    margin-top: 5px;
    box-shadow: 0 0 6px rgba(99, 102, 241, 0.6);
}

/* --- 5. Responsive Header Breakdown (Rule #6 — 5 Viewport Tiers) --- */

/* 5.1 Large Desktop (Tier 1: 1920px+) */
@media (min-width: 1441px) {
    .topbar {
        padding: 0 28px;
    }

    .topbar-title {
        font-size: 18px;
    }

    .topbar-actions {
        gap: 12px;
    }
}

/* 5.2 Tablet Viewport Tier (Tier 3: 768px - 1024px) */
@media (max-width: 1024px) {
    .topbar {
        padding: 0 16px;
    }

    .topbar-brand-group {
        gap: 10px;
    }

    .topbar-title {
        font-size: 16px;
        max-width: 220px;
    }

    .topbar-actions {
        gap: 8px;
    }

    .topbar-env-pill {
        padding: 4px 10px;
        font-size: 0.72rem;
    }
}

/* 5.3 Mobile & Tablet Drawer Trigger Breakpoint (< 992px) */
@media (max-width: 991px) {
    .sidebar-toggle {
        display: inline-flex;
        min-height: 40px;
        min-width: 40px;
        width: 40px;
        height: 40px;
        align-items: center;
        justify-content: center;
        border-radius: 8px;
        padding: 0;
        flex-shrink: 0;
    }

    .topbar-doc-trigger-btn .topbar-btn-text,
    .topbar-view-store .topbar-btn-text {
        display: none !important;
    }

    .topbar-doc-trigger-btn,
    .topbar-view-store {
        padding: 0 !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        border-radius: 9px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .topbar-doc-trigger-btn span.topbar-btn-icon,
    .topbar-view-store svg {
        margin: 0 !important;
        font-size: 16px;
    }

    .notif-bell-btn {
        width: 38px;
        height: 38px;
        border-radius: 9px;
    }

    #admin-language-switcher-slot .btn-lang-switcher {
        height: 38px;
        min-height: 38px;
        padding: 0 8px;
    }
}

/* 5.4 Mobile Landscape Tier (Tier 4: 481px - 767px) */
@media (min-width: 481px) and (max-width: 768px) {
    #admin-header, .admin-header {
        height: 56px;
    }

    .topbar {
        padding: 0 14px;
        height: 56px;
        gap: 8px;
    }

    .sidebar-toggle {
        min-height: 38px;
        min-width: 38px;
        width: 38px;
        height: 38px;
    }

    .topbar-brand-group {
        gap: 8px;
    }

    .topbar-title {
        font-size: 15px;
        max-width: 170px;
    }

    .topbar-actions {
        gap: 6px;
        flex-shrink: 0;
    }

    .topbar-doc-trigger-btn,
    .topbar-view-store {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        border-radius: 8px !important;
    }

    .notif-bell-btn {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }

    #admin-language-switcher-slot .btn-lang-switcher {
        height: 36px;
        min-height: 36px;
        padding: 0 7px;
    }

    .topbar-env-pill {
        padding: 4px 8px;
        font-size: 0.7rem;
        border-radius: 8px;
    }

    .notif-panel {
        position: fixed !important;
        top: 60px !important;
        right: 14px !important;
        left: auto !important;
        width: 340px !important;
        max-width: calc(100vw - 28px) !important;
        max-height: calc(100dvh - 75px) !important;
    }
}

/* 5.5 Mobile Portrait Tier (Tier 5: 320px - 480px) */
@media (max-width: 480px) {
    #admin-header, .admin-header {
        height: 54px;
    }

    .topbar {
        padding: 0 10px;
        height: 54px;
        gap: 6px;
    }

    .topbar-brand-group {
        gap: 8px;
        min-width: 0;
        flex: 1 1 auto;
        overflow: hidden;
    }

    .sidebar-toggle {
        display: inline-flex;
        min-height: 36px;
        min-width: 36px;
        width: 36px;
        height: 36px;
        align-items: center;
        justify-content: center;
        border-radius: 9px;
        padding: 0;
        flex-shrink: 0;
    }

    .topbar-title {
        font-size: 14px;
        max-width: 120px;
        min-width: 0;
        flex: 1 1 auto;
    }

    .topbar-actions {
        gap: 4px;
        flex-shrink: 0;
    }

    /* Environment Indicator Compact Icon Pill */
    .topbar-env-pill {
        width: 34px !important;
        min-width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 !important;
        border-radius: 9px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .topbar-env-pill .topbar-env-label {
        display: none !important;
    }

    .topbar-env-dot {
        font-size: 14px;
        margin: 0;
        line-height: 1;
    }

    /* Language Switcher Compact Icon Button */
    #admin-language-switcher-slot .btn-lang-switcher {
        width: 34px !important;
        min-width: 34px !important;
        height: 34px !important;
        min-height: 34px !important;
        padding: 0 !important;
        border-radius: 9px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    #admin-language-switcher-slot .lang-code-label,
    #admin-language-switcher-slot .lang-dropdown-chevron {
        display: none !important;
    }

    #admin-language-switcher-slot .lang-flag-badge {
        margin: 0;
        line-height: 0;
    }

    #admin-language-switcher-slot .lang-flag-svg {
        width: 18px;
        height: 12px;
    }

    #admin-language-switcher-slot .lang-dropdown-menu {
        position: fixed !important;
        top: 58px !important;
        right: 10px !important;
        left: auto !important;
        width: calc(100vw - 20px) !important;
        max-width: 250px !important;
        z-index: 1200 !important;
    }

    /* Docs Trigger Compact Button */
    .topbar-doc-trigger-btn .topbar-btn-text,
    .topbar-view-store .topbar-btn-text {
        display: none !important;
    }

    .topbar-doc-trigger-btn,
    .topbar-view-store {
        padding: 0 !important;
        width: 34px !important;
        height: 34px !important;
        min-width: 34px !important;
        min-height: 34px !important;
        border-radius: 9px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 0 !important;
    }

    .topbar-doc-trigger-btn span.topbar-btn-icon,
    .topbar-view-store svg {
        margin: 0 !important;
        font-size: 15px;
    }

    /* Notification Bell & Panel Full Viewport Fit */
    .notif-bell-btn {
        width: 34px;
        height: 34px;
        min-width: 34px;
        min-height: 34px;
        border-radius: 9px;
    }

    .notif-badge {
        top: -3px;
        right: -3px;
        min-width: 16px;
        height: 16px;
        font-size: 9.5px;
        border-width: 1.5px;
    }

    .notif-panel {
        position: fixed !important;
        top: 58px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        max-height: calc(100dvh - 72px) !important;
        z-index: 1200 !important;
        border-radius: 14px !important;
    }
}

/* 5.6 Ultra-Narrow Mobile Viewport (<= 360px, e.g. iPhone SE 320px) */
@media (max-width: 360px) {
    .topbar {
        padding: 0 6px;
        gap: 4px;
    }

    .topbar-brand-group {
        gap: 6px;
    }

    .topbar-title {
        font-size: 13px;
        max-width: 85px;
    }

    .topbar-actions {
        gap: 3px;
    }

    .sidebar-toggle {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
        border-radius: 8px;
    }

    .topbar-env-pill,
    #admin-language-switcher-slot .btn-lang-switcher,
    .topbar-doc-trigger-btn,
    .notif-bell-btn {
        width: 32px !important;
        min-width: 32px !important;
        height: 32px !important;
        min-height: 32px !important;
        border-radius: 8px !important;
    }

    /* On <= 360px, hide secondary external link from header to prevent overlap; accessible via drawer */
    .topbar-view-store {
        display: none !important;
    }
}

/* 5.7 WCAG 2.5.5 / 2.5.8 Touch Target Hit Area Guarantee (Rule #6 min 44px) */
@media (max-width: 768px) {
    .sidebar-toggle,
    .topbar-env-pill,
    #admin-language-switcher-slot .btn-lang-switcher,
    .topbar-doc-trigger-btn,
    .notif-bell-btn,
    .topbar-view-store {
        position: relative;
    }

    .sidebar-toggle::after,
    .topbar-env-pill::after,
    #admin-language-switcher-slot .btn-lang-switcher::after,
    .topbar-doc-trigger-btn::after,
    .notif-bell-btn::after,
    .topbar-view-store::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        min-width: 44px;
        min-height: 44px;
        width: 100%;
        height: 100%;
        pointer-events: auto;
    }
}

/* --- 6. Operator Profile Menu & Avatar Constraints (Rule #18) --- */
.topbar-operator-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.topbar-operator-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 2px 10px 2px 4px;
    border-radius: 9999px;
    background: var(--cc-bg-surface, rgba(255, 255, 255, 0.04));
    border: 1px solid var(--cc-border, rgba(255, 255, 255, 0.08));
    color: var(--cc-text-primary, #f8fafc);
    cursor: pointer;
    transition: all 0.15s ease;
}

.topbar-operator-btn:hover {
    background: var(--cc-bg-hover, rgba(255, 255, 255, 0.08));
    border-color: var(--cc-border-hover, rgba(255, 255, 255, 0.16));
}

.topbar-avatar-img {
    width: 28px !important;
    height: 28px !important;
    min-width: 28px !important;
    min-height: 28px !important;
    max-width: 28px !important;
    max-height: 28px !important;
    border-radius: 50% !important;
    object-fit: cover !important;
    display: block !important;
    border: 1px solid var(--cc-border, rgba(255, 255, 255, 0.15)) !important;
    flex-shrink: 0;
}

.topbar-avatar-initial {
    width: 28px;
    height: 28px;
    min-width: 28px;
    min-height: 28px;
    max-width: 28px;
    max-height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #ffffff;
    text-transform: uppercase;
    flex-shrink: 0;
}

.topbar-operator-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--cc-text-primary, #f8fafc);
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-operator-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--cc-text-muted, #94a3b8);
}

.topbar-operator-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 240px;
    background: var(--cc-bg-surface-elevated, #0f172a);
    border: 1px solid var(--cc-border, rgba(255, 255, 255, 0.1));
    border-radius: 12px;
    box-shadow: 0 16px 36px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    padding: 8px;
    z-index: 1200;
    display: none;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.topbar-operator-dropdown.is-open {
    display: block !important;
}

.topbar-user-card {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    margin-bottom: 6px;
}

.topbar-user-name {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--cc-text-primary, #f8fafc);
    line-height: 1.3;
}

.topbar-user-email {
    font-size: 12px;
    color: var(--cc-text-muted, #94a3b8);
    margin-top: 2px;
    word-break: break-all;
}

.topbar-user-role {
    display: inline-block;
    margin-top: 6px;
    font-size: 10.5px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 9999px;
    letter-spacing: 0.05em;
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--cc-text-secondary, #cbd5e1);
}

.topbar-menu-divider {
    height: 1px;
    background: var(--cc-border, rgba(255, 255, 255, 0.08));
    margin: 6px 0;
}

.topbar-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 8px 12px;
    font-size: 13px;
    color: var(--cc-text-secondary, #cbd5e1);
    border-radius: 8px;
    text-decoration: none;
    transition: all 0.12s ease;
    cursor: pointer;
    box-sizing: border-box;
}

.topbar-menu-item:hover {
    background: var(--cc-bg-hover, rgba(255, 255, 255, 0.06));
    color: var(--cc-text-primary, #ffffff);
}

.topbar-menu-item.text-danger {
    color: #f87171;
}

.topbar-menu-item.text-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}
