:root {
  --navy: #1e3345;
  --navy-deep: #152534;
  --navy-line: #3c5367;
  --navy-soft: #263e52;
  --cream: #f4efe8;
  --cream-dim: #e6ded2;
  --cream-line: #d6cbbc;
  --brick: #ad4936;
  --brick-hover: #923a2a;
  --sand: #c9b79a;
  --steel: #7e9aaf;
  --ink: #17222b;
  --muted: #5f6e79;
  --muted-light: #aebbc5;
  --wa: #d9fdd3;
  --focus: #f4efe8;
  --display: "Jost", "Futura", "Century Gothic", sans-serif;
  --body: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body { min-height: 100%; margin: 0; color: var(--ink); background: var(--cream); font-family: var(--body); font-size: 1rem; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { touch-action: manipulation; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
h1, h2, h3, p { margin: 0; }

.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 { position: fixed; top: .75rem; left: .75rem; z-index: 100; padding: .65rem .9rem; color: var(--navy-deep); background: var(--cream); border: 2px solid var(--brick); transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

.topbar { min-height: 3.25rem; padding: .75rem 1.5rem; display: flex; align-items: center; gap: 1.125rem; color: var(--cream); background: var(--navy-deep); border-bottom: 1px solid var(--navy-line); }
.mark { color: inherit; font-family: var(--display); font-size: .8125rem; font-weight: 500; letter-spacing: .22em; text-decoration: none; text-transform: uppercase; white-space: nowrap; }
.mark span { font-weight: 300; opacity: .72; }
.topbar .sep { width: 1px; height: 1.25rem; background: var(--navy-line); }
.topbar h1 { color: var(--muted-light); font-family: var(--display); font-size: .875rem; font-weight: 300; letter-spacing: .14em; text-transform: uppercase; }
.topbar .spacer { flex: 1; }

.btn { min-height: 2.5rem; padding: .55rem 1rem; border: 1px solid transparent; border-radius: .2rem; cursor: pointer; background: none; font-size: .875rem; font-weight: 500; transition: background-color .15s ease, border-color .15s ease, color .15s ease; }
.btn:hover { text-decoration: none; }
.btn:focus-visible, .link:focus-visible, .mark:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; box-shadow: 0 0 0 5px var(--brick); }
.btn-ghost-light { color: var(--cream); border-color: var(--navy-line); }
.btn-ghost-light:hover { background: var(--navy-soft); }
.btn-solid { color: #fff; background: var(--brick); }
.btn-solid:hover { background: var(--brick-hover); }
.btn-ghost { color: var(--ink); border-color: #bbae9d; }
.btn-ghost:hover { background: var(--cream-dim); }
.btn-ghost:focus-visible { outline-color: var(--navy-deep); box-shadow: 0 0 0 5px rgba(173, 73, 54, .35); }
.btn-line { min-height: 2.25rem; padding: .45rem .75rem; color: var(--cream-dim); border-color: var(--navy-line); font-size: .8125rem; }
.btn-line:hover { color: var(--cream); background: var(--navy-soft); }
.btn:disabled { opacity: .46; cursor: not-allowed; }

.shell { display: grid; grid-template-columns: minmax(21rem, 24.5rem) minmax(0, 1fr); min-height: calc(100vh - 3.25rem); }
.panel { padding: 1.625rem 1.5rem 2.5rem; color: var(--cream); background: var(--navy); }
.legend { width: 100%; margin: 0 0 1rem; padding: 0 0 .5rem; display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; color: var(--muted-light); border-bottom: 1px solid var(--navy-line); font-family: var(--display); font-size: .6875rem; font-weight: 500; letter-spacing: .23em; text-transform: uppercase; }
.legend.mt { margin-top: 1.875rem; }
.legend .link { padding: .2rem 0; color: var(--cream-dim); background: none; border: 0; border-bottom: 1px dotted var(--muted-light); cursor: pointer; font-family: var(--body); font-size: .75rem; letter-spacing: .01em; text-transform: none; }
.legend .link:hover { color: var(--cream); }
.field { margin-bottom: 1rem; }
.field label { display: block; margin-bottom: .375rem; color: var(--muted-light); font-size: .8125rem; letter-spacing: .02em; }
.required { color: #f0b4a7; }
.field input, .field select { width: 100%; min-height: 2.75rem; padding: .625rem .75rem; color: var(--cream); background-color: var(--navy-deep); border: 1px solid var(--navy-line); border-radius: .2rem; font-size: 1rem; }
.field input.num { font-family: var(--mono); letter-spacing: -.01em; }
.field input:focus, .field select:focus, .ctrl-pct input:focus, .ctrl-money input:focus { outline: 2px solid var(--focus); outline-offset: 2px; border-color: var(--brick); }
.field input[aria-invalid="true"] { border-color: #f0a696; box-shadow: 0 0 0 1px #f0a696; }
.field input::placeholder { color: #93a5b3; opacity: 1; }
.field select { appearance: none; padding-right: 2.5rem; background-image: linear-gradient(45deg, transparent 50%, var(--muted-light) 50%), linear-gradient(135deg, var(--muted-light) 50%, transparent 50%); background-position: calc(100% - 1rem) 1.2rem, calc(100% - .7rem) 1.2rem; background-repeat: no-repeat; background-size: .3125rem .3125rem; }
.field select option { color: var(--cream); background: var(--navy-deep); }
.field .sub { display: block; margin-top: .35rem; color: var(--muted-light); font-size: .75rem; }
.pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.pair.tight { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); }

.ctrl { margin-bottom: 1.25rem; }
.ctrl-head { display: flex; align-items: center; justify-content: space-between; gap: .625rem; margin-bottom: .25rem; }
.ctrl-head > label { color: var(--muted-light); font-size: .8125rem; }
.ctrl-pct { display: flex; align-items: center; gap: .25rem; }
.ctrl-pct input { width: 4.25rem; min-height: 2rem; padding: .3rem .45rem; color: var(--cream); background: var(--navy-deep); border: 1px solid var(--navy-line); border-radius: .2rem; font-family: var(--mono); font-size: .875rem; text-align: right; -moz-appearance: textfield; }
.ctrl-pct input::-webkit-outer-spin-button, .ctrl-pct input::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
.ctrl-pct span { min-width: 2.4rem; color: var(--muted-light); font-size: .8125rem; }
.ctrl-money { display: flex; align-items: center; gap: .5rem; margin-top: .125rem; }
.ctrl-money label { color: var(--muted-light); font-size: .75rem; white-space: nowrap; }
.ctrl-money input { flex: 1; min-width: 0; padding: .3rem 0; color: var(--cream); background: none; border: 0; border-bottom: 1px solid var(--navy-line); border-radius: 0; font-family: var(--mono); font-size: .875rem; text-align: right; }
input[type="range"] { width: 100%; height: 2rem; margin: 0; appearance: none; background: none; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--muted-light); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--muted-light); }
input[type="range"]::-webkit-slider-thumb { width: 1rem; height: 1rem; margin-top: -.4375rem; appearance: none; background: var(--brick); border: 2px solid var(--cream); border-radius: 50%; }
input[type="range"]::-moz-range-thumb { width: .875rem; height: .875rem; background: var(--brick); border: 2px solid var(--cream); border-radius: 50%; }
input[type="range"]:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.split-bar { height: .5rem; display: flex; overflow: hidden; margin: .875rem 0 .5rem; background: var(--navy-deep); border: 1px solid var(--navy-line); border-radius: .125rem; }
.split-bar i { display: block; height: 100%; }
.split-key { display: flex; flex-wrap: wrap; gap: .875rem; color: var(--muted-light); font-size: .75rem; }
.split-key span { display: flex; align-items: center; gap: .35rem; }
.split-key b { width: .5rem; height: .5rem; display: inline-block; border-radius: 50%; }
.key-eng { background: var(--steel); }
.key-obra { background: var(--sand); }
.key-contra { background: var(--brick); }
.alert { margin-top: .875rem; padding: .625rem .75rem; font-size: .875rem; line-height: 1.5; }
.alert.err { color: #ffd8cf; background: rgba(173, 73, 54, .2); border-left: 3px solid #f0a696; }
.alert.warn { color: #f2e8d5; background: rgba(201, 183, 154, .14); border-left: 3px solid var(--sand); }
.alert:empty { display: none; }
.panel-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.results { width: 100%; max-width: 60rem; padding: 2rem clamp(1.5rem, 4vw, 3.5rem) 3rem; }
.results:focus { outline: none; }
.res-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1.25rem; flex-wrap: wrap; }
.res-title { font-family: var(--display); font-size: clamp(1.5rem, 2.5vw, 1.875rem); font-weight: 400; letter-spacing: .01em; line-height: 1.2; }
.res-sub { margin-top: .3rem; color: var(--muted); font-size: .875rem; }
.res-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 1px; margin: 1.375rem 0 1.875rem; background: var(--cream-line); border: 1px solid var(--cream-line); }
.cell { min-width: 0; padding: .9rem 1rem; background: var(--cream); }
.cell .k { color: var(--muted); font-family: var(--display); font-size: .75rem; font-weight: 500; letter-spacing: .11em; text-transform: uppercase; }
.cell .v { margin-top: .3rem; overflow-wrap: anywhere; font-family: var(--mono); font-size: clamp(1rem, 2vw, 1.2rem); letter-spacing: -.02em; }
.cell .n { margin-top: .15rem; color: var(--muted); font-size: .75rem; }
.cell.accent { color: var(--cream); background: var(--navy); }
.cell.accent .k, .cell.accent .n { color: var(--muted-light); }
.section-label { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; padding-bottom: .5rem; color: var(--muted); border-bottom: 1px solid var(--cream-line); font-family: var(--display); font-size: .6875rem; letter-spacing: .22em; text-transform: uppercase; }
.section-label h3 { font: inherit; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th { padding: .75rem .625rem .625rem; color: var(--muted); font-family: var(--display); font-size: .6875rem; font-weight: 500; letter-spacing: .12em; text-align: left; text-transform: uppercase; }
.col-index { width: 2.25rem; }
thead th.r, td.r { text-align: right; }
tbody td, tbody th { padding: .6rem .625rem; border-top: 1px solid var(--cream-line); font-weight: 400; text-align: left; }
tbody tr.milestone td, tbody tr.milestone th { background: rgba(30, 51, 69, .055); font-weight: 600; }
tbody .num, tfoot .num { font-family: var(--mono); letter-spacing: -.02em; white-space: nowrap; }
tbody .saldo { color: var(--muted); font-family: var(--mono); letter-spacing: -.02em; white-space: nowrap; }
tbody .idx { width: 2.25rem; color: var(--muted); font-family: var(--mono); }
tbody .date { color: var(--muted); white-space: nowrap; }
tfoot td, tfoot th { padding: .75rem .625rem; border-top: 2px solid var(--navy); font-weight: 600; text-align: left; }
.empty-row { padding: 1.65rem .625rem; color: var(--muted); text-align: center; }
.scroll { max-height: 29rem; overflow: auto; scrollbar-gutter: stable; }
.scroll:focus-visible { outline: 2px solid var(--brick); outline-offset: 3px; }

.wa-wrap { margin-top: 2.125rem; }
.wa-stage { margin-top: .875rem; padding: 1.375rem; background: var(--navy); border-radius: .2rem; }
.bubble { max-width: 28rem; padding: .75rem .875rem; color: #111b21; background: var(--wa); border-radius: .5rem .125rem .5rem .5rem; box-shadow: 0 1px 1px rgba(0, 0, 0, .18); font-size: .875rem; line-height: 1.55; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble .b { font-weight: 600; }
.bubble .fine { display: block; margin-top: .625rem; color: #52655b; font-size: .75rem; line-height: 1.4; }
.bubble-time { display: block; margin-top: .25rem; color: #657d70; font-size: .6875rem; text-align: right; }
.wa-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .625rem; margin-top: 1rem; }
.copied { min-height: 1.25rem; color: var(--cream); font-size: .8125rem; }
.footnote { margin-top: 2.125rem; padding-top: .875rem; color: var(--muted); border-top: 1px solid var(--cream-line); font-size: .8125rem; line-height: 1.6; }

.mobile-bar { display: none; position: fixed; right: 0; bottom: 0; left: 0; z-index: 30; align-items: center; gap: .875rem; padding: .625rem 1rem calc(.625rem + env(safe-area-inset-bottom)); background: var(--navy-deep); border-top: 1px solid var(--navy-line); }
.mb-fig { flex: 1; min-width: 0; }
.mb-k { color: var(--muted-light); font-family: var(--display); font-size: .625rem; letter-spacing: .16em; text-transform: uppercase; }
.mb-v { display: block; overflow: hidden; color: var(--cream); font-family: var(--mono); font-size: 1rem; letter-spacing: -.02em; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 73.75rem) and (min-width: 56.3125rem) {
  .shell { grid-template-columns: minmax(20rem, 21.5rem) minmax(0, 1fr); }
  .panel { padding-inline: 1.125rem; }
}

@media (max-width: 56.25rem) {
  body { padding-bottom: calc(4.75rem + env(safe-area-inset-bottom)); }
  .shell { grid-template-columns: 1fr; min-height: 0; }
  .panel { padding: 1.375rem clamp(1rem, 4vw, 2rem) 1.875rem; }
  .results { max-width: none; padding: 1.5rem clamp(1rem, 4vw, 2rem) 2.5rem; }
  .topbar { padding: .75rem 1rem; gap: .625rem; }
  .topbar .sep { display: none; }
  .topbar h1 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
  .mobile-bar { display: flex; }
  input[type="range"] { height: 2.75rem; }
  input[type="range"]::-webkit-slider-thumb { width: 1.375rem; height: 1.375rem; margin-top: -.625rem; }
  input[type="range"]::-moz-range-thumb { width: 1.25rem; height: 1.25rem; }
  .scroll { max-height: none; overflow-x: auto; }
  table { min-width: 34rem; }
  .bubble { max-width: none; }
}

@media (max-width: 35rem) {
  .topbar .btn { padding-inline: .75rem; }
  .panel { padding-inline: 1rem; }
  .results { padding: 1.25rem 1rem 2.25rem; }
  .pair, .pair.tight { grid-template-columns: 1fr; gap: 0; }
  .summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cell { padding: .75rem .8rem; }
  .wa-stage { padding: 1rem; }
  .mobile-bar { gap: .5rem; }
  .mobile-bar .btn { padding-inline: .65rem; }
}

@media (max-width: 23.75rem) {
  .summary { grid-template-columns: 1fr; }
  .mark { letter-spacing: .15em; }
  .mobile-bar .mb-fig:nth-of-type(2) { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}

@media (prefers-contrast: more) {
  :root { --navy-line: #8296a6; --cream-line: #a99c8a; --muted: #3f4d57; }
  .btn, input, select { border-width: 2px; }
}

@media print {
  @page { margin: 14mm; }
  .topbar, .panel, .wa-wrap, .mobile-bar, .no-print, .skip-link { display: none !important; }
  body { padding-bottom: 0; background: #fff; color: #000; }
  .shell { display: block; }
  .results { max-width: none; padding: 0; }
  .scroll { max-height: none; overflow: visible; }
  table { min-width: 0; }
  .cell, .cell.accent { color: #000; background: #fff; border: 1px solid #777; }
  .cell.accent .k, .cell.accent .n { color: #333; }
  tbody tr { break-inside: avoid; }
}
