/* ===== EnergiAI — hoja de estilos responsive ===== */
:root {
    --verde: #5AA469;
    --verde-osc: #4C8E58;
    --verde-cl: #EAF6EC;
    --azul-osc: #233243;
    --gris: #58656F;
    --gris-cl: #C9D6CD;
    --bg: #F1FBF3;
    --card: #ffffff;
    --ok: #2E9E5B;
    --warn: #E0A800;
    --bad: #D0473B;
    --radio: 16px;
    --sombra: 0 4px 18px rgba(20, 50, 30, 0.08);
}

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

body {
    background: var(--bg);
    font-family: system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
    color: var(--azul-osc);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Topbar ---------- */
.topbar {
    background: var(--card);
    box-shadow: var(--sombra);
    padding: 14px clamp(16px, 5vw, 60px);
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.tema-btn {
    background: none; border: 1.5px solid var(--gris-cl); border-radius: 50%;
    width: 42px; height: 42px; cursor: pointer; font-size: 1.15rem; line-height: 1;
}
.tema-btn:hover { background: var(--verde-cl); }
.brand { display: flex; align-items: center; gap: 10px; font-size: 1.5rem; color: var(--azul-osc); }
.brand img { height: 34px; }
.brand b { color: var(--verde); }

/* ---------- Vistas ---------- */
.vista {
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: clamp(20px, 5vw, 48px) clamp(16px, 5vw, 40px);
    flex: 1;
}
[hidden] { display: none !important; }

h2 { font-size: clamp(1.4rem, 4vw, 2rem); margin-bottom: 6px; }
.subtitulo { color: var(--gris); margin-bottom: 22px; }

/* ---------- Botones ---------- */
.btn-primary, .btn-ghost {
    border: none; border-radius: 40px; cursor: pointer; font-size: 1rem;
    font-weight: 600; padding: 14px 32px; transition: .2s;
}
.btn-primary { background: var(--verde); color: #fff; }
.btn-primary:hover { background: var(--verde-osc); }
.btn-ghost { background: transparent; color: var(--gris); border: 1.5px solid var(--gris-cl); }
.btn-ghost:hover { background: #fff; }
.acciones { display: flex; justify-content: space-between; gap: 12px; margin-top: 24px; flex-wrap: wrap; }
.acciones.centrado { justify-content: center; }

/* ---------- Inicio / hero ---------- */
.hero {
    display: flex; align-items: center; gap: clamp(20px, 5vw, 60px);
    flex-wrap: wrap; margin-bottom: 50px;
}
.hero-text { flex: 1 1 320px; }
.hero-text h1 { font-size: clamp(1.8rem, 6vw, 3.2rem); line-height: 1.15; margin-bottom: 18px; }
.hero-text h1 span { color: var(--verde); }
.lead { font-size: clamp(1rem, 2.5vw, 1.2rem); color: var(--gris); margin-bottom: 26px; max-width: 560px; }
.hero-img { flex: 1 1 280px; max-width: 460px; width: 100%; height: auto; }

.pasos h2 { text-align: center; margin-bottom: 26px; }
.pasos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 20px; }
.paso { background: var(--card); border-radius: var(--radio); padding: 26px; box-shadow: var(--sombra); }
.paso-num {
    width: 40px; height: 40px; border-radius: 50%; background: var(--verde-cl); color: var(--verde-osc);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.2rem; margin-bottom: 14px;
}
.paso h3 { margin-bottom: 6px; }
.paso p { color: var(--gris); font-size: .95rem; }

/* ---------- Tarjetas ---------- */
.tarjeta { background: var(--card); border-radius: var(--radio); padding: clamp(18px, 3vw, 28px); box-shadow: var(--sombra); margin-bottom: 20px; }
.tarjeta h3 { margin-bottom: 14px; }

/* ---------- Formulario ---------- */
.grid-campos { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 18px; }
.campo { display: flex; flex-direction: column; gap: 6px; }
.campo label { font-weight: 600; font-size: .95rem; }
.campo small { color: var(--gris); font-size: .82rem; }
.campo input, .campo select {
    padding: 12px 14px; border: 1.5px solid var(--gris-cl); border-radius: 10px;
    font-size: 1rem; font-family: inherit; background: #fff; width: 100%;
}
.campo input:focus, .campo select:focus { outline: none; border-color: var(--verde); }

.campo-check { display: flex; align-items: center; gap: 14px; margin-top: 20px; }
.campo-check small { display: block; color: var(--gris); font-size: .82rem; }
.info-toggle { background: none; border: none; color: var(--verde-osc); cursor: pointer; font-size: .85rem; padding: 2px 0; font-weight: 600; }
.info-box { background: var(--verde-cl); border-left: 4px solid var(--verde); border-radius: 10px; padding: 14px 16px; margin-top: 12px; font-size: .9rem; color: #35503c; }

/* Switch toggle */
.switch { position: relative; display: inline-block; width: 48px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider-sw { position: absolute; inset: 0; background: var(--gris-cl); border-radius: 26px; transition: .2s; }
.slider-sw::before { content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider-sw { background: var(--verde); }
.switch input:checked + .slider-sw::before { transform: translateX(22px); }

.tarifa-nota { margin-top: 20px; color: var(--gris); font-size: .9rem; background: #f6f9f6; padding: 10px 14px; border-radius: 10px; }
.error { color: var(--bad); min-height: 1.2em; margin-top: 8px; }

/* ---------- Resultado ---------- */
.resumen { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.pre-badge { display: block; color: var(--gris); font-size: .9rem; margin-bottom: 6px; }
.badge { display: inline-block; padding: 10px 26px; border-radius: 30px; font-size: clamp(1.6rem, 5vw, 2.1rem); font-weight: 700; color: #fff; }
.badge.eficiente { background: var(--ok); }
.badge.moderado { background: var(--warn); }
.badge.ineficiente { background: var(--bad); }
.cat-desc { margin-top: 12px; font-size: 1.05rem; color: var(--azul-osc); max-width: 420px; }
.confianza { color: var(--gris); margin-top: 8px; font-size: .9rem; }
.gauge-wrap { position: relative; }

/* Frase explicativa de la diferencia */
.explica { background: #fff; border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px 20px; font-size: 1.05rem; color: var(--azul-osc); margin-bottom: 20px; border-left: 4px solid var(--verde); }

.indicadores { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.ind { text-align: center; margin-bottom: 0; }
.ind-label { display: block; color: var(--gris); font-size: .9rem; font-weight: 600; }
.ind-valor { display: block; font-size: clamp(2rem, 6vw, 2.6rem); font-weight: 800; color: var(--azul-osc); line-height: 1.1; margin: 4px 0; }
.ind-unidad { display: block; color: var(--gris); font-size: .82rem; }
.ind-valor.up { color: var(--bad); }
.ind-valor.down { color: var(--ok); }

.dos-columnas { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.costo-mes-linea { font-size: 1.15rem; color: var(--azul-osc); }
.costo-mes { font-size: clamp(2rem, 6vw, 2.6rem); font-weight: 800; color: var(--verde-osc); }
.costo-calc { font-size: .95rem; color: var(--gris); margin-top: 10px; }
.costo-anual { color: var(--gris); margin-top: 6px; font-size: 1rem; }

.recs { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.recs li { background: var(--verde-cl); border-radius: 10px; padding: 12px 16px; position: relative; padding-left: 40px; }
.recs li::before { content: "✓"; position: absolute; left: 14px; color: var(--verde-osc); font-weight: 700; }

/* ---------- Simulador ---------- */
.sim-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 24px; align-items: start; }
.sim-opciones { display: flex; flex-direction: column; gap: 12px; }
.sim-op { display: flex; align-items: center; gap: 12px; background: #f6f9f6; border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.sim-op input { width: 18px; height: 18px; accent-color: var(--verde); cursor: pointer; }
.sim-op span { font-size: .92rem; }
.sim-op .pct { margin-left: auto; color: var(--verde-osc); font-weight: 600; font-size: .85rem; white-space: nowrap; }
.sim-ahorro { margin-top: 14px; text-align: center; }
.sim-ahorro p { font-size: 1.05rem; }
.sim-ahorro .ahorro { color: var(--ok); font-size: 1.3rem; font-weight: 700; margin-top: 8px; }
.sim-ahorro .ahorro-anual { color: var(--ok); font-size: .95rem; margin-top: 2px; }
.sim-ahorro b { font-size: 1.15em; }

/* ---------- Comparación entre períodos ---------- */
.opcional { color: var(--gris); font-weight: normal; font-size: .85rem; }
.comp-tabla-wrap { overflow-x: auto; margin-top: 16px; }
.comp-tabla { width: 100%; border-collapse: collapse; font-size: .9rem; }
.comp-tabla th, .comp-tabla td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--gris-cl); }
.comp-tabla th { color: var(--gris); font-weight: 600; }
.var-up { color: var(--bad); font-weight: 600; }
.var-down { color: var(--ok); font-weight: 600; }

/* ---------- Footer ---------- */
.footer { background: var(--verde); color: #eafaf0; text-align: center; padding: 16px; font-size: .9rem; margin-top: 30px; }

/* ---------- Responsive fino ---------- */
@media (max-width: 560px) {
    .acciones { flex-direction: column-reverse; }
    .acciones button { width: 100%; }
    .resumen { flex-direction: column; text-align: center; }
    .badge { font-size: 1.3rem; }
}

/* ---------- Benchmarking ---------- */
.bench-frase { font-size: 1.1rem; margin-bottom: 14px; }
.bench-barra { position: relative; height: 14px; border-radius: 8px;
    background: linear-gradient(90deg, #2E9E5B, #E0A800, #D0473B); }
.bench-marker { position: absolute; top: -5px; left: 50%; width: 6px; height: 24px;
    background: var(--azul-osc); border: 2px solid #fff; border-radius: 3px; transform: translateX(-50%);
    box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: left .5s ease; }
.bench-extremos { display: flex; justify-content: space-between; color: var(--gris); font-size: .8rem; margin-top: 8px; }

/* ---------- Spinner de carga ---------- */
.cargando { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 16px; background: rgba(241,251,243,.9); color: var(--azul-osc); }
.spinner { width: 48px; height: 48px; border: 5px solid var(--gris-cl); border-top-color: var(--verde);
    border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Accesibilidad: foco visible ---------- */
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
    outline: 3px solid var(--verde); outline-offset: 2px;
}

/* ---------- Modo oscuro ---------- */
body[data-theme="dark"] {
    --azul-osc: #e8f0ea; --gris: #9fb0a6; --gris-cl: #3a4a40;
    --bg: #0f1a14; --card: #182620; --verde-cl: #20342a;
}
body[data-theme="dark"] .explica,
body[data-theme="dark"] .ind { background: var(--card); }
body[data-theme="dark"] .campo input,
body[data-theme="dark"] .campo select { background: #0f1a14; color: #e8f0ea; }
body[data-theme="dark"] .tarifa-nota,
body[data-theme="dark"] .sim-op { background: #12201a; }
body[data-theme="dark"] .cargando { background: rgba(15,26,20,.92); }
body[data-theme="dark"] .bench-marker { border-color: #182620; }

/* ---------- Impresión / PDF ---------- */
@media print {
    .topbar, .footer, .no-print, .simulador, .historial { display: none !important; }
    body { background: #fff; }
    .vista { max-width: 100%; padding: 0; }
    .tarjeta, .ind { box-shadow: none; border: 1px solid #e0e0e0; break-inside: avoid; }
    h2 { margin-top: 0; }
}
