body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background: #f4f6f8;
    color: #1f2937;
    overflow-x: hidden;
}

/* ==========================
   Layout principal
========================== */

.app {
    display: flex;
    height: 100vh;
    min-width: 0;
}

/* ==========================
   Sidebar
========================== */

.sidebar {
    width: 260px;
    background: white;
    border-right: 1px solid #e5e7eb;
    padding: 20px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.logo {
    margin-bottom: 40px;
    line-height: 0;
}

.sidebar ul {
    list-style: none;
    padding: 0;
}

.sidebar li {
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
}

.sidebar li.active,
.sidebar li:hover {
    background: #eef6f7;
}

.sidebar li.oculto {
    display: none;
}

/* ==========================
   Main
========================== */

.main-content {
    flex: 1;
    padding: 25px;
    min-width: 0;
    overflow-y: auto;
}

/* ==========================
   Header
========================== */

header h1 {
    margin: 0;
    color: #1f2937;
}

header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.status-pill {
    background: #e0f2fe;
    color: #075985;
    border: 1px solid #bae6fd;
    border-radius: 999px;
    font-size: 13px;
    font-weight: bold;
    padding: 8px 12px;
    white-space: nowrap;
}

.status-pill.loading::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: #0284c7;
    animation: pulse 1s infinite ease-in-out;
}

/* ==========================
   KPI Cards
========================== */

.kpis {
    display: flex;
    gap: 20px;
    margin-top: 25px;
    margin-bottom: 25px;
}

.card {
    background: white;
    flex: 1;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    min-width: 0;
}

.card h3 {
    margin: 0;
    font-size: 14px;
    color: #6b7280;
}

.card span {
    display: block;
    margin-top: 10px;
    font-size: 28px;
    font-weight: bold;
}

.kpi-hint {
    display: block;
    font-size: 11px;
    color: #9ca3af;
    margin-top: 4px;
}

/* ==========================
   Selector de simulacion
========================== */

.sim-selector {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    box-shadow: 0 2px 8px rgba(0,0,0,.04);
}

.selector-field {
    min-width: 0;
}

.selector-field label {
    display: block;
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 6px;
}

.selector-field select,
.selector-field input {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background: white;
    color: #1f2937;
    font-size: 14px;
    box-sizing: border-box;
}

/* ==========================
   Chat
========================== */

#chat {
    background: white;

    border-radius: 8px;

    padding: 20px;

    height: min(550px, calc(100vh - 285px));
    min-height: 320px;

    overflow-y: auto;

    border: 1px solid #ddd;

    display: flex;

    flex-direction: column;
}

.mensaje {

    max-width: 75%;

    margin-bottom: 15px;

    padding: 15px;

    border-radius: 8px;

    word-wrap: break-word;
}

.cliente {
   
    background: #eaf4ff;

    margin-right: auto;

    border-bottom-left-radius: 5px;
}

.asesor {
    background: #dcf8c6;

    margin-left: auto;

    text-align: left;

    border-bottom-right-radius: 5px;
}

.sistema {
    background: #fff7ed;
    border: 1px solid #fed7aa;
    color: #9a3412;
    margin-left: auto;
    margin-right: auto;
}

.boton-audio {
    display: block;
    margin-top: 10px;
    padding: 8px 14px;
    font-size: 13px;
    background: #007c89;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.boton-audio:hover {
    background: #00606a;
}

.boton-audio:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.loading-message::after {
    content: "";
    display: inline-block;
    width: 18px;
    text-align: left;
    animation: dots 1.2s infinite steps(4, end);
}

/* ==========================
   Input
========================== */

.input-area {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    align-items: center;
}

.boton-hablar {
    font-size: 16px;
    font-weight: bold;
    padding: 14px 20px;
    user-select: none;
    touch-action: none;
    white-space: nowrap;
}

.boton-hablar.escuchando {
    background: #dc2626;
    animation: pulso-escucha 1.2s infinite;
}

@keyframes pulso-escucha {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5);
    }

    50% {
        box-shadow: 0 0 0 10px rgba(220, 38, 38, 0);
    }
}

input {
    flex: 1;
    padding: 14px;
    font-size: 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

button {
    padding: 14px 20px;
    border: none;
    background: #007c89;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

button:hover {
    background: #00606a;
}

button:disabled,
input:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* ==========================
   Chat + Panel
========================== */

.chat-layout {

    display: flex;

    gap: 20px;

    margin-bottom: 20px;
}

.chat-container {

    flex: 3;
}

.cliente-panel {

    flex: 1;

    background: white;

    border-radius: 8px;

    padding: 20px;

    height: fit-content;

    box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.cliente-panel h3 {

    margin-top: 0;

    color: #007c89;
}

.info-item {

    margin-bottom: 20px;
}

.info-item label {

    display: block;

    font-size: 13px;

    color: #6b7280;

    margin-bottom: 5px;
}

.info-item span {

    font-size: 18px;

    font-weight: bold;

    color: #1f2937;
}

.info-item-bloque p {

    margin: 0;

    font-size: 14px;

    line-height: 1.4;

    color: #374151;
}

.autor {

    font-weight: bold;

    margin-bottom: 8px;

    font-size: 14px;
}

.texto {

    line-height: 1.5;
}

/* ==========================
   Evaluación
========================== */

.evaluacion-card {

    background: white;

    border-radius: 8px;

    padding: 25px;

    margin-top: 20px;

    box-shadow: 0 2px 8px rgba(0,0,0,.05);

    border-left: 6px solid #007c89;
}

.evaluacion-header {

    font-size: 24px;

    font-weight: bold;

    color: #007c89;

    margin-bottom: 20px;
}

.evaluacion-body {

    color: #1f2937;
}

.evaluacion-body pre {

    white-space: pre-wrap;

    font-family: 'Inter', system-ui, sans-serif;

    line-height: 1.7;

    margin: 0;
}

.score-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.score-card {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 14px;
    background: #f9fafb;
}

.score-label {
    color: #6b7280;
    font-size: 12px;
    font-weight: bold;
    min-height: 28px;
}

.score-value {
    color: #111827;
    font-size: 24px;
    font-weight: bold;
    margin: 8px 0;
}

.score-bar {
    height: 7px;
    overflow: hidden;
    background: #e5e7eb;
    border-radius: 999px;
}

.score-bar-fill {
    height: 100%;
    background: #007c89;
    border-radius: 999px;
}

.cierre-card {
    background: #ecfdf5;
    border-color: #bbf7d0;
}

.feedback-section {
    border-top: 1px solid #e5e7eb;
    padding-top: 16px;
    margin-top: 16px;
}

.feedback-section h4 {
    color: #007c89;
    margin: 0 0 10px;
    font-size: 15px;
}

.feedback-section pre {
    white-space: pre-wrap;
    font-family: 'Inter', system-ui, sans-serif;
    line-height: 1.6;
    margin: 0;
    color: #1f2937;
}

@keyframes pulse {
    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }
}

@keyframes dots {
    0% {
        content: "";
    }

    25% {
        content: ".";
    }

    50% {
        content: "..";
    }

    75%,
    100% {
        content: "...";
    }
}

/* ==========================
   Vistas (navegación)
========================== */

.view {
    display: none;
}

.view.active {
    display: block;
}

.view-hint {
    color: #6b7280;
    margin-top: 0;
    margin-bottom: 16px;
}

.view-vacio {
    color: #6b7280;
    background: white;
    border: 1px dashed #d1d5db;
    border-radius: 8px;
    padding: 24px;
    text-align: center;
}

/* ==========================
   Evaluaciones (historial)
========================== */

.evaluacion-item {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    margin-bottom: 10px;
    overflow: hidden;
}

.evaluacion-item-resumen {
    padding: 14px 18px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.evaluacion-item-resumen:hover {
    background: #f9fafb;
}

.evaluacion-item-titulo {
    font-weight: bold;
    color: #1f2937;
}

.evaluacion-item-meta {
    color: #6b7280;
    font-size: 13px;
}

.evaluacion-item-detalle {
    display: none;
    padding: 0 18px 18px;
    border-top: 1px solid #e5e7eb;
}

.evaluacion-item-detalle.abierto {
    display: block;
}

/* ==========================
   Ranking
========================== */

#tabla-ranking {
    overflow-x: auto;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.ranking-table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
}

.ranking-table th,
.ranking-table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
}

.ranking-table th {
    background: #f9fafb;
    color: #6b7280;
    font-weight: bold;
}

.ranking-table tbody tr:hover {
    background: #f9fafb;
}

.ranking-yo {
    background: #eef6f7;
    font-weight: 600;
}

/* ==========================
   Capacitación
========================== */

.capacitacion-card {
    background: white;
    border-radius: 8px;
    padding: 22px;
    margin-bottom: 18px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.capacitacion-card h3 {
    margin-top: 0;
    color: #007c89;
}

.capacitacion-card li {
    margin-bottom: 8px;
    line-height: 1.5;
}

/* ==========================
   Configuración
========================== */

.config-card {
    background: white;
    border-radius: 8px;
    padding: 22px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    max-width: 420px;
}

.config-card h3 {
    margin-top: 0;
    color: #007c89;
}

.config-card .selector-field {
    margin-bottom: 14px;
}

.config-guardado {
    margin-left: 10px;
    color: #16a34a;
    font-weight: bold;
    font-size: 13px;
}

@media (max-width: 1100px) {
    .kpis,
    .sim-selector,
    .score-grid {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chat-layout {
        flex-direction: column;
    }

    #chat {
        height: 420px;
    }
}

@media (max-width: 780px) {
    .app {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: auto;
        border-right: 0;
        border-bottom: 1px solid #e5e7eb;
    }

    .sidebar ul {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .sidebar li {
        margin-bottom: 0;
    }

    .input-area,
    .kpis,
    .sim-selector,
    .score-grid {
        grid-template-columns: 1fr;
    }

    header {
        align-items: flex-start;
        flex-direction: column;
    }

    .input-area {
        display: grid;
    }

    button {
        width: 100%;
    }

    .main-content {
        padding: 16px;
        padding-bottom: 230px;
    }

    .evaluacion-item-resumen {
        flex-direction: column;
        gap: 4px;
    }

    .config-card,
    .capacitacion-card {
        padding: 16px;
    }

    .boton-audio {
        width: auto;
    }

    .mic-hint {
        text-align: center;
    }

    .barra-mensaje {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 20;
        background: #f4f6f8;
        padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1);
    }

    .barra-mensaje .input-area {
        margin-top: 0;
    }
}

/* Pantalla de acceso con clave */
.acceso-overlay {
    position: fixed;
    inset: 0;
    background: #f4f6f8;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.acceso-overlay.oculto {
    display: none;
}

.acceso-card {
    background: white;
    border-radius: 12px;
    padding: 40px 36px;
    box-shadow: 0 4px 24px rgba(0,0,0,.10);
    text-align: center;
    max-width: 360px;
    width: 90%;
}

.acceso-card-ancha {
    max-width: 720px;
    text-align: left;
}

.acceso-card-ancha h2,
.acceso-card-ancha .view-hint {
    text-align: center;
}

.acceso-card img {
    margin-bottom: 16px;
}

.acceso-card h2 {
    margin: 0 0 8px;
    font-size: 20px;
    color: #1f2937;
}

.acceso-card > p {
    color: #6b7280;
    font-size: 14px;
    margin: 0 0 24px;
}

.acceso-card input[type="text"],
.acceso-card input[type="email"],
.acceso-card input[type="password"],
.acceso-card select {
    width: 100%;
    margin-bottom: 12px;
    box-sizing: border-box;
}

.acceso-card button {
    width: 100%;
}

.acceso-error {
    color: #dc2626;
    font-size: 13px;
    margin: 10px 0 0;
    min-height: 18px;
}

.acceso-admin-link {
    margin: 20px 0 0;
    font-size: 13px;
    color: #6b7280;
}

.acceso-admin-link a {
    color: #007c89;
    font-weight: 600;
    text-decoration: none;
}

.acceso-admin-link a:hover {
    text-decoration: underline;
}

/* Sidebar footer con nombre y cerrar sesión */
.sidebar-footer {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid #e5e7eb;
}

.sidebar-nombre-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-cerrar-sesion {
    background: none;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    font-size: 12px;
    padding: 6px 12px;
    width: 100%;
    border-radius: 6px;
}

.btn-cerrar-sesion:hover {
    background: #f9fafb;
    color: #374151;
}

/* #4 — Panel cliente: oculto hasta que inicie sesión */
.cliente-panel.oculto {
    display: none;
}

/* #6 — Botón secundario (outline) */
.btn-secundario {
    background: white;
    border: 1.5px solid #007c89;
    color: #007c89;
}

.btn-secundario:hover {
    background: #eef6f7;
    color: #007c89;
}

.btn-secundario:disabled {
    border-color: #d1d5db;
    color: #9ca3af;
}

/* #7 — Hint del micrófono */
.mic-hint {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-top: 6px;
    text-align: right;
}

/* ==========================
   Vista Admin
========================== */

.nav-admin-item {
    margin-top: 16px;
    border-top: 1px solid #e5e7eb;
    padding-top: 20px;
    color: #9ca3af;
    font-size: 14px;
}

.nav-admin-item.admin-activo {
    color: #1f2937;
}

.admin-kpis {
    flex-wrap: wrap;
}

.admin-section {
    background: white;
    border-radius: 8px;
    padding: 20px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    margin-bottom: 20px;
}

.admin-section.oculto {
    display: none;
}

.admin-section-title {
    margin: 0 0 16px 0;
    font-size: 15px;
    color: #374151;
}

.admin-section-mantenimiento {
    border: 2px solid #e5e7eb;
}

.admin-section-mantenimiento.mantenimiento-activo {
    border-color: #dc2626;
    background: #fef2f2;
}

.mantenimiento-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    font-weight: 600;
}

.mantenimiento-toggle input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.admin-tables-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.admin-table-wrap {
    flex: 1;
    background: white;
    border-radius: 8px;
    padding: 20px 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
    min-width: 0;
}

.adm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.adm-table th {
    text-align: left;
    padding: 8px 10px;
    background: #f9fafb;
    color: #6b7280;
    font-weight: 600;
    border-bottom: 1px solid #e5e7eb;
}

.adm-th-ordenable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.adm-th-ordenable:hover {
    color: #007c89;
}

.adm-table td {
    padding: 9px 10px;
    border-bottom: 1px solid #f3f4f6;
    color: #1f2937;
}

.adm-table tr:last-child td {
    border-bottom: none;
}

.adm-paginacion {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 14px 0 4px;
    font-size: 13px;
    color: #6b7280;
}

.adm-paginacion .btn-descarga {
    padding: 6px 14px;
    font-size: 13px;
}

.adm-paginacion .btn-descarga:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.adm-competencias-grid,
.adm-uso-dia-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.comp-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.comp-label {
    width: 110px;
    font-size: 13px;
    color: #374151;
    flex-shrink: 0;
}

.comp-bar-wrap {
    flex: 1;
    background: #f3f4f6;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.comp-bar {
    height: 100%;
    background: #007c89;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.top-errores-lista {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0;
    margin: 0;
}

.top-error-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 12px;
    background: #f9fafb;
    border-radius: 10px;
}

.top-error-rank {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #007c89;
    color: white;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

.top-error-cuerpo {
    flex: 1;
    min-width: 0;
}

.top-error-tema {
    font-size: 14px;
    color: #1f2937;
    font-weight: 500;
}

.top-error-cantidad {
    font-size: 12px;
    color: #007c89;
    font-weight: 600;
    margin-top: 2px;
}

.top-error-ejemplos {
    margin: 6px 0 0;
    padding-left: 18px;
    font-size: 12px;
    color: #6b7280;
}

.top-error-ejemplos li {
    margin-bottom: 2px;
}

.uso-dia-linea-svg {
    width: 100%;
    height: auto;
    display: block;
}

.uso-dia-linea-eje {
    stroke: #e5e7eb;
    stroke-width: 1;
}

.uso-dia-linea-trazo {
    fill: none;
    stroke: #007c89;
    stroke-width: 1.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.uso-dia-linea-punto {
    fill: #007c89;
    stroke: white;
    stroke-width: 1.5;
    cursor: pointer;
}

.uso-dia-linea-punto:hover,
.uso-dia-linea-punto:focus {
    fill: #005a63;
    outline: none;
}

.uso-dia-linea-valor {
    font-size: 10px;
    font-weight: 600;
    fill: #007c89;
}

.uso-dia-linea-fecha {
    font-size: 9px;
    fill: #6b7280;
}

.uso-dia-filtro {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #6b7280;
}

.uso-dia-filtro label {
    display: flex;
    align-items: center;
    gap: 6px;
}

.uso-dia-filtro label.oculto {
    display: none;
}

.uso-dia-filtro input[type="date"],
.uso-dia-filtro select {
    font-size: 13px;
    padding: 4px 6px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
}

.uso-dia-linea-detalle {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 6px;
    margin-top: 4px;
}

.uso-dia-linea-detalle.oculto {
    display: none;
}

.uso-dia-usuario {
    background: #eef6f7;
    color: #007c89;
    font-size: 12px;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}

.comp-val {
    width: 32px;
    text-align: right;
    font-size: 13px;
    font-weight: 600;
    color: #007c89;
}

.admin-descargas {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-descarga {
    padding: 10px 18px;
    border-radius: 8px;
    border: 1.5px solid #007c89;
    background: white;
    color: #007c89;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}

.btn-descarga:hover {
    background: #eef6f7;
}

.btn-descarga.oculto {
    display: none;
}

.adm-acciones {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.adm-acciones .btn-descarga {
    padding: 6px 10px;
    font-size: 12px;
    white-space: nowrap;
}
