/* ==========================================================================
   ARQUITECTURA CSS FRONT-END (Variables & Flex/Grid)
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,500;0,600;0,700;1,500&family=Inter:wght@400;500;600;700&display=swap');

:root {
    --primary: #1f3a5f;
    --primary-deep: #16283f;
    --secondary: #2f9e8f;
    --gold: #b8902f;
    --danger: #c0392b;
    --warning: #d68910;
    --success: #2e7d5b;
    --bg-app: #f6f4ee;
    --bg-card: #fbfaf6;
    --text: #2b2b28;
    --text-muted: #6f6d63;
    --border: #e2ddd1;
    --font-display: 'Lora', Georgia, serif;
    --font-body: 'Inter', 'Segoe UI', Tahoma, Arial, sans-serif;
}

* { box-sizing: border-box; }
body { font-family: var(--font-body); background-color: var(--bg-app); color: var(--text); margin: 0; padding: 0; overflow: hidden;}

/* --- UTILIDADES DE AISLAMIENTO SPA --- */
.hidden-view { display: none !important; }
.active-view { display: grid !important; }
.flex-col { display: flex; flex-direction: column; }
.flex-1 { flex: 1; }
.gap-15 { gap: 15px; }
.mt-10 { margin-top: 10px; }
.mb-10 { margin-bottom: 10px; }
.full-height { height: 100%; }

/* --- TOAST NOTIFICATIONS --- */
#psico-toast {
    position: fixed; top: 20px; right: 20px; padding: 15px 20px; border-radius: 8px; color: white; font-weight: bold; z-index: 10000;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2); transition: opacity 0.5s ease-in-out; display: flex; align-items: center; gap: 10px;
}
#psico-toast.success { background-color: var(--success); }
#psico-toast.error { background-color: var(--danger); }

/* --- LOGIN (GATEKEEPER) --- */
.login-fullscreen { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: linear-gradient(160deg, #f6f4ee 0%, #ece6d6 100%); display: flex; justify-content: center; align-items: center; z-index: 9999; }
.login-box { background: #ffffff; padding: 45px 40px; border-radius: 14px; border-top: 4px solid var(--gold); width: 400px; text-align: center; box-shadow: 0 20px 50px rgba(31,58,95,0.15); }
.logo-login { max-width: 170px; margin-bottom: 18px; }
.login-header h2 { font-family: var(--font-display); color: var(--primary); margin-bottom: 5px; }
.inspiration-text { font-family: var(--font-display); font-size: 0.95rem; color: var(--text-muted); font-style: italic; margin-bottom: 28px; line-height: 1.5; }

/* --- APP LAYOUT (MODIFICACIONES DE HEADER) --- */
#app-wrapper { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.app-header { background: #fff; padding: 15px 30px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); box-shadow: 0 2px 8px rgba(31,58,95,0.05); flex-shrink: 0; }
.logo-area { display: flex; align-items: center; gap: 15px; }
.logo-area h1 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; color: var(--primary); margin: 0; letter-spacing: 0.2px; }
.logo-area .subtitle { color: var(--gold); font-weight: 500; letter-spacing: 0.4px; }
.logo-area .fa-heart-pulse { color: var(--gold); font-size: 1.5rem; }
.header-main-logo { height: 50px; width: auto; object-fit: contain; } /* Asegura la proporción del logo */

.user-area { display: flex; align-items: center; gap: 20px; }
.user-info { display: flex; flex-direction: column; text-align: right; max-width: 540px; }
#texto-bienvenida { font-family: var(--font-display); font-weight: 600; color: var(--primary); font-size: 1.05rem; }
#subtexto-bienvenida.inspirational-greeting { font-size: 0.8rem; }
.inspirational-greeting { font-family: var(--font-display); font-size: 0.95rem; font-style: italic; color: var(--primary); font-weight: 500; line-height: 1.3; }

.nav-bar { background: var(--primary-deep); padding: 8px 20px; display: flex; gap: 10px; flex-shrink: 0; overflow-x: auto;}
.nav-btn { color: rgba(255,255,255,0.75); background: transparent; border: none; padding: 10px 15px; cursor: pointer; border-radius: 6px; font-weight: 500; display: flex; align-items: center; gap: 8px; transition: all 0.2s; white-space: nowrap; font-family: var(--font-body); }
.nav-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-btn.active { background: var(--gold); color: #fff; }
body[data-rol="psicologo"] .admin-only { display: none !important; }

/* --- BANNER PACIENTE ACTIVO (HUD GLOBAL) --- */
.active-banner { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%); color: white; padding: 15px 30px; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 10px rgba(0,0,0,0.15); border-bottom: 3px solid var(--gold); animation: slideDown 0.3s ease-out; flex-shrink: 0; }
@keyframes slideDown { from { transform: translateY(-10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.ap-info-wrapper { display: flex; align-items: center; gap: 20px; }
.ap-avatar { width: 50px; height: 50px; background: rgba(255,255,255,0.15); border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1.5rem; color: var(--gold); }
.ap-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 1px; opacity: 0.8; margin-bottom: 2px; display: block; }
.ap-name { margin: 0; font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; }
.ap-details { font-size: 0.85rem; opacity: 0.9; margin-top: 3px; display: block; }
.btn-close-patient { background: transparent; border: 1px solid rgba(255,255,255,0.4); color: white; border-radius: 6px; padding: 8px 15px; cursor: pointer; transition: 0.2s; font-size: 0.85rem; display: flex; align-items: center; gap: 8px; font-weight: bold;}
.btn-close-patient:hover { background: rgba(255,255,255,0.15); border-color: white; color: #fff; }

/* --- WORKSPACE & GRID SYSTEM --- */
.workspace { padding: 20px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; background: var(--bg-app); }
.grid-3-cols { display: grid; grid-template-columns: 320px 1fr 350px; gap: 20px; flex: 1; min-height: 600px; }
.grid-2-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; flex: 1; min-height: 600px; }
.grid-2-cols-aside { display: grid; grid-template-columns: 350px 1fr; gap: 20px; flex: 1; min-height: 600px; }

.card { background: var(--bg-card); padding: 20px; border-radius: 10px; border: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; height: 100%; box-shadow: 0 2px 10px rgba(31,58,95,0.04); }

/* --- SCROLLBARS ELEGANTES --- */
.lista-scrollable { flex: 1; overflow-y: auto; min-height: 0; padding-right: 5px; }
.lista-scrollable::-webkit-scrollbar { width: 6px; }
.lista-scrollable::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.lista-scrollable::-webkit-scrollbar-track { background: transparent; }

.header-actions { display: flex; gap: 10px; margin-bottom: 15px; align-items: center; justify-content: space-between; flex-shrink: 0; }
.col-title { font-family: var(--font-display); color: var(--primary); margin: 0 0 15px 0; font-size: 1.1rem; font-weight: 600; border-bottom: 2px solid var(--bg-app); padding-bottom: 10px; }

/* --- LISTADO DE PACIENTES --- */
.patient-item { padding: 12px; cursor: pointer; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); transition: background 0.2s; border-left: 4px solid transparent; }
.patient-item:hover { background: var(--bg-card); }
.patient-item.selected { background: #eef2ea; border-left-color: var(--primary); }
.pt-av { width: 40px; height: 40px; background: var(--primary); color: white; border-radius: 50%; display: flex; justify-content: center; align-items: center; font-size: 1.2rem; flex-shrink:0; }
.pt-info { display: flex; flex-direction: column; }
.pt-name { font-weight: 600; font-size: 13px; color: var(--text); }
.pt-rut { font-size: 11px; color: var(--text-muted); }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 20px; font-style: italic; }
.empty-state i { font-size: 3rem; color: #ccc; margin-bottom: 15px; display: block; }

/* --- COMPONENTES VISUALES --- */
.biblia-card { background: linear-gradient(180deg, #fffdf8 0%, #fbfaf6 100%); border: 1px solid var(--border); padding: 20px 22px; border-radius: 10px; margin-bottom: 16px; border-left: 4px solid var(--gold); box-shadow: 0 2px 8px rgba(184,144,47,0.06); }
.biblia-title { color: var(--gold); margin: 0 0 8px 0; font-size: 1.05rem; font-family: var(--font-display); font-weight: 600; letter-spacing: 0.3px; }
.biblia-text { font-size: 15px; margin: 8px 0 0 0; font-style: italic; color: var(--text); font-family: var(--font-display); line-height: 1.7; }
.biblia-theme-chip { padding: 7px 16px; font-size: 0.82rem; border: 1px solid var(--border); background: var(--bg-card); color: var(--primary); border-radius: 20px; cursor: pointer; transition: all 0.15s; font-weight: 500; }
.biblia-theme-chip:hover { background: var(--gold); color: #fff; border-color: var(--gold); transform: translateY(-1px); }
.biblia-search-hero { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-deep) 100%); border-radius: 12px; padding: 28px 30px; text-align: center; }
.biblia-search-hero input { width: 100%; max-width: 640px; padding: 14px 20px; border-radius: 30px; border: none; font-size: 1rem; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
.biblia-search-hero h2 { font-family: var(--font-display); color: #fff; font-size: 1.3rem; margin: 0 0 16px 0; font-weight: 600; }
.biblia-search-hero h2 i { color: var(--gold); }
.biblia-context { background: var(--bg-app); padding: 8px; border-radius: 4px; font-size: 11px; color: var(--text-muted); }

.data-table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 0.9rem; }
.data-table th { text-align: left; padding: 10px; border-bottom: 2px solid var(--primary); color: var(--primary); position: sticky; top: 0; background: white; z-index: 10; }
.data-table td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:hover td { background-color: var(--bg-card); }
.val-pos { color: var(--success); font-weight: bold; }
.badge-valor { background: #e8f5e9; color: #00695c; padding: 4px 8px; border-radius: 12px; font-weight: bold; font-size: 0.85rem; }

.dashboard-widget { background: #eef2ea; padding: 25px; border-radius: 10px; margin-top: 20px; text-align: center; border: 1px solid var(--border); }
.dashboard-widget .value { font-family: var(--font-display); font-size: 2.5rem; font-weight: 700; color: var(--primary); margin-top: 10px; }
.info-box { background: #eef2ea; padding: 12px; border-radius: 6px; font-size: 12px; margin-bottom: 15px; color: var(--primary); line-height: 1.5; border-left: 4px solid var(--secondary); }
.preview-box { background: white; border: 1px solid #ccc; padding: 30px; min-height: 500px; box-shadow: 0 4px 10px rgba(0,0,0,0.05); }

/* --- FORMULARIOS --- */
.form-group { margin-bottom: 15px; }
.form-group.full-grid { grid-column: 1 / -1; }
.form-group label { display: block; font-weight: 600; font-size: 0.85rem; color: var(--primary); margin-bottom: 5px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-family: inherit; transition: border 0.3s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(11, 67, 123, 0.1); }
.readonly-input { background-color: #e9ecef; cursor: not-allowed; border-color: #ddd; color: #666;}
.search-input { flex: 1; padding: 10px; border: 1px solid #ccc; border-radius: 4px; }
.ficha-textarea { width: 100%; min-height: 190px; border: 1px solid #ccc; border-radius: 4px; padding: 14px; resize: vertical; line-height: 1.6; font-size: 0.95rem; }
.short-textarea { min-height: 140px; resize: vertical; }
.editor-textarea { font-family: monospace; font-size: 13px; background: #282c34; color: #abb2bf; border-radius: 4px; border:none; padding:15px; min-height: 300px; width: 100%; resize: none; }
.full-select { width: 100%; padding: 8px; border-radius: 4px; border: 1px solid #ccc; }

/* --- BOTONES --- */
button { font-family: var(--font-body); font-size: 0.9rem; transition: opacity 0.2s, transform 0.1s, box-shadow 0.2s; }
button:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-primary:hover { box-shadow: 0 4px 12px rgba(31,58,95,0.25); }
.btn-secondary { background: var(--secondary); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-danger { background: var(--danger); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-success { background: var(--success); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-warning { background: var(--gold); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-outline { background: white; border: 1.5px solid var(--primary); color: var(--primary); padding: 10px 15px; border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn-outline:hover { background: var(--bg-app); }
.btn-icon { padding: 8px 12px; }
.fluid-btn { width: 100%; display: block; text-align: center; margin-bottom: 10px; }
.button-group { display: flex; gap: 10px; }
.button-group button { flex: 1; }
.disabled-actions { opacity: 0.5; pointer-events: none; }
.status-indicator { font-size: 0.85rem; color: var(--secondary); font-weight: 500; }

/* --- MODALES GLOBALES --- */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.6); display: none; justify-content: center; align-items: center; z-index: 2000; backdrop-filter: blur(3px); }
.modal-overlay.active { display: flex; }
.modal-content { background: white; border-radius: 8px; width: 100%; max-width: 650px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,0.2); animation: modalIn 0.3s ease-out; }
@keyframes modalIn { from { transform: translateY(-20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: var(--bg-app); border-radius: 8px 8px 0 0; flex-shrink:0; }
.modal-header.arrastrable { cursor: move; user-select: none; }
.modal-content.siendo-arrastrado { position: fixed; margin: 0; animation: none; }
.modal-header h2 { margin: 0; color: var(--primary); font-size: 1.2rem; }
.close-btn { background: transparent; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-muted); }
.close-btn:hover { color: var(--danger); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; background: var(--bg-app); border-radius: 0 0 8px 8px; flex-shrink:0; }