:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #e1e6e4;
  --accent: #0f766e;
  --accent-soft: #e2f3f0;
  --warn: #b45309;
  --ok: #047857;
  --input: #fbfcfc;
  color-scheme: light;
}
/* Oscuro: por preferencia del sistema (si no se eligió "claro") o por elección explícita. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1413;
    --card: #182120;
    --text: #e6eeeb;
    --muted: #94a3a0;
    --line: #2a3634;
    --accent: #2dd4bf;
    --accent-soft: #123a35;
    --warn: #fbbf24;
    --ok: #34d399;
    --input: #121918;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1413;
  --card: #182120;
  --text: #e6eeeb;
  --muted: #94a3a0;
  --line: #2a3634;
  --accent: #2dd4bf;
  --accent-soft: #123a35;
  --warn: #fbbf24;
  --ok: #34d399;
  --input: #121918;
  color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.top { max-width: 1100px; margin: 0 auto; padding: 24px 16px 4px; display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.theme-btn {
  flex: none; width: 40px; height: 40px; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  display: grid; place-items: center;
}
.theme-btn:hover { border-color: var(--accent); color: var(--accent); }
.theme-btn .moon { display: none; }
.theme-btn.is-dark .sun { display: none; }
.theme-btn.is-dark .moon { display: block; }
.top h1 { margin: 0; font-size: 1.5rem; }
.top p { margin: 4px 0 0; color: var(--muted); }

.grid {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
}
@media (min-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); align-items: start; }
  .result { position: sticky; top: 16px; }
}
.col { display: grid; gap: 16px; min-width: 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 0 6px; }
details > summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
details > summary::-webkit-details-marker { display: none; }
details > summary h2 { margin: 0; }
details > summary h2::before { content: "▸ "; color: var(--muted); }
details[open] > summary h2::before { content: "▾ "; }
details[open] > summary { margin-bottom: 12px; }

.fields { display: grid; gap: 12px; }
@media (min-width: 560px) { .fields.two { grid-template-columns: 1fr 1fr; } }
label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); font-weight: 600; min-width: 0; }
label.full { margin-top: 12px; }
input, select {
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.datefield { position: relative; }
.date-display {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 1rem; color: var(--text); background: var(--input);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-weight: 400;
}
.date-display svg { color: var(--muted); flex: none; }
.datefield:focus-within .date-display { outline: 2px solid var(--accent); outline-offset: -1px; }
input.date-native {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; cursor: pointer; padding: 0; border: 0;
}
input.date-native::-webkit-calendar-picker-indicator { position: absolute; inset: 0; width: auto; height: auto; cursor: pointer; }
.money { display: flex; gap: 8px; align-items: stretch; }
.money input { flex: 1; }

.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.row h2 { margin: 0; }
.sub { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); display: grid; gap: 10px; }
.sub[hidden] { display: none; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--input); }
.seg button {
  font: inherit; font-weight: 600; border: 0; background: transparent; color: var(--muted);
  padding: 8px 16px; cursor: pointer;
}
.seg.small button { padding: 6px 12px; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--card); }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--card); padding: 9px 14px;
}
.btn.small { padding: 6px 12px; }
.btn.ghost { background: transparent; color: var(--accent); justify-self: start; }
.link { font: inherit; background: none; border: 0; color: var(--accent); padding: 0; margin-top: 12px; cursor: pointer; text-decoration: underline; }

.msg { font-weight: 400; font-size: .8rem; color: var(--muted); min-height: 1em; }
.msg.warn { color: var(--warn); }
.msg.ok { color: var(--ok); }
.hint { color: var(--muted); font-size: .85rem; margin: 6px 0 0; }

.anticipo {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 10px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.anticipo:first-child { border-top: 0; padding-top: 4px; }
.anticipo label:nth-of-type(1) { grid-column: 1; }
.anticipo label:nth-of-type(2) { grid-column: 1; }
.anticipo .del { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
.anticipo .a-info { grid-column: 1 / -1; }
@media (min-width: 560px) {
  .anticipo { grid-template-columns: 170px minmax(0, 1fr) auto; }
  .anticipo label:nth-of-type(2) { grid-column: 2; grid-row: 1; }
  .anticipo .del { grid-column: 3; grid-row: 1; align-self: end; margin-bottom: 4px; }
}
.del {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; line-height: 1;
}
.del:hover { color: var(--warn); border-color: var(--warn); }

.hero { background: var(--accent-soft); border-radius: 12px; padding: 16px; display: grid; gap: 2px; }
.hero .label { font-weight: 600; color: var(--muted); font-size: .9rem; }
.copy {
  font: inherit; background: none; border: 0; color: inherit; cursor: pointer; padding: 2px 4px; margin: -2px -4px;
  border-radius: 6px; font-variant-numeric: tabular-nums; text-align: right;
}
.copy:hover { background: var(--accent-soft); }
.hero .big { font-size: 2rem; font-weight: 800; color: var(--accent); text-align: left; justify-self: start; overflow-wrap: anywhere; }
.hero .big:hover { background: transparent; text-decoration: underline; }

.lines { margin: 0; display: grid; }
.lines > div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lines > div[hidden] { display: none; }
.lines dt { color: var(--muted); }
.lines dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.lines .strong dt, .lines .strong dd { color: var(--text); font-weight: 800; }
.result.empty .lines dd, .result.empty .big { opacity: .5; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  transition: .2s; pointer-events: none; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
