@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
    --primary: #00364d; /* slightly deeper for elegance */
    --accent: #00A8CC;
    --accent-light: rgba(0, 168, 204, 0.1);
    --white: #ffffff;
    --bg-color: #f6f9fc;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    
    --shadow-soft: 0 8px 30px rgba(0,0,0,0.03);
    --shadow-float: 0 20px 40px rgba(0, 54, 77, 0.08);
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 28px;
    
    --nav-height: 70px;
}

[data-theme="dark"] {
    --primary: #38bdf8;
    --accent: #7dd3fc;
    --accent-light: rgba(56, 189, 248, 0.15);
    --white: #1e293b;
    --bg-color: #0f172a;
    --text-dark: #f8fafc;
    --text-muted: #94a3b8;
    --shadow-soft: 0 8px 30px rgba(0,0,0,0.2);
    --shadow-float: 0 20px 40px rgba(0,0,0,0.3);
}

/* Adjust featured card background in dark mode */
[data-theme="dark"] .featured-card {
    background: linear-gradient(135deg, #0f172a 0%, #020617 100%);
    border: 1px solid rgba(255,255,255,0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

.desktop-only {
    display: none !important;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-dark);
    line-height: 1.5;
    overflow-x: hidden;
    user-select: none;
    -webkit-user-select: none;
    display: flex;
    justify-content: center;
}

/* APP SHELL */
.app-container {
    max-width: 480px;
    width: 100%;
    min-height: 100vh;
    background: var(--bg-color);
    position: relative;
    box-shadow: none; /* Removed heavy web-like glow for a cleaner app feel */
    display: flex;
    flex-direction: column;
}

/* NATIVE-LIKE HEADER */
.app-header {
    padding: 40px 24px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: transparent;
}

.profile-greeting p {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}
.profile-greeting h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-top: 2px;
}

.profile-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--white);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(0,0,0,0.02);
}
.profile-avatar img {
    height: 24px;
    object-fit: contain;
}

/* MAIN DASHBOARD SCROLL AREA */
.app-main {
    flex: 1;
    padding: 10px 24px 100px; /* bottom padding accounting for floating nav */
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--primary);
    margin-top: 24px;
}

/* HERO SECTION */
.hero-section {
    position: relative;
    background: linear-gradient(140deg, var(--primary) 0%, #012d40 55%, #001a26 100%);
    border-radius: var(--radius-lg);
    padding: 36px 28px 32px;
    color: #fff;
    overflow: hidden;
    margin-bottom: 4px;
}
.hero-blob {
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(40px);
}
.hero-blob-1 {
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, rgba(0,168,204,0.35) 0%, transparent 70%);
    top: -60px;
    right: -40px;
}
.hero-blob-2 {
    width: 140px;
    height: 140px;
    background: radial-gradient(circle, rgba(56,189,248,0.2) 0%, transparent 70%);
    bottom: -30px;
    left: 20px;
}
.hero-body {
    position: relative;
    z-index: 1;
}
.hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.12);
    border: 1px solid rgba(255,255,255,0.2);
    backdrop-filter: blur(8px);
    color: rgba(255,255,255,0.9);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 50px;
    margin-bottom: 18px;
    letter-spacing: 0.02em;
}
.hero-title {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.15;
    margin-bottom: 14px;
    color: #fff;
    letter-spacing: -0.5px;
}
.hero-title-accent {
    color: var(--accent);
}
.hero-sub {
    font-size: 0.9rem;
    color: rgba(255,255,255,0.75);
    line-height: 1.65;
    margin-bottom: 24px;
    max-width: 480px;
}
.hero-ctas {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 28px;
}
.hero-btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 13px 22px;
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0,168,204,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
.hero-btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 28px rgba(0,168,204,0.5);
}
.hero-btn-primary:active { transform: scale(0.97); }

.hero-btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.25);
    padding: 13px 22px;
    border-radius: 14px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 0.2s, transform 0.2s;
    font-family: inherit;
}
.hero-btn-secondary:hover {
    background: rgba(255,255,255,0.18);
    transform: translateY(-1px);
}
.hero-btn-secondary:active { transform: scale(0.97); }

/* Trust Stats bar */
.hero-stats {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 14px;
    padding: 14px 20px;
    flex-wrap: wrap;
    gap: 8px;
}
.hero-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 50px;
}
.hero-stat strong {
    font-size: 1.1rem;
    font-weight: 800;
    color: #fff;
    line-height: 1;
    margin-bottom: 3px;
}
.hero-stat span {
    font-size: 0.68rem;
    color: rgba(255,255,255,0.6);
    font-weight: 500;
    white-space: nowrap;
}
.hero-stat-divider {
    width: 1px;
    height: 30px;
    background: rgba(255,255,255,0.15);
    flex-shrink: 0;
}


/* SECONDARY CARDS GRID */
.grid-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.secondary-card {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 20px 16px;
    cursor: pointer;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(0,0,0,0.02);
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.secondary-card:active {
    transform: scale(0.96);
}

.sec-icon {
    width: 42px;
    height: 42px;
    background: var(--accent-light);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent);
    margin-bottom: 16px;
}
.sec-icon svg { width: 22px; height: 22px; }

.secondary-card h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--primary);
}
.secondary-card p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* WIDE PARTNER CARDS */
.partner-card {
    display: flex;
    align-items: center;
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-soft);
    margin-bottom: 12px;
    border: 1px solid rgba(0,0,0,0.02);
}
.partner-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: rgba(217, 83, 79, 0.1);
    color: #d9534f;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 16px;
}
.partner-info h4 { font-size: 1rem; color: var(--text-dark); }
.partner-info p { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px;}

/* FLOATING BOTTOM NAV BAR */
.nav-wrapper {
    position: fixed;
    bottom: 24px;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    pointer-events: none; /* Let clicks pass through margins */
    z-index: 500;
    padding-bottom: env(safe-area-inset-bottom);
}

.app-nav {
    width: 85%;
    max-width: 380px;
    height: var(--nav-height);
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: 35px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
    box-shadow: var(--shadow-float);
    border: 1px solid rgba(255,255,255,0.4);
    pointer-events: auto; /* Re-enable clicks inside the bar */
}

.nav-item {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 50px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 25px;
    position: relative;
}

.nav-item svg {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s;
}

.nav-item span {
    display: none;
    font-size: 0.85rem;
    font-weight: 600;
    margin-left: 8px;
    opacity: 0;
}

/* Active Nav State - Floating Pill */
.nav-item.active {
    background: var(--accent-light);
    color: var(--accent);
    padding: 0 16px;
    flex: 1.5; /* expands perfectly */
}

.nav-item.active span {
    display: block;
    animation: fadeIn 0.3s ease forwards;
}

.nav-item.active svg {
    transform: scale(1.1);
}

/* VIEWS */
.view {
    display: none;
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.view.active {
    display: block;
}

/* ONBOARDING MODAL */
.onboarding-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 40, 0.4);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.onboarding-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.onboarding-sheet {
    background: var(--white);
    border-radius: 32px 32px 0 0;
    padding: 32px 24px 40px;
    width: 100%;
    margin: 0 auto;
    max-width: 480px;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
    box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
}

.onboarding-overlay.active .onboarding-sheet {
    transform: translateY(0);
}

.sheet-handle {
    width: 48px;
    height: 5px;
    background: #e2e8f0;
    border-radius: 10px;
    margin: 0 auto 32px;
}

.step-indicator {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-bottom: 32px;
}
.dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #cbd5e1;
    transition: all 0.3s;
}
.dot.active {
    background: var(--accent);
    width: 24px;
    border-radius: 4px;
}

.step-content {
    display: none;
    text-align: center;
}
.step-content.active {
    display: block;
    animation: zoomFade 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.step-image {
    width: 140px;
    height: 140px;
    background: var(--bg-color);
    border-radius: 30px;
    margin: 0 auto 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
}
.step-image svg { width: 64px; height: 64px; stroke-width: 1.5;}

.step-content h2 { font-size: 1.5rem; color: var(--primary); margin-bottom: 8px; }
.step-content p { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; padding: 0 10px;}

.btn-primary {
    background: var(--primary);
    color: white;
    width: 100%;
    padding: 16px;
    border: none;
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 600;
    margin-top: 32px;
    cursor: pointer;
    box-shadow: 0 8px 20px rgba(0, 54, 77, 0.2);
    transition: transform 0.2s, background 0.2s;
}
.btn-primary:active {
    transform: scale(0.98);
    background: #002233;
}

/* WIDGET BLOCKS */
.widget-box {
    background: var(--white);
    border-radius: var(--radius-md);
    padding: 24px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(0,0,0,0.02);
}

/* THEME SWITCH */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
}
.theme-switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .4s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}
input:checked + .slider {
    background-color: var(--primary);
}
input:checked + .slider:before {
    transform: translateX(22px);
}
.slider.round {
    border-radius: 34px;
}
.slider.round:before {
    border-radius: 50%;
}

/* ANIMATIONS */
@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-5px); }
    to { opacity: 1; transform: translateX(0); }
}

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes zoomFade {
}
#loading-spinner {
    display: none;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    margin-right: 10px;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* SPLASH SCREEN */
#splash-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-color);
    z-index: 9000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease-out;
}

#splash-screen img {
    width: 120px;
    height: auto;
    border-radius: 20px;
    box-shadow: 0 10px 30px rgba(0, 54, 77, 0.15);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* TOAST NOTIFICATION */
.toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background: #1e293b;
    color: white;
    padding: 14px 24px;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    z-index: 10000;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.4s;
    opacity: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 10px;
}
.toast-container.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* PROFILE AUTH PROMPT */
.auth-prompt-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    box-shadow: var(--shadow-soft);
    border: 1px solid rgba(0,0,0,0.02);
}
.auth-prompt-icon {
    width: 64px;
    height: 64px;
    background: rgba(0, 168, 204, 0.1);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}
.auth-prompt-icon svg { width: 32px; height: 32px; }
.auth-prompt-card h3 { font-size: 1.4rem; color: var(--text-dark); margin-bottom: 12px; }
.auth-prompt-card p { font-size: 0.95rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 24px; }
.auth-benefits { text-align: left; margin-bottom: 28px; display: inline-block; max-width: 100%;}
.auth-benefit { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.auth-benefit svg { width: 20px; height: 20px; color: #2ecc71; flex-shrink: 0;}
.auth-benefit span { font-size: 0.95rem; color: var(--text-dark); }
.auth-ctas { display: flex; flex-direction: column; gap: 12px; }
.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 2px solid var(--primary);
    width: 100%;
    padding: 14px;
    border-radius: 16px;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
}
.btn-secondary:active { background: rgba(0, 168, 204, 0.1); }

/* HELP & SUPPORT CONTACT CARDS */
.contact-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 16px;
    border-radius: var(--radius-md);
    text-align: center;
    border: 1px solid rgba(0,0,0,0.04);
    transition: transform 0.2s, box-shadow 0.2s;
    background: var(--white);
    box-shadow: var(--shadow-soft);
}
.contact-card:active { transform: scale(0.97); }
.contact-card.whatsapp { border-top: 4px solid #25D366; }
.contact-card.phone { border-top: 4px solid var(--accent); }
.contact-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}
.contact-card.whatsapp .contact-icon { background: rgba(37, 211, 102, 0.1); color: #25D366; }
.contact-card.phone .contact-icon { background: rgba(56, 189, 248, 0.1); color: var(--accent); }
.contact-icon svg { width: 24px; height: 24px; }
.contact-card h4 { font-size: 1.05rem; color: var(--text-dark); margin-bottom: 4px; }
.contact-card p { font-size: 0.8rem; color: var(--text-muted); }

/* FAQ ACCORDION */
.faq-container { display: flex; flex-direction: column; gap: 12px; }
.faq-item {
    background: var(--white);
    border-radius: var(--radius-md);
    border: 1px solid rgba(0,0,0,0.04);
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
    overflow: hidden;
}
.faq-question {
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 18px 20px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}
.faq-question svg { width: 20px; height: 20px; color: var(--text-muted); transition: transform 0.3s; }
.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s ease;
}
.faq-answer p {
    padding: 0 20px 20px;
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin: 0;
}
.faq-item.active .faq-question svg { transform: rotate(180deg); color: var(--primary);}
.faq-item.active .faq-answer { max-height: 500px; }

/* =========================================
   RESPONSIVE DESIGN (TABLET & DESKTOP)
   ========================================= */

/* TABLET VIEW */
@media (min-width: 768px) {
    body {
        padding: 40px 20px;
        height: 100vh;
        overflow: hidden; /* Prevent body from scrolling — sidebar stays anchored */
    }

    .app-container {
        max-width: 1024px;
        border-radius: var(--radius-lg);
        height: calc(100vh - 80px); /* Fixed height so sidebar always spans full panel */
        overflow: hidden;
        box-shadow: 0 20px 60px rgba(0, 54, 77, 0.08);
    }

    .app-header, .app-main {
        margin-left: 250px;
    }

    .app-main {
        padding-bottom: 40px;
        overflow-y: auto; /* Content scrolls inside the panel, not the body */
        flex: 1;
        min-height: 0; /* required for flex children to scroll */
    }

    /* Floating bottom nav becomes a rigid side nav */
    .nav-wrapper {
        position: absolute;
        top: 0;
        left: 0;
        bottom: 0;
        width: 250px;
        padding-bottom: 0;
        z-index: 200;
        background: var(--white);
        border-right: 1px solid rgba(0,0,0,0.05);
        border-radius: var(--radius-lg) 0 0 var(--radius-lg);
        pointer-events: auto;
        overflow: hidden; /* Clip to panel bounds */
        display: flex;
        flex-direction: column;
    }

    .app-nav {
        width: 100%;
        max-width: none;
        height: 100%; /* Fill the flex column wrapper */
        background: transparent;
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border-radius: 0;
        border: none;
        box-shadow: none;
        flex-direction: column;
        justify-content: flex-start;
        padding: 0 10px 0; /* No bottom padding needed — sidebar-version handles it */
        gap: 4px;
        overflow-y: auto;
        scrollbar-width: none;
        -ms-overflow-style: none;
        flex: 1;
        min-height: 0; /* Required for flex children to scroll */
    }
    .app-nav::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Opera */
    }

    /* Sidebar brand block – centred column layout */
    .sidebar-brand {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        padding: 20px 8px 16px;
        margin-bottom: 4px;
        border-bottom: 1px solid rgba(0,0,0,0.06);
        flex-shrink: 0;
    }
    .sidebar-brand img {
        width: 64px;
        height: 64px;
        border-radius: 14px;
        object-fit: cover;
        flex-shrink: 0;
    }
    .sidebar-brand-name {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--primary);
        letter-spacing: -0.3px;
        text-align: center;
    }
    /* Collapse btn sits as a normal flex child below the name */
    .sidebar-brand .sidebar-collapse-btn {
        margin-top: 2px;
    }
    /* Sidebar horizontal divider */
    .sidebar-divider {
        height: 1px;
        background: rgba(0,0,0,0.07);
        margin: 6px 8px;
        flex-shrink: 0;
    }
    /* Collapse toggle button */
    .sidebar-collapse-btn {
        background: none;
        border: none;
        cursor: pointer;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-muted);
        border-radius: 8px;
        padding: 4px;
        flex-shrink: 0;
        transition: background 0.2s, color 0.2s;
    }
    .sidebar-collapse-btn:hover {
        background: var(--accent-light);
        color: var(--accent);
    }
    .sidebar-collapse-btn svg {
        width: 16px;
        height: 16px;
        transition: transform 0.3s ease;
    }
    /* Version footer – also holds the dark-mode toggle */
    .sidebar-version {
        flex-shrink: 0; /* Never be squished — always visible */
        padding: 12px 8px 24px; /* 24px bottom to clear panel rounding */
        border-top: 1px solid rgba(0,0,0,0.06);
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
        background: var(--white);
    }
    /* Labelled dark-mode toggle row */
    .sidebar-dark-toggle {
        display: flex;
        align-items: center;
        gap: 10px;
        cursor: pointer;
        width: 100%;
        padding: 4px 8px;
        border-radius: 8px;
        transition: background 0.2s;
    }
    .sidebar-dark-toggle:hover {
        background: var(--accent-light);
    }
    .sidebar-dark-label {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-dark);
        flex: 1;
    }
    .sidebar-version-text {
        font-size: 0.68rem;
        color: var(--text-muted);
        font-weight: 500;
        opacity: 0.65;
        white-space: nowrap;
        padding-left: 8px;
    }
    /* Sidebar + content smooth transitions */
    .nav-wrapper {
        transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .app-header, .app-main {
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .desktop-only {
        display: flex !important;
    }

    .nav-item {
        width: 100%;
        height: 48px;
        min-height: 48px;
        justify-content: flex-start;
        padding: 0 16px;
        border-radius: 12px;
        color: var(--text-dark);
    }

    .nav-item span {
        display: block;
        opacity: 1;
        font-size: 0.95rem;
        margin-left: 14px;
    }

    .nav-item.active {
        flex: 0 0 48px; 
    }

    .nav-item.active span {
        color: var(--accent);
    }

    .grid-cards {
        grid-template-columns: repeat(3, 1fr);
    }

    /* Modal dialogs instead of bottom sheets */
    .onboarding-overlay.active {
        align-items: center;
        justify-content: center;
    }

    .onboarding-sheet {
        border-radius: 32px;
        max-width: 500px;
        transform: scale(0.9) translateY(0);
        opacity: 0;
        margin: auto;
        padding-top: 40px;
    }

    .onboarding-overlay.active .onboarding-sheet {
        transform: scale(1) translateY(0);
        opacity: 1;
    }

    .sheet-handle {
        display: none;
    }

    /* ---- COLLAPSED SIDEBAR STATE ---- */
    .app-container.sidebar-collapsed .nav-wrapper {
        width: 64px;
    }
    .app-container.sidebar-collapsed .app-header,
    .app-container.sidebar-collapsed .app-main {
        margin-left: 64px;
    }
    /* Hide text labels and non-essential elements */
    .app-container.sidebar-collapsed .sidebar-brand-name,
    .app-container.sidebar-collapsed .nav-item span,
    .app-container.sidebar-collapsed .sidebar-version-text,
    .app-container.sidebar-collapsed .sidebar-dark-label {
        display: none !important;
    }
    /* Compact dark toggle row when collapsed – show only the toggle */
    .app-container.sidebar-collapsed .sidebar-dark-toggle {
        justify-content: center;
        padding: 4px;
    }
    /* Centre icons */
    .app-container.sidebar-collapsed .nav-item {
        justify-content: center;
        padding: 0;
    }
    /* Centre brand block – show small logo only */
    .app-container.sidebar-collapsed .sidebar-brand {
        padding: 12px 4px 12px;
        gap: 0;
    }
    .app-container.sidebar-collapsed .sidebar-brand img {
        width: 38px;
        height: 38px;
        border-radius: 10px;
    }
    .app-container.sidebar-collapsed .sidebar-brand .sidebar-collapse-btn {
        margin-top: 6px;
    }
    /* Rotate chevron to point right */
    .app-container.sidebar-collapsed .sidebar-collapse-btn svg {
        transform: rotate(180deg);
    }
    /* Shrink dividers */
    .app-container.sidebar-collapsed .sidebar-divider {
        margin: 4px 10px;
    }
    .app-container.sidebar-collapsed .sidebar-version {
        padding: 8px 4px;
        align-items: center;
    }
}

/* DESKTOP VIEW */
@media (min-width: 1024px) {
    .app-container {
        max-width: 1200px;
    }

    .app-header, .app-main {
        margin-left: 280px; 
    }

    .nav-wrapper {
        width: 280px;
    }

    .grid-cards {
        grid-template-columns: repeat(4, 1fr);
    }

    .partner-card {
        max-width: 800px;
    }
    
    #splash-screen img {
        width: 160px;
    }

    /* Collapsed overrides at wider breakpoint */
    .app-container.sidebar-collapsed .nav-wrapper {
        width: 64px;
    }
    .app-container.sidebar-collapsed .app-header,
    .app-container.sidebar-collapsed .app-main {
        margin-left: 64px;
    }

    .sidebar-brand-name {
        font-size: 1.05rem;
    }
}

/* =========================================
   NIA AI CHAT: PREMIUM EXPERIENCE
   ========================================= */

#ai-chat {
    display: none;
    flex-direction: column;
    /* Sit inside the app-container panel, NOT over the whole viewport */
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 80px; /* Clear the mobile bottom nav */
    z-index: 100;
    background: #fdfdfe;
    overflow: hidden;
}

/* Reset height offset on desktop */
@media (min-width: 768px) {
    #ai-chat {
        bottom: 0; 
    }
}

[data-theme="dark"] #ai-chat {
    background: #0f172a;
}

[data-theme="dark"] .nav-wrapper {
    background: #1e293b;
    border-right-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .sidebar-version {
    background: #1e293b;
    border-top-color: rgba(255,255,255,0.06);
}

[data-theme="dark"] .sidebar-divider {
    background: rgba(255,255,255,0.06);
}

[data-theme="dark"] .sidebar-brand {
    border-bottom-color: rgba(255,255,255,0.06);
}

#ai-chat.active {
    display: flex;
}

/* Stunning Glass Header */
.chat-header {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    padding: calc(env(safe-area-inset-top) + 20px) 24px 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    border-bottom: 1px solid rgba(0,0,0,0.04);
    z-index: 100;
}

[data-theme="dark"] .chat-header {
    background: rgba(15, 23, 42, 0.75);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.chat-back-btn {
    background: rgba(0, 54, 77, 0.05);
    border: none;
    color: var(--primary);
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-back-btn:hover { background: rgba(0, 54, 77, 0.1); transform: scale(1.05); }

.chat-header-profile {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
}

.chat-download-btn {
    background: rgba(0, 54, 77, 0.05);
    border: none;
    color: var(--primary);
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.chat-download-btn:hover { background: var(--accent); color: white; transform: translateY(-2px); }

.chat-avatar-frame {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
    padding: 2px;
    position: relative;
    box-shadow: 0 8px 16px rgba(0, 168, 204, 0.15);
}

.chat-avatar-frame img {
    width: 100%;
    height: 100%;
    border-radius: 14px;
    object-fit: cover;
    background: var(--white);
}

.status-dot {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 13px;
    height: 13px;
    background: #10b981;
    border: 3px solid var(--white);
    border-radius: 50%;
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.chat-header-text h3 {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary);
    margin: 0;
    letter-spacing: -0.02em;
}

.chat-header-text span {
    font-size: 0.78rem;
    color: #10b981;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

/* Chat Stream area: Polished Message Flow */
.chat-stream {
    flex: 1;
    overflow-y: auto;
    padding: 24px 24px 160px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
    /* Ultra-subtle professional background */
    background: #fdfdfe;
    background-image: 
        radial-gradient(rgba(0, 168, 204, 0.03) 1px, transparent 1px);
    background-size: 32px 32px;
}

[data-theme="dark"] .chat-stream {
    background: #0f172a;
    background-image: 
        radial-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px);
}

.chat-bubble {
    max-width: 82%;
    padding: 16px 22px;
    font-size: 0.98rem;
    line-height: 1.6;
    animation: messageArrival 0.5s cubic-bezier(0.19, 1, 0.22, 1);
    position: relative;
}

@keyframes messageArrival {
    from { opacity: 0; transform: translateY(20px) scale(0.9); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.chat-bubble.bot {
    align-self: flex-start;
    background: var(--white);
    color: var(--text-dark);
    border-radius: 24px 24px 24px 6px;
    box-shadow: 
        0 4px 6px -1px rgba(0, 54, 77, 0.05),
        0 10px 15px -3px rgba(0, 54, 77, 0.03);
    border: 1px solid rgba(0, 54, 77, 0.02);
}

.chat-bubble.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--primary) 0%, #002233 100%);
    color: white;
    border-radius: 24px 24px 6px 24px;
    box-shadow: 
        0 10px 20px -5px rgba(0, 54, 77, 0.2),
        inset 0 -2px 5px rgba(0,0,0,0.1);
}

.bubble-content p { margin-bottom: 10px; }
.bubble-content p:last-child { margin-bottom: 0; }
.bubble-content strong { font-weight: 700; color: inherit; }

/* Action Buttons inside bubbles */
.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
}

.chat-action-btn {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bot .chat-action-btn {
    background: var(--accent-light);
    color: var(--primary);
    border: 1px solid rgba(0, 168, 204, 0.1);
}

.chat-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    background: var(--accent);
    color: white;
}

.chat-bubble.bot .image-attachment {
    max-width: 100%;
    border-radius: 12px;
    margin-top: 10px;
    display: block;
}

.chat-bubble.user .image-attachment {
    max-width: 100%;
    border-radius: 12px;
    margin-bottom: 10px;
    display: block;
}

/* Enhanced Quick Action Chips */
.quick-chips {
    padding: 0 24px 24px;
    display: flex;
    gap: 12px;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-top: -30px;
    z-index: 10;
}

.quick-chips::-webkit-scrollbar { display: none; }

.chip {
    white-space: nowrap;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 168, 204, 0.15);
    padding: 12px 22px;
    border-radius: 50px;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--primary);
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}

[data-theme="dark"] .chip {
    background: rgba(30, 41, 59, 0.8);
    border-color: rgba(255,255,255,0.1);
    color: var(--accent);
}

.chip:hover { 
    background: var(--accent); 
    color: white;
    transform: translateY(-4px); 
    box-shadow: 0 10px 20px rgba(0, 168, 204, 0.2); 
}
.chip:active { transform: scale(0.92); }

/* Premium Floating Input Dock */
.chat-input-area {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 24px 24px calc(env(safe-area-inset-bottom) + 30px);
    background: linear-gradient(to top, var(--bg-color) 40%, transparent);
    z-index: 110;
}

.chat-input-container {
    background: var(--white);
    border-radius: 40px;
    padding: 8px 10px 8px 18px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 
        0 20px 40px rgba(0, 54, 77, 0.12),
        0 0 0 1px rgba(0, 168, 204, 0.05);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-icon-btn:hover { background: rgba(0, 168, 204, 0.1); color: var(--accent); }
.chat-icon-btn.active { color: #f87171; animation: recordingPulse 1.5s infinite; }

@keyframes recordingPulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

[data-theme="dark"] .chat-input-container {
    background: #1e293b;
}

.chat-input-container:focus-within {
    transform: translateY(-2px);
    box-shadow: 
        0 25px 50px rgba(0, 54, 77, 0.18),
        0 0 0 2px var(--accent);
}

#chatInput {
    flex: 1;
    border: none;
    background: none;
    padding: 14px 0;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text-dark);
    outline: none;
}

.chat-send-btn {
    width: 54px;
    height: 54px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--primary) 100%);
    color: white;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 8px 20px rgba(0, 168, 204, 0.3);
}

.chat-send-btn:hover { 
    transform: scale(1.1) rotate(-15deg); 
    box-shadow: 0 12px 25px rgba(0, 168, 204, 0.4);
}
.chat-send-btn:active { transform: scale(0.85); }
.chat-send-btn svg { width: 24px; height: 24px; margin-left: 2px; }

/* Typing state refined */
.typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
}

.typing span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    opacity: 0.3;
}

.typing span:nth-child(1) { animation: typingFlow 1s infinite alternate; }
.typing span:nth-child(2) { animation: typingFlow 1s infinite alternate 0.2s; }
.typing span:nth-child(3) { animation: typingFlow 1s infinite alternate 0.4s; }

@keyframes typingFlow {
    to { opacity: 1; transform: scale(1.3) translateY(-2px); background: var(--accent); }
}

/* RESPONSIVE NIA FOR TABLET/DESKTOP */
@media (min-width: 768px) {
    #ai-chat {
        /* Sits inside .app-container, starts after the 250px sidebar */
        left: 250px;
        width: calc(100% - 250px);
        height: 100%; /* fill the panel, not the viewport */
        z-index: 100;
        box-shadow: none;
    }
    
    .chat-header {
        padding: 30px 40px;
    }
    
    .chat-stream {
        padding: 40px 60px 180px;
    }
    
    .chat-input-area {
        padding: 40px 60px;
    }
    
    .quick-chips {
        padding: 0 60px 40px;
        margin-top: -50px;
    }
}

@media (min-width: 1024px) {
    #ai-chat {
        left: 250px;
        width: calc(100% - 250px);
    }

    /* Collapsed sidebar: chat fills full area minus collapsed width */
    .app-container.sidebar-collapsed #ai-chat {
        left: 64px;
        width: calc(100% - 64px);
    }
}

/* MEDICAL CONSENT OVERLAY */
.consent-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

.consent-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.consent-card {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0,0,0,0.3);
    transform: translateY(20px);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.consent-overlay.active .consent-card {
    transform: translateY(0);
}

.consent-icon {
    width: 64px;
    height: 64px;
    background: rgba(245, 158, 11, 0.1);
    color: #f59e0b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
}

[data-theme="dark"] .consent-card {
    background: #1e293b;
    color: white;
}

/* ================================================
   NIA AI — ENHANCED CLINICAL UI
   ================================================ */

/* Nia AI badge */
.nia-badge {
    display: inline-block;
    font-size: 0.6rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    vertical-align: middle;
    margin-left: 4px;
    text-transform: uppercase;
}

/* Message timestamp */
.bubble-time {
    display: block;
    font-size: 0.68rem;
    color: var(--text-muted);
    margin-top: 4px;
    opacity: 0.65;
}
.chat-bubble.user .bubble-time { text-align: right; }
.chat-bubble.bot  .bubble-time { text-align: left; }

/* EMERGENCY MODE */
#ai-chat.emergency-mode { animation: emergency-pulse 1s ease-in-out 2; }
@keyframes emergency-pulse {
    0%,100% { box-shadow: none; }
    50%     { box-shadow: inset 0 0 0 3px #ef4444; }
}
.emergency-header-active {
    background: rgba(239,68,68,0.08) !important;
    border-bottom-color: rgba(239,68,68,0.3) !important;
}
.emergency-bubble {
    background: linear-gradient(135deg,#fff5f5,#fee2e2) !important;
    border: 1.5px solid #fca5a5 !important;
}
[data-theme="dark"] .emergency-bubble {
    background: linear-gradient(135deg,#3b0000,#450a0a) !important;
    border-color: #ef4444 !important;
}
.emergency-header { display:flex; align-items:center; gap:8px; color:#dc2626; margin-bottom:8px; }
.emergency-actions { display:flex; flex-direction:column; gap:8px; margin-top:12px; }
.emergency-btn {
    display:block; padding:10px 16px; border-radius:10px;
    font-size:0.9rem; font-weight:700; text-align:center; text-decoration:none; cursor:pointer;
}
.crisis-btn   { background:#dbeafe; color:#1e40af; border:1px solid #93c5fd; }
.ambulance-btn{ background:#fee2e2; color:#dc2626; border:1px solid #fca5a5; }
.crisis-btn:hover   { background:#bfdbfe; }
.ambulance-btn:hover{ background:#fecaca; }

/* PAIN SCALE COMPONENT */
.pain-scale-bubble {
    background: var(--white) !important;
    border: 1.5px solid var(--border-color) !important;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06) !important;
}
.pain-scale-content { width:100%; text-align:center; padding:4px 0; }
.pain-scale-title   { font-weight:700; color:var(--primary); margin-bottom:14px; font-size:0.95rem; }
.pain-scale-row     { display:flex; align-items:center; gap:10px; margin-bottom:10px; }
.pain-label         { font-size:0.78rem; font-weight:600; flex-shrink:0; }
.pain-label.mild    { color:#10b981; }
.pain-label.severe  { color:#ef4444; }
.pain-value { font-size:2rem; font-weight:800; margin:6px 0; color:var(--text-dark); transition:color .3s; }
.pain-emojis{ display:flex; justify-content:space-between; font-size:1.2rem; margin:6px 0 14px; }
.pain-submit-btn { width:100%; padding:10px; margin-top:0; }

/* VOICE RECORDING STATE */
#voiceBtn.recording {
    background: rgba(239,68,68,0.12) !important;
    color: #ef4444 !important;
    animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
    50%     { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}
#chatInput.recording { border-color:#ef4444 !important; background:rgba(239,68,68,0.04) !important; }

/* CHIP IMPROVEMENTS */
.chip {
    white-space: nowrap;
    font-size: 0.82rem;
    padding: 7px 13px;
    border-radius: 20px;
    background: var(--white);
    border: 1.5px solid rgba(0,0,0,0.08);
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}
.chip:hover {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    transform: translateY(-1px);
}
[data-theme="dark"] .chip {
    background: rgba(255,255,255,0.06);
    border-color: rgba(255,255,255,0.1);
    color: #e2e8f0;
}
[data-theme="dark"] .pain-scale-bubble {
    background: #1e293b !important;
    border-color: rgba(255,255,255,0.1) !important;
}
[data-theme="dark"] .bubble-time { color: rgba(255,255,255,0.35); }
