/* =========================================================
   PREMIUM CLINICAL TYPOGRAPHY & MICRO-INTERACTIONS
   ========================================================= */

/* 1. Tabular Numbers (Prevents layout jiggling during live calculations) */
.stat-value, .breathing-digit, .queue-count, .calc-digit-display, #liveZScore, .vital-status {
    font-family: "JetBrains Mono", "Space Grotesk", "SF Mono", ui-monospace, monospace !important;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.05em;
}

/* 2. Milestone Radar Pulse Effect */
@keyframes radarPulse {
    0% { filter: drop-shadow(0 0 2px var(--brand-cyan)); }
    50% { filter: drop-shadow(0 0 8px var(--brand-cyan)); }
    100% { filter: drop-shadow(0 0 2px var(--brand-cyan)); }
}
.radar-arc {
    animation: radarPulse 3s infinite ease-in-out;
}

/* =========================================
   MOBILE EXCLUSIVE FIXES & HACKS
   Loads only on viewports < 1023px via HTML link
   ========================================= */

/* 🚀 FIX 0: The Viewport Cage (Prevents 3D Deck Bleed) */
html, body, .app-shell, .main-content {
    overflow-x: hidden !important;
    max-width: 100vw !important;
}

/* FIX 1: The iOS Auto-Zoom Bug */
input, select, textarea { font-size: 16px !important; }

/* FIX 2: Squished Row Inputs */
.row-inputs { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important; }

/* FIX 3: Horizontal Table Blowouts */
.theory-table {
    display: block; max-width: 100%; overflow-x: auto;
    -webkit-overflow-scrolling: touch; white-space: nowrap; 
}

/* FIX 4: Tool Grid & Button Text Wrapping */
.tools-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)) !important; gap: 12px !important; }
.tool-btn { padding: 15px 5px !important; }
.tool-icon-wrapper { width: 50px !important; height: 50px !important; }
.tool-btn span { font-size: 0.8rem !important; }

/* FIX 5: Safe Area Insets (For iPhones) */
.main-nav { padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important; }
.main-content { padding-bottom: calc(110px + env(safe-area-inset-bottom)) !important; }

/* FIX 6: Floating Action Button & Toast Overlap */
.fab {
    bottom: calc(85px + env(safe-area-inset-bottom)) !important; right: 15px !important;
    width: 55px !important; height: 55px !important;
}
#systemToastContainer {
    align-items: center !important;
}

/* FIX 7: Modal Keyboard Squeeze */
.modal-content { max-height: 85vh !important; padding: 20px 15px !important; }

/* FIX 8: Live Rx Preview alignment */
#rxCartList { min-height: auto !important; }


/* =========================================
   NATIVE MOBILE SCROLL PHYSICS & GESTURES
   ========================================= */
* { -webkit-tap-highlight-color: transparent !important; }

.main-content, .modal-content, .rx-desktop-grid, .timeline-section, .sub-tabs-nav, #rxLedgerList {
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
}
.main-content::-webkit-scrollbar, 
.modal-content::-webkit-scrollbar, 
.rx-desktop-grid::-webkit-scrollbar, 
.timeline-section::-webkit-scrollbar,
.sub-tabs-nav::-webkit-scrollbar,
#rxLedgerList::-webkit-scrollbar {
    display: none !important;
}


/* =========================================
   STRICT MOBILE LAYOUT ENFORCEMENT
   ========================================= */
.hud-grid { display: flex !important; flex-direction: column !important; gap: 15px !important; width: 100% !important; }
.hud-global-inputs { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
.hud-global-inputs > div:last-child { grid-column: 1 / -1; }
#hudSmartDoseCards { padding: 10px 5px !important; gap: 10px !important; }
.rx-desktop-grid { display: flex !important; flex-direction: column !important; gap: 20px !important; width: 100% !important; }
.modal-overlay.active { align-items: flex-end !important; }
.modal-content { border-radius: 24px 24px 0 0 !important; width: 100% !important; }


/* ==========================================
   THE CORTEX PROTOCOL: KINETIC UI STYLES
   ========================================== */
.cortex-hidden { opacity: 0 !important; pointer-events: none !important; transform: translateY(20px); visibility: hidden; }

/* 🛑 DEPRECATED CORTEX PILL & INPUT POD REMOVED */
/* All interactions route via the unified Living Orb and Chat Sheet */

.pod-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.action-btn-mini { background: var(--success); color: white; border: none; padding: 8px 20px; border-radius: var(--radius-pill); font-weight: 800; box-shadow: var(--shadow-sm); cursor: pointer; }
.action-btn-mini:disabled { opacity: 0.5; background: var(--text-muted); pointer-events: none; }
.cortex-row { display: flex; gap: 12px; margin-bottom: 12px; }
.cortex-input-group label { color: var(--text-muted); font-size: 0.75rem; margin-bottom: 6px; display: block; font-weight: 700; text-transform: uppercase;}
.cortex-input-group input, .cortex-input-group select {
    width: 100%; border: 2px solid var(--border-soft); background: var(--bg-body);
    font-size: 1.3rem; font-weight: 800; color: var(--primary-dark);
    border-radius: var(--radius-md); padding: 12px; text-align: center;
    transition: border-color 0.2s;
}
.cortex-input-group input:focus { border-color: var(--brand-cyan); outline: none; background: #fff;}

/* THE ANCHOR PILL */
#cortexAnchorPill {
    position: relative; top: 10px; z-index: 7000;
    background: var(--bg-surface) !important;
    backdrop-filter: blur(25px) !important; -webkit-backdrop-filter: blur(25px) !important;
    border-radius: var(--radius-lg); box-shadow: var(--shadow-md);
    margin-bottom: 20px; border: 2px solid var(--primary);
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex !important; margin: 0 auto !important; max-width: 100% !important; 
    overflow-x: auto !important; scrollbar-width: none !important; 
}
#cortexAnchorPill::-webkit-scrollbar { display: none !important; }
.anchor-core { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; cursor: pointer; background: rgba(91, 97, 246, 0.05); border-radius: var(--radius-lg); }
.anchor-stats { font-size: 1.1rem; font-weight: 800; color: var(--primary-dark); display: flex; gap: 10px; align-items: center; }
.anchor-divider { color: var(--border-soft); }
.anchor-chevron { font-size: 1.2rem; color: var(--primary); font-weight: bold; transition: transform 0.3s; }

/* THE DRAWER */
#cortexDrawer { padding: 0 16px 16px 16px; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; transform-origin: top; transition: all 0.3s ease; }
#cortexDrawer.cortex-collapsed { visibility: hidden; pointer-events: none; }
.expanded-chevron { transform: rotate(180deg); }

.cortex-sticky-anchor {
    position: sticky !important; top: 10px !important; z-index: 5000 !important;
    display: flex !important; flex-direction: column !important; align-items: center !important; width: 100% !important;
    background: transparent !important; margin-bottom: 10px !important;
    margin-left: 0 !important; margin-right: 0 !important; padding-left: 0 !important; padding-right: 0 !important;
}
.cortex-greeting-wrapper {
    position: relative !important; display: block !important; margin-top: 35px !important; padding-top: 10px !important; clear: both !important;
}


/* =========================================
   TRANSPARENT BOTTOM APP NAVIGATION
   ========================================= */
nav.main-nav {
    position: fixed !important; bottom: 0 !important; left: 0 !important; width: 100vw !important; transform: none !important;
    background: linear-gradient(to top, rgba(0,0,0,0.95) 0%, rgba(0,0,0,0.4) 60%, transparent 100%) !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    border: none !important; border-radius: 0 !important; box-shadow: none !important;
    padding: 5px 0 calc(5px + env(safe-area-inset-bottom)) 0 !important; min-height: 0 !important; 
    display: flex !important; flex-direction: row !important; justify-content: space-evenly !important; align-items: flex-end !important; z-index: 9999 !important;
}
nav.main-nav button.nav-item {
    background: transparent !important; border: none !important; outline: none !important; display: flex !important; flex-direction: column !important;
    align-items: center !important; justify-content: center !important; padding: 4px !important; color: rgba(255,255,255,0.4) !important;
    transition: color 0.3s ease !important; transform: none !important; box-shadow: none !important;
}
nav.main-nav button.nav-item svg { width: 24px !important; height: 24px !important; margin-bottom: 4px !important; }
nav.main-nav button.nav-item span { font-size: 0.7rem !important; font-weight: 600 !important; }
nav.main-nav button.nav-item.active { color: var(--brand-cyan) !important; }
nav.main-nav button.nav-item.active svg { filter: drop-shadow(0 0 8px rgba(0, 229, 255, 0.6)) !important; }


/* =========================================
   MOBILE SPLASH SCREEN
   ========================================= */
.splash-screen {
    display: flex; position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh;
    background: var(--bg-body); z-index: 9999999; align-items: center; justify-content: center;
    flex-direction: column; transition: opacity 0.6s ease, visibility 0.6s;
}
.splash-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-waves {
    position: absolute; bottom: 0; left: 0; width: 100%; height: 35vh;
    background: linear-gradient(135deg, var(--brand-cyan), var(--brand-blue));
    mask-image: radial-gradient(ellipse at top, transparent 50%, black 100%);
    -webkit-mask-image: radial-gradient(ellipse at top, transparent 50%, black 100%);
    opacity: 0.2; z-index: 1;
}
.splash-content { z-index: 2; display: flex; flex-direction: column; align-items: center; text-align: center; }
.splash-content h1 { color: var(--primary-dark); font-size: 3.5rem; margin: 0; letter-spacing: -1px; }
.splash-content p { color: var(--text-muted); font-size: 1.1rem; margin-top: 5px; font-weight: 600; }
.splash-loader {
    margin-top: 50px; width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.1);
    border-left-color: var(--brand-cyan); border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }


/* =========================================================
   CORTEX POP SHEET PHYSICS (Bottom Sheet Modal)
   ========================================================= */
#cortexPopSheetOverlay {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100dvh;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
    z-index: 10500; transition: opacity 0.4s ease;
}
.cortex-pop-sheet {
    position: fixed; bottom: 0; left: 0; width: 100vw; height: 90dvh; 
    background: var(--bg-body); border-radius: 24px 24px 0 0; z-index: 10600; display: flex; flex-direction: column;
    box-shadow: 0 -20px 60px rgba(0,0,0,0.8), inset 0 2px 10px rgba(255,255,255,0.05);
    transform: translateY(100%); transition: transform 0.5s cubic-bezier(0.32, 0.72, 0, 1);
}
.cortex-pop-sheet.active { transform: translateY(0); }
.cortex-pop-sheet .sheet-drag-handle { width: 45px; height: 5px; background: rgba(255,255,255,0.2); border-radius: 5px; margin: 12px auto 15px auto; }
.cortex-pop-sheet .sheet-content { flex: 1; overflow-y: auto; padding: 20px; -webkit-overflow-scrolling: touch; }


/* =========================================
   THE HOLOGRAPHIC SWIPE ARROWS 
   ========================================= */
.holo-swipe-hint {
    display: flex !important; justify-content: center !important; align-items: center !important; gap: 15px !important;
    margin-top: 5px !important; margin-bottom: 15px !important; color: var(--brand-cyan) !important;
    font-size: 0.65rem !important; font-weight: 800 !important; text-transform: uppercase !important;
    letter-spacing: 2px !important; opacity: 0.8 !important; cursor: pointer !important; 
}
.hint-arrow { width: 14px !important; height: 14px !important; filter: drop-shadow(0 0 5px rgba(0, 229, 255, 0.6)) !important; transition: transform 0.2s ease !important; }
.holo-swipe-hint:active { transform: scale(0.95) !important; opacity: 1 !important; }
.arrow-left { animation: pulseLeft 2s cubic-bezier(0.4, 0, 0.2, 1) infinite !important; }
.arrow-right { animation: pulseRight 2s cubic-bezier(0.4, 0, 0.2, 1) infinite !important; }

@keyframes pulseLeft { 0%, 100% { transform: translateX(2px); opacity: 0.3; } 50% { transform: translateX(-4px); opacity: 1; } }
@keyframes pulseRight { 0%, 100% { transform: translateX(-2px); opacity: 0.3; } 50% { transform: translateX(4px); opacity: 1; } }


/* =========================================================
   INTELLIGENCE WORKSPACE & PREVIEW RAIL
   ========================================================= */

/* 1. The Dashboard Preview Rail */
.preview-rail {
    display: flex !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    gap: 12px !important;
    padding: 10px 5vw 20px 5vw !important;
    width: 100% !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
}
.preview-rail::-webkit-scrollbar { display: none !important; }

/* 2. Miniature Preview Cards */
.preview-card {
    scroll-snap-align: start !important;
    flex: 0 0 140px !important;
    height: 150px !important;
    background: rgba(10, 15, 25, 0.4) !important;
    backdrop-filter: blur(10px) !important;
    -webkit-backdrop-filter: blur(10px) !important;
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    border-radius: 20px !important;
    padding: 15px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    cursor: pointer !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    box-shadow: inset 0 2px 10px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.3) !important;
}
.preview-card:active {
    transform: scale(0.95) !important;
    box-shadow: inset 0 2px 15px rgba(0,0,0,0.5) !important;
}

.preview-header {
    display: flex !important;
    flex-direction: column !important;
    gap: 4px !important;
}
.preview-title {
    font-size: 0.75rem !important;
    font-weight: 800 !important;
    color: #fff !important;
    letter-spacing: 0.5px !important;
}
.preview-value {
    font-family: "JetBrains Mono", "Space Grotesk", "SF Mono", monospace !important;
    font-size: 2rem !important;
    font-weight: 900 !important;
    color: var(--brand-cyan) !important;
    line-height: 1 !important;
    margin-bottom: 4px !important;
}
.preview-label {
    font-size: 0.65rem !important;
    font-weight: 700 !important;
    color: var(--text-muted) !important;
    text-transform: uppercase !important;
}

/* 3. The Full-Screen Workspace Overlay */
.workspace-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100dvh !important;
    z-index: 10500 !important;
    background: rgba(11, 14, 20, 0.6) !important;
    display: none; /* Hidden by default via JS */
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    opacity: 0;
    transition: opacity 0.4s ease, backdrop-filter 0.4s ease !important;
}

/* 4. Background Dimming State */
.dashboard-blurred {
    filter: blur(10px) brightness(0.6) !important;
    pointer-events: none !important;
    transition: filter 0.4s ease, brightness 0.4s ease !important;
}

/* 5. Workspace Close Button */
.workspace-header {
    position: absolute !important;
    top: calc(15px + env(safe-area-inset-top)) !important;
    width: 100% !important;
    display: flex !important;
    justify-content: center !important;
    z-index: 10600 !important;
}
.workspace-close-btn {
    background: rgba(255, 255, 255, 0.1) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
    padding: 8px 20px !important;
    border-radius: 50px !important;
    font-size: 0.75rem !important;
    font-weight: 800 !important;
    letter-spacing: 1px !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    cursor: pointer !important;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5) !important;
}

/* =========================================================
   INTERNAL CROSS-FADE MORPHING (FLIP DETAIL LAYERS)
   ========================================================= */
.cortex-spatial-stage .bento-card {
    position: relative !important;
}

.card-preview-layer {
    position: absolute !important;
    top: 0; left: 0; width: 100%; height: 100%;
    padding: 15px !important;
    display: flex !important;
    flex-direction: column !important;
    justify-content: space-between !important;
    opacity: 1;
    transition: opacity 0.2s ease !important;
    z-index: 10;
}

.card-detail-layer {
    opacity: 0 !important;
    pointer-events: none !important;
    transition: opacity 0.4s ease 0.1s !important;
    height: 100% !important;
    width: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    flex-grow: 1 !important;
}

/* When the JS triggers the expansion */
.bento-card.is-expanded .card-preview-layer {
    opacity: 0 !important;
    pointer-events: none !important;
}

.bento-card.is-expanded .card-detail-layer {
    opacity: 1 !important;
    pointer-events: auto !important;
}

/* 🚀 SURGICAL FIX: Restoring Your Spatial Deck Architecture */
#workspaceCarousel {
    position: relative !important;
    width: 100vw !important;
    height: 100% !important;
    perspective: 1200px !important;
    perspective-origin: 50% 50% !important;
    transform-style: preserve-3d !important;
    overflow: hidden !important; /* No native scrolling! */
}

/* 🚀 SURGICAL FIX: Force HoloDeck Cards to Render */
#workspaceCarousel .bento-card {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important; /* The JS will override this via inline styles */
    clip-path: none !important;
    -webkit-clip-path: none !important;
}

/* =========================================================
   🚀 SURGICAL FIX: MOBILE RESPONSIVE GREETING & TELEMETRY
   ========================================================= */
@media (max-width: 768px) {
    /* Stack the row into a column */
    .cortex-greeting {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 16px !important;
    }
    
    /* Give the text full width instead of 65% */
    .greeting-text {
        max-width: 100% !important;
    }
    
    /* Scale down the font so the typing animation doesn't clip off-screen */
    .hero-greeting-font {
        font-size: 1.35rem !important;
    }
    
    .animated-time-icon {
        font-size: 1.4rem !important;
    }
}

/* =========================================================
   📱 SURGICAL PATCH: GOD-MODE ORB & SHEET FOR MOBILE
   ========================================================= */
@media screen and (max-width: 1023px) {
    /* 1. THE ORB: Rises above every possible app layer & clears bottom nav */
    #cortexSystem {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: fixed !important;
        bottom: 85px !important;
        right: 16px !important;
        width: 80px !important;
        height: 80px !important;
        z-index: 2147483647 !important; /* Maximum CSS Integer Limit */
        pointer-events: auto !important;
        touch-action: none !important;
    }

    /* 2. THE BACKDROP OVERLAY: Sits at the base layer */
    #cortexSheetOverlay {
        z-index: 2147483644 !important;
    }
    #cortexSheetOverlay.active {
        display: block !important;
        position: fixed !important;
        inset: 0 !important;
        width: 100vw !important;
        height: 100dvh !important;
        background: rgba(0, 0, 0, 0.75) !important;
        backdrop-filter: blur(8px) !important;
        -webkit-backdrop-filter: blur(8px) !important;
        z-index: 2147483645 !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* 3. THE CHAT SHEET: Explicit height, slides cleanly over backdrop */
    #cortexAiSheet {
        z-index: 2147483646 !important;
    }
    #cortexAiSheet.active {
        display: flex !important;
        flex-direction: column !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        height: auto !important;
        min-height: 380px !important; /* Prevents zero-height mobile compression trap! */
        max-height: 82dvh !important;
        background: #0a0a14 !important;
        border-top: 2px solid var(--brand-cyan) !important;
        box-shadow: 0 -15px 50px rgba(0, 0, 0, 0.95) !important;
        z-index: 2147483646 !important; /* Strictly higher than overlay (2147483645) */
        pointer-events: auto !important;
        transform: translateY(0) !important;
    }
}