/* ============================================
   AI Health Assistant - Modern UI Styles
   Sidebar layout, clean, professional design
   ============================================ */

:root {
    color-scheme: light;
    --primary: #0d9488;
    --primary-dark: #0f766e;
    --primary-light: #14b8a6;
    --accent: #0891b2;
    --bg-light: #f0fdfa;
    --bg-card: #ffffff;
    --sidebar-width: 260px;
    --sidebar-bg: #0f766e;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.08);
    --sidebar-text: rgba(255, 255, 255, 0.9);
    --sidebar-text-muted: rgba(255, 255, 255, 0.65);
    --text-primary: #134e4a;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-hover: 0 10px 25px -5px rgba(0, 0, 0, 0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-md: 10px;
    --transition: 0.2s ease;
}

/* Bootstrap 5.3 color mode + app chrome (sidebar uses CSS variables below) */
[data-bs-theme="dark"] {
    color-scheme: dark;
    --primary: #2dd4bf;
    --primary-dark: #14b8a6;
    --primary-light: #5eead4;
    --accent: #22d3ee;
    --bg-light: #0f172a;
    --bg-card: #1e293b;
    --sidebar-bg: #0c4a44;
    --sidebar-bg-hover: rgba(255, 255, 255, 0.1);
    --sidebar-text: rgba(255, 255, 255, 0.92);
    --sidebar-text-muted: rgba(255, 255, 255, 0.68);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-hover: 0 12px 28px -8px rgba(0, 0, 0, 0.45);
}

[data-bs-theme="dark"] body {
    color: var(--text-primary);
    background: var(--bg-light);
}

[data-bs-theme="dark"] .offline-banner {
    background: #422006;
    color: #fde68a;
    border-bottom-color: #b45309;
}

[data-bs-theme="dark"] .tier5-hero {
    background: linear-gradient(135deg, rgba(13, 148, 136, 0.22) 0%, rgba(8, 145, 178, 0.14) 50%, rgba(15, 23, 42, 0.98) 100%);
}

[data-bs-theme="dark"] .header-account-dropdown .btn-account-trigger {
    background: var(--bg-card);
    border-color: rgba(45, 212, 191, 0.45);
    color: var(--text-primary);
}

[data-bs-theme="dark"] .header-account-dropdown .btn-account-trigger:hover,
[data-bs-theme="dark"] .header-account-dropdown .btn-account-trigger:focus,
[data-bs-theme="dark"] .header-account-dropdown .btn-account-trigger.show {
    border-color: var(--primary);
    background: var(--bg-card);
    color: var(--text-primary);
}

[data-bs-theme="dark"] .sidebar {
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #06302c 100%);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="dark"] .firstaid-list .list-group-item:hover {
    background: rgba(45, 212, 191, 0.06);
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    color: var(--text-primary);
    background: var(--bg-light);
    min-height: 100vh;
}

/* W1-2: visible without Bootstrap if CDN fails offline */
.offline-banner {
    background: #fff3cd;
    color: #664d03;
    padding: 0.65rem 1rem;
    text-align: center;
    border-bottom: 1px solid #ffc107;
    font-size: 0.9rem;
    line-height: 1.4;
}

.offline-banner[hidden] {
    display: none !important;
}

/* W1-3: retry panels */
.network-retry-panel .btn {
    min-height: 44px;
    padding: 0.5rem 1rem;
}

/* ========== App Layout ========== */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ========== Sidebar (mobile-first: hidden by default) ========== */
.sidebar {
    position: fixed;
    top: env(safe-area-inset-top, 0px);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - env(safe-area-inset-top, 0px));
    height: calc(100dvh - env(safe-area-inset-top, 0px));
    background: linear-gradient(180deg, var(--sidebar-bg) 0%, #0d5d56 100%);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
    transition: transform var(--transition);
    transform: translateX(-100%);
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: inherit;
    transition: opacity var(--transition);
}

.sidebar-brand:hover {
    opacity: 0.95;
    color: inherit;
}

.sidebar-logo {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sidebar-brand-title {
    font-weight: 700;
    font-size: 1.15rem;
    color: white;
}

.sidebar-brand-subtitle {
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
    font-weight: 500;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.75rem;
}

.sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar-menu li {
    margin-bottom: 0.25rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    min-height: 44px;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: background var(--transition), color var(--transition);
}

.sidebar-link:hover {
    background: var(--sidebar-bg-hover);
    color: white;
}

.sidebar-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.sidebar-link i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
}

.sidebar-auth,
.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    color: var(--sidebar-text-muted);
}

.sidebar-user i {
    font-size: 1.25rem;
}

.sidebar-user-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout {
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    font: inherit;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 999;
    opacity: 0;
    transition: opacity var(--transition);
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

@media (min-width: 992px) {
    .sidebar-overlay {
        display: none !important;
    }
}

/* ========== Main Content Area (mobile-first: full width) ========== */
.main-content {
    flex: 1;
    margin-inline-start: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

.main-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    background: var(--bg-card);
    box-shadow: var(--shadow);
    z-index: 100;
    flex-wrap: wrap;
}

.sidebar-toggle {
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    color: var(--primary);
    cursor: pointer;
    transition: background var(--transition);
}

.sidebar-toggle:hover {
    background: rgba(13, 148, 136, 0.15);
}

.sidebar-toggle i {
    font-size: 1.5rem;
}

.main-header-title {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    font-size: 1.25rem;
    color: var(--text-primary);
}

.main-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-inline-start: auto;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* Narrow phones: title row + full-width toolbar (language, auth, install) */
@media (max-width: 575.98px) {
    .main-header {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-rows: auto auto;
        column-gap: 0.75rem;
        row-gap: 0.5rem;
        align-items: center;
    }

    .sidebar-toggle {
        grid-column: 1;
        grid-row: 1;
    }

    .main-header-title {
        grid-column: 2;
        grid-row: 1;
        font-size: 1.05rem;
    }

    .main-header-actions {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        margin-inline-start: 0;
        justify-content: flex-start;
        gap: 0.5rem;
    }

    .main-header-lang {
        flex: 1 1 auto;
        min-width: 0;
        margin-inline-end: auto !important;
    }

    .main-header-lang-select {
        min-width: 0;
        flex: 1 1 6.5rem;
        max-width: 11rem;
    }

    .main-header-install-btn {
        padding-inline: 0.5rem;
    }

    .header-account-dropdown .btn-account-trigger {
        min-height: 44px;
    }

    .main-header-actions > .btn {
        min-height: 44px;
    }
}

#languageSwitcher {
    min-width: 110px;
}

#themeSwitcher.theme-switcher-select {
    min-width: 7.25rem;
}

.header-account-name {
    font-size: 0.9rem;
    color: var(--text-secondary);
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Header account dropdown (avatar + name + menu) */
.header-account-dropdown {
    position: relative;
}

.header-account-dropdown .btn-account-trigger {
    max-width: min(260px, 72vw);
    padding: 0.4rem 0.75rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-card);
    border: 1px solid rgba(13, 148, 136, 0.45);
    border-radius: var(--radius-md);
    box-shadow: none;
}

.header-account-dropdown .btn-account-trigger:hover,
.header-account-dropdown .btn-account-trigger:focus,
.header-account-dropdown .btn-account-trigger.show {
    border-color: var(--primary);
    background: var(--bg-card);
    color: var(--text-primary);
}

.header-account-dropdown .btn-account-trigger:focus-visible {
    box-shadow: 0 0 0 0.2rem rgba(13, 148, 136, 0.25);
}

.account-menu-avatar {
    color: #7c3aed;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.account-menu-name {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.account-menu-caret {
    font-size: 0.65rem;
    opacity: 0.75;
    flex-shrink: 0;
}

.account-menu-dropdown {
    min-width: 220px;
    border-radius: var(--radius-md);
    margin-top: 0.35rem !important;
    z-index: 1050;
}

.account-menu-dropdown .dropdown-item {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
}

.account-menu-dropdown .dropdown-item:hover {
    background: rgba(13, 148, 136, 0.08);
}

.account-menu-logout {
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    cursor: pointer;
}

.account-menu-logout:hover {
    background: rgba(220, 53, 69, 0.08);
}

@media (min-width: 576px) {
    .header-account-name {
        max-width: 200px;
    }
}

.main-body {
    flex: 1;
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
}

.main-footer {
    padding: 1rem 1.5rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
    padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
    padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* Footer: grouped tools (theme vs reading) for clearer mobile layout */
.footer-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem 1.5rem;
}

.footer-copy {
    flex: 1 1 12rem;
    min-width: 0;
}

.footer-tool-groups {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 0.75rem 1rem;
    flex: 1 1 18rem;
    justify-content: flex-end;
}

.footer-tool-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: min(100%, 17rem);
}

.footer-tool-label {
    letter-spacing: 0.05em;
    font-size: 0.65rem;
}

.footer-tool-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.footer-tool-row--toggles {
    flex-direction: column;
    align-items: stretch;
    gap: 0.1rem;
}

@media (max-width: 575.98px) {
    .footer-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .footer-tool-groups {
        flex-direction: column;
        justify-content: stretch;
    }

    .footer-tool-group {
        min-width: 0;
        width: 100%;
    }

    /* Easier taps on phones (footer reading toggles) */
    .footer-tool-row--toggles .btn-link {
        min-height: 44px;
        padding-top: 0.35rem !important;
        padding-bottom: 0.35rem !important;
        display: inline-flex;
        align-items: center;
    }
}

[data-bs-theme="dark"] .footer-tool-group {
    background: rgba(15, 23, 42, 0.55);
}

/* Auth pages — consistent shell with account flows */
.auth-page .row.justify-content-center > [class*="col-"] {
    max-width: 420px;
}

.auth-page-header h1 {
    font-size: 1.65rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.auth-page-header h1 .bi {
    color: var(--primary);
    opacity: 0.95;
}

.password-toggle-btn {
    min-width: 2.75rem;
    flex-shrink: 0;
}

.input-group .password-toggle-btn:focus {
    z-index: 3;
}

/* Home — emergency quick tiles */
.emergency-tile-link {
    display: block;
    outline: none;
}

.emergency-tile-link:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.emergency-tile-card {
    transition: box-shadow var(--transition), transform var(--transition);
    border-width: 2px !important;
}

.emergency-tile-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.emergency-tile-link:hover .emergency-tile-card {
    box-shadow: var(--shadow-hover);
    transform: translateY(-2px);
}

html.low-data .emergency-tile-link:hover .emergency-tile-card {
    transform: none;
    box-shadow: var(--shadow);
}

/* ========== Main Content ========== */
main {
    padding-top: 0;
    padding-bottom: 0;
}

.page-header {
    margin-bottom: 2rem;
}

.page-header h1 {
    font-weight: 700;
    color: var(--text-primary);
    font-size: clamp(1.35rem, 0.5rem + 3.5vw, 2rem);
    line-height: 1.25;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.page-header .lead {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.disclaimer {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ========== Cards ========== */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
    overflow: hidden;
}

@media (prefers-reduced-motion: no-preference) {
    .card:hover {
        transform: translateY(-4px);
        box-shadow: var(--shadow-hover);
    }
}

/* Low-data mode: minimal motion, lighter chrome (W1-1) */
html.low-data .fade-in {
    animation: none !important;
}

html.low-data .card {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    transition: none !important;
}

html.low-data .card:hover {
    transform: none !important;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06) !important;
}

html.low-data .result-panel {
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

html.low-data #installBtn {
    display: none !important;
}

html.low-data .symptom-speech-extras,
html.low-data #voiceBtn {
    display: none !important;
}

html.low-data .low-data-voice-hint {
    display: block !important;
}

html.low-data *,
html.low-data *::before,
html.low-data *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
}

.card-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.card-icon i {
    font-size: 1.75rem;
    line-height: 1;
}

.card-icon.symptom { background: rgba(13, 148, 136, 0.15); color: var(--primary); }
.card-icon.education { background: rgba(8, 145, 178, 0.15); color: var(--accent); }
.card-icon.firstaid { background: rgba(239, 68, 68, 0.15); color: #ef4444; }
.card-icon.hospital { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.card-icon.pregnancy { background: rgba(236, 72, 153, 0.15); color: #ec4899; }

.card-title {
    font-weight: 600;
    color: var(--text-primary);
}

.card-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    border-radius: var(--radius-sm);
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    transition: background var(--transition), border-color var(--transition);
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* ========== Forms ========== */
.form-control,
.form-select {
    border-radius: var(--radius-sm);
    border-color: var(--border);
    padding: 0.75rem 1rem;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 0.2rem rgba(13, 148, 136, 0.2);
}

.form-label {
    font-weight: 600;
    color: var(--text-primary);
}

/* ========== Result Panels ========== */
.result-panel {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.result-panel h4 {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

/* ========== First Aid List ========== */
.firstaid-list .list-group-item {
    border: none;
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    transition: background var(--transition);
}

.firstaid-list .list-group-item {
    background: var(--bg-card);
    box-shadow: var(--shadow);
}

.firstaid-list .list-group-item:hover {
    background: var(--bg-light);
}

.firstaid-list .list-group-item a {
    text-decoration: none;
    color: var(--text-primary);
    font-weight: 500;
    display: block;
}

.firstaid-list .list-group-item a:hover {
    color: var(--primary);
}

/* ========== First Aid Detail ========== */
.detail-step {
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--primary);
}

/* ========== Footer ========== */
.footer {
    background: var(--bg-card) !important;
    box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.06);
    padding: 1.25rem 0;
}

/* ========== Loading & Animations ========== */
.fade-in {
    animation: fadeIn 0.3s ease;
}

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

/* ========== Responsive - Tablet and up ========== */
@media (min-width: 768px) {
    .main-body {
        padding: 1.5rem;
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
        padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
    }
}

/* ========== Responsive - Desktop: show sidebar ========== */
@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0);
    }

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

    .main-content {
        margin-inline-start: var(--sidebar-width);
    }

    .sidebar-toggle {
        display: none;
    }

    .main-header {
        padding-top: max(1rem, env(safe-area-inset-top, 0px));
        padding-bottom: 1rem;
        padding-left: max(1.5rem, env(safe-area-inset-left, 0px));
        padding-right: max(1.5rem, env(safe-area-inset-right, 0px));
    }
}

/* RTL: Arabic UI — sidebar on the right */
@media (max-width: 991.98px) {
    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(100%);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    }

    [dir="rtl"] .sidebar.open {
        transform: translateX(0);
    }
}

@media (min-width: 992px) {
    [dir="rtl"] .sidebar {
        left: auto;
        right: 0;
        transform: translateX(0);
        box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    }
}

[dir="rtl"] body {
    font-family: "Noto Sans Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* Drug lookup — preserve line breaks from AI / registry text */
.drug-rich-text {
    white-space: pre-line;
    line-height: 1.55;
}

/* AI Diagnostic Interpreter — full-screen processing state */
.adi-processing-overlay {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(2px);
}

.adi-processing-overlay[hidden] {
    display: none !important;
}

.adi-processing-panel {
    background: var(--bs-body-bg, #fff);
    border-radius: 0.75rem;
    padding: 1.75rem 2.25rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.22);
    text-align: center;
    min-width: 220px;
    border: 1px solid rgba(0, 0, 0, 0.06);
}
