/* ============================================================
   MNEMOS — Componentes Reutilizables
   Cards, Stats, Tablas, Forms, Tags, Modales, Paginacion
============================================================ */

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: 12px;
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 { font-size: 15px; font-weight: 700; }

.card-body { padding: 20px; }

/* ---- Stats ---- */
.fila-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.card-stat {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card-stat:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px var(--sombra);
}

.card-stat .stat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-stat .stat-icono { font-size: 28px; }

.card-stat .stat-trend {
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 2px;
}

.card-stat .stat-trend.positivo { color: var(--exito); }
.card-stat .stat-trend.negativo { color: var(--error); }

.card-stat .stat-numero { font-size: 32px; font-weight: 800; line-height: 1; }
.card-stat .stat-etiqueta { font-size: 13px; color: var(--texto-secundario); }

/* ---- Grid contenido ---- */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 24px; }
.grid-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }

@media (max-width: 1024px) {
    .grid-2, .grid-equal, .grid-3 { grid-template-columns: 1fr; }
}

/* ---- Tablas ---- */
.tabla-controles {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}

.tabla-datos {
    width: 100%;
    border-collapse: collapse;
}

.tabla-datos th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--texto-secundario);
    border-bottom: 2px solid var(--borde);
    font-weight: 600;
}

.tabla-datos td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--borde);
    vertical-align: middle;
}

.tabla-datos tbody tr {
    transition: background 0.15s ease;
    cursor: pointer;
}

.tabla-datos tbody tr:hover {
    background-color: var(--bg-input);
}

.tabla-info {
    font-size: 13px;
    color: var(--texto-secundario);
}

/* ---- Formularios ---- */
.form-grupo {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-grupo label {
    font-size: 13px;
    font-weight: 600;
    color: var(--texto-secundario);
}

.form-control {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--borde);
    border-radius: 8px;
    color: var(--texto);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s ease;
}

.form-control::placeholder,
.input-busqueda::placeholder {
    color: var(--texto-secundario);
    opacity: 0.6;
}

.form-control:focus {
    outline: none;
    border-color: var(--acento);
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.input-busqueda {
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--borde);
    border-radius: 6px;
    color: var(--texto);
    font-size: 13px;
    min-width: 220px;
    transition: border-color 0.2s ease;
}

.input-busqueda:focus {
    outline: none;
    border-color: var(--acento);
}

/* ---- Botones ---- */
.btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primario {
    background: var(--acento);
    color: var(--bg-principal);
}

.btn-primario:hover:not(:disabled) {
    background: var(--acento-hover);
}

.btn-secundario {
    background: var(--bg-input);
    color: var(--texto);
    border: 1px solid var(--borde);
}

.btn-secundario:hover:not(:disabled) {
    border-color: var(--acento);
    color: var(--acento);
}

.btn-peligro {
    background: var(--error);
    color: #fff;
}

.btn-peligro:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

.btn-grupo {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* ---- Tags / Badges ---- */
.tag {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 600;
    display: inline-block;
}

.tag-acento { background: rgba(232,162,61,0.15); color: var(--acento); }
.tag-exito { background: rgba(76,175,80,0.15); color: var(--exito); }
.tag-error { background: rgba(244,67,54,0.15); color: var(--error); }
.tag-advertencia { background: rgba(255,152,0,0.15); color: var(--advertencia); }
.tag-info { background: rgba(66,165,245,0.15); color: var(--info); }

.tag-tipo-episodic { background: rgba(66,165,245,0.15); color: var(--info); }
.tag-tipo-semantic { background: rgba(76,175,80,0.15); color: var(--exito); }
.tag-tipo-procedural { background: rgba(255,152,0,0.15); color: var(--advertencia); }
.tag-tipo-emotional { background: rgba(244,67,54,0.15); color: var(--error); }

/* ---- Tooltips ---- */
/* El tooltip se renderiza via JS en #mnemos-tooltip (position:fixed) para que
   no quede clipado por el overflow:hidden de las cards padres. */
[data-tip] {
    cursor: help;
    border-bottom: 1px dotted var(--texto-secundario);
    display: inline;
}

#mnemos-tooltip {
    position: fixed;
    background: var(--bg-sidebar);
    color: var(--texto);
    border: 1px solid var(--acento);
    border-radius: 8px;
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.6;
    white-space: normal;
    max-width: 300px;
    text-align: left;
    z-index: 9999;
    pointer-events: none;
    box-shadow: 0 8px 24px var(--sombra);
    font-weight: 400;
    opacity: 0;
    transition: opacity 0.15s ease;
}

#mnemos-tooltip.visible {
    opacity: 1;
}

/* Interpretacion de grafico */
.grafico-interpretacion {
    background: var(--bg-input);
    border: 1px solid var(--borde);
    border-left: 3px solid var(--acento);
    border-radius: 8px;
    padding: 12px 16px;
    margin-top: 12px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--texto-secundario);
}
.grafico-interpretacion strong { color: var(--texto); }

/* ---- Paginacion ---- */
.paginacion {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding-top: 16px;
}

.paginacion button {
    padding: 6px 12px;
    background: var(--bg-input);
    border: 1px solid var(--borde);
    border-radius: 6px;
    color: var(--texto);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s ease;
}

.paginacion button:hover:not(:disabled) {
    border-color: var(--acento);
    color: var(--acento);
}

.paginacion button.activo {
    background: var(--acento);
    color: var(--bg-principal);
    border-color: var(--acento);
}

.paginacion button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ---- Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fade-in 0.2s ease;
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--borde);
    border-radius: 16px;
    padding: 24px;
    max-width: 560px;
    width: calc(100% - 32px);
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px var(--sombra);
    animation: modal-in 0.25s ease;
}

.modal-titulo {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--borde);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modal-in {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* ---- Barras de progreso ---- */
.barra-progreso {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}

.barra-progreso .relleno {
    height: 100%;
    background: var(--acento);
    border-radius: 4px;
    transition: width 0.4s ease;
}

/* ---- Lista de items ---- */
.lista-items {
    list-style: none;
    display: flex;
    flex-direction: column;
}

.lista-items li {
    padding: 12px 16px;
    border-bottom: 1px solid var(--borde);
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.15s ease;
}

.lista-items li:hover {
    background: var(--bg-input);
}

.lista-items li:last-child {
    border-bottom: none;
}

/* ---- Detalle key-value ---- */
.detalle-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 12px 16px;
    font-size: 14px;
}

.detalle-grid .clave {
    font-weight: 600;
    color: var(--texto-secundario);
}

@media (max-width: 600px) {
    .detalle-grid { grid-template-columns: 1fr; }
    .fila-stats { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
    .fila-stats { grid-template-columns: 1fr; }
}

/* ---- Tabs ---- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--borde);
    margin-bottom: 20px;
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: var(--texto-secundario);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s ease;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: inherit;
}

.tab:hover { color: var(--texto); }

.tab.activo {
    color: var(--acento);
    border-bottom-color: var(--acento);
}

.tab-panel { display: none; }
.tab-panel.activo { display: block; }

/* ---- Utilidades ---- */
.texto-truncar {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.texto-centro { text-align: center; }
.texto-derecha { text-align: right; }
.texto-exito { color: var(--exito); }
.texto-error { color: var(--error); }
.texto-advertencia { color: var(--advertencia); }
.texto-secundario { color: var(--texto-secundario); }
.texto-acento { color: var(--acento); }

.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; }

.oculto { display: none !important; }

/* Satisfaction bar colors */
.satisfaccion-bajo { background: var(--peligro, #e74c3c); }
.satisfaccion-medio { background: var(--advertencia, #f39c12); }
.satisfaccion-alto { background: var(--exito, #2ecc71); }

/* ---- Responsive tables ---- */
@media (max-width: 768px) {
    .tabla-datos th,
    .tabla-datos td { padding: 8px 6px; font-size: 13px; }

    .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .tab { white-space: nowrap; padding: 8px 14px; font-size: 13px; }
}

/* ---- Focus / Accessibility ---- */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--acento);
    outline-offset: 2px;
}

.nav-enlace:focus-visible {
    outline: 2px solid var(--acento);
    outline-offset: -2px;
    border-radius: 4px;
}

/* Skip to content */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--acento);
    color: var(--bg-principal);
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
}
.skip-link:focus { top: 0; }
