body { overflow-x: hidden; line-height: 1.6; }

.editable-display {
background: transparent;
border: none;
border-bottom: 1px dashed rgba(201, 168, 76, 0.3);
color: var(--gold);
font-family: var(--font-num); font-variant-numeric: tabular-nums;
font-size: 0.8rem;
font-weight: 500;
text-align: right;
width: 110px;
outline: none;
cursor: text;
transition: border-color 0.2s;
padding-bottom: 1px;
}
.editable-display:hover {
border-bottom-color: rgba(201, 168, 76, 0.7);
}
.editable-display:focus {
border-bottom: 1px solid var(--gold);
background: rgba(201, 168, 76, 0.05);
border-radius: 3px 3px 0 0;
}

/* ===== NAVBAR ===== (la base está en /css/navbar.css; aquí la transición, el logo y los enlaces son algo distintos) */
.navbar { transition: all 0.4s; }
.nav-logo-text { font-size: 1.4rem; }
.nav-links a { font-weight: 400; }

/* ===== PAGE HEADER ===== */
.page-header {
    padding: 8rem 2rem 3rem;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.page-header::before {
    content: '';
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 0%, rgba(123, 45, 53, 0.2) 0%, transparent 60%);
}
.page-header-content { position: relative; z-index: 1; }
.page-title {
    font-family: var(--font-display);
    font-size: clamp(2.2rem, 5vw, 3.5rem);
    font-weight: 600; margin-bottom: 1rem; line-height: 1.2;
}
.page-subtitle {
    font-size: 1.1rem; color: var(--cream); opacity: 0.6;
    max-width: 600px; margin: 0 auto; font-weight: 300; line-height: 1.7;
}

/* ===== MAIN LAYOUT ===== */
.calc-section {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}
.calc-grid {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 2rem;
    align-items: start;
}
/* ===== INPUT PANEL ===== */
.input-panel {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.25);
    border-radius: 20px;
    padding: 2rem;
    position: sticky;
    top: 80px;
    backdrop-filter: blur(10px);
}
.input-panel-title {
    font-family: var(--font-display);
    font-size: 1.3rem; font-weight: 600;
    margin-bottom: 0.3rem;
}
.input-panel-desc {
    font-size: 0.85rem; color: var(--cream); opacity: 0.55;
    margin-bottom: 1.5rem;
}
.input-group {
    margin-bottom: 1.2rem;
}
.input-label {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 0.5rem;
}
.input-label label {
    font-size: 0.85rem; font-weight: 500; color: var(--cream); opacity: 0.8;
}

.input-wrapper {
    position: relative;
}
.input-wrapper input[type="range"] {
    width: 100%; height: 6px;
    -webkit-appearance: none; appearance: none;
    background: rgba(123, 45, 53, 0.3);
    border-radius: 3px; outline: none;
    cursor: pointer;
}
.input-wrapper input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none; appearance: none;
    width: 20px; height: 20px;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    border-radius: 50%; cursor: pointer;
    box-shadow: 0 2px 8px rgba(201, 168, 76, 0.4);
    transition: transform 0.2s;
}
.input-wrapper input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}
.input-wrapper input[type="range"]::-moz-range-thumb {
    width: 20px; height: 20px;
    background: linear-gradient(135deg, var(--gold), var(--gold-light));
    border-radius: 50%; cursor: pointer; border: none;
    box-shadow: 0 2px 8px rgba(201, 168, 76, 0.4);
}

.input-prefix {
    position: absolute; left: 1rem; top: 50%; transform: translateY(-50%);
    color: var(--cream); opacity: 0.55; font-size: 0.9rem;
    pointer-events: none;
}

.input-select {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid rgba(123, 45, 53, 0.3);
    border-radius: 10px;
    padding: 0.75rem 1rem;
    color: var(--cream);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    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='%23C9A84C' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    transition: all 0.3s;
}
.input-select:focus {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.1);
}
.input-select option {
    background: var(--bg-card);
    color: var(--cream);
}
.input-divider {
    height: 1px;
    background: rgba(123, 45, 53, 0.2);
    margin: 1.5rem 0;
}
.input-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--gold);
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.input-section-title::before {
    content: '';
    width: 16px; height: 2px;
    background: var(--gold);
    border-radius: 1px;
}
.toggle-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.6rem 0;
}
.toggle-label {
    font-size: 0.85rem; color: var(--cream); opacity: 0.7;
}
.toggle {
    width: 44px; height: 24px;
    background: rgba(123, 45, 53, 0.3);
    border-radius: 12px;
    position: relative;
    cursor: pointer;
    transition: background 0.3s;
    border: none;
}
.toggle.active {
    background: var(--gold);
}
.toggle::after {
    content: '';
    position: absolute;
    width: 18px; height: 18px;
    background: var(--white);
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform 0.3s;
}
.toggle.active::after {
    transform: translateX(20px);
}
.advanced-fields {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.5s ease;
}
.advanced-fields.open {
    max-height: 600px;
}

/* ===== RESULTS PANEL ===== */
.results-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Summary Cards */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 1rem;
}
.summary-card {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.2);
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s;
}
.summary-card:hover {
    border-color: rgba(201, 168, 76, 0.3);
    transform: translateY(-3px);
}
.summary-card-icon {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}
.summary-card-value {
    font-family: var(--font-num);
    font-variant-numeric: tabular-nums;
    font-size: 1.6rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}
.summary-card-value.gold { color: var(--gold); }
.summary-card-value.green { color: var(--success); }
.summary-card-value.burgundy { color: var(--burgundy-pale); }
.summary-card-value.blue { color: var(--blue); }
.summary-card-label {
    font-size: 0.75rem;
    color: var(--cream);
    opacity: 0.55;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Chart Area */
.chart-card {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.2);
    border-radius: 20px;
    padding: 2rem;
}
.chart-card-header {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.chart-card-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
}
.chart-tabs {
    display: flex; gap: 0.25rem;
    background: rgba(26, 10, 14, 0.5);
    border-radius: 8px;
    padding: 3px;
}
.chart-tab {
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: pointer;
    border: none;
    background: transparent;
    color: var(--cream);
    opacity: 0.55;
    transition: all 0.3s;
    font-family: var(--font-sans);
}
.chart-tab.active {
    background: var(--burgundy);
    opacity: 1;
}
.chart-area {
    position: relative;
    height: 350px;
}
.chart-area canvas {
    width: 100%;
    height: 100%;
}
.chart-legend {
    display: flex;
    gap: 1.5rem;
    margin-top: 1rem;
    justify-content: center;
}
.chart-legend-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--cream);
    opacity: 0.7;
}
.chart-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

/* Donut Chart */
.donut-section {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}
.donut-card {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.2);
    border-radius: 20px;
    padding: 2rem;
}
.donut-card-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    text-align: center;
}
.donut-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 2rem;
}
.donut-canvas {
    width: 180px;
    height: 180px;
}
.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.donut-legend-color {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    flex-shrink: 0;
}
.donut-legend-text {
    font-size: 0.85rem;
}
.donut-legend-text .dl-label {
    opacity: 0.6;
    font-size: 0.75rem;
}
.donut-legend-text .dl-value {
    font-family: var(--font-num); font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: 0.85rem;
}

/* Yearly Table */
.table-card {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.2);
    border-radius: 20px;
    padding: 2rem;
    overflow: hidden;
}
.table-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}
.table-card-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
}
.table-toggle {
    font-size: 0.8rem;
    color: var(--gold);
    cursor: pointer;
    background: none;
    border: none;
    font-family: var(--font-sans);
    transition: opacity 0.3s;
}
.table-toggle:hover { opacity: 0.7; }
.table-wrapper {
    border-radius: 12px;
    overflow: hidden;
}
.results-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.results-table thead {
    display: table;
    width: 100%;
    table-layout: fixed;
}
.results-table thead th {
    padding: 0.8rem 1rem;
    text-align: right;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--cream);
    opacity: 0.55;
    font-weight: 500;
    border-bottom: 1px solid rgba(123, 45, 53, 0.2);
    background: var(--bg-card);
}
.results-table tbody {
    display: block;
    max-height: 360px;
    overflow-y: auto;
    width: 100%;
}
.results-table tbody::-webkit-scrollbar { width: 4px; }
.results-table tbody::-webkit-scrollbar-track { background: transparent; }
.results-table tbody::-webkit-scrollbar-thumb { background: var(--burgundy); border-radius: 2px; }
.results-table tbody tr {
    display: table;
    width: 100%;
    table-layout: fixed;
}
.results-table thead th:first-child { text-align: center; }
.results-table tbody td {
    padding: 0.7rem 1rem;
    text-align: right;
    font-size: 0.85rem;
    font-family: var(--font-num); font-variant-numeric: tabular-nums;
    border-bottom: 1px solid rgba(123, 45, 53, 0.08);
    color: var(--cream);
    opacity: 0.8;
}
.results-table tbody td:first-child {
    text-align: center;
    font-weight: 600;
    opacity: 0.6;
}
.results-table tbody tr:hover {
    background: rgba(123, 45, 53, 0.1);
}
.results-table tbody tr:last-child td { border-bottom: none; }
.results-table .positive { color: var(--success); }
.results-table .neutral { color: var(--gold); }
/* Formula Section */
.formula-card {
    background: rgba(42, 16, 21, 0.7);
    border: 1px solid rgba(123, 45, 53, 0.2);
    border-radius: 20px;
    padding: 2rem;
    text-align: center;
}
.formula-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 1rem;
}
.formula-display {
    font-family: var(--font-num); font-variant-numeric: tabular-nums;
    font-size: 1.1rem;
    color: var(--gold);
    padding: 1.5rem;
    background: rgba(26, 10, 14, 0.5);
    border-radius: 12px;
    margin-bottom: 1rem;
    letter-spacing: 1px;
    overflow-x: auto;
}
.formula-explanation {
    font-size: 0.85rem;
    color: var(--cream);
    opacity: 0.55;
    line-height: 1.7;
    max-width: 500px;
    margin: 0 auto;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 1200px) {
    .calc-grid {
        grid-template-columns: 340px 1fr;
    }
    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}
@media (max-width: 900px) {
    .calc-grid {
        grid-template-columns: 1fr;
    }
    .input-panel {
        position: static;
    }
    .donut-section {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 600px) {
    .summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 0.6rem;
    }
    .summary-card { padding: 1rem 0.6rem; }
    .summary-card-value { font-size: 1.2rem; overflow-wrap: anywhere; }
    .chart-tabs { flex-wrap: wrap; }
    .chart-area { height: 250px; }
    .page-header { padding: 7rem 1.5rem 2rem; }
    .calc-section { padding: 1.5rem 1rem; }
    /* desglose anual: sin «Saldo inicio» (es el saldo final del año anterior) para que quepan las cifras */
    .results-table th:nth-child(3), .results-table td:nth-child(3) { display: none; }
    .results-table thead th { padding: 0.7rem 0.4rem; font-size: 0.6rem; letter-spacing: 0.4px; }
    .results-table tbody td { padding: 0.6rem 0.4rem; font-size: 0.74rem; }
    .results-table th:first-child, .results-table td:first-child { width: 2.6rem; }
}

/* ===== ANIMATIONS ===== */
.fade-in {
    opacity: 0;
    transform: translateY(20px);
    animation: fadeIn 0.6s ease forwards;
}
@keyframes fadeIn {
    to { opacity: 1; transform: translateY(0); }
}
.delay-1 { animation-delay: 0.1s; }
.delay-2 { animation-delay: 0.2s; }
.delay-3 { animation-delay: 0.3s; }
.delay-5 { animation-delay: 0.5s; }

/* Tooltip */
.info-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px; height: 16px;
    border-radius: 50%;
    background: rgba(123, 45, 53, 0.3);
    font-size: 0.6rem;
    color: var(--cream);
    opacity: 0.55;
    cursor: help;
    margin-left: 0.3rem;
    position: relative;
}
.info-tip:hover { opacity: 1; }
.info-tip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 130%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-card);
    border: 1px solid rgba(123, 45, 53, 0.3);
    color: var(--cream);
    font-size: 0.7rem;
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}
.info-tip:hover::after { opacity: 1; }
/* Móvil: la ayuda oculta ocupaba sitio a lo ancho y la página se movía de lado.
   Ahora no existe hasta que se toca, y parte la línea si es larga. */
@media (max-width: 900px) {
    .info-tip::after { display: none; white-space: normal; width: max-content; max-width: min(220px, 70vw); }
    .info-tip:hover::after, .info-tip:focus::after { display: block; }
}

/* Number animation */
.animate-number {
    transition: all 0.5s ease;
}

/* Móvil: que los paneles no se salgan de la pantalla. */
.calc-grid > *, .donut-section > * { min-width: 0; }
