/* Alepsol Auditor — Estilos globales */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
    --azul-oscuro: #0b1f33;
    --azul-medio: #123a5c;
    --azul-claro: #1a4d75;
    --cian: #2fb8c6;
    --cian-hover: #26a3b0;
    --gris-fondo: #f0f4f8;
    --gris-borde: #dfe6ea;
    --texto: #1c2b3a;
    --texto-suave: #5b6b78;
    --blanco: #ffffff;
    --sombra: 0 10px 30px rgba(11, 31, 51, 0.12);
    --verde: #2e7d5b;
    --rojo: #b8433a;
    --naranja: #c9932e;
    --radio: 10px;
    --transicion: 0.2s ease;
}

[data-theme="dark"] {
    --gris-fondo: #0d1520;
    --gris-borde: #243447;
    --texto: #e8edf2;
    --texto-suave: #9aabb8;
    --blanco: #152232;
    --sombra: 0 10px 30px rgba(0, 0, 0, 0.35);
}

*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--gris-fondo);
    color: var(--texto);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--cian); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.app-header {
    background: linear-gradient(135deg, var(--azul-oscuro), var(--azul-medio));
    color: #fff;
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(11, 31, 51, 0.25);
}

.app-header .brand h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.app-header .brand span {
    color: var(--cian);
}

.app-header .brand p {
    margin: 2px 0 0;
    font-size: 0.82rem;
    opacity: 0.8;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.contenedor {
    max-width: 1200px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}

.contenedor-estrecho {
    max-width: 900px;
}

/* ---------- Botones ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: 8px;
    padding: 11px 20px;
    font-size: 0.92rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background var(--transicion), transform var(--transicion), box-shadow var(--transicion);
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-cian {
    background: var(--cian);
    color: #06222b;
}

.btn-cian:hover {
    background: var(--cian-hover);
    color: #06222b;
}

.btn-oscuro {
    background: var(--azul-oscuro);
    color: #fff;
}

.btn-oscuro:hover {
    background: var(--azul-claro);
    color: #fff;
}

.btn-secundario {
    background: var(--blanco);
    color: var(--azul-oscuro);
    border: 1px solid var(--gris-borde);
}

.btn-secundario:hover {
    border-color: var(--cian);
    color: var(--azul-oscuro);
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
}

.btn-sm { padding: 7px 14px; font-size: 0.85rem; }

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 8px;
}

/* ---------- Stats ---------- */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--blanco);
    border-radius: var(--radio);
    padding: 20px;
    box-shadow: var(--sombra);
    animation: fadeSlideIn 0.45s ease both;
}

.stat-card:nth-child(2) { animation-delay: 0.05s; }
.stat-card:nth-child(3) { animation-delay: 0.1s; }
.stat-card:nth-child(4) { animation-delay: 0.15s; }

.stat-card .label {
    font-size: 0.8rem;
    color: var(--texto-suave);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.stat-card .value {
    font-size: 2rem;
    font-weight: 800;
    color: var(--azul-oscuro);
    line-height: 1.1;
    margin-top: 4px;
}

[data-theme="dark"] .stat-card .value { color: var(--cian); }

.stat-card .value small {
    font-size: 1rem;
    font-weight: 600;
    color: var(--texto-suave);
}

/* ---------- Filtros ---------- */

.panel {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 20px;
    margin-bottom: 24px;
    animation: fadeSlideIn 0.4s ease both;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--azul-medio);
}

[data-theme="dark"] .panel-header h2 { color: var(--cian); }

.filtros-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.campo label {
    display: block;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--texto-suave);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.campo input,
.campo select,
.campo textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--gris-borde);
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    background: var(--blanco);
    color: var(--texto);
    transition: border-color var(--transicion);
}

.campo input:focus,
.campo select:focus,
.campo textarea:focus {
    outline: none;
    border-color: var(--cian);
}

.campo textarea { resize: vertical; min-height: 90px; }

/* ---------- Tabla / tarjetas dashboard ---------- */

.tabla-wrap {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    overflow: hidden;
    animation: fadeSlideIn 0.5s ease both;
}

.tabla-auditorias {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.tabla-auditorias th {
    text-align: left;
    padding: 14px 16px;
    background: var(--azul-oscuro);
    color: #fff;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.tabla-auditorias td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--gris-borde);
    vertical-align: middle;
}

.tabla-auditorias tbody tr {
    transition: background var(--transicion);
}

.tabla-auditorias tbody tr:hover {
    background: rgba(47, 184, 198, 0.06);
}

.url-cell {
    max-width: 280px;
    word-break: break-all;
    font-weight: 500;
}

.url-cell a { color: var(--texto); font-weight: 600; }
.url-cell a:hover { color: var(--cian); }

.fecha-cell { color: var(--texto-suave); white-space: nowrap; font-size: 0.85rem; }

/* Score mini ring */
.score-mini {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.score-mini-ring {
    width: 44px;
    height: 44px;
    position: relative;
    flex-shrink: 0;
}

.score-mini-ring svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-mini-ring circle {
    fill: none;
    stroke-width: 6;
}

.score-mini-ring .bg { stroke: var(--gris-borde); }
.score-mini-ring .fg {
    stroke-linecap: round;
    transition: stroke-dashoffset 1s ease;
}

.score-mini-num {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
}

.estado-select {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1.5px solid var(--gris-borde);
    font-size: 0.82rem;
    font-family: inherit;
    background: var(--blanco);
    color: var(--texto);
    cursor: pointer;
    max-width: 150px;
}

.estado-select:focus { outline: none; border-color: var(--cian); }

.estado-nuevo { border-left: 3px solid var(--cian); }
.estado-contactado { border-left: 3px solid var(--azul-medio); }
.estado-en_negociacion { border-left: 3px solid var(--naranja); }
.estado-cliente { border-left: 3px solid var(--verde); }
.estado-descartado { border-left: 3px solid var(--rojo); }

/* Tarjetas móvil */
.tarjetas-movil { display: none; }

.tarjeta-audit {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 16px;
    margin-bottom: 12px;
    animation: fadeSlideIn 0.4s ease both;
    border-left: 4px solid var(--cian);
}

.tarjeta-audit .tarjeta-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 12px;
}

.tarjeta-audit .tarjeta-acciones {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.vacio-msg {
    text-align: center;
    padding: 48px 20px;
    color: var(--texto-suave);
}

/* ---------- Modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(11, 31, 51, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transicion), visibility var(--transicion);
}

.modal-overlay.activo {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--blanco);
    border-radius: 14px;
    width: 100%;
    max-width: 520px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    transform: translateY(16px);
    transition: transform var(--transicion);
}

.modal-overlay.activo .modal { transform: translateY(0); }

.modal-header {
    padding: 22px 24px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--azul-oscuro);
}

.modal-body { padding: 20px 24px 24px; }

.modal-cerrar {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--texto-suave);
    line-height: 1;
    padding: 4px;
}

.form-audit {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-audit .btn { align-self: flex-start; }

/* Skeleton */
.skeleton-wrap { display: none; }
.skeleton-wrap.activo { display: block; }

.skeleton {
    background: linear-gradient(90deg, var(--gris-borde) 25%, rgba(255,255,255,0.5) 50%, var(--gris-borde) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    border-radius: 8px;
}

.skeleton-line { height: 14px; margin-bottom: 10px; }
.skeleton-line.w60 { width: 60%; }
.skeleton-line.w80 { width: 80%; }
.skeleton-block { height: 120px; margin-top: 16px; }

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.error-box {
    background: rgba(184, 67, 58, 0.1);
    border: 1px solid var(--rojo);
    color: var(--rojo);
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-top: 12px;
    display: none;
}

.error-box.visible { display: block; }

.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--azul-oscuro);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    box-shadow: var(--sombra);
    z-index: 300;
    transform: translateY(80px);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast.visible {
    transform: translateY(0);
    opacity: 1;
}

/* ---------- Detalle / Informe ---------- */

.detalle-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    align-items: start;
}

.panel-crm {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 22px;
    position: sticky;
    top: 88px;
}

.panel-crm h3 {
    margin: 0 0 16px;
    font-size: 1rem;
    color: var(--azul-medio);
}

.panel-crm .campo { margin-bottom: 14px; }

.panel-crm .acciones-crm {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}

.panel-crm .acciones-crm .btn { width: 100%; }

.link-publico-box {
    display: none;
    margin-top: 12px;
    padding: 10px;
    background: rgba(47, 184, 198, 0.1);
    border-radius: 8px;
    font-size: 0.82rem;
    word-break: break-all;
}

.link-publico-box.visible { display: block; }

.evolucion-panel {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 20px;
    margin-bottom: 24px;
}

.evolucion-panel h3 {
    margin: 0 0 12px;
    font-size: 0.95rem;
    color: var(--azul-medio);
}

.chart-evolucion {
    width: 100%;
    height: 140px;
}

.chart-evolucion polyline {
    fill: none;
    stroke: var(--cian);
    stroke-width: 2.5;
    stroke-linejoin: round;
}

.chart-evolucion .chart-dot {
    fill: var(--cian);
}

.chart-evolucion .chart-grid {
    stroke: var(--gris-borde);
    stroke-width: 1;
}

.chart-leyenda {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    margin-top: 10px;
    font-size: 0.8rem;
    color: var(--texto-suave);
}

/* Informe */
.informe {
    background: var(--blanco);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    overflow: hidden;
    animation: fadeSlideIn 0.45s ease both;
}

.informe-cabecera {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 26px 28px;
    border-bottom: 1px solid var(--gris-borde);
    flex-wrap: wrap;
    gap: 16px;
}

.informe-cabecera .url-analizada {
    font-size: 0.95rem;
    color: var(--texto-suave);
    word-break: break-all;
}

.informe-cabecera .url-analizada strong {
    display: block;
    font-size: 1.15rem;
    color: var(--texto);
    margin-top: 4px;
}

.score-ring-wrap {
    width: 110px;
    height: 110px;
    position: relative;
    flex-shrink: 0;
}

.score-ring {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.score-ring-bg {
    fill: none;
    stroke: var(--gris-borde);
    stroke-width: 8;
}

.score-ring-fg {
    fill: none;
    stroke: var(--cian);
    stroke-width: 8;
    stroke-linecap: round;
    stroke-dasharray: 264;
    stroke-dashoffset: 264;
    transition: stroke-dashoffset 1.2s ease, stroke 0.3s ease;
}

.score-ring-label {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.score-ring-label .num {
    font-size: 1.9rem;
    line-height: 1;
    color: var(--score-color, var(--azul-oscuro));
}

.score-ring-label .txt {
    font-size: 0.68rem;
    color: var(--texto-suave);
    font-weight: 600;
}

.score-desglose {
    padding: 20px 28px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 14px;
    border-bottom: 1px solid var(--gris-borde);
    background: rgba(47, 184, 198, 0.04);
}

.score-bar-head {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 5px;
}

.score-bar-head small { color: var(--texto-suave); font-weight: 400; }

.score-bar-track {
    height: 6px;
    background: var(--gris-borde);
    border-radius: 99px;
    overflow: hidden;
}

.score-bar-fill {
    height: 100%;
    background: var(--cian);
    border-radius: 99px;
    transition: width 1s ease;
}

.secciones { padding: 8px 28px 28px; }

.seccion {
    padding: 18px 0;
    border-bottom: 1px solid var(--gris-borde);
}

.seccion:last-child { border-bottom: none; }

.seccion h3 {
    margin: 0 0 12px;
    font-size: 1.05rem;
    color: var(--azul-medio);
}

[data-theme="dark"] .seccion h3 { color: var(--cian); }

.fila {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    font-size: 0.95rem;
    align-items: flex-start;
}

.fila .etiqueta { color: var(--texto-suave); }
.fila .valor { text-align: right; font-weight: 600; }
.fila-detalle .valor { max-width: 55%; }
.texto-peq { font-size: 0.82rem; font-weight: 500 !important; }

.chk {
    display: inline-block;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    color: #fff;
    text-align: center;
    line-height: 22px;
    font-size: 0.75rem;
}

.chk.ok { background: var(--verde); }
.chk.bad { background: var(--rojo); }

/* Resumen ejecutivo del informe */
.resumen-ejecutivo {
    padding: 22px 28px;
    border-bottom: 1px solid var(--gris-borde);
    background: linear-gradient(135deg, rgba(11, 31, 51, 0.04), rgba(47, 184, 198, 0.06));
}

.resumen-ejecutivo h3 {
    margin: 0 0 10px;
    font-size: 1rem;
    color: var(--azul-medio);
}

.resumen-ejecutivo p {
    margin: 0 0 8px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--texto);
}

.resumen-fallos-count {
    font-size: 0.88rem !important;
    color: var(--texto-suave) !important;
}

/* Checks con fallo: explicación y prioridad */
.fila-check-fallo {
    background: rgba(184, 67, 58, 0.04);
    margin: 0 -8px;
    padding: 10px 8px !important;
    border-radius: 8px;
}

.etiqueta-check-fallo {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 72%;
}

.prioridad-badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    margin-bottom: 2px;
}

.check-explicacion {
    display: block;
    font-size: 0.82rem;
    font-weight: 400;
    color: var(--texto-suave);
    line-height: 1.45;
}

/* Pie de contacto del informe (visible en pantalla e impresión) */
.informe-pie-contacto {
    margin: 0;
    padding: 18px 28px;
    background: var(--azul-oscuro);
    color: #fff;
    font-size: 0.88rem;
    text-align: center;
    line-height: 1.6;
}

.informe-pie-contacto a {
    color: var(--cian);
    text-decoration: none;
}

.informe-pie-contacto a:hover {
    text-decoration: underline;
}

.aviso-comercial {
    background: rgba(47, 184, 198, 0.08);
    border-left: 4px solid var(--cian);
    padding: 18px 20px;
    margin: 0 28px 28px;
    border-radius: 0 8px 8px 0;
    font-size: 0.95rem;
    line-height: 1.55;
}

.botones-informe {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.app-footer {
    text-align: center;
    padding: 30px;
    color: var(--texto-suave);
    font-size: 0.85rem;
}

/* Vista pública */
.publico-header {
    text-align: center;
    padding: 32px 20px 20px;
}

.publico-header h1 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--azul-oscuro);
}

.publico-header .marca { color: var(--cian); }

/* Animaciones */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Print */
@media print {
    .app-header, .panel-crm, .botones-informe, .evolucion-panel,
    .app-footer, .modal-overlay, .toast, .no-print { display: none !important; }

    body { background: #fff; }
    .contenedor { padding: 0; max-width: 100%; }
    .detalle-grid { display: block; }
    .informe { box-shadow: none; border: 1px solid #ddd; }

    .seccion,
    .resumen-ejecutivo,
    .score-desglose,
    .aviso-comercial,
    .informe-cabecera {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .informe-pie-contacto {
        display: block !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #0b1f33 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .informe {
        padding-bottom: 56px;
    }

    .fila-check-fallo {
        background: #fafafa !important;
    }
}

/* Responsive */
@media (max-width: 900px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .detalle-grid { grid-template-columns: 1fr; }
    .panel-crm { position: static; }
}

@media (max-width: 768px) {
    .tabla-wrap { display: none; }
    .tarjetas-movil { display: block; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .filtros-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .filtros-grid { grid-template-columns: 1fr; }
    .app-header .brand h1 { font-size: 1.15rem; }
}
