/* ===================================================
   الشريط العلوي الرئيسي الموحد | منصة ثامر الرياضية والتربوية
   thamer-sports.com • إشراف وإعداد: أ / ثامر بن محمد العمير
   Scoped strictly to #thamerGlobalNavbar / .th-* to avoid CSS collisions
   =================================================== */

:root {
    --thamer-nav-h: 72px;
    --th-nav-bg: rgba(11, 19, 41, 0.95);
    --th-nav-border: rgba(255, 255, 255, 0.1);
    --th-nav-text: #f8fafc;
    --th-nav-text-sec: #94a3b8;
    --th-nav-card: #152454;
    --th-nav-primary: #0284c7;
    --th-nav-primary-dark: #0369a1;
    --th-nav-primary-light: #38bdf8;
    --th-nav-secondary: #d97706;
    --th-nav-font: 'Cairo', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

html[data-theme="light"],
body.light-theme,
body.light-mode {
    --th-nav-bg: rgba(255, 255, 255, 0.96);
    --th-nav-border: #e2e8f0;
    --th-nav-text: #0f172a;
    --th-nav-text-sec: #475569;
    --th-nav-card: #f1f5f9;
    --th-nav-primary-light: #0284c7;
}

/* Global Body Offset for Fixed Main Navbar */
html {
    scroll-padding-top: calc(var(--thamer-nav-h, 72px) + 18px);
}

body.has-thamer-global-nav {
    padding-top: var(--thamer-nav-h, 72px) !important;
}

/* Keep top scroll progress bars visible right on the top edge */
body.has-thamer-global-nav .scroll-progress,
body.has-thamer-global-nav #scrollProgressBar {
    z-index: 5010 !important;
}

/* Main Fixed Top Navbar */
#thamerGlobalNavbar.th-global-navbar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 5000 !important;
    background: var(--th-nav-bg) !important;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--th-nav-border) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
    direction: rtl;
    font-family: var(--th-nav-font) !important;
    line-height: 1.5;
    box-sizing: border-box;
    transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

#thamerGlobalNavbar *,
#thamerGlobalNavbar *::before,
#thamerGlobalNavbar *::after {
    box-sizing: border-box;
    font-family: var(--th-nav-font);
}

.th-nav-inner {
    width: 96%;
    max-width: 1680px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
}

/* Logo */
.th-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none !important;
    min-width: 0;
    flex-shrink: 1;
}

.th-logo-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--th-nav-primary), var(--th-nav-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 1.4rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.4);
}

.th-logo-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.th-logo-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--th-nav-text);
    line-height: 1.2;
    white-space: nowrap;
}

.th-logo-badge {
    font-size: 0.74rem;
    font-weight: 700;
    color: var(--th-nav-primary-light);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 290px;
    line-height: 1.45;
}

/* Center Nav Links */
.th-nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
    white-space: nowrap;
    flex-shrink: 1;
    min-width: 0;
}

.th-nav-link {
    color: var(--th-nav-text-sec) !important;
    text-decoration: none !important;
    font-size: 0.88rem;
    font-weight: 700;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all 0.2s ease;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
}

.th-nav-link:hover,
.th-nav-link.active {
    color: var(--th-nav-text) !important;
    background: rgba(56, 189, 248, 0.14);
}

/* Right/Left Actions Toolbar */
.th-nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.th-nav-btn-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.th-nav-btn {
    height: 38px;
    padding: 0 13px;
    font-size: 0.84rem;
    font-weight: 800;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none !important;
    cursor: pointer;
    white-space: nowrap !important;
    flex-shrink: 0;
    box-sizing: border-box;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
    border: 1px solid transparent;
    line-height: 1;
}

.th-nav-btn-icon {
    font-size: 1rem;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Action Button Themes */
.th-nav-btn-lessons {
    background: linear-gradient(135deg, #059669, #10b981);
    color: #ffffff !important;
    border: 1px solid rgba(52, 211, 153, 0.5);
    box-shadow: 0 3px 10px rgba(16, 185, 129, 0.3);
}

.th-nav-btn-lessons:hover,
.th-nav-btn-lessons.active {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(16, 185, 129, 0.5);
    filter: brightness(1.08);
}

.th-nav-btn-lessons.active {
    outline: 2px solid rgba(52, 211, 153, 0.7);
    outline-offset: 1px;
}

.th-nav-btn-games {
    background: linear-gradient(135deg, #7c3aed, #8b5cf6);
    color: #ffffff !important;
    border: 1px solid rgba(167, 139, 250, 0.55);
    box-shadow: 0 3px 10px rgba(139, 92, 246, 0.35);
}

.th-nav-btn-games:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(139, 92, 246, 0.55);
    filter: brightness(1.1);
}

.th-nav-btn-bmi {
    background: rgba(14, 165, 233, 0.14);
    border: 1px solid rgba(56, 189, 248, 0.45);
    color: #38bdf8 !important;
}

html[data-theme="light"] .th-nav-btn-bmi,
body.light-theme .th-nav-btn-bmi {
    color: #0284c7 !important;
}

.th-nav-btn-bmi:hover {
    background: rgba(14, 165, 233, 0.32);
    border-color: #7dd3fc;
    color: #ffffff !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(14, 165, 233, 0.35);
}

.th-nav-btn-calories {
    background: rgba(249, 115, 22, 0.14);
    border: 1px solid rgba(249, 115, 22, 0.5);
    color: #fb923c !important;
}

html[data-theme="light"] .th-nav-btn-calories,
body.light-theme .th-nav-btn-calories {
    color: #ea580c !important;
}

.th-nav-btn-calories:hover {
    background: rgba(249, 115, 22, 0.32);
    border-color: #fdba74;
    color: #ffffff !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.4);
}

.th-nav-btn-dashboard {
    background: linear-gradient(135deg, var(--th-nav-primary), var(--th-nav-primary-dark));
    color: #ffffff !important;
    border: 1px solid rgba(56, 189, 248, 0.4);
    box-shadow: 0 3px 10px rgba(2, 132, 199, 0.3);
}

.th-nav-btn-dashboard:hover,
.th-nav-btn-dashboard.active {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.5);
    filter: brightness(1.08);
}

.th-nav-btn-dashboard.active {
    outline: 2px solid rgba(56, 189, 248, 0.75);
    outline-offset: 1px;
}

/* Utility Icon Buttons (Sound, Theme, Mobile Menu) */
.th-nav-utils-group {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-right: 6px;
    border-right: 1px solid var(--th-nav-border);
}

.th-btn-icon {
    width: 38px;
    height: 38px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--th-nav-card);
    border: 1px solid var(--th-nav-border);
    color: var(--th-nav-text);
    cursor: pointer;
    font-size: 1rem;
    flex-shrink: 0;
    padding: 0;
    margin: 0;
    line-height: 1;
    transition: all 0.2s ease;
}

.th-btn-icon:hover {
    border-color: var(--th-nav-primary-light);
    background: rgba(56, 189, 248, 0.16);
    transform: translateY(-1px);
}

/* Keep sound button square even when home.js or portal.js injects a label span */
.th-nav-utils-group .th-btn-icon span {
    display: none !important;
}

/* Mobile Menu Button & Drawer */
.th-mobile-menu-btn {
    display: none;
}

.th-mobile-drawer {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--th-nav-bg);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid var(--th-nav-border);
    border-bottom: 1px solid var(--th-nav-border);
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.35);
    padding: 12px 4%;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: center;
}

.th-mobile-drawer.open {
    display: flex;
}

.th-mobile-drawer .th-nav-link {
    font-size: 0.85rem;
    padding: 7px 14px;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid var(--th-nav-border);
}

/* ===================================================
   Page-Specific Harmonization (Units, Dashboard, Login)
   =================================================== */

/* Unit pages: push the unit's own sticky sub-navbar neatly below the main pinned bar */
body.has-thamer-global-nav .navbar:not(#thamerGlobalNavbar) {
    top: var(--thamer-nav-h, 72px) !important;
    z-index: 950 !important;
}

/* Unit (lesson) pages: hide the unit's own secondary navbar — only the main unified bar stays.
   Its theme / sound / presentation buttons are still triggered from the main bar. */
body.has-thamer-global-nav.th-page-unit .navbar:not(#thamerGlobalNavbar) {
    display: none !important;
}

/* Presentation (smartboard) button shown in the main bar on unit pages */
.th-nav-btn-pres {
    background: linear-gradient(135deg, #d97706, #f59e0b);
    color: #ffffff !important;
    border: 1px solid rgba(251, 191, 36, 0.55);
    box-shadow: 0 3px 10px rgba(217, 119, 6, 0.35);
}

.th-nav-btn-pres:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(217, 119, 6, 0.55);
    filter: brightness(1.08);
}

/* When a page has a secondary unit navbar, give anchor jumps extra breathing room */
body.has-thamer-global-nav.has-unit-subnav {
    scroll-padding-top: calc(var(--thamer-nav-h, 72px) + 84px);
}

html.has-unit-subnav {
    scroll-padding-top: calc(var(--thamer-nav-h, 72px) + 84px);
}

/* Smartboard Presentation Mode must always cover the global navbar */
body.has-thamer-global-nav .presentation-overlay,
body.has-thamer-global-nav #presentationOverlay {
    z-index: 10050 !important;
}

/* Dashboard harmonization */
body.has-thamer-global-nav.th-page-dashboard {
    display: block !important;
    overflow-x: clip;
}

body.has-thamer-global-nav.th-page-dashboard .dashboard-layout {
    min-height: calc(100vh - var(--thamer-nav-h, 72px)) !important;
}

body.has-thamer-global-nav.th-page-dashboard .sidebar {
    top: var(--thamer-nav-h, 72px) !important;
    height: calc(100vh - var(--thamer-nav-h, 72px)) !important;
}

body.has-thamer-global-nav.th-page-dashboard .dashboard-main {
    overflow-y: visible !important;
}

body.has-thamer-global-nav.th-page-dashboard .dash-topbar {
    top: var(--thamer-nav-h, 72px) !important;
}

/* Login page harmonization */
body.has-thamer-global-nav.th-page-login .login-page-wrapper {
    min-height: calc(100vh - var(--thamer-nav-h, 72px)) !important;
}

/* ===================================================
   Responsive Breakpoints (Matches home.css faithfully)
   =================================================== */

@media (min-width: 1800px) {
    .th-nav-inner {
        max-width: 1760px;
    }
}

@media (max-width: 1760px) {
    .th-nav-btn-bmi > span:not(.th-nav-btn-icon),
    .th-nav-btn-calories > span:not(.th-nav-btn-icon),
    .th-nav-btn-dashboard > span:not(.th-nav-btn-icon) {
        display: none;
    }
    .th-nav-btn-bmi,
    .th-nav-btn-calories,
    .th-nav-btn-dashboard {
        width: 40px;
        padding: 0;
    }
}

/* Unit pages carry one extra button (وضع العرض), so compact the toolbar earlier */
@media (max-width: 2040px) {
    body.th-page-unit .th-nav-btn-bmi > span:not(.th-nav-btn-icon),
    body.th-page-unit .th-nav-btn-calories > span:not(.th-nav-btn-icon),
    body.th-page-unit .th-nav-btn-dashboard > span:not(.th-nav-btn-icon) {
        display: none;
    }
    body.th-page-unit .th-nav-btn-bmi,
    body.th-page-unit .th-nav-btn-calories,
    body.th-page-unit .th-nav-btn-dashboard {
        width: 40px;
        padding: 0;
    }
}

@media (max-width: 1380px) {
    body.th-page-unit .th-nav-links {
        display: none;
    }
    body.th-page-unit .th-mobile-menu-btn {
        display: inline-flex;
    }
}

@media (max-width: 1480px) {
    .th-nav-inner {
        gap: 10px;
    }
    .th-logo-badge {
        max-width: 220px;
    }
    .th-nav-link {
        font-size: 0.82rem;
        padding: 5px 8px;
    }
    .th-nav-links {
        gap: 3px;
    }
}

@media (max-width: 1240px) {
    .th-nav-links {
        display: none;
    }
    .th-mobile-menu-btn {
        display: inline-flex;
    }
}

@media (max-width: 1080px) {
    .th-logo-badge {
        display: none;
    }
    .th-logo-title {
        font-size: 1.02rem;
    }
    .th-nav-btn {
        padding: 0 10px;
        font-size: 0.8rem;
    }
}

@media (max-width: 920px) {
    .th-nav-inner {
        flex-wrap: wrap;
        padding: 8px 0;
        gap: 8px;
    }
    .th-logo-title {
        font-size: 1rem;
    }
    .th-logo-icon {
        width: 38px;
        height: 38px;
        font-size: 1.2rem;
    }
    .th-nav-actions {
        width: 100%;
        overflow-x: auto;
        padding: 2px 0 4px;
        scrollbar-width: none;
        -webkit-overflow-scrolling: touch;
    }
    .th-nav-actions::-webkit-scrollbar {
        display: none;
    }
    body.has-thamer-global-nav.th-page-dashboard .sidebar {
        position: relative !important;
        top: 0 !important;
        height: auto !important;
    }
}

@media (max-width: 768px) {
    .th-nav-btn {
        height: 34px;
        padding: 0 10px;
        font-size: 0.78rem;
    }
    .th-nav-btn-bmi,
    .th-nav-btn-calories,
    .th-nav-btn-dashboard {
        width: 36px;
        padding: 0;
    }
    .th-btn-icon {
        width: 34px;
        height: 34px;
        font-size: 0.92rem;
    }
    /* On small mobile screens, let the secondary unit navbar scroll naturally so two fixed bars don't crowd the viewport */
    body.has-thamer-global-nav .navbar:not(#thamerGlobalNavbar) {
        position: relative !important;
        top: 0 !important;
    }
}

/* Hide global navbar cleanly when printing certificates or student cards */
@media print {
    #thamerGlobalNavbar {
        display: none !important;
    }
    body.has-thamer-global-nav {
        padding-top: 0 !important;
    }
}
