@font-face {
    font-family: Manrope;
    src: url("fonts/manrope-latin.woff2") format("woff2");
    font-weight: 200 800;
    font-display: swap;
}

@font-face {
    font-family: "Space Grotesk";
    src: url("fonts/space-grotesk-latin.woff2") format("woff2");
    font-weight: 300 700;
    font-display: swap;
}

:root {
    color-scheme: light;
    --canvas: #eef2ee;
    --surface: #fdfefb;
    --ink: #19231f;
    --muted: #515e54;
    --line: #d6ded5;
    --control: #819083;
    --soft: #e5ece3;
    --forest: #22372c;
    --rail-text: #f5f8ef;
    --rail-muted: #b7c7ba;
    --rail-item: #304037;
    --rail-line: #53675a;
    --accent: #d7ef78;
    --accent-hover: #e6f69e;
    --accent-line: #a7bd5c;
    --bar: #52735a;
    --bar-hover: #2d4d36;
    --alert-bg: #fff0e7;
    --alert-text: #713b2c;
    --radius: 20px;
    --page-gutter: clamp(22px, 3.3vw, 52px);
    --display: "Space Grotesk", Manrope, system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; background: var(--canvas); color: var(--ink); font: 15px/1.5 Manrope, system-ui, sans-serif; }
h1, h2, p, dl, dd, figure { margin: 0; }
h1, h2 { font-family: var(--display); font-weight: 700; line-height: 1.08; letter-spacing: -.04em; overflow-wrap: anywhere; }
h1 { font-size: clamp(2.15rem, 4vw, 3.15rem); }
h2 { font-size: clamp(1.3rem, 2.5vw, 1.65rem); }
a { color: inherit; }
button, input { font: inherit; }
small { font-size: .78rem; }
:focus-visible { outline: 2px solid var(--bar-hover); outline-offset: 4px; }
.page-main, .app-header-inner { width: 100%; max-width: 1400px; margin-inline: auto; padding-inline: var(--page-gutter); }
.page-main { padding-block: 39px 70px; }
.icon { display: block; width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link:focus { position: fixed; z-index: 3; inset: 8px auto auto 8px; padding: 10px 14px; background: var(--surface); }

.app-header { background: var(--ink); color: var(--rail-text); }
.app-header-inner { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 16px; min-height: 70px; padding-block: 10px; }
.app-header :focus-visible { outline-color: var(--accent); outline-offset: 2px; }
.brand { display: flex; align-items: center; gap: 11px; width: fit-content; text-decoration: none; }
.brand-mark { display: grid; width: 40px; height: 40px; flex: none; place-items: center; border-radius: 12px; background: var(--accent); color: var(--ink); }
.brand-mark .icon { width: 25px; height: 25px; stroke-width: 2; }
.brand-type { display: grid; gap: 1px; }
.brand-type strong { font: 700 1.55rem/1 var(--display); letter-spacing: -.05em; }
.brand-type small { color: var(--rail-muted); font-size: .72rem; }
.primary-nav { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; }
.primary-nav a { display: flex; align-items: center; gap: 11px; min-height: 45px; padding: 8px 11px; border-radius: 9px; color: var(--rail-muted); font-size: .86rem; font-weight: 750; text-decoration: none; }
.primary-nav a:hover, .primary-nav a[aria-current="page"] { background: var(--rail-item); color: var(--rail-text); }
.primary-nav a[aria-current="page"] .icon { color: var(--accent); }
.account { display: flex; justify-self: end; align-items: center; gap: 10px; }
.account-role { color: var(--rail-muted); font-size: .75rem; }

.button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: .86rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background .16s ease, border-color .16s ease, transform .12s ease;
}
.button:active { transform: translateY(1px); }
.button-primary { background: var(--forest); color: var(--rail-text); }
.button-primary:hover { background: var(--bar-hover); }
.button-quiet { border-color: var(--control); background: var(--surface); color: var(--ink); }
.button-quiet:hover { background: var(--soft); }
.button-account { border-color: var(--rail-line); color: var(--rail-text); white-space: nowrap; }
.button-account:hover { background: var(--rail-item); }
.icon-button, .edit-payment { width: 44px; flex: none; padding: 0; }

.page-heading, .section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; }
.page-heading { margin-bottom: 28px; }
.section-heading { margin-bottom: 15px; }
.page-heading p, .section-heading p, .planner-heading p { margin-top: 4px; color: var(--muted); }
.section-heading p, .planner-heading p { font-size: .85rem; }
.page-actions { display: flex; flex: none; flex-wrap: wrap; gap: 8px; }
.overview-grid { display: grid; grid-template-columns: minmax(0, 1.82fr) minmax(0, 1fr); gap: 16px; }
.overview-grid:has(.forecast-disclosure[open]) .balance-panel { align-self: start; }
.planner, .balance-panel, .purchase-balance, .purchase-summary, .form-panel { padding: clamp(17px, 2.2vw, 27px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.planner, .ledger, .form-panel { scroll-margin-block-start: 20px; }
.planner-heading, .purchase-balance-heading { display: flex; align-items: center; gap: 12px; }
.panel-mark { display: grid; place-items: center; width: 42px; height: 42px; flex: none; border-radius: 11px; background: var(--soft); color: var(--forest); }
.panel-mark .icon { width: 22px; height: 22px; }
.planner-total { margin-top: 20px; }
.planner-total dt { color: var(--muted); font-size: .8rem; font-weight: 750; }
.planner-total dd, .balance-amount, .purchase-summary > strong { display: block; font: 700 clamp(1.95rem, 4vw, 3rem)/1.04 var(--display); letter-spacing: -.06em; overflow-wrap: anywhere; }
.planner-total dd { margin-top: 3px; }
.planner-total dd, .balance-amount, .balance-metrics dd, .balance-progress strong, .forecast-frame, .forecast-list strong,
.plan-next strong, .ledger-table td, .purchase-summary > strong, .purchase-amounts dd, .history-row > strong { font-variant-numeric: tabular-nums; }

.forecast { margin-top: 18px; }
.forecast-frame { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 9px; row-gap: 6px; font-size: .7rem; color: var(--muted); }
.forecast-scale { display: grid; grid-template-rows: auto 1fr auto; justify-items: end; }
.forecast-scale span:first-child { line-height: 1; }
.forecast-scale span:nth-child(2) { align-self: center; }
.forecast-plot {
    position: relative;
    min-width: 0;
    height: clamp(105px, 12vw, 155px);
    overflow: hidden;
    border-bottom: 1px solid var(--line);
    background: linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 50% repeat-y;
}
.forecast-bars, .forecast-layer { position: absolute; inset: 0; }
.forecast-bars, .forecast-steps { display: grid; grid-template-columns: repeat(var(--periods), minmax(0, 1fr)); justify-items: center; }
.forecast-bars { align-items: end; }
.forecast-bars span { width: min(74%, 46px); height: var(--fill); border-radius: 5px 5px 0 0; background: var(--bar); }
.forecast-bars span:first-child { background: var(--accent); box-shadow: inset 0 0 0 1px var(--bar-hover); }
.forecast-plot.is-enhanced .forecast-bars { visibility: hidden; }
.forecast-unit { text-align: right; }
.forecast-disclosure { margin-top: 13px; border-top: 1px solid var(--line); }
.forecast-disclosure summary { padding: 11px 0 1px; color: var(--forest); font-size: .83rem; font-weight: 800; cursor: pointer; }
.forecast-disclosure summary:hover { text-decoration: underline; text-underline-offset: 3px; }
.forecast-disclosure p { margin-top: 8px; color: var(--muted); font-size: .8rem; }
.forecast-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr)); gap: 0 16px; margin: 10px 0 0; padding: 0; list-style: none; }
.forecast-list li { display: flex; justify-content: space-between; gap: 8px; padding-block: 7px; border-top: 1px solid var(--line); font-size: .8rem; }
.forecast-list li span { flex: none; }
.forecast-list strong { overflow-wrap: anywhere; text-align: right; }
.planner-empty { margin-top: 18px; background: var(--canvas); }

.balance-panel { display: flex; flex-direction: column; background: var(--accent); border-color: var(--accent-line); }
.balance-panel h2, .purchase-balance h2, .purchase-summary h2 { font: 800 1rem/1.3 Manrope, system-ui, sans-serif; letter-spacing: -.025em; }
.balance-amount { margin-top: 8px; font-size: clamp(2rem, 3.6vw, 3.55rem); }
.balance-note, .balance-progress p { margin-top: 7px; font-size: .78rem; }
.balance-metrics { display: grid; margin-top: 19px; border-top: 1px solid var(--accent-line); }
.balance-metrics > div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; min-width: 0; padding: 10px 0; border-bottom: 1px solid var(--accent-line); }
.balance-metrics dt { font-size: .81rem; font-weight: 800; }
.balance-metrics small { display: block; font-size: .71rem; font-weight: 500; }
.balance-metrics dd { font: 700 clamp(.95rem, 1.55vw, 1.2rem)/1.2 var(--display); text-align: right; overflow-wrap: anywhere; }
.balance-progress { margin-top: 16px; }
.balance-panel .balance-progress { margin-top: auto; padding-top: 16px; }
.balance-progress > div { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 7px; font-size: .8rem; font-weight: 750; }
progress { display: block; width: 100%; min-width: 0; height: 6px; border: 0; border-radius: 6px; overflow: hidden; appearance: none; background: var(--line); color: var(--bar); }
progress::-webkit-progress-bar { background: var(--line); }
progress::-webkit-progress-value { border-radius: 6px; background: var(--bar); }
progress::-moz-progress-bar { border-radius: 6px; background: var(--bar); }
.balance-panel progress { background: var(--accent-line); }
.balance-panel progress::-webkit-progress-bar { background: var(--accent-line); }

.installments, .ledger, .payments-layout, #nueva-compra { margin-top: 33px; }
.installment-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 242px), 1fr)); gap: 11px; margin: 0; padding: 0; list-style: none; }
.plan-link {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "term arrow" "name name" "next remaining";
    align-items: start;
    gap: 9px 12px;
    height: 100%;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: var(--surface);
    text-decoration: none;
    overflow-wrap: anywhere;
    transition: border-color .16s ease, background .16s ease;
}
.plan-link:hover { border-color: var(--control); background: var(--soft); }
.plan-term { grid-area: term; width: fit-content; padding: 3px 7px; border-radius: 4px; background: var(--soft); color: var(--forest); font-size: .72rem; font-weight: 750; }
.plan-arrow { grid-area: arrow; justify-self: end; width: 17px; height: 17px; color: var(--bar-hover); }
.plan-name { grid-area: name; align-self: start; font-weight: 800; }
.plan-next { grid-area: next; }
.plan-next strong { display: block; font: 700 1.23rem/1.1 var(--display); }
.plan-next small { display: block; margin-top: 2px; color: var(--muted); font-size: .7rem; }
.plan-left { grid-area: remaining; align-self: center; text-align: right; color: var(--muted); font-size: .73rem; font-weight: 750; }

.ledger-filters { display: inline-flex; align-items: center; gap: 2px; padding: 3px; border-radius: 9px; background: var(--soft); }
.ledger-filters button { min-height: 38px; padding: 5px 11px; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: .79rem; font-weight: 800; }
.ledger-filters button:hover { color: var(--ink); }
.ledger-filters button[aria-pressed="true"] { border-color: var(--accent-line); background: var(--accent); color: var(--ink); }
.ledger-table { width: 100%; table-layout: fixed; border-spacing: 0 5px; text-align: left; }
.ledger-table th, .ledger-table td { padding: 12px clamp(8px, 1.15vw, 15px); overflow-wrap: anywhere; }
.ledger-table thead th { padding-block: 4px; color: var(--muted); font-size: .74rem; font-weight: 800; }
.ledger-table thead th:first-child { width: 26%; }
.ledger-table thead th:nth-child(2), .ledger-table thead th:nth-child(3) { width: 17%; }
.ledger-table thead th:nth-child(4) { width: 15%; }
.ledger-table thead th:nth-child(5) { width: 20%; }
.ledger-table thead th:last-child { width: 5%; }
.ledger-table tbody tr { position: relative; background: var(--surface); }
.ledger-table tbody tr:hover, .ledger-table tbody tr:focus-within { background: var(--soft); }
.ledger-table tbody th, .ledger-table td { border-block: 1px solid var(--line); }
.ledger-table tbody th { border-inline-start: 1px solid var(--line); border-radius: 9px 0 0 9px; }
.ledger-table tbody td:last-child { border-inline-end: 1px solid var(--line); border-radius: 0 9px 9px 0; }
.ledger-table td { font-size: .86rem; }
.ledger-table small { display: block; margin-top: 3px; color: var(--muted); font-weight: 550; }
.purchase-link { font-weight: 800; text-decoration: none; }
.purchase-link::after { position: absolute; inset: 0; content: ""; }
.purchase-link:hover, .purchase-link:focus-visible { text-decoration: underline; text-underline-offset: 3px; }
.payment-count { display: inline-block; padding: 3px 7px; border-radius: 5px; background: var(--soft); color: var(--forest); font-size: .76rem; font-weight: 800; }
.row-arrow { color: var(--bar-hover); }
.row-arrow .icon { margin-inline-start: auto; width: 16px; height: 16px; transition: transform .16s ease; }
.ledger-table tbody tr:hover .row-arrow .icon, .ledger-table tbody tr:focus-within .row-arrow .icon { transform: translateX(2px); }
.mobile-label { display: none; }
.progress-line { display: flex; align-items: center; gap: 7px; max-width: 156px; color: var(--muted); font-size: .72rem; font-weight: 800; }
.progress-line span { flex: none; white-space: nowrap; }
.empty-state { padding: 17px; border: 1px dashed var(--control); border-radius: 11px; }
.empty-state p { margin-top: 4px; color: var(--muted); font-size: .84rem; }
.notice { margin-block: 0 18px; padding: 12px 15px; border: 1px solid var(--alert-text); border-radius: 8px; background: var(--alert-bg); color: var(--alert-text); font-size: .88rem; font-weight: 750; }

.purchase-form { display: grid; grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr)) auto; align-items: end; gap: 12px; }
.form-stack { display: grid; gap: 14px; }
label { display: grid; min-width: 0; gap: 5px; font-size: .81rem; font-weight: 800; }
.optional { color: var(--muted); font-weight: 550; }
input:not([type="hidden"]) { min-width: 0; width: 100%; min-height: 44px; padding: 8px 11px; border: 1px solid var(--control); border-radius: 8px; background: var(--surface); color: var(--ink); font-size: 1rem; font-weight: 550; }
input::placeholder { color: var(--muted); }
input:focus-visible { border-color: var(--bar-hover); outline-offset: 2px; }

.back-link { display: inline-flex; gap: 7px; align-items: center; min-height: 44px; margin-block: -7px 11px; color: var(--forest); font-size: .84rem; font-weight: 800; text-decoration: none; }
.back-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.detail-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: stretch; }
.purchase-balance-heading { justify-content: space-between; }
.purchase-status { padding: 4px 8px; border-radius: 5px; background: var(--soft); color: var(--forest); font-size: .73rem; font-weight: 800; }
.purchase-balance .balance-progress { margin-top: 14px; }
.purchase-amounts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 17px; padding-top: 12px; border-top: 1px solid var(--line); }
.purchase-amounts dt { color: var(--muted); font-size: .78rem; }
.purchase-amounts dd { margin-top: 2px; font: 700 clamp(1rem, 2.5vw, 1.4rem)/1.2 var(--display); overflow-wrap: anywhere; }
.purchase-summary { display: flex; flex-direction: column; align-items: start; justify-content: center; gap: 6px; background: var(--forest); color: var(--rail-text); }
.purchase-summary .panel-mark { width: 37px; height: 37px; margin-bottom: 7px; background: var(--rail-item); color: var(--accent); }
.purchase-summary > strong { color: var(--accent); }
.purchase-summary p { color: var(--rail-muted); font-size: .84rem; }
.payments-layout.with-form { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); align-items: start; gap: 20px; }
.payment-history { display: grid; gap: 5px; margin: 0; padding: 0; list-style: none; }
.history-row { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.history-mark { display: grid; flex: none; width: 33px; height: 33px; place-items: center; border-radius: 7px; background: var(--soft); color: var(--bar-hover); }
.history-row > div { min-width: 0; margin-inline-end: auto; }
.history-row time { color: var(--muted); font-size: .75rem; }
.history-row p { margin-top: 1px; font-weight: 750; overflow-wrap: anywhere; }
.history-row > strong { font: 700 1rem/1.25 var(--display); text-align: right; overflow-wrap: anywhere; }
.edit-dialog { width: min(460px, calc(100% - 32px)); max-height: calc(100% - 32px); padding: 22px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); color: var(--ink); }
.edit-dialog .section-heading { align-items: center; }
.edit-dialog::backdrop { background: rgb(25 35 31 / .65); }

.login-page { max-width: 1030px; padding-top: clamp(28px, 8vh, 80px); }
.login-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, .9fr); gap: 14px; }
.login-form { padding: clamp(20px, 3.4vw, 38px); }
.login-form .panel-mark { margin-bottom: 15px; }
.login-form h1 { font-size: clamp(1.85rem, 3.1vw, 2.65rem); }
.login-form .section-heading { margin-bottom: 23px; }
.login-intro { position: relative; display: block; min-height: 270px; overflow: hidden; padding: clamp(20px, 3.2vw, 38px); border-radius: var(--radius); background: var(--accent); }
.login-intro p { position: relative; z-index: 1; font: 700 clamp(1.7rem, 3.7vw, 2.75rem)/1.05 var(--display); letter-spacing: -.05em; }
.login-intro span { position: relative; z-index: 1; display: block; margin-top: 6px; font-size: .87rem; }
.login-art { position: absolute; inset: auto 0 0 auto; width: min(100%, 360px); color: var(--bar-hover); pointer-events: none; }

@media (min-width: 681px) {
    .installment-list > li:only-child .plan-link {
        grid-template-columns: minmax(0, 1fr) auto auto auto;
        grid-template-areas: "name next remaining arrow" "term next remaining arrow";
        column-gap: clamp(14px, 3vw, 36px);
        row-gap: 3px;
    }
    .installment-list > li:only-child :is(.plan-arrow, .plan-next) { align-self: center; }
}

@media (max-width: 1030px) {
    .account-role { display: none; }
    .page-main { padding-top: 27px; }
}

@media (max-width: 760px) {
    :root { --page-gutter: 16px; }
    .app-header-inner { grid-template-columns: minmax(0, 1fr) auto; gap: 7px 10px; padding-bottom: 7px; }
    .primary-nav { grid-area: 2 / 1 / 3 / -1; gap: 3px; }
    .primary-nav a { justify-content: center; gap: 6px; min-height: 44px; padding-inline: 8px; font-size: .81rem; }
    .primary-nav .icon { width: 15px; height: 15px; }
    .account { grid-area: 1 / 2; }
    .page-main { padding-block: 24px 48px; }
    .overview-grid, .detail-grid, .payments-layout.with-form { grid-template-columns: minmax(0, 1fr); }
    .page-heading, .ledger .section-heading { flex-direction: column; align-items: flex-start; gap: 12px; }
    .page-heading { margin-bottom: 20px; }
    .balance-metrics dd { font-size: 1.1rem; }
    .installments, .ledger, .payments-layout, #nueva-compra { margin-top: 27px; }
    .purchase-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .purchase-form label:first-of-type, .purchase-form .button { grid-column: 1 / -1; }
    .ledger-table, .ledger-table tbody { display: block; }
    .ledger-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
    .ledger-table tbody { display: grid; gap: 7px; }
    .ledger-table tbody tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; padding: 13px; border: 1px solid var(--line); border-radius: 11px; }
    .ledger-table tbody th, .ledger-table td, .ledger-table tbody td:last-child { padding: 0; border: 0; }
    .ledger-table .purchase-name { grid-column: 1 / -1; padding-inline-end: 24px; }
    .ledger-table .row-arrow { position: absolute; inset: 15px 13px auto auto; pointer-events: none; }
    .mobile-label { display: block; margin-bottom: 2px; color: var(--muted); font-size: .72rem; font-weight: 750; }
}

@media (max-width: 560px) {
    .brand-mark { width: 35px; height: 35px; }
    .brand-type strong { font-size: 1.36rem; }
    .button-account { padding-inline: 9px; }
    .button-account .icon { width: 15px; height: 15px; }
    .forecast-steps.is-dense span:not(:first-child):not(:last-child):nth-child(odd),
    .forecast-steps.is-dense span:nth-child(2),
    .forecast-steps.is-dense span:nth-last-child(2) { visibility: hidden; }
    .forecast-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .login-layout { grid-template-columns: minmax(0, 1fr); }
    .login-intro { min-height: 150px; }
    .login-art { width: min(56%, 255px); }
    .history-row { gap: 8px; }
    .history-mark { display: none; }
}

@media (max-width: 360px) {
    .primary-nav .icon { display: none; }
}

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