/* ═══════════════════════════════════════════════════
   Jarvis OR Guardian — Medical-Grade Dark UI
   Clinical Monitoring & Decision Support
   ═══════════════════════════════════════════════════ */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #151d2e;
    --bg-card-hover: #1a2438;
    --bg-input: #1e293b;
    --border: #1e3a5f;
    --border-subtle: #1a2740;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --green: #10b981;
    --green-glow: #00ff88;
    --yellow: #f59e0b;
    --orange: #f97316;
    --red: #ef4444;
    --red-glow: #ff3333;
    --purple: #a855f7;
    --vital-hr: #ef4444;
    --vital-spo2: #06b6d4;
    --vital-bp: #10b981;
    --vital-map: #22d3ee;
    --vital-etco2: #a855f7;
    --vital-rr: #f59e0b;
    --vital-temp: #f97316;
    --vital-si: #ec4899;
    --radius: 10px;
    --radius-sm: 6px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

.hidden { display: none !important; }

/* ─── Header ─── */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 28px; cursor: pointer; }
.header-titles h1 { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-subtitle { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }
.header-right { display: flex; align-items: center; gap: 12px; }

.status-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    display: inline-block;
}
.dot-disconnected { background: var(--text-muted); }
.dot-connected { background: var(--green); box-shadow: 0 0 8px var(--green-glow); }
.dot-off { background: var(--text-muted); }
.dot-active { background: var(--green); box-shadow: 0 0 6px var(--green-glow); animation: pulse-dot 2s infinite; }

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ─── Alert Banner ─── */

.alert-banner {
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 14px;
    transition: all 0.3s;
}

.alert-none { background: linear-gradient(90deg, #064e3b, #065f46); color: #6ee7b7; }
.alert-watch { background: linear-gradient(90deg, #78350f, #92400e); color: #fde68a; }
.alert-concern { background: linear-gradient(90deg, #9a3412, #c2410c); color: #fed7aa; animation: pulse-concern 2s infinite; }
.alert-critical { background: linear-gradient(90deg, #991b1b, #dc2626); color: #fecaca; animation: pulse-critical 0.8s infinite; }

@keyframes pulse-concern { 0%,100%{opacity:1} 50%{opacity:0.85} }
@keyframes pulse-critical { 0%,100%{opacity:1} 50%{opacity:0.6} }

#alert-time { margin-left: auto; font-weight: 400; opacity: 0.7; font-size: 12px; }

/* ─── Safety Alarms Bar ─── */

.safety-alarms-bar {
    background: rgba(239, 68, 68, 0.08);
    border-bottom: 1px solid rgba(239, 68, 68, 0.2);
    padding: 8px 24px;
}

.safety-alarms-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.safety-alarm-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    animation: pulse-alarm 1.5s infinite;
}

.safety-alarm-badge.alarm-critical {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.4);
}

.safety-alarm-badge.alarm-warning {
    background: rgba(249, 115, 22, 0.15);
    color: #fdba74;
    border: 1px solid rgba(249, 115, 22, 0.3);
}

@keyframes pulse-alarm { 0%,100%{opacity:1} 50%{opacity:0.7} }

/* ─── Critical Overlay ─── */

.critical-overlay {
    position: fixed;
    inset: 0;
    background: rgba(153, 27, 27, 0.92);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: critical-flash 0.6s infinite;
    backdrop-filter: blur(4px);
}

@keyframes critical-flash {
    0%, 100% { background-color: rgba(153, 27, 27, 0.92); }
    50% { background-color: rgba(220, 38, 38, 0.95); }
}

.critical-content {
    text-align: center;
    max-width: 500px;
    padding: 40px;
}

.critical-icon { font-size: 72px; margin-bottom: 16px; }
.critical-content h1 { font-size: 36px; margin-bottom: 12px; letter-spacing: 2px; }
.critical-content p { font-size: 18px; margin-bottom: 24px; opacity: 0.9; }
.critical-vitals-row { display: flex; gap: 16px; justify-content: center; margin-bottom: 28px; flex-wrap: wrap; }

.critical-vital {
    background: rgba(0,0,0,0.3);
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 700;
}

/* ─── Disclaimer Modal ─── */

.disclaimer-modal-wrap {
    z-index: 10000;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
}

.disclaimer-modal-content {
    text-align: center;
    max-width: 560px;
}

.disclaimer-header-icon {
    font-size: 56px;
    margin-bottom: 12px;
}

.disclaimer-app-name {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 10px;
    letter-spacing: -0.3px;
}

.disclaimer-app-tagline {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-secondary);
    margin-bottom: 20px;
    text-align: center;
}

.disclaimer-divider {
    height: 1px;
    background: var(--border);
    margin: 0 0 20px;
}

.disclaimer-title {
    font-size: 18px;
    color: var(--yellow);
    margin-bottom: 16px;
}

.disclaimer-body {
    text-align: left;
    margin-bottom: 28px;
}

.disclaimer-body p {
    font-size: 14px;
    line-height: 1.8;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.disclaimer-body strong {
    color: var(--text-primary);
}

/* ─── Buttons ─── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-sans);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent-blue); color: white; }
.btn-primary:hover:not(:disabled) { background: #2563eb; }
.btn-secondary { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-card-hover); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover:not(:disabled) { background: var(--bg-input); }
.btn-danger { background: var(--red); color: white; padding: 12px 32px; font-size: 16px; }
.btn-danger:hover { background: #dc2626; }
.btn-icon { background: transparent; color: var(--text-secondary); padding: 6px; font-size: 18px; border: none; cursor: pointer; }
.btn-icon:hover { color: var(--text-primary); }
.btn-small { padding: 4px 10px; font-size: 11px; }
.btn-large { padding: 14px 32px; font-size: 16px; width: 100%; }

/* ─── Form Controls ─── */

.input-field {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    width: 100%;
    transition: border-color 0.2s;
    font-family: var(--font-sans);
}

.input-field:focus { outline: none; border-color: var(--accent-blue); }
.input-field.textarea { resize: vertical; font-family: var(--font-sans); }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.5px; }
.field-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; display: block; }

.select-field {
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* ─── Setup Panel ─── */

.setup-panel {
    display: flex;
    justify-content: center;
    min-height: calc(100vh - 60px);
    padding: 24px;
    overflow-y: auto;
}

.setup-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    max-width: 600px;
    width: 100%;
    box-shadow: var(--shadow);
}

.setup-card-wide {
    max-width: 780px;
    margin: 24px auto;
}

.setup-header { text-align: center; margin-bottom: 28px; }
.setup-header .setup-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.setup-header h2 { font-size: 24px; margin-bottom: 6px; }
.setup-subtitle { color: var(--text-secondary); font-size: 14px; }

.setup-section { margin-bottom: 20px; }
.setup-divider { height: 1px; background: var(--border-subtle); margin: 24px 0; }
.section-title { font-size: 14px; color: var(--text-secondary); margin-bottom: 0; text-transform: uppercase; letter-spacing: 0.5px; }

.setup-row { display: flex; gap: 12px; margin-bottom: 12px; }
.setup-field { flex: 1; margin-bottom: 12px; }
.setup-field.flex-2 { flex: 2; }

.baseline-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 8px;
}

.disclaimer { text-align: center; font-size: 11px; color: var(--text-muted); margin-top: 16px; }

/* ─── Form Sections (Collapsible) ─── */

.form-section {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    margin-bottom: 12px;
    background: var(--bg-secondary);
    overflow: hidden;
}

.form-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.form-section-header:hover { background: var(--bg-card-hover); }

.form-section-num {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-blue);
    color: white;
    font-size: 12px;
    font-weight: 700;
    flex-shrink: 0;
}

.form-section-header .section-title {
    flex: 1;
    margin-bottom: 0;
}

.form-section-chevron {
    color: var(--text-muted);
    font-size: 14px;
    transition: transform 0.2s;
}

.form-section-header.collapsed .form-section-chevron {
    transform: rotate(-90deg);
}

.form-section-body {
    padding: 12px 16px 16px;
    border-top: 1px solid var(--border-subtle);
}

.form-section-body.hidden {
    display: none !important;
}

/* ─── Required Marker ─── */

.req { color: var(--yellow); font-size: 11px; }

/* ─── Checkbox / Radio Grids ─── */

.checkbox-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 16px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    padding: 5px 0;
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--accent-blue);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ─── Anesthesia Technique Categories ─── */

.anesthesia-category-grid {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.anesthesia-category {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px 14px 12px;
}

.anesthesia-cat-header {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-subtle);
}

.anesthesia-subcat-header {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 10px 0 4px;
    padding-left: 2px;
}

.anesthesia-category .checkbox-grid {
    gap: 4px 16px;
}

.toggle-row {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 4px 0;
}

.toggle-row .toggle-label {
    gap: 6px;
}

.toggle-row input[type="radio"] {
    accent-color: var(--accent-blue);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.radio-label {
    font-size: 13px;
    color: var(--text-primary);
}

/* ─── Read-only Input ─── */

.input-readonly {
    opacity: 0.7;
    cursor: default;
}

/* ─── Setup Submit ─── */

.setup-submit {
    margin-top: 24px;
    text-align: center;
}

.setup-req-note {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* ─── Dashboard Layout ─── */

.dashboard {
    padding: 16px;
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.dash-top { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-mid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.dash-bottom { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.trends-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ─── Panels ─── */

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.panel-header h3 { font-size: 14px; font-weight: 600; }
.timestamp { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

.panel-header-collapse {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.panel-header-collapse:hover { background: var(--bg-card-hover); }

.panel-note {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: 8px;
    flex: 1;
}

.collapse-chevron {
    color: var(--text-muted);
    font-size: 14px;
    transition: transform 0.2s;
}

/* ─── Camera Panel ─── */

.camera-viewport {
    position: relative;
    background: #000;
    aspect-ratio: 16 / 10;
    overflow: hidden;
}

.camera-viewport video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-viewport canvas { display: none; }

.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.camera-placeholder span { font-size: 48px; margin-bottom: 8px; }
.camera-placeholder p { font-size: 13px; }

.capture-flash {
    position: absolute;
    inset: 0;
    background: white;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s;
}

.capture-flash.flash { opacity: 0.6; transition: opacity 0s; }

.camera-controls {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
}

.auto-capture-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px 10px;
    font-size: 12px;
}

.auto-status { color: var(--text-muted); font-size: 11px; }

/* Toggle Switch */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
}

.toggle-label input { display: none; }

.toggle-slider {
    width: 36px;
    height: 20px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 10px;
    position: relative;
    transition: all 0.2s;
}

.toggle-slider::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: all 0.2s;
}

.toggle-label input:checked + .toggle-slider {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.toggle-label input:checked + .toggle-slider::after {
    left: 18px;
    background: white;
}

.upload-fallback {
    padding: 8px 16px 12px;
    border-top: 1px solid var(--border-subtle);
}

.upload-label { font-size: 12px; color: var(--text-muted); display: block; margin-bottom: 6px; }
.file-input { font-size: 12px; color: var(--text-secondary); }

.camera-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.roi-toggle-label { margin-left: auto; }

/* ─── ROI Overlay ─── */

.roi-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

.roi-box {
    position: absolute;
    border: 2px dashed var(--accent-cyan);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
    pointer-events: auto;
    cursor: move;
    touch-action: none;
    z-index: 11;
}

.roi-label {
    position: absolute;
    top: -22px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-cyan);
    background: rgba(0, 0, 0, 0.7);
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.roi-handle {
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-primary);
    border-radius: 3px;
    pointer-events: auto;
    touch-action: none;
    z-index: 12;
}

.roi-handle-nw { top: -7px; left: -7px; cursor: nwse-resize; }
.roi-handle-ne { top: -7px; right: -7px; cursor: nesw-resize; }
.roi-handle-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.roi-handle-se { bottom: -7px; right: -7px; cursor: nwse-resize; }

/* ─── SIM Badge ─── */

.sim-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--red);
    color: white;
    font-size: 10px;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 4px;
    letter-spacing: 1px;
    z-index: 15;
    animation: pulse-sim 1.5s infinite;
}

@keyframes pulse-sim {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ─── Vitals Panel ─── */

.vitals-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 12px;
}

.vital-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    padding: 12px 8px;
    text-align: center;
    border: 1px solid transparent;
    transition: all 0.3s;
}

.vital-card.vital-alert {
    border-color: var(--red);
    box-shadow: 0 0 12px rgba(239, 68, 68, 0.3);
    animation: vital-alert-pulse 1s infinite;
}

@keyframes vital-alert-pulse {
    0%, 100% { box-shadow: 0 0 12px rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 20px rgba(239, 68, 68, 0.6); }
}

.vital-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.vital-value {
    font-family: var(--font-mono);
    font-size: 28px;
    font-weight: 700;
    line-height: 1.1;
}

.vital-unit {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 2px;
}

.vital-hr .vital-label { color: var(--vital-hr); }
.vital-hr .vital-value { color: var(--vital-hr); }
.vital-spo2 .vital-label { color: var(--vital-spo2); }
.vital-spo2 .vital-value { color: var(--vital-spo2); }
.vital-bp .vital-label { color: var(--vital-bp); }
.vital-bp .vital-value { color: var(--vital-bp); }
.vital-map .vital-label { color: var(--vital-map); }
.vital-map .vital-value { color: var(--vital-map); }
.vital-etco2 .vital-label { color: var(--vital-etco2); }
.vital-etco2 .vital-value { color: var(--vital-etco2); }
.vital-rr .vital-label { color: var(--vital-rr); }
.vital-rr .vital-value { color: var(--vital-rr); }
.vital-temp .vital-label { color: var(--vital-temp); }
.vital-temp .vital-value { color: var(--vital-temp); }
.vital-si .vital-label { color: var(--vital-si); }
.vital-si .vital-value { color: var(--vital-si); }

.vital-si.vital-alert-si {
    border-color: var(--orange);
    box-shadow: 0 0 12px rgba(249, 115, 22, 0.3);
}

.waveform-section { padding: 10px 16px; border-top: 1px solid var(--border-subtle); }
.waveform-section h4 { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }

.waveform-item {
    font-size: 12px;
    color: var(--text-primary);
    padding: 3px 0;
}

.waveform-item strong { color: var(--accent-cyan); }

.trajectory-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-top: 1px solid var(--border-subtle);
}

.trajectory-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
}

.reading-count { font-size: 11px; color: var(--text-muted); }

/* ─── Manual Data Entry Panel ─── */

.manual-entry-panel {
    border: 1px solid var(--border);
    border-style: dashed;
}

.manual-entry-body {
    padding: 16px;
}

.manual-section {
    margin-bottom: 16px;
}

.manual-section h4 {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-subtle);
}

.manual-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.manual-field .input-field {
    padding: 8px 10px;
    font-size: 13px;
}

.manual-derived {
    display: flex;
    gap: 24px;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--text-secondary);
}

.manual-derived strong {
    color: var(--accent-cyan);
}

#manual-submit {
    width: 100%;
}

/* ─── Trend Charts ─── */

.chart-container { padding: 12px 16px; height: 260px; position: relative; }
.chart-container-sm { height: 200px; }

.trend-deltas {
    display: flex;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius);
    flex-wrap: wrap;
}

.delta-item {
    font-family: var(--font-mono);
    font-size: 12px;
}

.delta-item .delta-label { color: var(--text-muted); margin-right: 4px; }
.delta-item .delta-value { font-weight: 700; }
.delta-positive { color: var(--red); }
.delta-negative { color: var(--green); }
.delta-neutral { color: var(--text-secondary); }

.trend-controls { display: flex; gap: 6px; }

/* ─── Clinical Card ─── */

.clinical-card .card-section { padding: 12px 16px; border-top: 1px solid var(--border-subtle); }
.clinical-card .card-section h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.clinical-card .card-section p { font-size: 14px; line-height: 1.6; }
.clinical-card ol { padding-left: 20px; }
.clinical-card ol li { font-size: 13px; padding: 2px 0; }

.check-item, .action-item, .alarm-item {
    font-size: 13px;
    padding: 4px 0;
}

.check-item::before { content: '☐ '; color: var(--accent-cyan); }
.action-item::before { content: '→ '; color: var(--green); }
.alarm-item { color: var(--yellow); }
.alarm-item::before { content: '⚠ '; }

.card-quality {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ─── Fluid Balance Panel ─── */

.fluid-body { padding: 16px; }

.fluid-input-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.fluid-input-item .field-label {
    margin-bottom: 6px;
}

.fluid-input-row {
    display: flex;
    gap: 6px;
}

.fluid-input-row .input-field {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
}

.fluid-summary {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.fluid-summary-item {
    flex: 1;
    padding: 10px;
    border-radius: var(--radius-sm);
    text-align: center;
}

.fluid-loss {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.fluid-input-total {
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.fluid-balance-val {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.fluid-summary-label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.fluid-summary-value {
    display: block;
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.fluid-log {
    max-height: 120px;
    overflow-y: auto;
}

.fluid-log-entry {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--text-secondary);
}

.fluid-log-entry .fluid-log-time {
    color: var(--accent-cyan);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* ─── Drug Administration Panel ─── */

.drug-body { padding: 16px; }

.drug-entry-form { margin-bottom: 12px; }

.drug-entry-row {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
}

.drug-entry-row .input-field {
    flex: 1;
    padding: 8px 10px;
    font-size: 13px;
}

.drug-entry-row select.input-field {
    max-width: 200px;
}

.drug-log-list {
    max-height: 200px;
    overflow-y: auto;
}

.drug-log-entry {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 12px;
}

.drug-log-time {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    font-size: 11px;
    white-space: nowrap;
}

.drug-log-cat {
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    white-space: nowrap;
}

.drug-log-detail {
    flex: 1;
    color: var(--text-primary);
}

/* ─── Alarm Panel ─── */

.alarm-panel {
    border-color: rgba(239, 68, 68, 0.2);
}

.active-alarms {
    padding: 12px 16px;
}

.active-alarm-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    margin-bottom: 6px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
}

.active-alarm-item.alarm-active {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    animation: pulse-alarm 1.5s infinite;
}

.alarm-thresholds {
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
}

.alarm-thresholds h4 {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 10px;
}

.alarm-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.alarm-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.alarm-item label {
    white-space: nowrap;
    min-width: 70px;
}

.alarm-item .input-field {
    width: 60px;
    padding: 4px 6px;
    font-size: 12px;
    text-align: center;
}

.alarm-item span {
    font-size: 11px;
    color: var(--text-muted);
}

/* ─── Surgical Events (Enhanced) ─── */

.events-panel { display: flex; flex-direction: column; }

.events-quick-section {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
}

.quick-category { margin-bottom: 10px; }

.quick-category h4 {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.quick-btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.quick-event-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    font-family: var(--font-sans);
}

.quick-event-btn:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
    border-color: var(--accent-blue);
}

.quick-event-btn:active {
    transform: scale(0.95);
}

.quick-event-critical {
    border-color: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
}

.quick-event-critical:hover {
    border-color: var(--red);
    background: rgba(239, 68, 68, 0.1);
}

.quick-event-warn {
    border-color: rgba(249, 115, 22, 0.3);
    color: #fdba74;
}

.quick-event-warn:hover {
    border-color: var(--orange);
    background: rgba(249, 115, 22, 0.1);
}

.events-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 100px;
    max-height: 300px;
}

.events-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 20px 0; }

.event-item {
    display: flex;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 13px;
}

.event-time {
    font-family: var(--font-mono);
    color: var(--accent-cyan);
    font-size: 12px;
    white-space: nowrap;
}

.event-item.event-critical {
    color: #fca5a5;
}

.event-item.event-warn {
    color: #fdba74;
}

.event-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-subtle);
}

.event-input-row .input-field { flex: 1; }

/* ─── Postoperative Risk Panel ─── */

.postop-body {
    padding: 16px;
}

.postop-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.postop-risk-item {
    padding: 14px;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
}

.postop-risk-item h4 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.postop-risk-bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.postop-risk-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.postop-risk-fill.risk-low { background: var(--green); }
.postop-risk-fill.risk-moderate { background: var(--yellow); }
.postop-risk-fill.risk-high { background: var(--orange); }
.postop-risk-fill.risk-critical { background: var(--red); }

.postop-risk-label {
    font-size: 13px;
    font-weight: 600;
}

.postop-risk-label.risk-low { color: var(--green); }
.postop-risk-label.risk-moderate { color: var(--yellow); }
.postop-risk-label.risk-high { color: var(--orange); }
.postop-risk-label.risk-critical { color: var(--red); }

/* ─── Chat Panel ─── */

.chat-panel { display: flex; flex-direction: column; max-height: 500px; }

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 200px;
    max-height: 400px;
}

.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.assistant { justify-content: flex-start; }

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
}

.chat-msg.user .chat-bubble {
    background: var(--accent-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg.assistant .chat-bubble {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    border-bottom-left-radius: 4px;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-subtle);
}

.chat-input-row .input-field { flex: 1; }

/* ─── Settings Drawer ─── */

.settings-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 360px;
    height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border);
    z-index: 200;
    box-shadow: -8px 0 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-subtle);
}

.settings-body { padding: 20px; overflow-y: auto; flex: 1; }
.settings-body h4 { font-size: 13px; color: var(--text-secondary); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ─── Modal ─── */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 480px;
    width: 90%;
    box-shadow: var(--shadow);
}

.modal-content h3 { margin-bottom: 16px; }

.preflight-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-weight: 600;
}

.preflight-ready { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.preflight-not-ready { background: rgba(249, 115, 22, 0.15); color: var(--orange); }

.preflight-list {
    font-size: 13px;
    padding: 8px 0;
}

.preflight-list li {
    padding: 2px 0;
    list-style: none;
}

.preflight-list li::before { content: '• '; }

/* ─── Footer ─── */

.app-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-subtle);
    font-size: 12px;
    color: var(--text-muted);
}

.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: var(--accent-blue);
    text-decoration: underline;
}

/* ─── Scrollbar ─── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ─── Spinner ─── */

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.analyzing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.08);
    border-top: 1px solid rgba(6, 182, 212, 0.2);
}

/* ─── Voice Recording (Gemini Live) ─── */

.btn-recording {
    background: var(--red) !important;
    color: white !important;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    animation: pulse-record 1.2s ease-in-out infinite;
    position: relative;
}

.btn-voice-active {
    background: var(--accent-cyan) !important;
    color: var(--bg-primary) !important;
    border-radius: 6px;
}

@keyframes pulse-record {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* ─── Export PDF Button ─── */

.btn-export {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.25s;
    letter-spacing: 0.2px;
}

.btn-export:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
    transform: translateY(-1px);
}

.btn-export:active {
    transform: translateY(0);
}

/* ─── Responsive ─── */

@media (max-width: 1100px) {
    .manual-grid { grid-template-columns: repeat(3, 1fr); }
    .alarm-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
    .dash-top, .dash-mid, .dash-bottom, .trends-row { grid-template-columns: 1fr; }
    .baseline-grid { grid-template-columns: repeat(2, 1fr); }
    .setup-card { padding: 24px; }
    .setup-card-wide { max-width: 100%; }
    .vitals-grid { grid-template-columns: repeat(3, 1fr); }
    .settings-drawer { width: 100%; }
    .manual-grid { grid-template-columns: repeat(2, 1fr); }
    .fluid-input-grid { grid-template-columns: 1fr; }
    .postop-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
    .app-header { padding: 10px 16px; }
    .header-titles h1 { font-size: 15px; }
    .btn-export { padding: 5px 10px; font-size: 11px; }
    .dashboard { padding: 10px; }
    .vitals-grid { grid-template-columns: repeat(2, 1fr); }
    .vital-value { font-size: 22px; }
    .setup-row { flex-direction: column; }
    .setup-row .setup-field { margin-bottom: 8px; }
    .checkbox-grid { grid-template-columns: 1fr; }
    .baseline-grid { grid-template-columns: repeat(2, 1fr); }
    .manual-grid { grid-template-columns: 1fr 1fr; }
    .alarm-grid { grid-template-columns: 1fr; }
    .fluid-summary { flex-direction: column; }
    .drug-entry-row { flex-direction: column; }
    .drug-entry-row select.input-field { max-width: 100%; }
    .app-footer { flex-direction: column; gap: 4px; text-align: center; }
}
