/* Header Components Styles (App Menu & Account Menu) */

/* =========================================
   1. Trigger Buttons (Top Level)
   ========================================= */

.bio-header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    color: inherit;
    /* Inherit color from parent header (usually correctly set by page) */
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    margin: 0;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
}

.bio-header-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.bio-header-btn .material-symbols-outlined {
    font-size: 24px;
}

/* Dark Mode / Stats Mode Hover for Trigger */
.dark .bio-header-btn:hover,
body[style*="#1A202C"] .bio-header-btn:hover,
.bio-panel .bio-header-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}


/* =========================================
   2. Containers
   ========================================= */

.kamos-header-menu-unified {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    /* bio-gap-3 */
}

.header-app-menu-container,
.header-account-menu-container {
    position: relative;
    display: flex;
    align-items: center;
}


/* =========================================
   3. Dropdown Menu (The Box)
   ========================================= */

.header-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    width: 260px;
    z-index: 2000;
    padding: 0.5rem;

    border-radius: 0.75rem;

    /* Animation */
    opacity: 1;
    transform: translateY(0) scale(1);
    transition: all 0.2s ease-out;
    transform-origin: top right;

    /* Base Theme (Light Mode Default) */
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    color: #2d3748;
    /* Dark Text */
}

.header-dropdown-menu.kamos-hidden {
    display: none;
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    pointer-events: none;
}

/* Dark Mode / Stats Mode Override for Dropdown Box */
.dark .header-dropdown-menu,
body[style*="#1A202C"] .header-dropdown-menu,
.bio-panel .header-dropdown-menu {
    background-color: #1a202c;
    /* Dark BG */
    border-color: #4a5568;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5), 0 4px 6px -2px rgba(0, 0, 0, 0.3);
    color: #e2e8f0;
    /* Light Text */
}


/* =========================================
   4. User Info Section
   ========================================= */

.header-user-info {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 0.5rem;
}

.header-user-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1a202c;
    /* Dark Text */
    margin: 0 0 0.25rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-user-email {
    font-size: 0.75rem;
    color: #718096;
    /* Gray Text */
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Dark Mode / Stats Mode Override for User Info */
.dark .header-user-info,
body[style*="#1A202C"] .header-user-info,
.bio-panel .header-user-info {
    border-color: #4a5568;
}

.dark .header-user-name,
body[style*="#1A202C"] .header-user-name,
.bio-panel .header-user-name {
    color: #f7fafc;
    /* Light Text */
}

.dark .header-user-email,
body[style*="#1A202C"] .header-user-email,
.bio-panel .header-user-email {
    color: #cbd5e0;
    /* Light Gray Text */
}


/* =========================================
   5. Menu Items (Links)
   ========================================= */

.header-menu-item {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.75rem 1rem;

    /* Text & Layout */
    color: #2d3748;
    /* Dark Text by default */
    text-decoration: none !important;
    text-align: left;
    font-size: 0.95rem;
    font-weight: 500;
    line-height: 1.5;

    /* Box */
    border-radius: 0.5rem;
    margin-bottom: 2px;
    background: transparent;
    border: none;
    width: 100%;

    /* Interaction */
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    font-family: inherit;
}

.header-menu-item:last-child {
    margin-bottom: 0;
}

.header-menu-item:hover {
    background-color: #edf2f7;
    /* Light Mode Hover BG */
    transform: translateX(4px);
}

.header-menu-item .menu-item-icon {
    font-size: 1.25rem;
    margin-right: 0.75rem;
    color: #718096;
    /* Light Mode Icon Color */
    transition: color 0.2s ease;

    /* Alignment Fixes */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    background: transparent !important;
}

.header-menu-item:hover .menu-item-icon {
    color: #48BB78;
    /* Kamos Green Highlight */
}

/* Dark Mode / Stats Mode Override for Menu Items */
.dark .header-menu-item,
body[style*="#1A202C"] .header-menu-item,
.bio-panel .header-menu-item {
    color: #f7fafc;
    /* Light Text on Dark */
}

.dark .header-menu-item:hover,
body[style*="#1A202C"] .header-menu-item:hover,
.bio-panel .header-menu-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
    /* Dark Mode Hover BG */
}

.dark .header-menu-item .menu-item-icon,
body[style*="#1A202C"] .header-menu-item .menu-item-icon,
.bio-panel .header-menu-item .menu-item-icon {
    color: #a0aec0;
    /* Dark Mode Icon Color */
}

.dark .header-menu-item:hover .menu-item-icon,
body[style*="#1A202C"] .header-menu-item:hover .menu-item-icon,
.bio-panel .header-menu-item:hover .menu-item-icon {
    color: #68D391;
    /* Brighter Green Highlight */
}


/* =========================================
   6. Sign Out Button (Distinct)
   ========================================= */

.header-signout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 1rem;
    margin-top: 0.5rem;

    /* Text & Layout */
    color: #e53e3e !important;
    /* Red Text - Force */
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;

    /* Box */
    background-color: #fff5f5 !important;
    /* Light Red BG - Force */
    border: 1px solid #feb2b2;
    border-radius: 0.5rem;

    /* Interaction */
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    box-sizing: border-box;
    text-shadow: none !important;
    /* Ensure no white shadow hiding text on light bg */
}

.header-signout-btn:hover {
    background-color: #fed7d7 !important;
    transform: translateY(-1px);
}

/* Dark Mode / Stats Mode Override for Sign Out */
/* Dark Mode / Stats Mode Override for Sign Out */
.dark .header-signout-btn,
body[style*="#1A202C"] .header-signout-btn,
.bio-panel .header-signout-btn {
    color: #fc8181 !important;
    /* Light Red Text - Force */
    background-color: rgba(229, 62, 62, 0.15) !important;
    border-color: rgba(229, 62, 62, 0.3) !important;
}

.dark .header-signout-btn:hover,
body[style*="#1A202C"] .header-signout-btn:hover,
.bio-panel .header-signout-btn:hover {
    background-color: rgba(229, 62, 62, 0.25) !important;
}


/* =========================================
   6.5 Admin Core Cache Refresh Button
   ========================================= */

.header-core-cache-container {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px dashed rgba(255, 255, 255, 0.15);
}

.header-core-cache-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.35);
    border-radius: 6px;
    color: #10b981;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}

.header-core-cache-btn:hover:not(:disabled) {
    background: rgba(16, 185, 129, 0.22);
    border-color: rgba(16, 185, 129, 0.6);
    color: #34d399;
}

.header-core-cache-btn:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.header-core-cache-btn .spin {
    animation: kamos-spin 1s linear infinite;
    display: inline-block;
}

@keyframes kamos-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}


/* =========================================
   7. Utilities & Helpers
   ========================================= */

.kamos-list-none {
    list-style: none;
}

.kamos-p-0 {
    padding: 0;
}

.kamos-m-0 {
    margin: 0;
}

.kamos-relative {
    position: relative;
}

.kamos-flex {
    display: flex;
}

.kamos-items-center {
    align-items: center;
}

.kamos-hidden {
    display: none !important;
}

.kamos-w-full {
    width: 100%;
}

.kamos-border-none {
    border: none;
}

.kamos-border-t {
    border-top-width: 1px;
}

.kamos-border-light {
    border-color: #e2e8f0;
}

/* Default light border for separator */

/* Dark mode separator */
.dark .kamos-border-light,
body[style*="#1A202C"] .kamos-border-light,
.bio-panel .kamos-border-light {
    border-color: #4a5568;
}

/* =========================================
   8. App Sidebar (Side Panel Replacement)
   ========================================= */

.header-app-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    width: 320px;
    height: 100vh;
    background-color: #ffffff; /* Light Theme Default */
    z-index: 3000;
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 30px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.header-app-sidebar.kamos-transform-x-full {
    transform: translateX(100%);
}

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

.dark .header-app-sidebar {
    background-color: #1a202c; /* Matches dark theme */
    border-left: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.dark .sidebar-header {
    border-color: rgba(255, 255, 255, 0.1);
}

.sidebar-title {
    font-family: 'Josefin Sans', 'Noto Sans JP', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: #2d3748;
}

.dark .sidebar-title {
    color: #ffffff;
}

.sidebar-close-btn {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #718096;
    transition: all 0.2s;
}

.sidebar-close-btn:hover {
    background-color: rgba(0, 0, 0, 0.05);
    color: #2d3748;
    transform: rotate(90deg);
}

.dark .sidebar-close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* Sidebar Items */
.sidebar-item {
    margin-bottom: 0.5rem;
    padding: 1rem 1.25rem !important;
}

.sidebar-item .menu-item-icon {
    font-size: 1.5rem !important;
    width: 32px !important;
    height: 32px !important;
}

.sidebar-item .menu-item-text {
    font-size: 1.1rem !important;
}

/* Backdrop */
.header-sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2900;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: auto;
}

.header-sidebar-backdrop.visible {
    opacity: 1;
}

.header-sidebar-backdrop.kamos-hidden {
    display: none !important;
}

/* Custom Scrollbar */
.custom-scrollbar::-webkit-scrollbar {
    width: 6px;
}

.custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

.dark .custom-scrollbar::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
}

.dark .custom-scrollbar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.custom-scrollbar::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* Global Reset for Menu Icons inside Anchors/Buttons */
a .menu-item-icon,
button .menu-item-icon {
    background: transparent !important;
}

/* Desktop Main Navbar (Tier 1) */
.bio-navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    height: 56px !important;
    min-height: 56px !important;
    box-sizing: border-box !important;
    padding: 0 1.5rem !important;
    z-index: 1001 !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    background: rgba(255, 255, 255, 0.92) !important;
    backdrop-filter: blur(16px) saturate(180%) !important;
    -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02) !important;
}

.dark .bio-navbar,
html.dark .bio-navbar {
    background: rgba(15, 23, 42, 0.92) !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
}

/* Inlined Custom Actions (Unified 1-Line Header) */
.header-custom-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-custom-divider {
    height: 24px;
    margin: 0 4px;
}

/* Base Body Padding for All Apps */
body {
    padding-top: 56px !important;
}

/* ==========================================================================
   9. Modern Mobile Navigation 2.0 (All Apps Common 2-Tier Architecture)
   ========================================================================== */
@media (max-width: 768px) {
    /* 1. Main Top App Bar (Tier 1) */
    .bio-navbar {
        padding-top: calc(6px + env(safe-area-inset-top, 0px)) !important;
        padding-bottom: 6px !important;
        padding-left: max(10px, env(safe-area-inset-left, 0px)) !important;
        padding-right: max(10px, env(safe-area-inset-right, 0px)) !important;
        height: calc(52px + env(safe-area-inset-top, 0px)) !important;
        min-height: calc(52px + env(safe-area-inset-top, 0px)) !important;
        box-sizing: border-box !important;
        background: rgba(255, 255, 255, 0.88) !important;
        backdrop-filter: blur(20px) saturate(180%) !important;
        -webkit-backdrop-filter: blur(20px) saturate(180%) !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03) !important;
    }

    .dark .bio-navbar,
    html.dark .bio-navbar {
        background: rgba(15, 23, 42, 0.88) !important;
        border-bottom: 1px solid rgba(255, 255, 255, 0.08) !important;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2) !important;
    }
    
    /* 2. Brand Section: Logo + Title */
    .header-left-brand {
        gap: 8px !important;
        min-width: 0 !important;
        flex: 1 1 auto !important;
        overflow: hidden !important;
    }

    .header-titles-wrapper {
        min-width: 0 !important;
        overflow: hidden !important;
    }

    .bio-navbar h1 {
        font-size: 0.9375rem !important;
        line-height: 1.25rem !important;
        font-weight: 700 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        letter-spacing: 0.015em !important;
    }

    .bio-navbar p {
        display: none !important;
    }

    .bio-divider {
        height: 18px !important;
        margin: 0 2px !important;
        background-color: rgba(0, 0, 0, 0.1) !important;
    }

    .dark .bio-divider {
        background-color: rgba(255, 255, 255, 0.15) !important;
    }
    
    .bio-logo {
        height: 26px !important;
        width: auto !important;
        object-fit: contain !important;
        flex-shrink: 0 !important;
    }

    .bio-logo-link {
        flex-shrink: 0 !important;
        display: block !important;
    }
    
    /* 3. Header Right Tools: Always strictly displayed */
    .header-right-tools,
    #header-menu {
        gap: 4px !important;
        margin-left: auto !important;
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
    }

    /* Action Trigger Buttons (Theme Toggle, App Menu, Account) */
    .bio-header-btn,
    #darkModeToggle {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        border-radius: 9999px !important;
        transition: transform 0.15s ease, background-color 0.2s ease !important;
    }

    .bio-header-btn:active,
    #darkModeToggle:active {
        transform: scale(0.92) !important;
    }

    .bio-header-btn .material-symbols-outlined,
    #darkModeToggle .material-symbols-outlined {
        font-size: 20px !important;
    }

    /* 4. Mobile Inlined Custom Actions */
    .header-custom-actions {
        gap: 2px !important;
    }

    .header-custom-divider {
        display: none !important;
    }

    .header-custom-actions .kamos-btn span:not(.material-symbols-outlined) {
        display: none !important;
    }

    .header-custom-actions .kamos-btn {
        width: 32px !important;
        height: 32px !important;
        min-height: 32px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    .header-custom-actions .bio-header-btn {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        padding: 0 !important;
    }

    .header-custom-actions #api-counter-container {
        display: none !important;
    }

    /* 5. Responsive Body Padding */
    body {
        padding-top: calc(52px + env(safe-area-inset-top, 0px)) !important;
    }
}