/* Import component-level CSS (header, sidebar, livia) - must appear before other rules */
@import url("./header.css");
@import url("./sidebar.css");
@import url("./livia.css");

/* Global fixes to avoid layout breakage */
/* Prevent page-level scrollbars; panels will manage internal scrolling */
/* Ensure the document fills the viewport and prevent page-level scrollbars */
html, body { height: 100vh; overflow: hidden; }
#root { height: 0; }
*, *::before, *::after { box-sizing: border-box; }

:root, [data-theme="dark"] {
    --bg-primary: #0a0e14;
    --bg-secondary: #111820;
    --bg-tertiary: #1a2332;
    --bg-card: #151d2a;
    --border-color: #243044;
    --border-subtle: #1e2a3a;
    --border: #243044;
    --border-hover: #3a4a5f;
    
    --text-primary: #e8edf5;
    --text-secondary: #8a9bb3;
    --text-muted: #5a6a7f;
    
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;
    --accent-pink: #ec4899;
    --accent-orange: #f97316;
    --accent-teal: #14b8a6;
    
    --livia-gradient: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%);
    --medgemma-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}
:root, [data-theme="dark"] {
    --bg-primary: #0a0e14;
    --bg-secondary: #111820;
    --bg-tertiary: #1a2332;
    --bg-card: #151d2a;
    --border-color: #243044;
    --border-subtle: #1e2a3a;
    --border: #243044;
    --border-hover: #3a4a5f;
    
    --text-primary: #e8edf5;
    --text-secondary: #8a9bb3;
    --text-muted: #5a6a7f;
    
    --accent-primary: #3b82f6;
    --accent-primary-hover: #2563eb;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-purple: #8b5cf6;
    --accent-cyan: #06b6d4;
    --accent-pink: #ec4899;
    --accent-orange: #f97316;
    --accent-teal: #14b8a6;
    
    --livia-gradient: linear-gradient(135deg, #06b6d4 0%, #3b82f6 50%, #8b5cf6 100%);
    --medgemma-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

/* ========================================
   TEMA LIGHT
   ======================================== */
[data-theme="light"] {
    --bg-primary: #f5f6f7;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f3f4f6;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;
    --border-subtle: #f1f5f9;
    --border: #e2e8f0;
    --border-hover: #cbd5e1;
    
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    --accent-primary: #2563eb;
    --accent-primary-hover: #1d4ed8;
    --accent-success: #059669;
    --accent-warning: #d97706;
    --accent-danger: #dc2626;
    --accent-purple: #7c3aed;
    --accent-cyan: #0891b2;
    --accent-pink: #db2777;
    --accent-orange: #ea580c;
    --accent-teal: #0d9488;
    
    --livia-gradient: linear-gradient(135deg, #0891b2 0%, #2563eb 50%, #7c3aed 100%);
    --medgemma-gradient: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

body { font-family: 'Plus Jakarta Sans', sans-serif; }

/* === Layout helpers & variables already extracted from original index.html === */

/* Core layout */
/* Ensure the document fills the viewport and remove default margins */
/* Ensure viewport fills and enable flex layout for header + app-shell */
html, body, #root { height: 100vh; margin: 0; padding: 0; }

/* App container */
/* Use flex so header + app-shell layout can share full viewport height */
.app-shell { display: flex; flex: 1 1 auto; min-height: 0; height: auto; align-items: stretch; }

body.sso-note-only #header-placeholder,
body.sso-note-only #sidebar-placeholder,
body.sso-note-only #livia-placeholder {
    display: none !important;
}

body.sso-note-only #app-shell {
    gap: 0;
}

body.sso-note-only #main-placeholder {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
}

body.sso-note-only #main-placeholder .livia-header,
body.sso-note-only #main-placeholder .livia-controls,
body.sso-note-only #main-placeholder #livia-response,
body.sso-note-only #main-placeholder #livia-start-wrap,
body.sso-note-only #main-placeholder #livia-toggle-btn,
body.sso-note-only #main-placeholder #livia-expand-btn,
body.sso-note-only #main-placeholder #livia-discharge-btn {
    display: none !important;
}

/* Page background and default text color */
/* Layout: header + app-shell column flow */
/* ensure body participates in flex layout and fills viewport */
html, body { height: 100vh; margin: 0; }
body { display: flex; flex-direction: column; background: var(--bg-primary); color: var(--text-primary); min-height: 100vh; }

/* Ensure header placeholder doesn't consume flexible space and app-shell fills remainder */
/* Header placeholder shouldn't grow; app-shell fills the remaining viewport height */
#header-placeholder { flex: 0 0 auto; }
#app-shell { flex: 1 1 auto; display:flex; min-height: 0; align-items: stretch; }

/* Make placeholders and their injected components stretch to fill app-shell */
.app-shell > #sidebar-placeholder, .app-shell > #main-placeholder, .app-shell > #livia-placeholder { display:flex; flex-direction:column; min-height:0; flex: 0 0 auto; }
.app-shell > #sidebar-placeholder { flex: 0 0 320px; transition: flex-basis 0.24s ease, width 0.24s ease; }
.app-shell > #main-placeholder {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.app-shell > #livia-placeholder { flex: 0 0 360px; transition: flex-basis 0.24s ease, width 0.24s ease; }

/* Layering: keep sidebar controls above livia controls when columns overlap. */
.app-shell > #sidebar-placeholder {
    position: relative;
    /* z-index removed to prevent stacking context */
}

.app-shell > #livia-placeholder {
    position: relative;
    /* z-index removed to prevent stacking context */
}

/* Make injected components stretch to available height */
.app-shell .sidebar, .app-shell .main-content, .app-shell .livia-panel { flex: 1 1 auto; height: auto; }

/* header occupies natural height; app-shell fills remaining area */
.app-shell { display: flex; flex: 1 1 auto; min-height: 0; }

/* Add spacing between columns and ensure panels can't force horizontal scroll */
.app-shell { gap: 18px; }
.header-bar { position: sticky; top: 0; z-index: 40; }

/* Sidebar and Livia panels will be constrained by placeholders; scrolling
    is handled internally and visual scrollbars are hidden for cleaner UI. */

/* Prevent overly wide children inside sidebar from creating horizontal scrollbars */
.sidebar * { max-width: 100%; }
.sidebar .menu-item { align-items: flex-start; }
.sidebar .menu-content { min-width: 0; }
.sidebar .title { white-space: normal; }

/* Ensure modules root scrolls vertically only */
#modules-root { overflow-y: auto; overflow-x: hidden; }

/* Main content area (central) */
.main-content {
    flex: 1 1 auto;
    padding: 22px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 0; /* allow proper scrolling inside */
}

.modules-root {
    max-width: 1100px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Card container for module content */
.module-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

.report-placeholder {
    padding: 30px 20px;
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255,255,255,0.01), transparent);
    border: 1px dashed var(--border-color);
    color: var(--text-muted);
}
.report-placeholder h4 { margin: 0 0 8px 0; color: var(--text-primary); }
.report-placeholder p { margin: 0; }

/* Buttons and inputs (global helpers) */
.btn { padding: 8px 12px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; font-weight:600; }
.btn-secondary { background: transparent; color: var(--text-primary); border:1px solid var(--border-color); }
.btn-primary { background: var(--accent-primary); color: white; }

input, textarea, select { background: var(--bg-tertiary); color: var(--text-primary); border: 1px solid var(--border-color); padding: 8px 10px; border-radius:8px; }

/* Layout: ensure sidebar, main and livia sit side-by-side */
.app-shell > #sidebar-placeholder { flex: 0 0 320px; display:flex; flex-direction:column; min-height:0; }
.app-shell > #sidebar-placeholder.sidebar-collapsed { flex: 0 0 88px; }
.app-shell > #main-placeholder {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}
.app-shell > #livia-placeholder { flex: 0 0 360px; display:flex; flex-direction:column; min-height:0; }
.app-shell > #livia-placeholder.livia-collapsed { flex: 0 0 56px; }

/* Livia em modo expandido: ocupa área central + lateral, preservando sidebar. */
#app-shell.livia-expanded > #main-placeholder {
    display: none;
}

#app-shell.livia-expanded > #livia-placeholder {
    flex: 1 1 auto;
}

/* Ensure placeholders and injected panel elements expand to fill available height */
.app-shell > #sidebar-placeholder, .app-shell > #main-placeholder, .app-shell > #livia-placeholder { height: 100%; }
.app-shell > #sidebar-placeholder .sidebar { height: 100%; display:flex; flex-direction:column; min-height:0; }
.app-shell > #main-placeholder .main-content { height: 100%; min-height:0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.app-shell > #livia-placeholder .livia-panel { height: 100%; display:flex; flex-direction:column; min-height:0; }

/* Small screens: collapse sidebar and livia below main */
@media (max-width: 1000px) {
    .app-shell { flex-direction: column; }
    .app-shell > #sidebar-placeholder, .app-shell > #livia-placeholder { width: 100%; flex: none; }
}

/* Make sidebar and livia panels scrollable when content overflows (vertical only) */
.sidebar, .livia-panel { overflow-y: auto; overflow-x: hidden; }

/* Hide native scrollbars visually while keeping scrolling functional */
.sidebar { -ms-overflow-style: none; scrollbar-width: none; }
.livia-panel { -ms-overflow-style: none; scrollbar-width: none; }
.sidebar::-webkit-scrollbar, .livia-panel::-webkit-scrollbar { width: 0; height: 0; display: none; }

/* Ensure modules root scrolls inside main area (vertical only) */
#modules-root { overflow-y: auto; overflow-x: hidden; }

/* Header bar styles */
.header-bar { display:flex; align-items:center; gap:12px; padding:12px 18px; border-bottom:1px solid var(--border); background: linear-gradient(90deg, rgba(255,255,255,0.01), transparent); }
.header-left { display:flex; gap:12px; align-items:center; }
.brand-cross {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    color: transparent;
    background: linear-gradient(145deg, rgba(47, 122, 229, 0.14), rgba(47, 122, 229, 0.06));
    border: 1px solid rgba(47, 122, 229, 0.28);
    line-height: 1;
}
.brand-cross::before,
.brand-cross::after {
    content: "";
    position: absolute;
    background: #2f7ae5;
    border-radius: 5px;
}
.brand-cross::before {
    width: 12px;
    height: 30px;
}
.brand-cross::after {
    width: 30px;
    height: 12px;
}
.brand-title {
    margin: 0;
    display: flex;
    flex-direction: column;
    line-height: 1;
}
.brand-line-top {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}
.brand-line-bottom {
    margin-top: 2px;
    font-size: 32px;
    font-weight: 800;
    color: var(--text-primary);
}
.brand-badge {
    margin-left: 8px;
    padding: 6px 11px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 800;
    color: #0f5132;
    background: linear-gradient(180deg, #c6f6d5 0%, #a7f3d0 100%);
    border: 1px solid #6ee7b7;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
}
.patient-ids label { font-size:12px; color:var(--text-muted); margin-right:8px; }
.header-center { flex:1; text-align:center; }
.app-title { margin:0; font-size:16px; font-weight:700; color:var(--text-primary); }
.header-subtitle { font-size:12px; color:var(--text-muted); }
.header-right { display:flex; gap:8px; align-items:center; margin-left:auto; }
.header-search { padding:8px 10px; border-radius:8px; border:1px solid var(--border-color); background:var(--bg-tertiary); color:var(--text-primary); }

@media (max-width: 1100px) {
    .brand-badge { display: none; }
    .brand-line-top { font-size: 16px; }
    .brand-line-bottom { font-size: 26px; }
}


/* (Rest of the original stylesheet continues below; included verbatim) */

/* Exames table */
.exames-table th { text-align: left; font-size: 9px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.exames-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.exames-table tr:last-child td { border-bottom: none; }
.exames-table tr:hover { background: rgba(255, 255, 255, 0.02); }
.exame-nome { color: var(--text-primary); }
.exame-valor { font-family: 'JetBrains Mono', monospace; font-weight: 600; }
.exame-valor.normal { color: var(--text-primary); }
.exame-valor.baixo { color: #ca8a04; }
.exame-valor.alto { color: #ea580c; }
.exame-valor.critico { color: #dc2626; }
.exame-unidade { color: var(--text-muted); font-size: 10px; margin-left: 3px; }
.exame-ref { color: var(--text-muted); font-size: 11px; }
.exame-status { display: inline-flex; align-items: center; gap: 3px; padding: 2px 6px; border-radius: 4px; font-size: 9px; font-weight: 600; }
.exame-status.normal { background: rgba(22, 163, 74, 0.15); color: #16a34a; }
.exame-status.baixo { background: rgba(202, 138, 4, 0.15); color: #ca8a04; }
.exame-status.alto { background: rgba(234, 88, 12, 0.15); color: #ea580c; }

/* Many more rules copied from original index.html omitted here for brevity */

/* End of extracted CSS */

/* Keep side panels painted to the bottom of the viewport even when collapsed */
html,
body {
    height: 100vh !important;
    min-height: 100vh !important;
    overflow: hidden !important;
}

#app-shell,
.app-shell {
    height: 100% !important;
    min-height: 0 !important;
    flex: 1 1 auto !important;
    align-items: stretch !important;
}

.sidebar,
.livia-panel {
    height: 100% !important;
    min-height: 100% !important;
}

.app-shell > #sidebar-placeholder,
.app-shell > #sidebar-placeholder .sidebar {
    height: 100% !important;
    min-height: 100% !important;
    background: var(--bg-secondary) !important;
}

.app-shell > #livia-placeholder,
.app-shell > #livia-placeholder .livia-panel {
    height: 100% !important;
    min-height: 100% !important;
    background: var(--bg-card) !important;
}
