/* ============================================================================
   CostoReal · EstudioReal · css/app.css
   Fuentes locales (Poppins), sin recursos externos.
   ============================================================================ */

/* --- FUENTES LOCALES --- */
@font-face { font-family: 'Poppins'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/poppins-400.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/poppins-500.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/poppins-600.woff2') format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/poppins-700.woff2') format('woff2'); }

/* --- VARIABLES COMPARTIDAS (claro) --- */
:root {
    --er-esmeralda: #00D289;
    --er-esmeralda-oscuro: #007A52;
    --er-ambar: #F59E0B;
    --er-marino: #1B365D;
    --er-texto: #1f2937;
    --er-fondo: #F8F9FA;
    --er-superficie: #ffffff;
    --er-panel: #eef2f5;
    --er-borde: #d5dbe1;
    --er-suave: #4b5563;
    --er-peligro: #C62828;
    --er-sobre-esmeralda: #04281c;
    --er-sombra: rgba(0, 0, 0, 0.1);
    color-scheme: light;
}

/* --- MODO OSCURO (se activa con data-tema="oscuro" en <html>) --- */
:root[data-tema="oscuro"] {
    --er-marino: #8fb4ea;
    --er-texto: #e5e7eb;
    --er-fondo: #0f172a;
    --er-superficie: #1e293b;
    --er-panel: #273449;
    --er-borde: #3b4a63;
    --er-suave: #b6c0cf;
    --er-peligro: #ff8a80;
    --er-sombra: rgba(0, 0, 0, 0.5);
    color-scheme: dark;
}

/* --- BASE --- */
*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    padding: 20px 20px 90px;
    font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--er-fondo);
    color: var(--er-texto);
    line-height: 1.5;
}

.container {
    position: relative;
    max-width: 850px;
    margin: auto;
    padding: 30px;
    background: var(--er-superficie);
    border-radius: 15px;
    box-shadow: 0 10px 30px var(--er-sombra);
}

h1, h2, h3 { line-height: 1.25; }
section { margin-bottom: 25px; }

h2 {
    margin: 0 0 15px;
    padding-left: 10px;
    border-left: 5px solid var(--er-esmeralda);
    font-size: 1.1rem;
    color: var(--er-marino);
    text-transform: uppercase;
}

/* --- ACCESIBILIDAD --- */
.sr-only {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: 12px; top: -60px; z-index: 20000;
    padding: 12px 18px; background: var(--er-marino); color: var(--er-superficie);
    border-radius: 8px; font-weight: 600; text-decoration: none;
}
.skip-link:focus { top: 12px; }

:focus-visible { outline: 3px solid var(--er-ambar); outline-offset: 2px; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--er-ambar); outline-offset: 2px; }

.icono { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; flex: none; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* --- ENCABEZADO --- */
header { text-align: center; margin-bottom: 25px; padding-bottom: 10px; border-bottom: 3px solid var(--er-esmeralda); }
.barra-superior { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.logo-container { display: flex; justify-content: center; align-items: center; min-height: 60px; margin-bottom: 15px; }
.logo { height: 60px; width: auto; max-width: 200px; border-radius: 8px; }
.text-logo { display: none; margin: 0; font-size: 2.2rem; font-weight: 700; letter-spacing: -1px; color: var(--er-marino); }
.text-logo span { color: var(--er-esmeralda-oscuro); }
header h1 { margin: 0 0 10px; font-size: 1.6rem; color: var(--er-marino); }
.badge { display: inline-block; padding: 5px 15px; border-radius: 20px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font-size: 0.8rem; font-weight: 700; }

.btn-tema {
    display: inline-flex; align-items: center; gap: 8px; min-height: 44px; min-width: 44px;
    padding: 8px 14px; border: 1px solid var(--er-borde); border-radius: 22px;
    background: var(--er-superficie); color: var(--er-texto); font: inherit; font-size: 0.9rem; cursor: pointer;
}

/* --- MENSAJES FIJOS --- */
.privacidad-fija {
    display: flex; gap: 10px; align-items: flex-start; margin: 0 0 20px; padding: 12px 14px;
    background: var(--er-panel); border-left: 4px solid var(--er-esmeralda);
    border-radius: 8px; font-size: 0.9rem; color: var(--er-texto);
}
.deslinde { margin: 16px 0 0; padding: 12px 14px; border: 1px dashed var(--er-borde); border-radius: 8px; font-size: 0.85rem; color: var(--er-suave); }

/* --- NAVEGACIÓN Y MÓDULOS --- */
.tabs { display: none; flex-wrap: wrap; gap: 10px; margin-bottom: 25px; padding-bottom: 10px; border-bottom: 2px solid var(--er-borde); }
.tab-btn { flex: 1; min-height: 44px; padding: 12px 20px; border: none; border-radius: 8px; background: var(--er-panel); color: var(--er-texto); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; }
.tab-btn.active { background: var(--er-marino); color: var(--er-superficie); box-shadow: 0 4px 10px var(--er-sombra); }
:root[data-tema="oscuro"] .tab-btn.active { color: #0f172a; }

.modulo { display: none; }
.modulo.active { display: block; animation: aparecer 0.3s; }
@keyframes aparecer { from { opacity: 0; } to { opacity: 1; } }

.hero-section { text-align: center; padding: 20px 0 30px; }
.hero-section h2 { margin-bottom: 10px; padding: 0; border: none; font-size: 1.8rem; text-transform: none; }
.hero-section p { margin: 0 0 25px; font-size: 1.05rem; color: var(--er-suave); }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.sys-card {
    padding: 25px; border: 2px solid var(--er-borde); border-radius: 12px; background: var(--er-superficie);
    text-align: center; cursor: pointer; font: inherit; color: inherit; transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    box-shadow: 0 4px 6px var(--er-sombra);
}
.sys-card:hover, .sys-card:focus-visible { transform: translateY(-4px); border-color: var(--er-esmeralda); }
.sys-icon { display: block; margin: 0 auto 12px; width: 3rem; height: 3rem; color: var(--er-marino); }
.sys-title { display: block; margin-bottom: 10px; font-size: 1.25rem; font-weight: 700; color: var(--er-marino); }
.sys-desc { display: block; margin-bottom: 15px; font-size: 0.9rem; color: var(--er-suave); }
.sys-phrase { display: block; padding: 10px; border-radius: 8px; background: var(--er-panel); font-size: 0.85rem; font-weight: 600; font-style: italic; color: var(--er-texto); }

/* --- FORMULARIOS --- */
.module-card { margin-bottom: 30px; padding: 25px; border-radius: 12px; background: var(--er-superficie); box-shadow: 0 4px 12px var(--er-sombra); }
.config-panel { margin-bottom: 25px; padding: 20px; border: 1px dashed var(--er-borde); border-radius: 10px; background: var(--er-panel); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 15px; }
.row { display: grid; grid-template-columns: 2fr 1fr 1.2fr 48px; gap: 10px; margin-bottom: 10px; align-items: center; }
.header-row { font-size: 0.85rem; font-weight: 600; color: var(--er-suave); }

label { display: block; margin-bottom: 4px; font-size: 0.9rem; font-weight: 500; }
input, select {
    width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--er-borde); border-radius: 8px;
    background: var(--er-superficie); color: var(--er-texto); font: inherit; font-size: 1rem;
}
input::-webkit-inner-spin-button, input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

.tooltip-info { display: block; margin-top: 5px; font-size: 0.8rem; line-height: 1.4; color: var(--er-suave); }
.tooltip-info b { color: var(--er-marino); }

#msg-area { display: none; margin-bottom: 20px; padding: 15px; border-radius: 10px; font-size: 0.95rem; line-height: 1.5; }
.msg-error { background: #fee2e2; color: #7f1d1d; border: 1px solid #f87171; }
:root[data-tema="oscuro"] .msg-error { background: #4c1d1d; color: #fecaca; border-color: #b91c1c; }

/* --- BOTONES (mínimo 44 px) --- */
button { font-family: inherit; }
.btn-home, .btn-calc, .btn-save, .btn-action, .btn-wa, .btn-borrar {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
    border: none; border-radius: 8px; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn-home { display: none; margin-bottom: 20px; padding: 10px 20px; background: var(--er-marino); color: var(--er-superficie); }
:root[data-tema="oscuro"] .btn-home { color: #0f172a; }
.btn-calc { width: 100%; margin-top: 10px; padding: 14px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font-size: 1.15rem; }
.btn-save { width: 100%; margin-top: 15px; padding: 10px; background: var(--er-marino); color: var(--er-superficie); }
:root[data-tema="oscuro"] .btn-save { color: #0f172a; }
.btn-action { padding: 8px 14px; border: 1px solid var(--er-borde); background: var(--er-panel); color: var(--er-texto); font-size: 0.9rem; }
.btn-wa { padding: 8px 16px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font-size: 0.9rem; }
.btn-borrar { width: 48px; padding: 0; background: transparent; border: 1px solid var(--er-borde); color: var(--er-peligro); }

/* --- RESULTADOS --- */
.results-card { display: none; margin-top: 30px; padding: 25px; border-bottom: 5px solid var(--er-esmeralda); border-radius: 12px; background: #1B365D; color: #ffffff; }
.res-line { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; padding-bottom: 5px; border-bottom: 1px solid rgba(255, 255, 255, 0.15); }
.total-final { margin-top: 10px; padding-top: 10px; border-top: 2px solid var(--er-esmeralda); font-size: 1.6rem; font-weight: 700; color: var(--er-esmeralda); }
.break-even-box { margin-top: 15px; padding: 15px; border: 1px dashed rgba(255, 255, 255, 0.5); border-radius: 8px; background: rgba(255, 255, 255, 0.1); }
.riesgo-box { margin-top: 15px; padding: 12px; border: 1px solid #ff8a80; border-radius: 8px; background: rgba(229, 57, 53, 0.15); color: #ffe0de; font-size: 0.9rem; line-height: 1.4; }

/* --- HISTORIAL --- */
.history-container { margin-top: 40px; padding-top: 20px; border-top: 2px dashed var(--er-borde); }
.history-item { margin-bottom: 15px; padding: 15px; border: 1px solid var(--er-borde); border-left: 5px solid var(--er-esmeralda); border-radius: 10px; background: var(--er-superficie); }
.history-item.com, .history-item.srv { border-left-color: var(--er-marino); }
.lbl-dinamico { display: block; margin-top: 8px; font-size: 0.9rem; font-weight: 600; color: var(--er-marino); }
.desglose-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; padding: 15px; border: 1px solid var(--er-borde); border-left: 4px solid var(--er-marino); border-radius: 8px; background: var(--er-panel); }
.desglose-grid small { font-size: 0.8rem; text-transform: uppercase; color: var(--er-suave); }
.desglose-grid strong { display: block; margin-top: 2px; font-size: 0.95rem; color: var(--er-marino); }

/* --- RESPALDO --- */
.respaldo-panel { margin-top: 30px; padding: 20px; border: 1px solid var(--er-borde); border-radius: 12px; background: var(--er-panel); }
.respaldo-panel h3 { margin: 0 0 8px; font-size: 1.05rem; color: var(--er-marino); }
.respaldo-panel p { margin: 0 0 14px; font-size: 0.9rem; color: var(--er-texto); }
.respaldo-acciones { display: flex; flex-wrap: wrap; gap: 10px; }
.aviso-cache { margin-top: 14px; padding: 12px 14px; border-left: 4px solid var(--er-ambar); border-radius: 8px; background: var(--er-superficie); font-size: 0.88rem; }

/* --- PREMIUM PARA CLIENTES --- */
.premium-panel { margin-top: 30px; padding: 25px; border: 2px solid var(--er-esmeralda); border-radius: 12px; background: var(--er-superficie); text-align: center; box-shadow: 0 8px 20px var(--er-sombra); }
.premium-panel h3 { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0 0 12px; font-size: 1.1rem; color: var(--er-marino); }
.premium-panel p { margin: 0 0 16px; font-size: 0.95rem; color: var(--er-texto); }
.premium-acciones { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.btn-premium-wa, .btn-premium-enlace {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 12px 22px;
    border-radius: 10px; font-weight: 600; font-size: 0.95rem; text-decoration: none; cursor: pointer;
}
.btn-premium-wa { background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); border: 2px solid var(--er-esmeralda); }
.btn-premium-enlace { background: transparent; color: var(--er-marino); border: 2px solid var(--er-marino); }

/* --- BOTÓN FLOTANTE WHATSAPP --- */
.fab-wa {
    position: fixed; right: 20px; bottom: 20px; z-index: 999; display: inline-flex; align-items: center; gap: 8px;
    min-height: 48px; padding: 12px 20px; border-radius: 50px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda);
    font-weight: 700; text-decoration: none; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
}

/* --- PIE --- */
.pie-app { margin-top: 30px; padding: 18px 10px 0; border-top: 1px solid var(--er-borde); text-align: center; font-size: 0.85rem; color: var(--er-suave); }
.pie-app p { margin: 0 0 8px; }
.pie-app a, .enlace-cruzado a { color: var(--er-marino); font-weight: 600; text-underline-offset: 3px; }
.pie-app a { display: inline-block; padding: 8px 6px; }
.enlace-cruzado { margin-top: 10px; font-size: 0.85rem; }
.module-footer { margin-top: 18px; padding: 12px 10px; text-align: center; font-size: 0.9rem; color: var(--er-suave); }

/* --- MODALES Y AVISOS --- */
.custom-modal { display: none; position: fixed; inset: 0; z-index: 10000; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, 0.65); backdrop-filter: blur(4px); }
.custom-modal.abierto { display: flex; }
.custom-modal-content { width: 100%; max-width: 440px; max-height: 92vh; overflow-y: auto; border: 1px solid var(--er-borde); border-radius: 16px; background: var(--er-superficie); box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.25); }
.modal-cabecera { padding: 22px 20px 16px; background: #1B365D; color: #ffffff; text-align: center; }
.modal-cabecera h3 { margin: 8px 0 0; font-size: 1.15rem; }
.modal-cuerpo { padding: 20px; font-size: 0.95rem; }
.modal-cuerpo p { margin: 0 0 12px; }
.modal-cuerpo a { color: var(--er-marino); font-weight: 600; }
.modal-pie { display: flex; flex-direction: column; gap: 10px; padding: 0 20px 20px; }
.btn-modal-principal { min-height: 48px; padding: 12px; border: none; border-radius: 10px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font-size: 1rem; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.btn-close-modal { min-height: 44px; width: 100%; border: none; border-radius: 8px; background: transparent; color: var(--er-suave); font-size: 0.95rem; cursor: pointer; }

.aviso-actualizacion {
    position: fixed; left: 50%; bottom: 84px; z-index: 10001; display: none; align-items: center; gap: 10px;
    max-width: calc(100% - 24px); padding: 10px 14px; transform: translateX(-50%);
    border-radius: 12px; background: #1B365D; color: #ffffff; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); font-size: 0.9rem;
}
.aviso-actualizacion.visible { display: flex; }
.aviso-actualizacion button { min-height: 44px; padding: 8px 16px; border: none; border-radius: 8px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font-weight: 700; cursor: pointer; }

.custom-toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 10002; display: flex; align-items: center; gap: 8px;
    padding: 14px 28px; border-radius: 12px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda);
    font-size: 15px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2); opacity: 0; pointer-events: none;
    transform: translateX(-50%) translateY(20px); transition: transform 0.3s ease, opacity 0.3s ease;
}
.custom-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --- ADAPTABLE --- */
@media (max-width: 768px) {
    body { padding: 10px 10px 100px; }
    .container { margin: 0; padding: 20px; border-radius: 10px; }
    .tabs { flex-direction: column; gap: 8px; }
    .module-card, .results-card { padding: 20px; }
    .row { grid-template-columns: 1fr; gap: 8px; }
    .header-row { display: none; }
    .desglose-grid { grid-template-columns: 1fr; gap: 8px; }
    .fab-wa { right: 15px; bottom: 15px; }
}
@media (max-width: 600px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 10px; }
}
@media (max-width: 480px) {
    .container { padding: 15px; }
    .logo { height: 45px; max-width: 150px; }
    header h1 { font-size: 1.25rem; }
    .hero-section h2 { font-size: 1.35rem; }
    .btn-calc, .btn-save { font-size: 1.05rem; }
}

/* --- COMPLEMENTOS DE index.html --- */
[hidden] { display: none !important; }
.sys-card { display: block; width: 100%; }
.btn-ancho { width: 100%; margin-top: 6px; }
.espacio-arriba { margin-top: 15px; }
.campo-obligatorio { margin-bottom: 15px; border-color: var(--er-esmeralda-oscuro); border-width: 2px; }
.modal-cuerpo h3 { margin: 0 0 10px; font-size: 1.2rem; color: var(--er-marino); }
.caja-mensaje { width: 100%; height: 160px; padding: 12px; border: 1px solid var(--er-borde); border-radius: 8px; background: var(--er-panel); color: var(--er-texto); font: inherit; font-size: 0.9rem; resize: none; }
.btn-modal-peligro { min-height: 48px; padding: 12px; border: none; border-radius: 10px; background: var(--er-peligro); color: #ffffff; font-size: 1rem; font-weight: 700; cursor: pointer; }
:root[data-tema="oscuro"] .btn-modal-peligro { color: #1a0000; }
.nota-resultado { margin: 12px 0 0; font-size: 0.82rem; opacity: 0.9; }
.nota-resultado:empty { display: none; }
.equilibrio-titulo { margin-bottom: 10px; text-align: center; font-size: 1.05rem; }
.equilibrio-cifra { font-size: 1.6rem; color: #FFC107; }
.equilibrio-mensaje { margin-bottom: 15px; padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.25); text-align: center; font-size: 0.95rem; }
.semaforo { display: flex; min-height: 52px; overflow: hidden; border-radius: 8px; font-weight: 600; text-align: center; }
.sem { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; padding: 4px; line-height: 1.2; }
.sem-chico { font-size: 0.75rem; }
.sem-rojo { background: #C62828; color: #ffffff; }
.sem-amarillo { background: #FFC107; color: #1f2937; border-left: 2px solid #ffffff; border-right: 2px solid #ffffff; }
.sem-verde { background: #00D289; color: #04281c; }

/* --- INSTALAR APP (Android: evento del navegador; iPhone: guía) --- */
.barra-superior, .barra-herramientas { gap: 10px; flex-wrap: wrap; }
.btn-instalar { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 16px; border: 2px solid var(--er-esmeralda); border-radius: 22px; background: var(--er-esmeralda); color: var(--er-sobre-esmeralda); font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; }
.guia-instalar { margin: 0 0 12px; padding-left: 22px; }
.guia-instalar li { margin-bottom: 10px; }
.guia-instalar .icono { width: 1.4em; height: 1.4em; }

/* Enlace cruzado del pie: sin espacio antes del punto */
.enlace-cruzado a { display: inline; padding: 0; }
