:root {
  --ink: #17312b;
  --muted: #66726d;
  --bg: #f4f2eb;
  --card: #fffefa;
  --line: #dfdfd7;
  --accent: #1d5b4d;
  --accent-2: #cff3ad;
  --needs: #1d5b4d;
  --lifestyle: #f0a85d;
  --future: #8cbf68;
  --danger: #b04c3f;
  --shadow: 0 14px 35px rgba(31, 55, 48, 0.07);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--ink); }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(29, 91, 77, 0.28); outline-offset: 2px; }

.skip-link { position: fixed; left: 16px; top: -60px; z-index: 100; background: var(--ink); color: white; padding: 10px 14px; border-radius: 8px; }
.skip-link:focus { top: 12px; }
.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; }

.topbar { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px max(24px, calc((100vw - 1280px) / 2)); border-bottom: 1px solid rgba(23, 49, 43, 0.1); background: rgba(244, 242, 235, 0.88); backdrop-filter: blur(16px); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: var(--ink); color: var(--accent-2); font-weight: 900; font-size: 21px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: -0.02em; }
.brand small { color: var(--muted); margin-top: 1px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.privacy-pill { color: var(--muted); font-size: 13px; padding-right: 8px; }
.privacy-pill span { color: #67a352; font-size: 10px; margin-right: 5px; }

.shell { max-width: 1280px; margin: 0 auto; padding: 48px 24px 64px; }
.welcome { display: flex; justify-content: space-between; align-items: end; gap: 32px; margin-bottom: 28px; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: 11px; letter-spacing: .15em; font-weight: 800; }
h1, h2, p { margin-top: 0; }
h1 { max-width: 700px; margin-bottom: 10px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(38px, 5vw, 64px); line-height: .98; letter-spacing: -.04em; font-weight: 500; }
h2 { margin-bottom: 6px; font-family: Georgia, "Times New Roman", serif; font-size: 27px; line-height: 1.08; letter-spacing: -.025em; font-weight: 600; }
.welcome-copy { max-width: 650px; color: var(--muted); font-size: 17px; margin-bottom: 0; }
.month-control { display: grid; gap: 8px; min-width: 190px; font-size: 12px; color: var(--muted); font-weight: 700; }
.month-control input { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); padding: 0 12px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); }
.planner-grid { display: grid; grid-template-columns: 1.06fr .94fr; gap: 18px; }
.income-card, .distribution-card { padding: 26px; min-height: 354px; }
.card-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.card-heading.compact { align-items: center; }
.income-icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 50%; background: #ecf5e7; color: var(--accent); font-size: 21px; }
.money-input-wrap { display: flex; align-items: center; gap: 10px; margin-top: 18px; border-bottom: 1px solid var(--line); }
.money-input-wrap span { font-family: Georgia, serif; font-size: 38px; color: var(--muted); }
.money-input-wrap input { width: 100%; border: 0; background: transparent; color: var(--ink); font-family: Georgia, serif; font-size: clamp(44px, 5vw, 68px); line-height: 1; padding: 7px 0 12px; outline: none; letter-spacing: -.04em; }
.money-input-wrap input::-webkit-inner-spin-button { appearance: none; }
.field-help, .preset-box p { color: var(--muted); font-size: 12px; }
.field-help { margin: 8px 0 20px; }
.preset-box { background: #f4f7ef; border: 1px solid #e2eadb; padding: 14px; border-radius: 15px; }
.preset-box > label { display: block; font-size: 11px; font-weight: 800; margin-bottom: 7px; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
.preset-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.preset-box select { min-width: 0; width: 100%; height: 40px; border: 1px solid #d9e4d3; border-radius: 10px; background: white; padding: 0 10px; color: var(--ink); }
.preset-box p { margin: 8px 2px 0; line-height: 1.45; }

.button { border: 0; border-radius: 11px; min-height: 40px; padding: 0 15px; color: var(--ink); font-weight: 750; font-size: 13px; transition: transform .16s ease, background .16s ease, box-shadow .16s ease; }
.button:hover { transform: translateY(-1px); }
.button-primary { background: var(--ink); color: white; box-shadow: 0 8px 18px rgba(23, 49, 43, .16); }
.button-soft { background: var(--accent-2); color: var(--ink); }
.button-ghost { border: 1px solid var(--line); background: rgba(255,255,255,.55); }
.status-badge { padding: 7px 10px; background: #edf7e6; color: #3c6d2c; border-radius: 999px; font-size: 11px; font-weight: 800; }
.status-badge.warning { background: #fff0db; color: #986027; }
.status-badge.danger { background: #fbe6e2; color: var(--danger); }
.distribution-body { display: grid; grid-template-columns: minmax(160px, .95fr) 1.05fr; align-items: center; gap: 28px; margin-top: 20px; }
.donut { width: min(100%, 210px); aspect-ratio: 1; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; background: conic-gradient(var(--needs) 0 50%, var(--lifestyle) 50% 80%, var(--future) 80% 100%); position: relative; box-shadow: inset 0 0 0 1px rgba(23,49,43,.06); }
.donut::after { content: ""; width: 67%; aspect-ratio: 1; border-radius: 50%; background: var(--card); position: absolute; box-shadow: 0 0 0 1px rgba(23,49,43,.05); }
.donut-center { z-index: 1; text-align: center; padding: 10px; }
.donut-center span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.donut-center strong { font-size: 20px; letter-spacing: -.03em; }
.legend { display: grid; gap: 16px; }
.legend > div { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px; font-size: 13px; }
.legend strong { font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.legend-dot.needs { background: var(--needs); }
.legend-dot.lifestyle { background: var(--lifestyle); }
.legend-dot.future { background: var(--future); }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.metric-card { min-width: 0; padding: 16px; background: rgba(255,254,250,.72); border: 1px solid var(--line); border-radius: 16px; display: grid; grid-template-columns: auto 1fr; column-gap: 11px; align-items: center; }
.metric-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; font-weight: 800; }
.metric-icon.assigned { color: var(--needs); background: #e7f1e7; }
.metric-icon.remaining { color: #93612d; background: #f9ead7; }
.metric-icon.savings { color: #4d7a31; background: #ebf5df; }
.metric-icon.spent { color: #516985; background: #e8eef5; }
.metric-card div { min-width: 0; }
.metric-card span { display: block; color: var(--muted); font-size: 11px; }
.metric-card strong { display: block; margin-top: 2px; font-size: 19px; letter-spacing: -.025em; overflow: hidden; text-overflow: ellipsis; }
.metric-card small { grid-column: 2; color: var(--muted); font-size: 10px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.budget-section { overflow: hidden; }
.section-heading { padding: 24px 26px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.section-heading p:not(.eyebrow) { color: var(--muted); font-size: 13px; margin-bottom: 0; }
.section-heading.slim { padding: 0; }
.allocation-notice { margin: 0 26px 14px; padding: 11px 13px; border-radius: 11px; font-size: 12px; background: #f2f7ec; color: #496a38; }
.allocation-notice.warning { background: #fff3e2; color: #8d5b23; }
.allocation-notice.danger { background: #fbe9e6; color: #963f34; }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { padding: 10px 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); color: var(--muted); background: #f8f7f2; font-size: 10px; text-transform: uppercase; letter-spacing: .08em; text-align: left; }
th:first-child, td:first-child { padding-left: 26px; width: 23%; }
th:nth-child(2) { width: 13%; }
th:nth-child(3), th:nth-child(4) { width: 12%; }
th:nth-child(5) { width: 16%; }
th:nth-child(6) { width: 18%; }
th:last-child, td:last-child { width: 46px; padding-right: 20px; }
td { padding: 12px; border-bottom: 1px solid #ecebe5; font-size: 13px; vertical-align: middle; }
.category-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.category-color { width: 8px; height: 34px; border-radius: 999px; flex: 0 0 auto; }
.category-color.needs { background: var(--needs); }
.category-color.lifestyle { background: var(--lifestyle); }
.category-color.future { background: var(--future); }
.category-name { min-width: 0; }
.category-name strong, .category-name small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-name strong { font-size: 13px; }
.category-name small { color: var(--muted); font-size: 10px; margin-top: 2px; }
.rule-control { display: grid; grid-template-columns: 1fr 42px; min-width: 94px; }
.rule-control input, .actual-input, .account-input { width: 100%; min-width: 0; height: 36px; border: 1px solid #deded6; background: white; color: var(--ink); border-radius: 9px; padding: 0 9px; }
.rule-control select { width: 42px; min-width: 0; border: 1px solid #deded6; border-left: 0; background: #f6f5ef; color: var(--muted); border-radius: 0 9px 9px 0; padding-left: 4px; }
.rule-control input { border-radius: 9px 0 0 9px; text-align: right; }
.planned-value { font-weight: 800; white-space: nowrap; }
.progress-cell { min-width: 100px; }
.progress-track { height: 6px; border-radius: 99px; background: #ecece6; overflow: hidden; }
.progress-fill { height: 100%; border-radius: inherit; background: var(--accent); }
.progress-fill.over { background: var(--danger); }
.progress-label { display: flex; justify-content: space-between; gap: 8px; margin-top: 5px; color: var(--muted); font-size: 10px; }
.remove-button { width: 30px; height: 30px; border: 0; background: transparent; color: #8d9692; border-radius: 8px; font-size: 18px; }
.remove-button:hover { background: #f5e5e2; color: var(--danger); }
.budget-footer { display: flex; justify-content: flex-end; gap: 30px; padding: 18px 26px 22px; background: #f8f7f2; }
.budget-footer > div { min-width: 126px; }
.budget-footer span, .budget-footer strong { display: block; }
.budget-footer span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.budget-footer strong { margin-top: 4px; font-size: 18px; }
.footer-remaining { padding-left: 24px; border-left: 1px solid var(--line); }

.history-section { margin-top: 38px; }
.history-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 16px; }
.history-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: rgba(255,254,250,.7); text-align: left; color: var(--ink); }
.history-card.current { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.history-card span, .history-card small { display: block; color: var(--muted); }
.history-card span { font-size: 11px; text-transform: capitalize; }
.history-card strong { display: block; margin: 4px 0 9px; font-size: 17px; }
.mini-bar { display: flex; width: 100%; height: 5px; overflow: hidden; background: #e7e6df; border-radius: 99px; }
.mini-bar i { height: 100%; }
.mini-bar .needs { background: var(--needs); }
.mini-bar .lifestyle { background: var(--lifestyle); }
.mini-bar .future { background: var(--future); }
.history-card small { margin-top: 7px; font-size: 9px; }
.empty-history { grid-column: 1 / -1; padding: 24px; border: 1px dashed #cfcfc7; color: var(--muted); border-radius: 14px; text-align: center; }

.dialog { width: min(540px, calc(100vw - 32px)); border: 0; border-radius: 20px; padding: 24px; color: var(--ink); background: var(--card); box-shadow: 0 30px 80px rgba(15, 35, 30, .28); }
.dialog::backdrop { background: rgba(18, 34, 30, .45); backdrop-filter: blur(4px); }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.icon-button { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--muted); font-size: 22px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 22px; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 700; }
.form-grid label.full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: white; color: var(--ink); padding: 0 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.backup-dialog > p { color: var(--muted); line-height: 1.5; }
.backup-actions { display: grid; gap: 9px; margin-top: 18px; }
.backup-option { min-height: 66px; display: grid; grid-template-columns: 38px 1fr; align-items: center; text-align: left; column-gap: 10px; border: 1px solid var(--line); border-radius: 12px; background: white; padding: 10px 13px; color: var(--ink); cursor: pointer; }
.backup-option > span { grid-row: 1 / span 2; width: 34px; height: 34px; display: grid; place-items: center; background: #eff5e9; border-radius: 9px; font-size: 18px; }
.backup-option strong { align-self: end; font-size: 13px; }
.backup-option small { align-self: start; color: var(--muted); font-size: 10px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translate(-50%, 30px); z-index: 100; opacity: 0; pointer-events: none; background: var(--ink); color: white; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; transition: .22s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 980px) {
  .planner-grid { grid-template-columns: 1fr; }
  .income-card, .distribution-card { min-height: unset; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .history-grid { grid-template-columns: repeat(3, 1fr); }
  .privacy-pill { display: none; }
  table { min-width: 880px; }
}

@media (max-width: 640px) {
  .topbar { min-height: 66px; padding: 11px 16px; }
  .brand small { display: none; }
  .topbar-actions .button { padding: 0 11px; font-size: 0; }
  .topbar-actions .button::after { content: "Copia"; font-size: 12px; }
  .shell { padding: 30px 14px 48px; }
  .welcome { align-items: stretch; flex-direction: column; gap: 20px; }
  .month-control { min-width: 100%; }
  h1 { font-size: 42px; }
  .planner-grid { gap: 12px; }
  .income-card, .distribution-card { padding: 20px; border-radius: 18px; }
  .distribution-body { grid-template-columns: 1fr; }
  .donut { width: 176px; }
  .legend { width: min(100%, 330px); margin: 0 auto; }
  .metrics { gap: 8px; }
  .metric-card { padding: 12px; grid-template-columns: 30px 1fr; column-gap: 8px; }
  .metric-icon { width: 30px; height: 30px; }
  .metric-card strong { font-size: 16px; }
  .section-heading { align-items: flex-start; padding: 20px; }
  .section-heading:not(.slim) { flex-direction: column; }
  .allocation-notice { margin-inline: 20px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; }
  thead { display: none; }
  table { min-width: 0; }
  tbody { padding: 0 14px 4px; }
  tr { position: relative; display: grid; grid-template-columns: 1fr 1fr; gap: 11px 10px; margin-bottom: 10px; padding: 14px; border: 1px solid var(--line); border-radius: 14px; }
  td { display: block; padding: 0 !important; border: 0; }
  td:first-child { grid-column: 1 / -1; }
  td::before { content: attr(data-label); display: block; margin-bottom: 5px; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
  td:first-child::before, td:last-child::before { display: none; }
  td:nth-child(5), td:nth-child(6) { grid-column: 1 / -1; }
  td:last-child { position: absolute; right: 9px; top: 10px; }
  .category-cell { padding-right: 34px; }
  .budget-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 18px 20px; }
  .budget-footer > div { min-width: 0; }
  .footer-remaining { grid-column: 1 / -1; padding: 13px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .section-heading.slim { align-items: flex-start; flex-direction: column; }
  .history-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.full { grid-column: auto; }
}

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