/* --- FUENTES Y VARIABLES GLOBALES --- */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans:wght@400;500;700&display=swap');
:root { --main-red: #B92F32; --main-blue: #1D3557; --accent-blue: #457B9D; --system-bubble-bg: #f7f9fc; --user-bubble-bg: #1D3557; --text-color: #111; --border-color: #e9ecef; --light-gray-bg: #f1f5f9; --medium-gray-text: #475569; }

#pida-header-title { display: none; }

/* ESTILOS PARA LA SECCIÓN DE PERFIL DE USUARIO */
#pida-user-profile {
    position: fixed;
    top: 20px;
    right: 30px;
    z-index: 10002;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 15px;
    font-family: 'Noto Sans', sans-serif;
}
.pida-user-details { display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
.pida-user-name { font-weight: 700; font-size: 15px; color: var(--main-blue); }
.pida-user-email { font-size: 12px; color: var(--medium-gray-text); margin-top: -8px; }
.pida-logout-link { font-size: 15px; color: var(--accent-blue); text-decoration: none; margin-top: -8px; text-align: right; }
.pida-logout-link:hover { text-decoration: none; }
.pida-avatar-container { display: flex; flex-direction: column; align-items: stretch; }
#pida-user-profile .avatar { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--border-color); margin-bottom: 8px; align-self: center; }

/* --- LAYOUT PRINCIPAL (REESTRUCTURADO CON GRID) --- */
#pida-app-layout {
    font-family: 'Noto Sans', sans-serif;
    display: grid; /* <-- CAMBIO CLAVE */
    grid-template-rows: 80px 1fr; /* <-- CAMBIO CLAVE: Fila superior de 80px, el resto flexible */
    grid-template-columns: auto 1fr; /* <-- CAMBIO CLAVE: Columna para sidebar, el resto para contenido */
    position: fixed;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background: #fff;
    z-index: 9999;
}

/* --- BARRA LATERAL --- */
#pida-sidebar {
    grid-row: 1 / 3; /* <-- CAMBIO CLAVE: Ocupa ambas filas */
    grid-column: 1 / 2; /* <-- CAMBIO CLAVE: Ocupa la primera columna */
    width: 260px; /* Ancho fijo */
    background-color: var(--system-bubble-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: margin-left .3s ease-in-out;
    position: relative;
    overflow-x: hidden;
    z-index: 10001; 
}
.pida-logo-container { padding: 1.5rem 1.5rem 1rem 1.5rem; text-align: center; border-bottom: 1px solid var(--border-color); }
.pida-sidebar-logo { max-width: 150px; height: auto; }
.pida-sidebar-content { flex-grow: 1; overflow-y: auto; }
.pida-sidebar-header { position: relative; padding: 1.5rem 1.5rem 0 1.5rem; }
.pida-sidebar-header h2 { font-size: 15px; color: var(--main-blue); font-weight: 700; margin: 0 0 1rem 0; }

/* --- NAVEGACIÓN PRINCIPAL --- */
.pida-main-nav { display: flex; flex-direction: column; gap: 0.5rem; padding: 1.5rem; border-bottom: 1px solid var(--border-color); }
.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem; border-radius: 8px;
    text-decoration: none; font-weight: 500; color: var(--medium-gray-text);
    transition: background-color 0.2s, color 0.2s;
    background: transparent; border: none; width: 100%;
    font-family: 'Noto Sans', sans-serif; cursor: pointer; text-align: left;
    font-size: 14px; white-space: normal; line-height: 1.4;
}
.nav-link:hover { background-color: #eef2f7; }
.nav-link.active { background-color: var(--main-blue); color: white; }
.nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }

/* Contenedor y Botones de Acción de la Barra Lateral */
.pida-sidebar-action-wrapper { padding: 0 1.5rem; margin-bottom: 1rem; }
.pida-sidebar-btn {
    width: 100%; padding: 10px; background: #fff;
    border: 1px solid var(--border-color); border-radius: 8px;
    font-size: 14px; color: var(--medium-gray-text); font-weight: 500;
    cursor: pointer; text-align: center; transition: background-color 0.2s;
}
.pida-sidebar-btn:hover { background-color: #eef2f7; }

/* --- SECCIÓN HISTORIAL --- */
#pida-history-list { margin-top: 0; padding: 0 1.5rem 1.5rem 1.5rem; }
.pida-history-item { 
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%; 
    padding: 10px 12px; 
    margin-bottom: 8px; 
    border: none; 
    background: transparent; 
    border-radius: 8px; 
    text-align: left; 
    color: #334155; 
    cursor: pointer; 
    transition: background-color 0.2s;
    font-size: 14px;
    overflow: hidden;
}
.pida-history-item:hover { background-color: #eef2f7; }
.pida-history-item.active { background-color: #e2e8f0; font-weight: 600; }
.pida-history-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
    padding-right: 1rem;
}
.pida-history-item:hover .remove-file-btn { 
    opacity: 1; 
    visibility: visible; 
}


/* --- CONTENIDO PRINCIPAL --- */
.hidden { display: none !important; }
#pida-main-content {
    grid-row: 2 / 3; /* <-- CAMBIO CLAVE: Empieza en la segunda fila */
    grid-column: 2 / 3; /* <-- CAMBIO CLAVE: Ocupa la segunda columna */
    position: relative;
    z-index: 1000;
    display: flex; flex-direction: column;
    overflow: hidden; background: #fff;
}
.pida-view { width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.pida-view-content { flex-grow: 1; overflow-y: auto; display: flex; flex-direction: column; padding: 1.5rem; } /* Se elimina el padding-top */
.pida-view-form { padding: 1.5rem; border-top: 1px solid var(--border-color); max-width: 900px; width: 100%; margin: 0 auto; box-sizing: border-box; flex-shrink: 0; background: #fff; }
#pida-chat-box { padding: 0; max-width: 900px; width: 100%; margin: 0 auto; gap: 15px; display: flex; flex-direction: column; }

/* --- COMPONENTES Y OTROS --- */
.pida-button-primary { flex-grow: 1; display: flex; justify-content: center; align-items: center; padding: 0.8rem 1.25rem; font-size: 15px; font-weight: 700; color: #ffffff; background-color: var(--accent-blue); border: none; border-radius: 8px; cursor: pointer; transition: background-color 0.2s ease; }
.pida-button-primary:hover { background-color: var(--main-blue); }
.pida-button-primary:disabled { background-color: #a0aec0; cursor: not-allowed; }
.pida-button-secondary { flex-shrink: 0; padding: 0.8rem 1.25rem; font-size: 15px; font-weight: 500; background-color: transparent; color: var(--medium-gray-text); border: 1px solid var(--border-color); border-radius: 8px; cursor: pointer; transition: background-color 0.2s ease, color 0.2s ease; }
.pida-button-secondary:hover { background-color: var(--light-gray-bg); color: var(--main-blue); }
.pida-textarea { display: block; width: 100%; min-height: 80px; padding: 0.75rem 1rem; font-size: 16px; font-family: 'Noto Sans', sans-serif; border: 1px solid var(--border-color); border-radius: 8px; resize: vertical; box-sizing: border-box; background: #fff; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.pida-form-actions { display: flex; gap: 0.75rem; margin-top: 1rem; }
.pida-disclaimer { font-size: 0.65rem !important; color: var(--medium-gray-text) !important; text-align: center !important; margin-top: 1rem !important; padding: 0 1rem !important; margin-bottom: 0 !important; display: block !important; width: 100% !important; line-height: 1; }

.pida-download-controls { display: none; text-align: right; padding-bottom: 1rem; justify-content: flex-end;}
.pida-download-controls button { background-color: var(--light-gray-bg); border: 1px solid var(--border-color); color: var(--medium-gray-text); border-radius: 8px; padding: 5px 15px; cursor: pointer; margin-left: 8px; font-size: 13px; font-weight: 500; transition: background-color 0.2s; }
.pida-download-controls button:hover { background-color: #e2e8f0; }

.follow-up-card{border-top:1px solid var(--border-color);padding:20px 0 5px;margin-top:15px;display:flex;flex-direction:column;gap:10px}
.follow-up-card h3{margin:0 0 10px;font-size:1.1em;color:var(--main-blue)}
.follow-up-btn{background-color:#fff;color:var(--main-blue);border:1px solid var(--border-color);border-radius:8px;padding:12px;text-align:left;cursor:pointer;transition:transform .2s ease,box-shadow .2s ease;font-size:14px}
.follow-up-btn:hover{transform:translateY(-2px);box-shadow:0 4px 8px rgba(0,0,0,.08)}

.user-message-bubble { background-color: var(--user-bubble-bg); color: white; align-self: flex-end; max-width: 90%; padding: 15px 20px; border-radius: 18px; border-bottom-right-radius: 4px; line-height: 1.6; font-size: 15px; word-wrap: break-word; }
.pida-message-bubble { align-self: flex-start; max-width: 90%; background-color: var(--system-bubble-bg); border: 1px solid var(--border-color); color: var(--text-color); padding: 15px 20px; border-radius: 18px; border-bottom-left-radius: 4px; text-align: left; line-height: 1.6; font-size: 14px; word-wrap: break-word; box-sizing: border-box; }
blockquote{border-left:4px solid var(--accent-blue);margin:1.2em 0;padding:.5em 15px;background-color:#fdfdff;border-radius:4px}
.pida-message-bubble a{color:var(--main-blue)!important;text-decoration:underline}

/* --- ESTILOS ESPECÍFICOS DEL ANALIZADOR --- */
#analyzer-file-list-container { padding: 0 1.5rem; }
#analyzer-file-list { margin-top: 0.5rem; display: flex; flex-direction: column; gap: 0.5rem; list-style: none; padding-left: 0; }
#analyzer-file-list li { display: flex; align-items: center; justify-content: space-between; background-color: #f1f5f9; padding: 0.5rem; border-radius: 0.375rem; font-size: 0.875rem; overflow: hidden; }
.pida-filename { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; padding-right: 1rem; flex-grow: 1; }
.remove-file-btn { background: transparent; border: none; color: #9ca3af; cursor: pointer; padding: 0.25rem; border-radius: 9999px; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s, color 0.2s; opacity: 0; visibility: hidden; }
.remove-file-btn:hover { background-color: #fee2e2; color: #ef4444; }
.remove-file-btn svg { width: 1rem; height: 1rem; }
.loader { border: 4px solid #f3f3f3; border-top: 4px solid var(--main-blue); border-radius: 50%; width: 40px; height: 40px; animation: spin 1s linear infinite; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

#analyzer-results-section {
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}
#analyzer-analysis-result {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-color);
    text-align: left;
    word-wrap: break-word;
}
#analyzer-analysis-result h1,
#analyzer-analysis-result h2,
#analyzer-analysis-result h3 {
    color: var(--main-blue);
    margin-top: 1.5em;
    margin-bottom: 0.5em;
    line-height: 1.3;
}
#analyzer-analysis-result p {
    margin-bottom: 1em;
}
#analyzer-analysis-result ul,
#analyzer-analysis-result ol {
    padding-left: 25px;
    margin-bottom: 1em;
}
#analyzer-analysis-result li {
    margin-bottom: 0.5em;
}
#analyzer-analysis-result blockquote {
    border-left: 4px solid var(--accent-blue);
    margin: 1.5em 0;
    padding: 0.5em 20px;
    background-color: #fdfdff;
    border-radius: 4px;
}
#analyzer-analysis-result a {
    color: var(--main-blue) !important;
    text-decoration: underline;
}

/* --- LÓGICA DE COLAPSO (DESKTOP) --- */
#pida-collapse-btn { 
    position: absolute; top: 1.5rem; right: -15px; 
    width: 30px; height: 30px; background: #fff; 
    border: 1px solid var(--border-color); border-radius: 50%; 
    cursor: pointer; padding: 5px; opacity: 1; 
    transition: opacity 0.2s, right .3s ease-in-out; 
    display: flex; align-items: center; justify-content: center;
    z-index: 1002;
}
#pida-collapse-btn:hover { background-color: var(--light-gray-bg); }
#pida-collapse-btn svg { stroke: #64748B; }
.icon-expand { display: none; }
#pida-app-layout.sidebar-collapsed #pida-sidebar { margin-left: -210px; }
#pida-app-layout.sidebar-collapsed .icon-collapse { display: none; }
#pida-app-layout.sidebar-collapsed .icon-expand { display: block; }
#pida-app-layout.sidebar-collapsed #pida-collapse-btn { right: -15px; }

/* --- AJUSTES PARA MÓVIL (SOLUCIÓN DEFINITIVA) --- */
@media (max-width: 768px) {
    /* --- ESTRUCTURA Y ESTILOS BASE (SIN CAMBIOS) --- */
    #pida-user-profile {
        top: 15px;
        right: 15px;
    }
    #pida-app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 90px 1fr;
    }
    #pida-main-content {
        grid-column: 1 / 2;
    }
    .pida-view-content {
        padding-top: 0 !important;
    }
    #pida-sidebar {
        position: absolute;
        height: 100%;
        width: 80%;
        max-width: 300px;
        box-shadow: 2px 0 15px rgba(0,0,0,0.1);
        margin-left: -305px;
        /* Se elimina z-index de aquí para un control más específico abajo */
    }
    #pida-app-layout:not(.sidebar-open-mobile) .icon-collapse { display: none; }
    #pida-app-layout:not(.sidebar-open-mobile) .icon-expand { display: block; }
    #pida-app-layout.sidebar-open-mobile .icon-collapse { display: block; }
    #pida-app-layout.sidebar-open-mobile .icon-expand { display: none; }
    .pida-view-form, .pida-view-header {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    /* --- LÓGICA DE CAPAS CORREGIDA --- */

    /* 1. Botón de ABRIR (hamburguesa): Se posiciona sobre el perfil para ser siempre clickeable. */
    #pida-collapse-btn {
        position: fixed;
        top: 15px;
        left: 15px;
        right: auto;
        width: 40px;
        height: 40px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        z-index: 10003; /* ✅ Superior al z-index: 10002 del perfil. */
    }

    /* 2. Cuando el menú se ABRE, todo el layout se eleva por encima del perfil. */
    /* Esto oculta el perfil temporalmente, pero es necesario para que el menú sea funcional. */
    #pida-app-layout.sidebar-open-mobile {
        z-index: 10010; /* ✅ El layout completo se pone encima de todo. */
    }

    /* 3. El sidebar se muestra dentro del layout ya elevado. */
    #pida-app-layout.sidebar-open-mobile #pida-sidebar {
        margin-left: 0;
    }

    /* 4. El botón de CERRAR ('X') se mantiene visible y funcional. */
    #pida-app-layout.sidebar-open-mobile #pida-collapse-btn {
        position: absolute;
        top: 1rem;
        left: auto;
        right: 10px;
        /* No necesita z-index aquí, ya que el layout padre lo elevó por encima de todo. */
    }
}

/* --- ESTILOS PARA LA PANTALLA DE BLOQUEO --- */
.pida-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(247, 249, 252, 0.9); /* Fondo semi-transparente */
    z-index: 10001; /* Encima de la app, debajo del perfil */
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px); /* Efecto de desenfoque */
}
.pida-overlay.hidden {
    display: none;
}
.pida-overlay-content {
    text-align: center;
    font-family: 'Noto Sans', sans-serif;
    padding: 40px;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
}
.pida-overlay-content h2 {
    font-size: 24px;
    color: var(--main-blue);
    margin-bottom: 15px;
}
.pida-overlay-content p {
    font-size: 16px;
    color: var(--medium-gray-text);
    margin-bottom: 25px;
    max-width: 400px;
}
.pida-overlay-btn {
    padding: 12px 30px;
    font-size: 16px;
    font-weight: 700;
    color: #ffffff;
    background-color: var(--accent-blue);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s ease;
}
.pida-overlay-btn:hover {
    background-color: var(--main-blue);
    color: #ffffff;
    text-decoration: none;
}