html {
    scroll-behavior: smooth;
    scroll-padding-top: 4.5rem;
}

.nav-link {
    position: relative;
    padding: 0.25rem 0;
    transition: color 180ms ease;
}

.nav-link:hover,
.nav-link:focus-visible {
    color: var(--ink);
}

.nav-link::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -2px;
    height: 1px;
    background: currentColor;
    transform: scaleX(0);
    transform-origin: left center;
    transition: transform 220ms ease;
}

.nav-link:hover::after,
.nav-link:focus-visible::after {
    transform: scaleX(1);
}

:root {
    --ink: #0a0a0a;
    --ink-light: #2a2a2a;
    --ink-secondary: #404040;
    --ink-muted: #737373;
    --surface: #fafafa;
    --surface-elevated: #ffffff;
    --surface-inset: #f5f5f5;
    --line: #e5e5e5;
    --line-light: #f0f0f0;
    --danger: #b91c1c;
}

*::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--ink);
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background: #000;
    background-clip: padding-box;
    border: 2px solid transparent;
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

html {
    scrollbar-color: var(--ink) transparent;
    scrollbar-width: thin;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    text-decoration: none;
}

.skip-link:focus-visible {
    top: 0.375rem;
}

.form-field {
    width: 100%;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: max(16px, 0.9rem);
    background: var(--surface-elevated);
    color: var(--ink);
    min-height: 44px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

.form-field:focus {
    outline: none;
    border-color: var(--ink);
    box-shadow: 0 0 0 3px rgba(10, 10, 10, 0.06);
}

.form-field-prefix {
    padding-left: 1.75rem;
}

.form-field-suffix {
    padding-right: 3rem;
}

.form-group.error .form-field {
    border-color: var(--danger);
    box-shadow: 0 0 0 2px rgba(185, 28, 28, 0.15);
}

.error-message {
    font-size: 0.775rem;
    color: var(--danger);
    margin-top: 0.25rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.error-message::before {
    content: "!";
    font-size: 0.6rem;
    font-weight: 600;
    width: 14px;
    height: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--danger);
    color: #fff;
    border-radius: 50%;
    flex-shrink: 0;
}

.error-message.hidden {
    display: none;
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.btn-primary,
.btn-export {
    position: relative;
}

.btn-primary .btn-text,
.btn-export .btn-text {
    transition: opacity 0.15s ease;
}

.btn-primary.loading .btn-text,
.btn-export.loading .btn-text {
    opacity: 0;
    position: absolute;
}

.btn-primary.loading .btn-loading,
.btn-export.loading .btn-loading {
    display: inline-flex;
}

.select-arrow {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23525252' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 16px;
}

.summary-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.625rem 0.875rem;
    background: var(--surface-inset);
    border-radius: 8px;
}

.summary-row>span:first-child {
    font-size: 0.775rem;
    color: var(--ink-secondary);
}

.summary-row>span:last-child {
    font-size: 0.825rem;
    font-weight: 500;
    color: var(--ink);
    font-variant-numeric: tabular-nums;
}

.stat-cell {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 0.5rem;
    background: var(--surface-inset);
    border-radius: 8px;
    text-align: center;
}

.stat-cell-label {
    font-size: 0.6rem;
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.125rem;
}

.stat-cell-value {
    font-family: 'Instrument Serif', Georgia, serif;
    font-size: clamp(1rem, 3vw, 1.35rem);
    color: var(--ink);
}

.stat-cell-sub {
    font-size: 0.675rem;
    color: var(--ink-muted);
}

.milestone-cell {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
    padding: 1rem 0.5rem;
    background: var(--surface-inset);
    border-radius: 8px;
    text-align: center;
    transition: background 0.15s ease;
}

.milestone-cell:hover {
    background: rgba(10, 10, 10, 0.04);
}

.legend-indicator {
    flex-shrink: 0;
    display: inline-block;
}

.legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
}

.legend-initial {
    background: rgba(10, 10, 10, 0.22);
}

.legend-invested {
    background: rgba(10, 10, 10, 0.55);
}

.legend-interest {
    background: #0a0a0a;
}

/* Toast notifications (JS-injected, fixed at bottom) */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: 4.5rem;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    z-index: 9999;
    pointer-events: none;
    width: max-content;
    max-width: calc(100% - 2rem);
}

.toast {
    background: var(--ink);
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: 10px;
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
    animation: toastIn 0.25s ease;
    pointer-events: auto;
    max-width: 100%;
}

.toast::before {
    font-weight: 600;
}

.toast-success::before {
    content: "\2713";
}

.toast-error {
    background: #b91c1c;
}

.toast-error::before {
    content: "\26A0";
}

.toast-out {
    animation: toastOut 0.25s ease forwards;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(8px);
    }
}

.yearly-table th {
    background: var(--ink);
    color: #fff;
    font-weight: 500;
    padding: 0.75rem;
    text-align: center;
    border-bottom: 1px solid var(--line);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.yearly-table th:nth-child(n+2) {
    text-align: right;
}

.yearly-table td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--line-light);
    color: var(--ink);
    white-space: nowrap;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.yearly-table td:first-child {
    text-align: center;
    font-weight: 500;
}

.yearly-table tbody tr:not([aria-label="Fila de resumen total"]):hover {
    background: rgba(10, 10, 10, 0.035);
}

.yearly-table tr[aria-label="Fila de resumen total"]:hover {
    background: #0a0a0a;
}

.yearly-table tr[aria-label="Fila de resumen total"]:hover td {
    color: #ffffff;
}

.yearly-table tr[aria-label="Fila de resumen total"] {
    background: var(--surface-inset);
}

.yearly-table tr[aria-label="Fila de resumen total"] td {
    font-weight: 600;
    border-top: 2px solid var(--ink);
}

.yearly-table td:focus,
.yearly-table th:focus {
    outline: 2px solid var(--ink);
    outline-offset: -2px;
    background: rgba(10, 10, 10, 0.04);
}

.chart-canvas-wrap {
    position: relative;
}

.chart-canvas-wrap>canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

@media (min-width: 1000px) {
    .yearly-table {
        font-size: 0.825rem;
        min-width: 600px;
    }
}

/* 4-column dashboard only on 4K+ displays; below that, the Tailwind
   lg:/xl: 2-column layout handles it. Unwraps main-layout/insights-layout
   so their children slot into the .dashboard grid directly. */
@media (min-width: 2560px) {
    body>div:has(> .dashboard) {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        gap: 1.5rem;
    }

    body>div:has(> .dashboard)>section:first-of-type {
        gap: 1.5rem;
        margin-bottom: 0;
    }

    .dashboard {
        display: grid;
        grid-template-columns: minmax(0, 0.7fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
        grid-template-rows: minmax(0, 780px);
        gap: 1.5rem;
        align-items: stretch;
        overflow: visible;
        margin-bottom: 0;
    }

    .dashboard>.main-layout,
    .dashboard>.insights-layout {
        display: contents;
    }

    .dashboard .calc-section,
    .dashboard .results-section,
    .dashboard .chart-section,
    .dashboard .table-section {
        margin: 0;
        position: static;
        min-width: 0;
        overflow: hidden;
        align-self: stretch;
    }

    .dashboard .calc-section>div,
    .dashboard .results-section>div,
    .dashboard .chart-section>div,
    .dashboard .table-section>div {
        height: 100%;
        overflow: auto;
    }

    .dashboard .chart-section,
    .dashboard .table-section {
        display: flex;
        flex-direction: column;
    }

    .dashboard .calc-section>div {
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .dashboard .results-section {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 100%;
    }

    .dashboard .results-section>div {
        flex: 0 0 auto;
        height: auto;
        overflow: visible;
    }

    .dashboard .chart-canvas-wrap {
        min-height: 380px;
        max-height: 480px;
        flex: 1;
    }

    .dashboard .calc-section>div,
    .dashboard .results-section>div,
    .dashboard .chart-section>div,
    .dashboard .table-section>div {
        padding: 1.25rem;
    }

    .yearly-table {
        min-width: 0;
        font-size: 0.78rem;
        table-layout: fixed;
    }

    .yearly-table th,
    .yearly-table td {
        padding: 0.55rem 0.5rem;
        overflow: hidden;
        text-overflow: ellipsis;
    }
}

@media (min-width: 1000px) and (max-width: 2559px) {
    .dashboard .chart-canvas-wrap {
        height: 400px;
    }
}

@media (min-width: 3840px) {
    .dashboard {
        grid-template-columns: minmax(0, 0.7fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 2fr);
        gap: 2rem;
    }

    .dashboard .chart-canvas-wrap {
        min-height: 420px;
        max-height: 520px;
    }

    .dashboard {
        grid-template-rows: minmax(0, 860px);
    }

    .yearly-table {
        font-size: 0.9rem;
    }

    .yearly-table th,
    .yearly-table td {
        padding: 0.75rem;
    }
}

/* Mobile: unify gaps between card sections */
@media (max-width: 1023px) {

    .main-layout,
    .insights-layout,
    .results-section {
        gap: 1rem;
    }

    .main-layout {
        margin-bottom: 1rem;
    }

    body>div:has(> .dashboard)>section:first-of-type,
    .dashboard>section:first-of-type {
        margin-bottom: 1rem;
    }

    main>section.grid {
        gap: 1rem;
        margin-bottom: 1rem;
    }
}

/* Mobile: transform table rows into cards using data-label attrs from JS */
@media (max-width: 768px) {
    .yearly-table {
        font-size: 0.8rem;
        border: 0;
    }

    .yearly-table,
    .yearly-table thead,
    .yearly-table tbody,
    .yearly-table th,
    .yearly-table td,
    .yearly-table tr {
        display: block;
    }

    .yearly-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    .yearly-table tr {
        border: 1px solid var(--line);
        border-radius: 8px;
        margin-bottom: 0.625rem;
        padding: 0.875rem;
        background: #fff;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    }

    .yearly-table td {
        border: none;
        padding: 0.25rem 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        text-align: right;
    }

    .yearly-table td::before {
        content: attr(data-label);
        font-weight: 500;
        color: var(--ink-muted);
        text-transform: uppercase;
        font-size: 0.7rem;
        letter-spacing: 0.05em;
        margin-right: 1rem;
    }

    .yearly-table td:first-child {
        text-align: left;
        font-weight: 600;
        padding-bottom: 0.5rem;
        margin-bottom: 0.5rem;
        border-bottom: 1px solid var(--line-light);
        justify-content: flex-start;
    }

    .yearly-table td:first-child::before {
        display: none;
    }

    .yearly-table tr[aria-label="Fila de resumen total"] {
        background: var(--ink);
        border: 1px solid var(--ink);
        color: var(--surface);
    }

    .yearly-table tr[aria-label="Fila de resumen total"] td {
        border-top: none;
        color: var(--surface);
    }

    .yearly-table tr[aria-label="Fila de resumen total"] td::before {
        color: rgba(255, 255, 255, 0.7);
    }

    .yearly-table tr[aria-label="Fila de resumen total"] td:first-child {
        border-bottom-color: rgba(255, 255, 255, 0.2);
    }
}

@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

@media print {

    .btn-primary,
    .btn-export,
    .skip-link {
        display: none !important;
    }

    .calc-section {
        position: static !important;
    }

    #chartContainer,
    #yearlyResultsCard {
        break-inside: avoid;
    }
}

/* Info tooltip trigger */
.info-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 4px;
    border-radius: 999px;
    background: #e0e0e0;
    color: var(--ink-muted);
    font-family: "Instrument Serif", Georgia, serif;
    font-style: italic;
    font-size: 11px;
    line-height: 1;
    cursor: help;
    vertical-align: middle;
    transition: background 0.15s ease, color 0.15s ease;
}

.info-tip:hover,
.info-tip:focus-visible {
    background: #d4d4d4;
    color: var(--ink-secondary);
    outline: none;
}

/* Floating tooltip bubble (appended to body, positioned via JS) */
.info-tip-bubble {
    position: fixed;
    z-index: 1000;
    max-width: 240px;
    padding: 0.625rem 0.75rem;
    background: #e5e5e5;
    color: var(--ink-secondary);
    border-radius: 8px;
    font-family: "DM Sans", system-ui, sans-serif;
    font-size: 0.775rem;
    line-height: 1.4;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
    opacity: 0;
    transform: translateY(4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.info-tip-bubble.is-visible {
    opacity: 1;
    transform: translateY(0);
}

/* Financial ticker banner */
@keyframes ticker-scroll {
    0% {
        transform: translateX(0);
    }

    100% {
        transform: translateX(var(--ticker-offset, -50%));
    }
}

.ticker-track {
    display: flex;
    width: max-content;
    animation: ticker-scroll var(--ticker-duration, 40s) linear infinite;
    gap: 0;
    align-items: center;
}

.ticker-track:hover,
#tickerBanner:focus-within .ticker-track,
body.is-hidden .ticker-track {
    animation-play-state: paused;
}

.ticker-item {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0 0.125rem;
}

a.ticker-link {
    position: relative;
    text-decoration: none;
    color: inherit;
}

a.ticker-link::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 1px;
    height: 1px;
    background: rgba(255, 255, 255, 0.7);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

a.ticker-link:hover::after,
a.ticker-link:focus-visible::after {
    opacity: 1;
}

a.ticker-link:focus-visible {
    outline: none;
}

.ticker-label {
    font-weight: 700;
    font-size: 0.8125rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.95);
}

.ticker-value {
    font-weight: 500;
    font-size: 0.9375rem;
    color: #ffffff;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.005em;
}

.ticker-unit {
    margin-left: 0.3125rem;
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.75);
    font-variant-numeric: normal;
    vertical-align: baseline;
}

[data-legend-value] {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 0.375rem;
}

.legend-val-num {
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.legend-val-unit {
    flex-shrink: 0;
    min-width: 2.25em;
    text-align: left;
    color: var(--ink-secondary);
    font-size: 0.6875rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    font-variant-numeric: normal;
}

.ticker-change {
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
}

.ticker-change.up {
    color: #22c55e;
}

.ticker-change.down {
    color: #ef4444;
}

[data-legend-change] .ticker-change.up,
[data-stat].ticker-change.up {
    color: #166534;
}

[data-legend-change] .ticker-change.down,
[data-stat].ticker-change.down {
    color: #b91c1c;
}

.ticker-divider {
    width: 1px;
    height: 1.125rem;
    margin: 0 1.125rem;
    background: rgba(255, 255, 255, 0.18);
    flex-shrink: 0;
    align-self: center;
}

@media (prefers-reduced-motion: reduce) {
    .ticker-track {
        animation: none;
        overflow-x: auto;
    }

    .ticker-track .ticker-content[aria-hidden="true"] {
        display: none;
    }
}

.info-tip-bubble::after {
    content: "";
    position: absolute;
    left: var(--arrow-x, 50%);
    top: 100%;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border: 6px solid transparent;
    border-top-color: #e5e5e5;
}

/* Legend row link (main page) */
.legend-link {
    color: inherit;
    text-decoration: none;
}

.legend-row:hover .legend-link,
.legend-link:hover,
.legend-link:focus-visible {
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
    outline: none;
}

.legend-row {
    cursor: pointer;
}

/* Indicator detail page */
.indicator-unit {
    font-family: "DM Sans", system-ui, sans-serif;
    font-size: 0.875rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #737373;
    margin-left: 0.375rem;
    font-variant-numeric: normal;
}

.indicator-change-badge {
    font-size: 0.9375rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    padding: 0.125rem 0.5rem;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
}

.indicator-change-badge.up {
    color: #15803d;
    background: rgba(34, 197, 94, 0.12);
}

.indicator-change-badge.down {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.1);
}

.period-selector {
    display: inline-flex;
    align-items: center;
    background: #f5f5f5;
    border-radius: 999px;
    padding: 3px;
    gap: 2px;
}

.period-btn {
    border: 0;
    background: transparent;
    color: #737373;
    font-family: "DM Sans", system-ui, sans-serif;
    font-weight: 500;
    font-size: 0.75rem;
    letter-spacing: 0.02em;
    padding: 0.375rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.period-btn:hover {
    color: #0a0a0a;
}

.period-btn.is-active {
    background: #ffffff;
    color: #0a0a0a;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.period-btn:focus-visible {
    outline: 2px solid #ff7a1a;
    outline-offset: 1px;
}

.indicator-chart-wrap {
    position: relative;
    width: 100%;
    height: 260px;
}

@media (min-width: 1000px) {
    .indicator-chart-wrap {
        height: 340px;
    }
}

@media (min-width: 2560px) {
    .indicator-chart-wrap {
        height: 420px;
    }
}