/*
 * style-additions.css
 * ──────────────────────────────────────────────────────────
 * Drop-in additions for MedAI / Nurabilt.
 * Provides:
 *   • nb-* modal system (overlay, card, buttons, inputs)
 *   • Doctor code modal
 *   • API key modal (4-provider grid)
 *   • Login-required modal with Google button
 *   • Guest mode banner
 *   • Full mobile-first responsive overhaul
 *
 * Add after style.css in index.html:
 *   <link rel="stylesheet" href="static/style-additions.css">
 * ──────────────────────────────────────────────────────────
 */

/* ═══════════════════════════════════════════════════════════
   MODAL FOUNDATION
═══════════════════════════════════════════════════════════ */

.nb-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(15, 23, 42, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: nbOverlayIn .2s ease;
}
@keyframes nbOverlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.nb-card {
    background: #ffffff;
    border-radius: 24px;
    padding: 40px 36px;
    width: 100%;
    max-width: 460px;
    box-shadow: 0 32px 80px rgba(15, 23, 42, 0.28);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    position: relative;
    animation: nbCardIn .28s cubic-bezier(.34, 1.4, .64, 1);
    overflow: visible;
}
.nb-card::before {
    content: '';
    position: absolute;
    inset-inline: 0;
    top: 0;
    height: 4px;
    background: linear-gradient(90deg, #0f7fdb, #00c89e);
    border-radius: 24px 24px 0 0;
}
.nb-card-sm { max-width: 400px; }

@keyframes nbCardIn {
    from { opacity: 0; transform: scale(.94) translateY(16px); }
    to   { opacity: 1; transform: none; }
}

.nb-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #f1f5f9;
    border: none;
    color: #64748b;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    line-height: 1;
}
.nb-close-btn:hover { background: #e2e8f0; color: #0f172a; }

.nb-card-icon {
    width: 64px;
    height: 64px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 26px;
    margin-bottom: 20px;
    flex-shrink: 0;
    box-shadow: 0 8px 24px rgba(0,0,0,.16);
}

.nb-card-title {
    font-family: 'Sora', sans-serif;
    font-size: 22px;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 8px;
    line-height: 1.25;
}

.nb-card-sub {
    font-size: 14px;
    color: #64748b;
    line-height: 1.6;
    margin: 0 0 24px;
    max-width: 340px;
}

/* ── Fields ── */

.nb-field {
    width: 100%;
    text-align: left;
    margin-bottom: 16px;
}

.nb-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 7px;
}

.nb-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
    overflow: visible
}

.nb-input {
    width: 100%;
    padding: 12px 44px 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    color: #0f172a;
    background: white;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
    box-sizing: border-box;
}
.nb-input:focus {
    border-color: #0f7fdb;
    box-shadow: 0 0 0 4px rgba(15,127,219,.1);
}

.nb-eye {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 15px;
    padding: 4px;
    line-height: 1;
    z-index: 2
}
.nb-eye:hover { color: #475569; }

.nb-error {
    margin-top: 8px;
    padding: 9px 12px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    font-size: 13px;
    color: #dc2626;
    text-align: left;
}

/* ── Buttons ── */

.nb-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.nb-btn-primary {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #0f7fdb, #0a65b5);
    color: white;
    border: none;
    border-radius: 12px;
    font-family: 'Sora', sans-serif;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all .18s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.nb-btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(15,127,219,.35);
}
.nb-btn-primary:disabled { opacity: .65; cursor: not-allowed; }

.nb-btn-amber {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    border-radius: 12px;
    font-family: 'Sora', sans-serif;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all .18s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.nb-btn-amber:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(245,158,11,.35);
}
.nb-btn-amber:disabled { opacity: .65; cursor: not-allowed; }

.nb-btn-ghost {
    width: 100%;
    padding: 11px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 500;
    color: #64748b;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.nb-btn-ghost:hover { background: #f1f5f9; border-color: #cbd5e1; }

.nb-google-btn {
    width: 100%;
    padding: 12px 16px;
    background: white;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all .18s;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.nb-google-btn:hover {
    background: #f8fafc;
    border-color: #bfdbfe;
    box-shadow: 0 4px 14px rgba(15,127,219,.12);
    transform: translateY(-1px);
}

.nb-divider {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #94a3b8;
    font-size: 12px;
    margin: 6px 0;
}
.nb-divider::before,
.nb-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e2e8f0;
}

/* ═══════════════════════════════════════════════════════════
   API KEY MODAL — 4-provider grid
═══════════════════════════════════════════════════════════ */

.nb-apikey-card {
    max-width: 540px;
    background: #ffffff;
    border: 1px solid #e8edf5;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12), 0 4px 16px rgba(15, 23, 42, 0.06);
    text-align: left;
    padding: 0;
    overflow: hidden;
    border-radius: 20px;
}
.nb-apikey-card::before {
    background: linear-gradient(90deg, #6366f1, #0f7fdb, #06b6d4);
    height: 3px;
}

/* ── Header strip ── */
.nb-apikey-header {
    padding: 26px 30px 0;
    display: flex;
    align-items: center;
    gap: 14px;
}
.nb-apikey-logo-mark {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    background: linear-gradient(135deg, #6366f1, #0f7fdb);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    box-shadow: 0 4px 14px rgba(99,102,241,0.3);
    color: white;
}
.nb-apikey-header-text { flex: 1; }
.nb-apikey-header-text h2 {
    font-size: 17px;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 3px;
    letter-spacing: -0.3px;
}
.nb-apikey-header-text p {
    font-size: 12.5px;
    color: #64748b;
    margin: 0;
    line-height: 1.5;
}
.nb-apikey-header-text strong { color: #6366f1; font-weight: 700; }

/* ── Body ── */
.nb-apikey-body {
    padding: 20px 30px 26px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ── Provider grid ── */
.nb-prov-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    width: 100%;
}

.nb-prov-card {
    position: relative;
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 12px 6px 10px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    transition: all .18s ease;
    text-align: center;
}
.nb-prov-card:hover {
    border-color: #6366f1;
    background: #f5f3ff;
    transform: translateY(-2px);
    box-shadow: 0 4px 14px rgba(99,102,241,0.12);
}
.nb-prov-card.nb-prov-sel {
    background: #f5f3ff;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
}

.nb-prov-badge {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, #10b981, #059669);
    color: white;
    font-size: 8.5px;
    font-weight: 800;
    letter-spacing: 0.4px;
    padding: 2px 7px;
    border-radius: 20px;
    text-transform: uppercase;
    white-space: nowrap;
    box-shadow: 0 2px 6px rgba(16,185,129,0.35);
}

.nb-prov-emoji  { font-size: 22px; line-height: 1; margin-top: 2px; }
.nb-prov-name   { font-size: 12px; font-weight: 700; color: #0f172a; }
.nb-prov-model  { font-size: 9.5px; color: #94a3b8; }
.nb-prov-tag    { font-size: 9.5px; color: #64748b; line-height: 1.3; }

/* Per-provider selected accent */
.nb-prov-groq.nb-prov-sel      { border-color: #7c3aed; background: #f5f3ff; box-shadow: 0 0 0 3px rgba(124,58,237,.1); }
.nb-prov-gemini.nb-prov-sel    { border-color: #4285f4; background: #eff6ff; box-shadow: 0 0 0 3px rgba(66,133,244,.1); }
.nb-prov-openai.nb-prov-sel    { border-color: #10a37f; background: #f0fdf4; box-shadow: 0 0 0 3px rgba(16,163,127,.1); }
.nb-prov-anthropic.nb-prov-sel { border-color: #c96442; background: #fff7ed; box-shadow: 0 0 0 3px rgba(201,100,66,.1); }

/* ── How-to hint ── */
.nb-prov-how {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-left: 3px solid #0ea5e9;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 12px;
    color: #0369a1;
    line-height: 1.6;
    width: 100%;
}
.nb-prov-how > i { color: #0ea5e9; margin-top: 2px; flex-shrink: 0; }
.nb-prov-how a  { color: #0284c7; font-weight: 700; text-decoration: none; }
.nb-prov-how a:hover { text-decoration: underline; }
.nb-prov-how code {
    background: #e0f2fe;
    color: #0369a1;
    padding: 1px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    font-weight: 600;
}

/* ═══════════════════════════════════════════════════════════
   GUEST MODE BANNER
═══════════════════════════════════════════════════════════ */

.nb-guest-banner {
    background: linear-gradient(135deg, #0f172a 0%, #0f3d72 100%);
    padding: 10px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    position: sticky;
    top: 0;
    z-index: 89;
    animation: nbGuestBannerIn .4s ease;
}
@keyframes nbGuestBannerIn {
    from { opacity: 0; transform: translateY(-8px); }
    to   { opacity: 1; transform: none; }
}

.nb-guest-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 900px;
    margin: 0 auto;
}

.nb-guest-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.nb-guest-icon {
    width: 36px;
    height: 36px;
    background: rgba(255,255,255,.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    font-size: 15px;
    flex-shrink: 0;
}

.nb-guest-text {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}
.nb-guest-text strong {
    font-size: 13px;
    font-weight: 700;
    color: white;
    white-space: nowrap;
}
.nb-guest-text span {
    font-size: 11.5px;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nb-guest-cta {
    flex-shrink: 0;
    padding: 8px 16px;
    background: white;
    border: none;
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 13px;
    font-weight: 700;
    color: #1a1a2e;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all .18s;
    white-space: nowrap;
}
.nb-guest-cta:hover {
    background: #f0f8ff;
    box-shadow: 0 4px 14px rgba(255,255,255,.2);
    transform: translateY(-1px);
}
.nb-guest-cta .fab { color: #4285f4; }

@media (max-width: 500px) {
    .nb-guest-text span  { display: none; }
    .nb-guest-text strong { font-size: 12px; }
    .nb-guest-cta        { padding: 7px 12px; font-size: 12px; }
}

/* ═══════════════════════════════════════════════════════════
   MOBILE — Full responsive overhaul
═══════════════════════════════════════════════════════════ */

@media (max-width: 900px) {

    /* Sidebar: slide-in drawer on mobile */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
        height: 100vh;
        height: 100dvh;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 40px rgba(0,0,0,.35);
    }
    .sidebar-close { display: block !important; }

    /* Main content fills full width */
    .main-content { margin-left: 0 !important; }

    /* Mobile topbar */
    .mobile-topbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        height: 56px;
        background: white;
        border-bottom: 1px solid #e2e8f0;
        /* position:relative in flex body — does NOT cause overflow */
        position: relative;
        z-index: 150;
        box-shadow: 0 1px 0 #e2e8f0;
        flex-shrink: 0;
        width: 100%;
    }

    /* Hamburger always visible */
    .hamburger { display: flex !important; }

    /* Top header hidden — replaced by mobile topbar */
    .top-header { display: none; }

    /* Section padding tighter */
    .section { padding: 16px 14px 20px; }

    /* Page card fills width */
    .page-card { padding: 20px 16px; border-radius: 12px; }
    .page-card.wide { padding: 16px 14px; }

    /* Form rows → single column */
    .form-row { grid-template-columns: 1fr !important; }
    .input-row { flex-direction: column; }

    /* Auth overlay cards */
    .auth-modal { padding: 28px 20px; border-radius: 18px; }

    /* Portal select cards */
    .portal-cards { flex-direction: column !important; gap: 12px !important; }

    /* nb-card modal padding */
    .nb-card { padding: 32px 22px; border-radius: 20px; }

    /* Chat input */
    .chat-input-row { gap: 6px !important; }
    #chat-input { font-size: 14px !important; }

    /* Appointments card */
    .appt-card { flex-direction: column !important; gap: 8px !important; }

    /* Disclaimer bar shorter text */
    .disclaimer-bar { font-size: 11.5px; padding: 7px 14px; }

    /* Switch bar */
    #nurabilt-switch-bar { padding: 6px 14px; }

    /* Header badge — shorter */
    .header-badge .badge-text { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

@media (max-width: 600px) {

    /* Tighter section padding */
    .section { padding: 12px 12px 20px; }

    /* Quick tags wrap nicely */
    .quick-tags { gap: 6px; }
    .quick-tags button { font-size: 11px; padding: 4px 10px; }

    /* Result box font */
    .result-box { font-size: 13px; padding: 14px 14px; }

    /* BMI/Stats cards */
    .rc-bmi-top { flex-direction: column !important; gap: 12px !important; }
    .rc-macros   { gap: 10px; }

    /* Drug fields */
    .rc-drug-fields { gap: 10px; }

    /* Nutrition card */
    .rc-nutr-body { flex-direction: column !important; gap: 10px; }

    /* Modals */
    .nb-card { border-radius: 16px; }
    .nb-card-title { font-size: 19px; }

    /* Provider grid — 2 col */
    .nb-prov-grid { grid-template-columns: 1fr 1fr; }

    /* Share link box */
    .share-link-box { flex-direction: column !important; gap: 8px; }
    .share-link-url  { word-break: break-all; font-size: 12px; }

    /* History cards */
    .history-content { font-size: 13px; }

    /* Profile pic section */
    .profile-pic-section { flex-direction: column !important; text-align: center; align-items: center !important; }

    /* Patient database table — horizontal scroll */
    .patient-db-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .patient-db-table { min-width: 700px; }

    /* Medical calculators tabs — wrap */
    .calc-tab { font-size: 11px !important; padding: 6px 8px !important; }

    /* Doctor dashboard stat cards */
    .ds-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; }

    /* Appointment card */
    .appt-time-col { text-align: left !important; }

    /* LLM badge text hidden on very small screens */
    .badge-text { display: none; }

    /* Auth modal */
    .auth-modal { padding: 22px 16px; }
}

@media (max-width: 400px) {
    /* Portal card text shorter */
    .portal-card h3  { font-size: 16px !important; }
    .portal-card p   { font-size: 12px !important; }

    /* Tiny nb-card */
    .nb-card { padding: 24px 14px; }
    .nb-card-icon { width: 52px; height: 52px; font-size: 22px; }
    .nb-card-title { font-size: 17px; }
    .nb-card-sub   { font-size: 13px; }

    /* Buttons slightly smaller */
    .nb-btn-primary,
    .nb-btn-amber,
    .nb-btn-ghost { padding: 11px; font-size: 14px; }
}


/* ═══════════════════════════════════════════════════════════
   MODERN UI POLISH
═══════════════════════════════════════════════════════════ */

/* Smooth section transitions */
.section { transition: none; }
.section.active { animation: nbFadeIn .2s ease; }
@keyframes nbFadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* Auth overlay portal cards — more visual weight */
.portal-card {
    transition: all .2s cubic-bezier(.34, 1.2, .64, 1) !important;
}
.portal-card:hover {
    transform: translateY(-4px) scale(1.01) !important;
}

/* Input focus ring */
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    border-color: #0f7fdb !important;
    box-shadow: 0 0 0 4px rgba(15,127,219,.1) !important;
}

/* Primary button ripple feel */
.primary-btn:active { transform: scale(.98) !important; }
.nb-btn-primary:active, .nb-btn-amber:active { transform: scale(.98) !important; }

/* Message bubbles — slightly larger on mobile */
@media (max-width: 600px) {
    .message-content { font-size: 14px !important; line-height: 1.65 !important; }
    .message-avatar  { width: 30px !important; height: 30px !important; font-size: 12px !important; }
}

/* Sidebar scrollbar thinner */
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.12); }


/* ═══════════════════════════════════════════════════════════
   API KEY MODAL — WARNING + CLEAN LIGHT OVERRIDES
═══════════════════════════════════════════════════════════ */
.nb-apikey-warning {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 3px solid #ef4444;
    border-radius: 10px;
    padding: 11px 14px;
    width: 100%;
    text-align: left;
}
.nb-apikey-warning i {
    color: #ef4444;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}
.nb-apikey-warning div { display: flex; flex-direction: column; gap: 2px; }
.nb-apikey-warning strong { font-size: 12.5px; font-weight: 700; color: #b91c1c; }
.nb-apikey-warning span  { font-size: 12px; color: #dc2626; line-height: 1.5; }

/* ── Input styling (overrides for clean look) ── */
#nb-apikey-modal .nb-label {
    color: #374151;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
}
#nb-apikey-modal .nb-input {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #0f172a;
    font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 13px;
    letter-spacing: 0.3px;
}
#nb-apikey-modal .nb-input::placeholder { color: #94a3b8; }
#nb-apikey-modal .nb-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99,102,241,0.12);
    background: #fff;
}

/* ── Actions row ── */
#nb-apikey-modal .nb-actions {
    flex-direction: row;
    gap: 10px;
    align-items: center;
}
#nb-apikey-modal .nb-btn-amber {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    border: none;
    flex: 1;
    font-size: 14px;
    font-weight: 700;
    padding: 13px 20px;
    box-shadow: 0 4px 14px rgba(99,102,241,0.35);
    letter-spacing: 0.1px;
}
#nb-apikey-modal .nb-btn-amber:hover:not(:disabled) {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    box-shadow: 0 6px 20px rgba(99,102,241,0.45);
    transform: translateY(-1px);
}
#nb-apikey-modal .nb-btn-ghost {
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    color: #64748b;
    font-size: 12.5px;
    padding: 13px 16px;
    white-space: nowrap;
}
#nb-apikey-modal .nb-btn-ghost:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #374151;
}

/* ── Close btn ── */
#nb-apikey-modal .nb-close-btn {
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #e2e8f0;
}
#nb-apikey-modal .nb-close-btn:hover { background: #e2e8f0; color: #0f172a; }

/* "Browse without AI" */
.nb-skip-guest { opacity: 0.75; font-size: 11.5px !important; }
.nb-skip-guest:hover { opacity: 1; }

/* ═══════════════════════════════════════════════════════════
   FIX 3: CHAT — ensure quick-questions + controls shrink correctly
═══════════════════════════════════════════════════════════ */
.quick-questions {
    flex-shrink: 0;
    padding: 6px 14px 4px;
}
.chat-controls {
    flex-shrink: 0;
    padding: 4px 14px 2px;
}

/* ═══════════════════════════════════════════════════════════
   FIX 4: RESPONSIVE ADDITIONS for nb- modals
═══════════════════════════════════════════════════════════ */

/* Tablet / small screens: modal as bottom sheet */
@media (max-width: 540px) {
    .nb-overlay {
        padding: 0;
        align-items: flex-end;
    }
    .nb-card {
        border-radius: 24px 24px 0 0;
        max-height: 94vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 28px 18px 20px;
        width: 100%;
        max-width: 100%;
    }
    .nb-card::before {
        border-radius: 24px 24px 0 0;
    }
    .nb-card-sm { max-width: 100%; }
    .nb-apikey-card { padding: 24px 16px 20px; }
    .nb-prov-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .nb-apikey-header { padding: 18px 18px 0; gap: 12px; }
    .nb-apikey-body   { padding: 14px 18px 20px; gap: 12px; }
    .nb-prov-card     { padding: 10px 5px; }
    .nb-prov-name     { font-size: 11px; }
    .nb-prov-model { font-size: 10px; }
    .nb-actions {
        flex-direction: column;
        width: 100%;
        gap: 8px;
    }
    .nb-btn-amber, .nb-btn-primary, .nb-btn-ghost, .nb-google-btn {
        width: 100%;
        justify-content: center;
    }
}

/* Landscape phone: keep modal visible */
@media (max-width: 900px) and (orientation: landscape) {
    .nb-overlay { align-items: center; padding: 8px; }
    .nb-card {
        max-height: 95vh;
        overflow-y: auto;
        border-radius: 20px;
    }
}

/* ── FIX 4: Large screen / TV extras ─── */
@media (min-width: 1800px) {
    .nb-card { max-width: 560px; padding: 48px 44px; }
    .nb-prov-grid { grid-template-columns: repeat(4, 1fr); }
}
/* ═══════════════════════════════════════════════════════════
   LLM CONNECTIONS PAGE
   Session-scoped, card-based, clean professional UI
═══════════════════════════════════════════════════════════ */
.llm-page { max-width: 860px; margin: 0 auto; padding: 4px 0 40px; display: flex; flex-direction: column; gap: 20px; }

/* Header */
.llm-page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.llm-page-title-row { display: flex; align-items: flex-start; gap: 14px; }
.llm-page-icon { width: 46px; height: 46px; background: linear-gradient(135deg, #0f7fdb, #00c89e); border-radius: 14px; display: flex; align-items: center; justify-content: center; color: white; font-size: 20px; flex-shrink: 0; }
.llm-page-title { font-family: 'Sora', sans-serif; font-size: 22px; font-weight: 700; color: #0f172a; margin-bottom: 4px; }
.llm-page-sub { font-size: 13.5px; color: #64748b; line-height: 1.5; max-width: 540px; }

/* Session pill */
.llm-session-pill { display: inline-flex; align-items: center; gap: 7px; background: #f1f5f9; border: 1.5px solid #e2e8f0; border-radius: 99px; padding: 6px 14px; font-size: 12.5px; font-weight: 600; color: #64748b; white-space: nowrap; flex-shrink: 0; transition: all .3s; }
.llm-session-pill-on { background: #f0fdf4; border-color: #86efac; color: #15803d; }
.llm-session-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; flex-shrink: 0; }
.llm-session-dot-on { background: #22c55e; box-shadow: 0 0 0 3px #bbf7d0; animation: llmPulse 2s infinite; }
@keyframes llmPulse { 0%,100%{box-shadow:0 0 0 3px #bbf7d0;} 50%{box-shadow:0 0 0 6px #dcfce7;} }

/* Security notice */
.llm-security-notice { display: flex; align-items: flex-start; gap: 12px; background: #fffbeb; border: 1.5px solid #fde68a; border-radius: 12px; padding: 14px 18px; font-size: 13px; color: #92400e; }
.llm-security-notice i { color: #d97706; font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.llm-security-notice strong { display: block; font-weight: 700; margin-bottom: 2px; color: #78350f; }
.llm-security-notice span { line-height: 1.5; }

/* Provider cards grid */
.llm-providers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Individual card */
.llm-provider-card { background: #fff; border: 1.5px solid #e2e8f0; border-radius: 16px; overflow: hidden; transition: border-color .25s, box-shadow .25s; }
.llm-provider-card:hover { border-color: #cbd5e1; box-shadow: 0 4px 20px rgba(0,0,0,.07); }
.llm-card-header { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px; border-bottom: 1px solid #f1f5f9; }
.llm-card-logo { width: 42px; height: 42px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 18px; color: white; flex-shrink: 0; }
.llm-logo-groq      { background: linear-gradient(135deg, #7c3aed, #6d28d9); }
.llm-logo-gemini    { background: linear-gradient(135deg, #4285f4, #1a73e8); }
.llm-logo-openai    { background: linear-gradient(135deg, #10a37f, #0d8c6d); }
.llm-logo-anthropic { background: linear-gradient(135deg, #c96442, #a0522d); }
.llm-card-info { flex: 1; min-width: 0; }
.llm-card-name { font-weight: 700; font-size: 14.5px; color: #0f172a; display: flex; align-items: center; gap: 6px; }
.llm-card-model { font-size: 11.5px; color: #94a3b8; margin-top: 1px; }
.llm-free-badge { font-size: 9px; background: #7c3aed; color: white; padding: 2px 6px; border-radius: 99px; font-weight: 800; letter-spacing: .04em; }
.llm-card-status { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #94a3b8; font-weight: 500; white-space: nowrap; }
.llm-dot-off { width: 7px; height: 7px; background: #cbd5e1; border-radius: 50%; display: inline-block; }
.llm-dot-on  { width: 7px; height: 7px; background: #22c55e; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 2px #bbf7d0; }

/* Card body */
.llm-card-body { padding: 14px 16px; }
.llm-input-row { display: flex; gap: 8px; align-items: stretch; }
.llm-input-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.llm-key-input { width: 100%; padding: 9px 36px 9px 12px; border: 1.5px solid #e2e8f0; border-radius: 10px; font-size: 13px; font-family: 'DM Sans', monospace; color: #0f172a; background: #f8fafc; outline: none; transition: border .2s, box-shadow .2s; }
.llm-key-input:focus { border-color: #0f7fdb; box-shadow: 0 0 0 3px rgba(15,127,219,.1); background: white; }
.llm-key-input:disabled { background: #f1f5f9; color: #94a3b8; cursor: not-allowed; }
.llm-eye-btn { position: absolute; right: 8px; background: none; border: none; color: #94a3b8; cursor: pointer; padding: 4px; font-size: 13px; transition: color .15s; }
.llm-eye-btn:hover { color: #475569; }
.llm-connect-btn { padding: 0 16px; background: linear-gradient(135deg, #0f7fdb, #0a65b5); color: white; border: none; border-radius: 10px; font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 700; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap; transition: all .2s; flex-shrink: 0; height: 40px; }
.llm-connect-btn:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(15,127,219,.35); }
.llm-connect-btn:disabled { cursor: default; background: #22c55e; box-shadow: none; transform: none; }
.llm-connect-btn-secondary { background: #f1f5f9; color: #374151; border: 1.5px solid #e2e8f0; }
.llm-connect-btn-secondary:hover:not(:disabled) { background: #e2e8f0; box-shadow: none; transform: none; }
.llm-card-hint { font-size: 11.5px; color: #94a3b8; margin-top: 8px; line-height: 1.4; }
.llm-card-hint a { color: #0f7fdb; }
.llm-card-hint code { background: #f1f5f9; padding: 1px 5px; border-radius: 4px; font-size: 11px; color: #475569; }
.llm-card-result { margin-top: 8px; font-size: 12.5px; min-height: 18px; }
.llm-result-success { color: #15803d; display:flex; align-items:center; gap:6px; }
.llm-result-error   { color: #dc2626; display:flex; align-items:center; gap:6px; }
.llm-result-warn    { color: #d97706; display:flex; align-items:center; gap:6px; }
.llm-result-loading { color: #64748b; display:flex; align-items:center; gap:6px; }

/* Connected bar */
.llm-connected-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: linear-gradient(90deg, #f0fdf4, #dcfce7); border-top: 1px solid #bbf7d0; gap: 10px; }
.llm-bar-left { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: #15803d; }
.llm-bar-left i { color: #22c55e; }
.llm-disconnect-btn { background: none; border: 1px solid #86efac; border-radius: 8px; color: #dc2626; font-size: 11.5px; font-weight: 600; padding: 4px 10px; cursor: pointer; display: flex; align-items: center; gap: 5px; transition: all .2s; font-family: 'DM Sans', sans-serif; }
.llm-disconnect-btn:hover { background: #fef2f2; border-color: #fca5a5; }

/* Optional USDA section */
.llm-optional-section { background: white; border: 1.5px solid #e2e8f0; border-radius: 14px; padding: 18px 20px; }
.llm-optional-header { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.llm-optional-header i { color: #10b981; font-size: 16px; }
.llm-optional-header strong { font-weight: 700; font-size: 14px; color: #0f172a; }
.llm-optional-tag { font-size: 10px; background: #f0fdf4; color: #15803d; border: 1px solid #86efac; padding: 2px 7px; border-radius: 99px; font-weight: 700; }

/* Responsive */
@media (max-width: 700px) {
  .llm-providers-grid { grid-template-columns: 1fr; }
  .llm-page-header { flex-direction: column; align-items: flex-start; }
  .llm-session-pill { align-self: flex-start; }
}
@media (max-width: 480px) {
  .llm-page { padding: 0 0 20px; }
  .llm-page-icon { width: 38px; height: 38px; font-size: 16px; }
  .llm-page-title { font-size: 18px; }
  .llm-input-row { flex-direction: column; }
  .llm-connect-btn { width: 100%; justify-content: center; padding: 10px; height: auto; }
  .llm-connected-bar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .llm-disconnect-btn { width: 100%; justify-content: center; }
  .llm-key-input { font-size: 16px !important; }
}



/* ═══════════════════════════════════════════════════════════════════
   NURABILT — UNIVERSAL RESPONSIVE CSS
   Covers: iPhone SE → iPhone Pro Max → iPad Mini → iPad Pro →
           Android phones → Android tablets → Laptops → 4K screens
   Paste this at the VERY BOTTOM of style-additions.css
   ═══════════════════════════════════════════════════════════════════ */

/* ──────────────────────────────────────────────────────────────────
   CORE CHAT LAYOUT FIX — applies to ALL screen sizes
   The input bar must NEVER float. This is the foundation.
   ────────────────────────────────────────────────────────────────── */

/* ══════════════════════════════════════════════════════════════
   CORE CHAT LAYOUT — iOS + Android safe, all screen sizes
   This is the single source of truth for chat layout.
   The flex chain handles everything mathematically.
   ══════════════════════════════════════════════════════════════ */

/* html/body lock: prevents iOS rubber-band scroll on document */
html {
    height: 100%;
    overflow: hidden;
}

body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    padding-bottom: 0 !important;
    /* flex column so mobile-topbar + main-content stack correctly */
    display: flex;
    flex-direction: column;
}

/* Main content = fills remaining viewport after mobile-topbar */
.main-content {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    /* Keep explicit height as fallback for browsers without flex support */
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

/* section-chat hidden unless active */
.section#section-chat:not(.active) {
    display: none !important;
}

/* section-chat active: flex column, fills remaining height */
.section#section-chat.active {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    padding: 0 !important;
    background: #f0f4f8 !important;
}

/* chat-container: flex column, fills section */
.chat-container {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    background: #f0f4f8 !important;
}

/* chat-messages: the ONLY scrolling element */
.chat-messages {
    flex: 1 1 0 !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior-y: contain !important;
}

/* chat-input-area: anchored to bottom, NEVER moves */
.chat-input-area {
    flex: 0 0 auto !important;
    position: relative !important;
    z-index: 50 !important;
    width: 100% !important;
    background: white !important;
    /* iOS safe area built-in */
    padding-bottom: max(12px, env(safe-area-inset-bottom, 12px)) !important;
}

/* quick-questions and controls never shrink the message area */
.quick-questions { flex-shrink: 0 !important; }
.chat-controls   { flex-shrink: 0 !important; }
.chat-preview-bar { flex-shrink: 0 !important; }

/* ──────────────────────────────────────────────────────────────────
   4K / ULTRA-WIDE (≥ 2560px)
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 2560px) {
    :root { --sidebar-w: 320px; }
    html { font-size: 18px; }
    .page-card { max-width: 1100px; padding: 56px; }
    .message-content { max-width: 60%; font-size: 16px; }
    .chat-messages { padding: 32px 40px 10px; gap: 18px; }
    #chat-input { font-size: 16px; min-height: 50px; }
}

/* ──────────────────────────────────────────────────────────────────
   2K / LARGE DESKTOP (1920px – 2559px)
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1920px) and (max-width: 2559px) {
    :root { --sidebar-w: 300px; }
    html { font-size: 16px; }
    .page-card { max-width: 980px; }
    .message-content { max-width: 65%; }
}

/* ──────────────────────────────────────────────────────────────────
   STANDARD DESKTOP (1440px – 1919px)
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1440px) and (max-width: 1919px) {
    :root { --sidebar-w: 280px; }
    .page-card { max-width: 860px; }
    .message-content { max-width: 68%; }
}

/* ──────────────────────────────────────────────────────────────────
   SMALL DESKTOP / LAPTOP (1280px – 1439px)
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1280px) and (max-width: 1439px) {
    :root { --sidebar-w: 250px; }
    .page-card { max-width: 760px; }
    .message-content { max-width: 72%; }
}

/* ──────────────────────────────────────────────────────────────────
   LAPTOP SMALL (1024px – 1279px)
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) and (max-width: 1279px) {
    :root { --sidebar-w: 230px; }
    .page-card { max-width: 680px; }
    .message-content { max-width: 76%; }
    .two-col-layout { grid-template-columns: 1fr 260px; }
}

/* ──────────────────────────────────────────────────────────────────
   IPAD PRO 12.9" LANDSCAPE (1366px wide)
   Also covers Surface Pro, large Android tablets landscape
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1200px) and (max-width: 1400px) and (max-height: 1100px) {
    :root { --sidebar-w: 240px; }
    .chat-messages { padding: 16px 20px 8px; }
    .message-content { max-width: 74%; }
}

/* ──────────────────────────────────────────────────────────────────
   IPAD PRO 12.9" PORTRAIT (1024px wide)
   Also covers iPad Air landscape, large Android tablets
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 1024px) and (max-width: 1199px) {
    :root { --sidebar-w: 220px; }

    .main-content { margin-left: var(--sidebar-w) !important; }

    .section.active:not(#section-chat) {
        overflow-y: auto !important;
        padding: 20px 18px 40px !important;
    }

    .page-card { max-width: 100%; padding: 24px 20px; }
    .two-col-layout { grid-template-columns: 1fr; }
    .right-panel {
        position: static !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    .message-content { max-width: 78%; }
    .chat-messages { padding: 16px 18px 8px; }
}

/* ──────────────────────────────────────────────────────────────────
   IPAD AIR / IPAD PRO 11" PORTRAIT (820px – 1023px)
   Also covers Galaxy Tab, Surface Go landscape
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 820px) and (max-width: 1023px) {
    :root { --sidebar-w: 240px; }

    .sidebar {
        transform: translateX(-100%) !important;
        height: 100vh;
        height: 100dvh;
        transition: transform .28s cubic-bezier(.4,0,.2,1);
    }
    .sidebar.open { transform: none !important; box-shadow: 4px 0 32px rgba(0,0,0,.22); }
    .sidebar-close { display: block !important; }
    .hamburger { display: flex !important; }
    .main-content { margin-left: 0 !important; }

    /* iPad portrait: mobile topbar replaces desktop header */
    .top-header { display: none !important; }
    .mobile-topbar {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        padding: 0 20px;
        height: 56px;
        background: white;
        border-bottom: 1px solid #e2e8f0;
        position: relative;
        z-index: 150;
        box-shadow: 0 1px 0 #e2e8f0;
        flex-shrink: 0;
        width: 100%;
    }

    .section.active:not(#section-chat) {
        padding: 18px 16px 20px !important;
        overflow-y: auto !important;
    }

    .page-card { max-width: 100%; padding: 22px 18px; }
    .form-row { grid-template-columns: 1fr 1fr; } /* keep 2 col on tablets */
    .two-col-layout { grid-template-columns: 1fr; }
    .right-panel {
        position: static !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 12px !important;
    }
    .message-content { max-width: 80%; }
    .chat-messages { padding: 14px 16px 10px; }

    /* Bottom nav */
    .section.active:not(#section-chat) { padding-bottom: 20px !important; }

    /* iOS font-size: prevent zoom on input focus */
    #chat-input { font-size: 16px !important; }
}

/* ──────────────────────────────────────────────────────────────────
   IPAD MINI / SMALL TABLETS (768px – 819px)
/* ──────────────────────────────────────────────────────────────────
   SIDEBAR GAP FIX: 901px – 1023px
   style.css sidebar rule only fires at ≤900px. This block ensures
   the sidebar is a hidden drawer at 901-1023px too.
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 901px) and (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%) !important;
        transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
    }
    .sidebar.open {
        transform: none !important;
        box-shadow: 4px 0 32px rgba(0,0,0,.22) !important;
    }
    .main-content { margin-left: 0 !important; }
    .hamburger { display: flex !important; }
    .sidebar-close { display: block !important; }
}

   Also covers Galaxy Tab 7", Kindle Fire
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 768px) and (max-width: 819px) {
    .sidebar {
        transform: translateX(-100%);
        height: 100vh;
        height: 100dvh;
        transition: transform .28s cubic-bezier(.4,0,.2,1);
    }
    .sidebar.open { transform: none; }
    .sidebar-close { display: block !important; }
    .hamburger { display: flex !important; }
    .main-content { margin-left: 0 !important; }
    .top-header { display: none !important; }
    .mobile-topbar { display: flex !important; flex-shrink: 0; }

    .section.active:not(#section-chat) {
        padding: 16px 14px 20px !important;
        overflow-y: auto !important;
    }

    .page-card { padding: 18px 14px; border-radius: 12px; }
    .form-row { grid-template-columns: 1fr 1fr; }
    .message-content { max-width: 84%; }
    .chat-messages { padding: 12px 14px 10px; }
    .llm-providers-grid { grid-template-columns: 1fr 1fr; }
    .doc-tool-grid { grid-template-columns: repeat(4, 1fr); }
    .doc-stats-row { grid-template-columns: repeat(2, 1fr); }

    /* iOS font-size: prevent zoom on input */
    #chat-input { font-size: 16px !important; }
}

/* ──────────────────────────────────────────────────────────────────
   LARGE PHONES LANDSCAPE + SMALL TABLETS (600px – 767px)
   iPhone Plus/Max landscape, Galaxy S Ultra landscape, Pixel landscape
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 600px) and (max-width: 767px) {
    html { font-size: 14px; }

    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; }
    .sidebar-close { display: block !important; }
    .hamburger { display: flex !important; }
    .main-content { margin-left: 0 !important; }
    .top-header { display: none; }

    .section.active:not(#section-chat) {
        padding: 14px 12px 20px !important;
        overflow-y: auto !important;
    }

    .page-card { padding: 16px 12px; border-radius: 10px; max-width: 100%; }
    .form-row { grid-template-columns: 1fr; }
    .message-content { max-width: 88%; font-size: 13.5px; }
    .chat-messages { padding: 12px 10px 8px; gap: 8px; }
    .chat-input-area { padding: 8px 10px; }
    #chat-input { font-size: 16px !important; }

    .llm-providers-grid { grid-template-columns: 1fr; }
    .nb-prov-grid { grid-template-columns: 1fr 1fr; }
    .doc-tool-grid { grid-template-columns: repeat(3, 1fr); }
    .doc-stats-row { grid-template-columns: repeat(2, 1fr); }
    .rc-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .two-col-layout { grid-template-columns: 1fr; }
    .right-panel { display: none; }

    /* Disclaimer shorter */
    .disclaimer-bar { font-size: 11px; padding: 5px 12px; }

    /* Badge text hidden */
    .badge-text { max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ──────────────────────────────────────────────────────────────────
   STANDARD PHONES PORTRAIT (480px – 599px)
   iPhone 12/13/14/15, Pixel 6/7, Galaxy S21/S22/S23
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 480px) and (max-width: 599px) {
    html { font-size: 14px; }

    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; box-shadow: 4px 0 32px rgba(0,0,0,.3); }
    .main-content { margin-left: 0 !important; }
    .top-header { display: none; }
    .hamburger { display: flex !important; }

    .section.active:not(#section-chat) {
        padding: 12px 12px 20px !important;
        overflow-y: auto !important;
    }

    .page-card { padding: 14px 12px; border-radius: 10px; }
    .page-card-header { flex-direction: column; gap: 10px; }
    .form-row { grid-template-columns: 1fr !important; }

    .message-content { max-width: 90%; font-size: 13.5px; }
    .chat-messages { padding: 10px 10px 5px; gap: 8px; }
    .chat-input-area {
        padding: 8px 10px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }

    /* Prevent iOS zoom on inputs */
    #chat-input,
    .form-group input,
    .form-group textarea,
    .form-group select,
    .auth-field input,
    .nb-input,
    .llm-key-input { font-size: 16px !important; }
    .badge-text { display: none; }

    .nb-prov-grid { grid-template-columns: 1fr 1fr; }
    .llm-providers-grid { grid-template-columns: 1fr; }
    .doc-tool-grid { grid-template-columns: repeat(3, 1fr); }
    .doc-stats-row { grid-template-columns: 1fr 1fr; }
    .about-grid { grid-template-columns: 1fr; }
    .rc-stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ──────────────────────────────────────────────────────────────────
   SMALL PHONES (390px – 479px)
   iPhone 12 Mini, iPhone SE 3rd gen, Pixel 5, Galaxy S10e
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 390px) and (max-width: 479px) {
    html { font-size: 13.5px; }

    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: none; }
    .main-content { margin-left: 0 !important; }
    .top-header { display: none; }

    .section.active:not(#section-chat) {
        padding: 10px 10px 20px !important;
        overflow-y: auto !important;
    }

    .auth-modal { padding: 22px 16px; border-radius: 16px; }
    .page-card { padding: 12px 10px; border-radius: 10px; }
    .page-card-header { flex-direction: column; gap: 8px; }

    .message-content { max-width: 92%; font-size: 13px; }
    .message-avatar { width: 28px !important; height: 28px !important; font-size: 11px !important; }
    .chat-messages { padding: 10px 8px 4px; gap: 8px; }
    .chat-input-area {
        padding: 7px 8px;
        padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
    }
    #chat-input { min-height: 40px; }

    /* Prevent iOS zoom */
    #chat-input,
    .form-group input,
    .form-group textarea,
    .form-group select,
    .auth-field input,
    .nb-input,
    .llm-key-input { font-size: 16px !important; }
    .badge-text { display: none; }
    .header-badge { padding: 4px 8px; font-size: 10px; }

    .nb-prov-grid { grid-template-columns: 1fr 1fr; }
    .llm-providers-grid { grid-template-columns: 1fr; }
    .llm-input-row { flex-direction: column; }
    .llm-connect-btn { width: 100%; justify-content: center; }

    .doc-tool-grid { grid-template-columns: repeat(3, 1fr); }
    .doc-stats-row { grid-template-columns: 1fr 1fr; }
    .doc-welcome { flex-direction: column; }

    .nb-card { padding: 24px 14px; }
    .nb-card-title { font-size: 18px; }
    .nb-actions { flex-direction: column; }
    .nb-btn-primary, .nb-btn-amber, .nb-btn-ghost, .nb-google-btn { width: 100% !important; }

    .rc-stats-grid { grid-template-columns: 1fr 1fr; }
    .disclaimer-bar { font-size: 10.5px; padding: 5px 10px; }

    #nurabilt-switch-bar { padding: 6px 10px; }
    .nsb-label { display: none; }
}

/* ──────────────────────────────────────────────────────────────────
   VERY SMALL PHONES (320px – 389px)
   iPhone SE 1st/2nd gen, Galaxy A03, older Android phones
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 389px) {
    html { font-size: 13px; }

    .sidebar { transform: translateX(-100%); }
    .main-content { margin-left: 0 !important; }
    .top-header { display: none; }

    .section.active:not(#section-chat) {
        padding: 8px 8px 20px !important;
        overflow-y: auto !important;
    }

    .auth-modal { padding: 18px 12px; }
    .auth-logo { font-size: 20px; }
    .auth-logo-icon { width: 36px; height: 36px; font-size: 16px; }

    .page-card { padding: 10px 8px; border-radius: 8px; }
    .message-content { max-width: 96%; font-size: 13px; }
    .message-avatar { width: 26px !important; height: 26px !important; }
    .chat-messages { padding: 8px 6px 4px; gap: 7px; }
    .chat-input-area { padding: 6px 6px; padding-bottom: max(6px, env(safe-area-inset-bottom, 6px)); }
    #chat-input { min-height: 38px; font-size: 16px !important; }
    .header-badge { display: none; }
    .nb-prov-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
    .nb-prov-card { padding: 8px 4px; }
    .nb-prov-name { font-size: 10px; }
    .nb-card { padding: 20px 12px; }

    .doc-tool-grid { grid-template-columns: repeat(2, 1fr); }
    .calc-big-num { font-size: 36px !important; }
    .nsb-btn { padding: 5px 10px; font-size: 11px; }
    .nsb-label { display: none; }
}

/* ──────────────────────────────────────────────────────────────────
   DRUG INFO TABS — Responsive fix
   4 tabs overflow on narrow screens.
   ≤480px: icon-only  |  ≤380px: horizontally scrollable
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    .drug-tabs { gap: 2px !important; padding: 3px !important; }
    .drug-tab {
        padding: 8px 4px !important;
        font-size: 10px !important;
        gap: 2px !important;
        flex-direction: column !important;
    }
    .drug-tab i { font-size: 13px !important; }
    .drug-tab .drug-tab-label { display: none !important; }
}
@media (max-width: 380px) {
    .drug-tabs {
        overflow-x: auto !important;
        flex-wrap: nowrap !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .drug-tab { flex: 0 0 auto !important; min-width: 52px !important; }
}

/* ──────────────────────────────────────────────────────────────────
   LANDSCAPE ORIENTATION — phones
   Handles landscape on all phones (typically 480px–900px wide)
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    /* Very tight — phone landscape */
    .chat-messages { padding: 6px 10px 4px; gap: 6px; }
    .chat-input-area { padding: 6px 10px; }
    .disclaimer-bar { display: none; } /* hide to save space */
    .quick-questions { display: none; } /* hide suggestions */
    .chat-controls { display: none; }
    /* Other sections */
    .section.active:not(#section-chat) {
        padding: 8px 12px 20px !important;
    }

    /* Modal as full screen in landscape */
    .nb-overlay { align-items: center; padding: 8px; }
    .nb-card {
        max-height: 96vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 16px;
        padding: 20px 16px;
    }
}

/* ──────────────────────────────────────────────────────────────────
   IOS SAFE AREA (notch, home indicator, Dynamic Island)
   Applies to: iPhone X and later, all iPad Pro with Face ID
   ────────────────────────────────────────────────────────────────── */
@supports (padding: env(safe-area-inset-bottom)) {
    .chat-input-area {
        padding-top: 8px !important;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px)) !important;
        padding-left: max(10px, env(safe-area-inset-left, 10px)) !important;
        padding-right: max(10px, env(safe-area-inset-right, 10px)) !important;
    }
    /* Topbar respects Dynamic Island / notch */
    .top-header, .mobile-topbar {
        padding-top: env(safe-area-inset-top, 0) !important;
    }
    /* body uses dvh — excludes Safari browser chrome */
    body {
        height: 100dvh !important;
    }
    .sidebar { height: 100dvh !important; }
}

/* ──────────────────────────────────────────────────────────────────
   IPAD SPLIT VIEW / SLIDE OVER
   When iPad runs app in split view, it behaves like a phone width
   ────────────────────────────────────────────────────────────────── */
@media (min-width: 320px) and (max-width: 500px) and (min-height: 700px) {
    /* Tall narrow — iPad split view */
    .message-content { max-width: 90%; }
    .page-card { padding: 14px 12px; }
    .form-row { grid-template-columns: 1fr !important; }
}

/* ──────────────────────────────────────────────────────────────────
   ANDROID-SPECIFIC FIXES
   Android chrome bottom bar eats space — compensate
   ────────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    /* Use dvh (dynamic viewport height) where supported — handles
       Android Chrome's collapsing/expanding browser chrome */
    .main-content {
        height: 100dvh !important;
        max-height: 100dvh !important;
    }

    /* Fallback for browsers that don't support dvh */
    @supports not (height: 100dvh) {
        .main-content {
            height: -webkit-fill-available !important;
            max-height: -webkit-fill-available !important;
        }
    }
}

/* ──────────────────────────────────────────────────────────────────
   PRINT STYLES
   ────────────────────────────────────────────────────────────────── */
@media print {
    .sidebar, .top-header, .chat-input-area,
    .quick-questions, .chat-controls,
    .disclaimer-bar, #nurabilt-switch-bar { display: none !important; }

    .main-content { margin-left: 0 !important; }
    .section.active { display: block !important; overflow: visible !important; }
    .message-content { max-width: 100% !important; break-inside: avoid; }
    body { background: white; color: black; font-size: 12pt; }
}

/* ──────────────────────────────────────────────────────────────────
   HIGH CONTRAST / ACCESSIBILITY
   ────────────────────────────────────────────────────────────────── */
@media (prefers-contrast: high) {
    .message-content { border: 2px solid #000 !important; }
    .nav-btn { color: rgba(255,255,255,.9) !important; }
    .primary-btn { background: #0000cc !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}