/* ==========================================================================
   CONSULTOR DE TÉCNICAS COGNITIVAS (TCC) - ROBERT L. LEAHY, PH.D.
   IDENTIDAD VISUAL, PALETA Y TIPOGRAFÍA OFICIAL SRS-2 (TEMA CLARO ARMONIZADO)
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    /* Tipografía Oficial SRS-2 */
    --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

    /* ==========================================================================
       PALETA OFICIAL SRS-2 - TEMA CLARO (FONDO BLANCO POR DEFECTO)
       ========================================================================== */
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #f5f3ff;
    --primary-alpha: rgba(99, 102, 241, 0.08);
    --primary-alpha-25: rgba(99, 102, 241, 0.18);

    --secondary: #ec4899;
    --secondary-hover: #db2777;
    --secondary-alpha: rgba(236, 72, 153, 0.08);

    --accent: #6366f1;
    --accent-alpha: rgba(99, 102, 241, 0.08);

    /* Fondos Limpios (Fondo Blanco Luminoso SRS-2) */
    --bg-app: #f8fafc;
    --bg-canvas: #ffffff;
    --bg-surface: #ffffff;
    --bg-card: rgba(255, 255, 255, 0.96);
    --card-bg: rgba(255, 255, 255, 0.96);
    --bg-card-hover: #ffffff;
    --bg-input: #ffffff;
    --border-color: rgba(226, 232, 240, 0.85);
    --border-subtle: rgba(226, 232, 240, 0.5);
    --border-light: #e2e8f0;
    --card-border: rgba(226, 232, 240, 0.8);

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --text-main: #0f172a;

    /* Jerarquías Clínicas Leahy Armonizadas */
    --tier-first: #10b981;
    --tier-first-border: #10b981;
    --tier-first-bg: rgba(16, 185, 129, 0.08);

    --tier-second: #6366f1;
    --tier-second-border: #6366f1;
    --tier-second-bg: rgba(99, 102, 241, 0.08);

    --tier-schema: #ec4899;
    --tier-schema-border: #ec4899;
    --tier-schema-bg: rgba(236, 72, 153, 0.08);

    --success: #10b981;
    --success-light: #ecfdf5;
    --success-alpha: rgba(16, 185, 129, 0.1);

    --danger: #ef4444;
    --danger-light: #fef2f2;
    --danger-alpha: rgba(239, 68, 68, 0.1);

    --warning: #f59e0b;
    --warning-alpha: rgba(245, 158, 11, 0.1);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.02);
    --shadow-lg: 0 10px 25px -5px rgba(99, 102, 241, 0.08), 0 8px 10px -6px rgba(99, 102, 241, 0.04);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    --glass-blur: blur(12px);
    --transition-fast: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   PALETA SRS-2 DARK MODE (DISPONIBLE CON EL BOTÓN DE ALTERNAR)
   ========================================================================== */
[data-theme="dark"],
body.dark-mode {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-light: #1e1b4b;
    --primary-alpha: rgba(129, 140, 248, 0.15);
    --primary-alpha-25: rgba(129, 140, 248, 0.25);

    --secondary: #f472b6;
    --secondary-hover: #ec4899;
    --secondary-alpha: rgba(244, 114, 182, 0.15);

    --accent: #818cf8;
    --accent-alpha: rgba(129, 140, 248, 0.15);

    --bg-app: #0b0f19;
    --bg-canvas: #0f172a;
    --bg-surface: #111827;
    --bg-card: rgba(17, 24, 39, 0.78);
    --card-bg: rgba(17, 24, 39, 0.75);
    --bg-card-hover: rgba(30, 41, 59, 0.85);
    --bg-input: rgba(255, 255, 255, 0.04);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-subtle: rgba(255, 255, 255, 0.04);
    --border-light: rgba(255, 255, 255, 0.08);
    --card-border: rgba(255, 255, 255, 0.05);

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-main: #f8fafc;

    --tier-first: #34d399;
    --tier-first-border: #34d399;
    --tier-first-bg: rgba(52, 211, 153, 0.12);

    --tier-second: #818cf8;
    --tier-second-border: #818cf8;
    --tier-second-bg: rgba(129, 140, 248, 0.12);

    --tier-schema: #f472b6;
    --tier-schema-border: #f472b6;
    --tier-schema-bg: rgba(244, 114, 182, 0.12);

    --success: #34d399;
    --success-light: #064e3b;
    --success-alpha: rgba(52, 211, 153, 0.15);

    --danger: #f87171;
    --danger-light: #450a0a;
    --danger-alpha: rgba(248, 113, 113, 0.15);

    --warning: #fbbf24;
    --warning-alpha: rgba(251, 191, 36, 0.15);

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */

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

body {
    font-family: var(--font-body);
    background-color: var(--bg-app);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ==========================================================================
   CABECERA SUPERIOR (ESTILO SRS-2)
   ========================================================================== */

.app-header {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 0.95rem 2rem;
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.brand-area {
    display: flex;
    align-items: center;
    gap: 0.95rem;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    color: #ffffff;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
}

.brand-title h1 {
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: -0.3px;
    line-height: 1.15;
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-title p {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* ==========================================================================
   BOTONES Y ELEMENTOS DE ACCIÓN (SRS-2)
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.15rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    border: 1px solid transparent;
    transition: var(--transition-fast);
    text-decoration: none;
    line-height: 1.2;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff !important;
    box-shadow: 0 2px 8px var(--primary-alpha);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px var(--primary-alpha-25);
}

.btn-secondary {
    background: var(--primary-alpha);
    border: 1px solid var(--primary-alpha);
    color: var(--primary);
}

.btn-secondary:hover {
    background: var(--primary);
    color: #ffffff;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-alpha);
}

.btn-danger {
    background: var(--danger-alpha);
    color: var(--danger);
    border: 1px solid var(--danger-alpha);
}

.btn-danger:hover {
    background: var(--danger);
    color: #ffffff;
}

.btn-sm {
    padding: 0.38rem 0.75rem;
    font-size: 0.78rem;
}

/* Botón Especial de IA con Degradado SRS-2 */
.ai-hero-btn {
    background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
    color: #ffffff !important;
    border: none;
    font-family: var(--font-heading);
    font-weight: 700;
    padding: 0.65rem 1.25rem;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.25);
    transition: var(--transition-fast);
    text-decoration: none;
}

.ai-hero-btn:hover {
    opacity: 0.94;
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}

/* Píldora de Estado de IA estilo Badge SRS-2 */
.ai-status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 700;
    padding: 0.35rem 0.85rem;
    border-radius: var(--radius-sm);
    background: var(--primary-alpha);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--primary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.ai-status-pill:hover {
    background: var(--primary-alpha-25);
    transform: translateY(-1px);
}

/* ==========================================================================
   BANNER HERO DE CONSULTA POR MOTIVO DEL PACIENTE (SRS-2)
   ========================================================================== */

.consult-hero {
    background: linear-gradient(180deg, var(--bg-surface) 0%, var(--bg-app) 100%);
    border-bottom: 1px solid var(--border-color);
    padding: 2.25rem 2rem 1.85rem 2rem;
}

.consult-hero-inner {
    max-width: 1180px;
    margin: 0 auto;
}

.hero-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.hero-header h2 {
    font-family: var(--font-heading);
    font-size: 1.85rem;
    font-weight: 800;
    letter-spacing: -0.4px;
    margin-bottom: 0.4rem;
    background: linear-gradient(135deg, var(--text-primary) 30%, var(--primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero-header p {
    font-family: var(--font-body);
    color: var(--text-secondary);
    font-size: 0.92rem;
    max-width: 760px;
    margin: 0 auto;
    line-height: 1.5;
}

/* Buscador Principal */
.search-box-wrapper {
    position: relative;
    max-width: 860px;
    margin: 0 auto 1.25rem auto;
}

.search-input {
    width: 100%;
    padding: 1.05rem 3.5rem 1.05rem 1.35rem;
    font-size: 1rem;
    font-family: var(--font-body);
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    transition: var(--transition-fast);
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-alpha), 0 8px 24px rgba(0, 0, 0, 0.2);
    background: var(--bg-surface);
}

.search-clear-btn {
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    line-height: 1;
    display: none;
}

.search-clear-btn:hover {
    color: var(--danger);
}

/* Chips de Síntomas / Problemáticas (Estilo Version-btn de SRS-2) */
.symptom-chips-container {
    max-width: 1020px;
    margin: 0 auto;
}

.symptom-chips-title {
    font-family: var(--font-heading);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    font-weight: 700;
    margin-bottom: 0.75rem;
    text-align: center;
}

.symptom-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.chip {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.45rem 0.95rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-fast);
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.chip:hover {
    background: var(--primary-alpha);
    color: var(--primary);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.chip.active {
    background: var(--primary);
    color: #ffffff !important;
    border-color: var(--primary);
    box-shadow: 0 2px 8px var(--primary-alpha);
}

/* ==========================================================================
   PESTAÑAS DE NAVEGACIÓN (SRS-2 MODE-TOGGLE)
   ========================================================================== */

.nav-tabs {
    display: flex;
    gap: 0.4rem;
    background: var(--primary-alpha);
    padding: 0.35rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    width: fit-content;
}

.nav-tab-btn {
    padding: 0.55rem 1.15rem;
    font-size: 0.85rem;
    font-weight: 700;
    font-family: var(--font-heading);
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.nav-tab-btn:hover {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
}

.nav-tab-btn.active {
    background: var(--primary);
    color: #ffffff !important;
    box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   LAYOUT PRINCIPAL: CONTENIDO + PLAN DE SESIÓN
   ========================================================================== */

.main-layout {
    max-width: 1440px;
    margin: 0 auto;
    padding: 1.75rem 2rem;
    display: grid;
    grid-template-columns: 1fr 310px;
    gap: 1.5rem;
    align-items: start;
}

@media (max-width: 992px) {
    .main-layout {
        grid-template-columns: 1fr;
        padding: 1rem;
    }
}

.content-area {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ==========================================================================
   PANEL LATERAL: PLAN DE SESIÓN (ESTILO SRS-2)
   ========================================================================== */

.session-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.35rem;
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-lg);
    position: sticky;
    top: 5rem;
}

.session-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.85rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.session-header h3 {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.session-badge {
    background: var(--primary);
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 800;
}

.session-list {
    max-height: 420px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 1rem;
}

.session-item {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: var(--transition-fast);
}

.session-item:hover {
    border-color: var(--primary);
    background: var(--primary-alpha);
}

.session-item-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-remove-session {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

.btn-remove-session:hover {
    color: #ffffff;
}

.session-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* ==========================================================================
   RESUMEN CLÍNICO PRESCRIPTIVO Y TIERS
   ========================================================================== */

.clinical-summary-box {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 5px solid var(--primary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-sm);
}

.clinical-summary-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--primary);
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.clinical-summary-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.match-tag {
    font-family: var(--font-heading);
    font-size: 0.76rem;
    font-weight: 700;
    background: var(--primary-alpha);
    color: var(--primary);
    padding: 3px 9px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.clinical-summary-desc {
    font-size: 0.88rem;
    line-height: 1.55;
    color: var(--text-primary);
}

.tier-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: var(--glass-blur);
    box-shadow: var(--shadow-sm);
}

.tier-section.firstLine { border-left: 5px solid var(--tier-first); }
.tier-section.secondLine { border-left: 5px solid var(--tier-second); }
.tier-section.schemaLevel { border-left: 5px solid var(--tier-schema); }

.tier-header {
    margin-bottom: 1.25rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
}

.tier-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.tier-count {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.tier-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ==========================================================================
   TARJETAS DE TÉCNICAS (ESTILO SRS-2)
   ========================================================================== */

.techniques-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.1rem;
}

.tech-card {
    background: var(--bg-card);
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.tech-card:hover {
    border-color: var(--primary);
    background: var(--primary-alpha);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tech-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.65rem;
}

.tech-code {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.82rem;
    color: var(--primary);
    background: var(--primary-alpha);
    padding: 3px 8px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.tech-chapter-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 4px;
}

.tech-title {
    font-family: var(--font-heading);
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.45rem;
    line-height: 1.35;
}

.tech-excerpt {
    font-size: 0.83rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 1.1rem;
    flex-grow: 1;
}

.tech-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color);
    gap: 8px;
}

.tech-level-badge {
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--primary-alpha);
    padding: 2px 8px;
    border-radius: 4px;
}

.btn-card-action {
    padding: 0.35rem 0.65rem;
    font-size: 0.78rem;
    font-weight: 700;
    font-family: var(--font-heading);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-card-action:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.btn-card-action.added {
    background: var(--success-alpha);
    color: var(--success);
    border-color: var(--success);
}

/* ==========================================================================
   BARRA DE FILTROS DE CATÁLOGO Y FORMATOS
   ========================================================================== */

.filters-bar {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    background: var(--bg-card);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    align-items: center;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.filter-select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 0.5rem 0.85rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-body);
    font-size: 0.85rem;
    outline: none;
    cursor: pointer;
}

.filter-select:focus {
    border-color: var(--primary);
}

/* ==========================================================================
   MODAL DE DETALLE Y FORMATOS (SRS-2)
   ========================================================================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1.5rem;
}

.modal-overlay.active {
    display: flex;
}

.modal-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 960px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    padding: 1.25rem 1.75rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
}

.modal-title-wrap h3 {
    font-family: var(--font-heading);
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-primary);
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.75rem;
    cursor: pointer;
    line-height: 1;
}

.modal-close-btn:hover {
    color: var(--danger);
}

.modal-body {
    padding: 1.5rem 1.75rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 1.1rem 1.75rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    background: var(--bg-surface);
}

.modal-tabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 1.75rem;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
}

.modal-tab-btn {
    padding: 0.7rem 1rem;
    font-size: 0.82rem;
    font-weight: 700;
    font-family: var(--font-heading);
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.modal-tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.modal-tab-content {
    display: none;
    font-size: 0.9rem;
    line-height: 1.6;
}

.modal-tab-content.active {
    display: block;
}

/* ==========================================================================
   FORMATOS CLÍNICOS E HOJAS DE TRABAJO (LEAHY DENTRO DEL MODAL)
   ========================================================================== */

.clinical-form-wrapper {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    color: var(--text-primary);
}

.clinical-form-header {
    border-bottom: 2px solid var(--border-color);
    padding-bottom: 1.25rem;
    margin-bottom: 1.5rem;
}

.clinic-logo-text .badge-tech-code {
    background: var(--primary);
    color: #ffffff;
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.85rem;
}

.clinic-logo-text .manual-title {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    text-transform: uppercase;
}

.clinical-form-title {
    font-family: var(--font-heading);
    font-size: 1.35rem;
    font-weight: 800;
    color: var(--text-primary);
    margin: 0.25rem 0;
}

.clinical-form-subtitle {
    font-size: 0.88rem;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 1rem;
}

.patient-metadata-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    background: var(--bg-input);
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 1rem;
}

.patient-metadata-grid .meta-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.patient-metadata-grid .meta-field.full-width {
    grid-column: 1 / -1;
}

.patient-metadata-grid label {
    font-family: var(--font-heading);
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.form-control-underline {
    background: transparent;
    border: none;
    border-bottom: 1px dashed var(--border-color);
    color: var(--text-primary);
    font-size: 0.9rem;
    padding: 4px 0;
    outline: none;
    width: 100%;
}

.form-control-underline:focus {
    border-bottom-color: var(--primary);
}

.clinical-instructions-alert {
    display: flex;
    gap: 10px;
    background: var(--primary-alpha);
    border-left: 4px solid var(--primary);
    padding: 0.85rem 1rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: 0.88rem;
    line-height: 1.45;
}

/* Tablas Clínicas */
.form-table-container {
    overflow-x: auto;
    margin: 1.25rem 0;
}

.clinical-worktable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.clinical-worktable th {
    background: var(--primary-alpha);
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    font-family: var(--font-heading);
    font-weight: 700;
    text-align: left;
    color: var(--primary);
}

.clinical-worktable td {
    border: 1px solid var(--border-color);
    padding: 8px 10px;
    vertical-align: top;
}

.form-control-cell {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.88rem;
    resize: vertical;
    outline: none;
}

.btn-cell-delete {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1.25rem;
    cursor: pointer;
    line-height: 1;
}

/* Diseños A-B-C, Flecha Descendente, Costos-Beneficios */
.abc-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin: 1rem 0;
}

.abc-box {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
}

.abc-box .abc-header {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 800;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
}

.box-a .abc-header { color: #6366f1; }
.box-b .abc-header { color: #f59e0b; }
.box-c .abc-header { color: #ec4899; }

.downward-arrow-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 1.25rem 0;
}

.arrow-step {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.85rem;
}

.arrow-down-icon {
    text-align: center;
    font-size: 0.85rem;
    color: var(--primary);
    margin-top: 8px;
    font-weight: 700;
}

.cost-benefit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin: 1rem 0;
}

.cb-column {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
}

.advantages-col { border: 1px solid #a7f3d0; border-top: 1px solid #d1fae5; border-bottom: 2px solid #059669; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }
.disadvantages-col { border: 1px solid #fecaca; border-top: 1px solid #fee2e2; border-bottom: 2px solid #dc2626; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,0.03); }

.cb-header {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

.advantages-col .cb-header { color: var(--success); }
.disadvantages-col .cb-header { color: var(--danger); }

.signatures-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    margin-top: 2.5rem;
    text-align: center;
}

.signature-box .sig-line {
    border-bottom: 1px solid var(--text-muted);
    margin-bottom: 8px;
}

.signature-box span {
    font-size: 0.78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

/* ==========================================================================
   ANÁLISIS PROFUNDO CON IA (ESTILO SRS-2)
   ========================================================================== */

.ai-formulation-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.ai-section-title {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.distortion-chips-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 1.25rem;
}

.distortion-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    color: white;
}

.maintenance-cycle-box {
    background: var(--bg-input);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin: 1rem 0;
    font-size: 0.88rem;
    line-height: 1.5;
}

.phased-plan-timeline {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin: 1.5rem 0;
}

.phase-card {
    background: var(--bg-input);
    border-left: 4px solid var(--primary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 1rem 1.25rem;
}

.phase-header {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 1rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.phase-goal {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.phase-tech-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.phase-tech-pill {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 0.82rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.llm-narrative-output {
    background: var(--bg-input);
    border: 1px solid rgba(99, 102, 241, 0.3);
    border-radius: var(--radius-sm);
    padding: 1.25rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
    white-space: pre-wrap;
    color: var(--text-primary);
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3.5rem 1.5rem;
    background: var(--bg-card);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
}

.empty-state-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.empty-state-title {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 800;
    color: var(--text-primary);
    margin-bottom: 0.35rem;
}

.empty-state-desc {
    font-size: 0.88rem;
    color: var(--text-secondary);
    max-width: 520px;
    margin: 0 auto;
    line-height: 1.5;
}

/* ==========================================================================
   REGLAS DE IMPRESIÓN PROFESIONAL (@media print)
   ========================================================================== */

@media print {
    body {
        background: #ffffff !important;
        color: #000000 !important;
        padding: 0 !important;
    }

    header, nav, aside, .consult-hero, .filters-bar, .modal-footer, .no-print,
    .search-box-wrapper, .symptom-chips-container, .modal-close-btn, .modal-tabs,
    .header-actions, .session-panel, #aiStatusPill, .btn, button {
        display: none !important;
    }

    .modal-overlay {
        position: static !important;
        background: transparent !important;
        display: block !important;
        padding: 0 !important;
    }

    .modal-dialog {
        width: 100% !important;
        max-width: 100% !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #ffffff !important;
        color: #000000 !important;
    }

    .clinical-form-wrapper {
        border: 1px solid #000000 !important;
        background: #ffffff !important;
        color: #000000 !important;
        padding: 20px !important;
        border-radius: 0 !important;
    }

    .clinical-worktable th {
        background: #f1f5f9 !important;
        color: #000000 !important;
        border: 1px solid #000000 !important;
    }

    .clinical-worktable td {
        border: 1px solid #000000 !important;
        color: #000000 !important;
    }

    .form-control-cell, .form-control, .form-control-underline {
        color: #000000 !important;
    }

    .patient-metadata-grid, .abc-box, .arrow-step, .cb-column {
        background: #fafafa !important;
        border: 1px solid #000000 !important;
        color: #000000 !important;
    }
}
