/* ==============================================
   RENTABILIDADREAL.COM — Estilos globales
   ===============================================
   Estructura:
   1. Variables y reset
   2. Base (body, tipografía)
   3. Nav
   4. Layout (container, hero)
   5. Card
   6. Formulario
   7. Resultado principal (sell/hold)
   8. Gráficos
   9. Momentos clave
   10. Costes
   11. Tabla
   12. Footer
   13. Responsive (móvil)
================================================ */


/* -----------------------------------------------
   1. VARIABLES Y RESET
----------------------------------------------- */

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

:root {
    --azul:    #2563eb;
    --verde:   #16a34a;
    --naranja: #ea580c;
    --rojo:    #dc2626;
    --morado:  #7c3aed;
    --gris:    #6b7280;
    --fondo:   #f6f7f9;
    --blanco:  #ffffff;
    --borde:   #e5e7eb;
    --texto:   #1f2933;
}


/* -----------------------------------------------
   2. BASE
----------------------------------------------- */

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--fondo);
    color: var(--texto);
    line-height: 1.6;
    font-size: 16px;
}

h1, h2, h3, h4 { line-height: 1.2; }

h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: 16px; }
h3 { font-size: 1rem;   font-weight: 700; margin-bottom: 12px; }
h4 { font-size: 0.95rem; font-weight: 600; margin: 16px 0 8px; color: #374151; }

strong { color: #111827; }

p { margin-bottom: 10px; }
p:last-child { margin-bottom: 0; }

ul { padding-left: 20px; }
li { margin-bottom: 6px; }

hr {
    border: none;
    border-top: 1px solid var(--borde);
    margin: 20px 0;
}

.formula {
    background: #f1f5f9;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    margin: 10px 0;
}

.frase-educativa {
    font-size: 0.88rem;
    color: var(--gris);
    font-style: italic;
    margin-top: 10px;
}

.explicacion {
    font-size: 0.85rem;
    color: var(--gris);
    line-height: 1.5;
    display: block;
    margin-top: 4px;
}

.nota-secundaria {
    font-size: 0.82rem;
    color: var(--gris);
    font-style: italic;
}


/* -----------------------------------------------
   4. LAYOUT
----------------------------------------------- */

.container {
    max-width: 860px;
    margin: 0 auto;
    padding: 32px 16px 64px;
}

/* HERO */
.hero {
    text-align: center;
    margin-bottom: 32px;
}

.hero-badge {
    display: inline-block;
    background: #dbeafe;
    color: var(--azul);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    margin-bottom: 14px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.hero h1 {
    font-size: clamp(1.6rem, 4vw, 2.2rem);
    font-weight: 800;
    margin-bottom: 12px;
    color: var(--texto);
}

.hero h1 em {
    font-style: normal;
    color: var(--azul);
}

.hero p {
    font-size: 1.05rem;
    color: var(--gris);
    max-width: 580px;
    margin: 0 auto;
    line-height: 1.7;
}


/* -----------------------------------------------
   5. CARD
----------------------------------------------- */

.card {
    background: var(--blanco);
    border-radius: 14px;
    padding: 24px 28px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.06);
    margin-bottom: 20px;
}


/* -----------------------------------------------
   6. FORMULARIO
----------------------------------------------- */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.campo {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.campo label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
}

.campo input,
.campo select {
    padding: 10px 12px;
    border: 1.5px solid var(--borde);
    border-radius: 8px;
    font-size: 0.95rem;
    color: var(--texto);
    font-family: inherit;
    transition: border-color 0.15s;
    width: 100%;
    background: var(--blanco);
}

.campo input:focus,
.campo select:focus {
    outline: none;
    border-color: var(--azul);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

.campo-full {
    grid-column: 1 / -1;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    font-weight: 500;
    color: #374151;
    cursor: pointer;
}

.checkbox-label input {
    width: auto !important;
    margin: 0;
}

.btn-avanzado {
    width: 100%;
    padding: 10px;
    background: var(--fondo);
    color: var(--gris);
    border: 1.5px solid var(--borde);
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
}

.btn-avanzado:hover { background: #edf0f3; }

.btn-calcular {
    width: 100%;
    padding: 13px;
    background: var(--azul);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    margin-top: 12px;
    transition: background 0.15s, transform 0.1s;
}

.btn-calcular:hover  { background: #1d4ed8; }
.btn-calcular:active { transform: scale(0.99); }


/* -----------------------------------------------
   7. RESULTADO PRINCIPAL — sell vs hold
----------------------------------------------- */

.label-real {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--gris);
    margin-left: 6px;
}

.sell-hold-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-bottom: 16px;
}

.resultado-tarjeta {
    border-radius: 10px;
    padding: 18px 20px;
    border: 1.5px solid var(--borde);
}

.resultado-tarjeta.hold {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.resultado-tarjeta.sell {
    border-color: var(--borde);
    background: #fafafa;
}

.tarjeta-label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--gris);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.tarjeta-valor {
    font-size: 1.55rem;
    font-weight: 800;
    color: var(--texto);
    line-height: 1.1;
    margin-bottom: 6px;
}

.resultado-tarjeta.hold .tarjeta-valor { color: var(--verde); }

.tarjeta-sub {
    font-size: 0.82rem;
    color: var(--gris);
}

.diferencia-texto {
    font-size: 0.9rem;
    color: #374151;
    padding: 12px 14px;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 10px;
}


/* -----------------------------------------------
   8. GRÁFICOS
----------------------------------------------- */

.grafico-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.grafico-header h3 { margin-bottom: 4px; }

.grafico-header p {
    font-size: 0.82rem;
    color: var(--gris);
    margin: 0;
}

.nivel-pill {
    font-size: 0.68rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
}

.pill-0 { background: #dcfce7; color: #15803d; }
.pill-1 { background: #dbeafe; color: #1d4ed8; }

.canvas-container {
    position: relative;
    height: 280px;
}

.leyenda {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 14px;
}

.leyenda-grid4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px 16px;
    margin-top: 14px;
}

@media (max-width: 640px) {
    .leyenda-grid4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.leyenda-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: #374151;
}

.leyenda-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Gráficos bloqueados nivel 1 */
.grafico-bloqueado {
    position: relative;
}

.canvas-blur {
    filter: blur(5px);
    pointer-events: none;
    user-select: none;
}

.overlay-registro {
    position: absolute;
    inset: 80px 0 0 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    z-index: 10;
}

.overlay-registro p {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--texto);
}

.overlay-registro span {
    font-size: 0.8rem;
    color: var(--gris);
}

.btn-registro {
    padding: 9px 20px;
    background: var(--azul);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    margin-top: 4px;
}


/* -----------------------------------------------
   9. MOMENTOS CLAVE
----------------------------------------------- */

.momentos-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-top: 8px;
}

.momento-bloque h4 { margin-top: 0; }

.momento-bloque p {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--verde);
    margin: 4px 0 6px;
}

.metrica-valor {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--verde);
    margin: 6px 0;
}

.metrica-explicacion {
    font-size: 0.88rem;
    color: #374151;
    line-height: 1.6;
}


/* -----------------------------------------------
   10. COSTES
----------------------------------------------- */

.costes-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.coste-bloque {
    background: #fafafa;
    border: 1px solid var(--borde);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
}

.coste-icono { font-size: 1.3rem; margin-bottom: 6px; }

.coste-label {
    font-size: 0.75rem;
    color: var(--gris);
    font-weight: 500;
    margin-bottom: 6px;
    line-height: 1.3;
}

.coste-valor {
    font-size: 0.92rem;
    font-weight: 700;
}

.coste-valor.rojo { color: var(--rojo); }

.coste-total-bloque {
    background: #f8fafc;
    border-radius: 8px;
    padding: 14px 16px;
    font-size: 0.88rem;
    color: #374151;
}

.coste-total-bloque p { margin-bottom: 6px; }


/* -----------------------------------------------
   11. TABLA
----------------------------------------------- */

.table-container {
    overflow-x: auto;
    margin-top: 16px;
    margin-bottom: 16px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

th, td {
    padding: 8px 10px;
    text-align: right;
    white-space: nowrap;
}

th {
    background: #f1f5f9;
    text-align: center;
    font-size: 0.78rem;
    font-weight: 600;
    color: #374151;
}

td:first-child { text-align: center; }

tbody tr:hover { background: #f8fafc; }

.badge-venta {
    margin-left: 6px;
    padding: 2px 6px;
    font-size: 0.72rem;
    border-radius: 6px;
    background: #fee2e2;
    color: #991b1b;
    font-weight: 600;
}

.btn-expandir-tabla {
    display: block;
    margin: 10px auto 0;
    padding: 8px 20px;
    background: #f1f5f9;
    border: 1px solid var(--borde);
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-expandir-tabla:hover { background: #e2e8f0; }

tr.fila-oculta          { display: none; }
tr.fila-oculta.visible  { display: table-row; }

.tabla-leyenda {
    font-size: 0.82rem;
    color: var(--gris);
    line-height: 1.6;
    margin-top: 8px;
}


/* -----------------------------------------------
   12. FOOTER
----------------------------------------------- */

footer {
    max-width: 860px;
    margin: 0 auto;
    padding: 28px 16px;
    border-top: 1px solid var(--borde);
    text-align: center;
    font-size: 0.82rem;
    color: var(--gris);
    line-height: 1.6;
}

footer p { margin-bottom: 6px; }

footer a { color: var(--gris); }
footer a:hover { color: var(--azul); }


/* -----------------------------------------------
   13. RESPONSIVE (móvil)
----------------------------------------------- */

@media (max-width: 640px) {

    .container { padding: 20px 12px 48px; }

    .card { padding: 18px 16px; }

    .form-grid { grid-template-columns: 1fr; }

    .sell-hold-grid { grid-template-columns: 1fr; }

    .momentos-grid { grid-template-columns: 1fr; }

    .costes-grid { grid-template-columns: repeat(2, 1fr); }

    .grafico-header { flex-direction: column; gap: 8px; }

    /* Tabla en móvil: scroll horizontal, todas las columnas visibles */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 0.75rem;
        min-width: 600px;
    }

    th, td {
        padding: 6px 8px;
    }
}

/* COSTE REAL DE UN GASTO */
.btn-secundario {
    padding: 10px 20px;
    background: transparent;
    color: var(--azul);
    border: 2px solid var(--azul);
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-secundario:hover {
    background: var(--azul);
    color: white;
}

.coste-gasto-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 14px;
}

.coste-gasto-item {
    background: var(--fondo);
    border-radius: 10px;
    padding: 14px 16px;
    text-align: center;
}

.cg-label {
    font-size: 0.75rem;
    color: var(--gris);
    font-weight: 500;
    margin-bottom: 6px;
}

.cg-valor {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--verde);
}

.cg-explicacion {
    font-size: 0.85rem;
    color: var(--gris);
    line-height: 1.6;
    padding: 12px 16px;
    background: #f0fdf4;
    border-left: 3px solid var(--verde);
    border-radius: 0 8px 8px 0;
}

@media (max-width: 640px) {
    .coste-gasto-grid { grid-template-columns: 1fr; }
}
