/* Tema: automático según el sistema; data-theme="light|dark" lo fuerza (elegido en Ajustes). */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f7f9, #111317);
  --surface: light-dark(#ffffff, #181b20);
  --ink: light-dark(#181a1f, #e9ebef);
  --ink-2: light-dark(#5b6170, #a1a7b4);
  --line: light-dark(#e3e6eb, #262a31);
  --line-2: light-dark(#d3d7de, #343943);
  --accent: light-dark(#4b4fd6, #8b8ef5);
  --accent-ink: light-dark(#ffffff, #111317);
  --accent-soft: light-dark(#ecedfc, #23254a);
  --ok: light-dark(#17794a, #5fd39a);    --ok-bg: light-dark(#e5f4ec, #12301f);
  --warn: light-dark(#8a5a00, #f0bf5a);  --warn-bg: light-dark(#fdf1d8, #352812);
  --bad: light-dark(#b42323, #f28b8b);   --bad-bg: light-dark(#fbe8e8, #3a1717);
  --info: light-dark(#2c5fb3, #8fb4f5);  --info-bg: light-dark(#e7eefb, #172440);
  --neutral-bg: light-dark(#eef0f3, #23272e);
  --shadow: 0 1px 2px light-dark(rgb(20 24 32 / 0.06), rgb(0 0 0 / 0.4)), 0 4px 16px light-dark(rgb(20 24 32 / 0.06), rgb(0 0 0 / 0.3));
  --radius: 8px;
  --tap: 44px;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); -webkit-text-size-adjust: 100%; }
::selection { background: var(--accent-soft); color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
a { color: var(--accent); text-underline-offset: 3px; }
h1 { font-size: 1.6rem; line-height: 1.2; letter-spacing: -0.015em; margin: 0 0 0.75rem; text-wrap: balance; display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
h2 { font-size: 0.95rem; margin: 2.25rem 0 0.6rem; }
code { font-size: 0.9em; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }
.pad { padding: 1rem; }
.calm { margin: 0; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- Barra superior / inferior ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 2rem;
  padding: 0 max(1.25rem, env(safe-area-inset-left));
  height: 56px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; color: var(--ink); text-decoration: none; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 0.25rem; }
.tabs a {
  display: flex; align-items: center; gap: 0.45rem;
  min-height: 36px; padding: 0 0.75rem; border-radius: 6px;
  color: var(--ink-2); text-decoration: none; font-weight: 500;
}
.tabs a:hover { color: var(--ink); background: var(--neutral-bg); }
.tabs a[aria-current] { color: var(--ink); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line-2); }
.tabs svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

main { max-width: 920px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; outline: none; }

@media (max-width: 719px) {
  /* sin backdrop-filter: haría que la barra fija se posicione dentro del header en vez de abajo */
  .top { height: 52px; backdrop-filter: none; background: var(--bg); }
  .tabs {
    position: fixed; inset: auto 0 0 0;
    justify-content: space-around; gap: 0;
    padding: 0.35rem 0 max(0.35rem, env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.4) blur(10px);
    border-top: 1px solid var(--line);
  }
  .tabs a { flex-direction: column; gap: 2px; min-height: var(--tap); padding: 0.25rem 0.5rem; font-size: 0.72rem; flex: 1; justify-content: center; }
  .tabs a[aria-current] { background: none; box-shadow: none; color: var(--accent); }
  .tabs svg { width: 22px; height: 22px; }
  main { padding: 1.25rem 1rem calc(6rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.4rem; }
}

/* ---------- Encabezados de vista ---------- */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.head h1 { margin: 0; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-top: 1.25rem; }
.head .actions { margin-top: 0; }
.back { display: inline-flex; align-items: center; gap: 0.3rem; min-height: 32px; margin-bottom: 0.5rem; color: var(--ink-2); text-decoration: none; font-size: 0.9rem; }
.back::before { content: ""; width: 7px; height: 7px; border-left: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: rotate(45deg); }
.back:hover { color: var(--ink); }
.notice { margin: 1rem 0; padding: 0.7rem 0.9rem; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn); }
.notice a { color: inherit; font-weight: 600; }

/* ---------- Totales del mes ---------- */
.totals { margin: 1rem 0 0; }
.totals + .totals { margin-top: 0.9rem; }
.totals .cur { margin: 0 0 0.15rem; font-size: 0.75rem; font-weight: 600; color: var(--ink-2); letter-spacing: 0.02em; }
.totals dl { display: grid; grid-template-columns: repeat(4, minmax(0, max-content)); gap: 0.25rem 2.5rem; margin: 0; }
.totals dt { font-size: 0.8rem; color: var(--ink-2); }
.totals dd { margin: 0; font-size: 1.3rem; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; white-space: nowrap; }
.totals dd.pending { color: var(--warn); }
.totals dd.neg { color: var(--bad); }
@media (max-width: 559px) { .totals dl { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem 1rem; } .totals dd { font-size: 1.15rem; } }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 0.75rem; min-height: 60px; padding: 0.6rem 1rem; color: inherit; text-decoration: none; }
a.row:hover, li.row:hover { background: color-mix(in srgb, var(--neutral-bg) 55%, transparent); }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; color: inherit; text-decoration: none; }
.title { font-weight: 560; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sub { font-size: 0.85rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { font-variant-numeric: tabular-nums; font-weight: 560; white-space: nowrap; }
.amount small { font-weight: 400; color: var(--ink-2); margin-left: 1px; }
.num { font-variant-numeric: tabular-nums; font-size: 0.85rem; color: var(--ink-2); min-width: 4.2em; }

@media (max-width: 559px) {
  .row { flex-wrap: wrap; row-gap: 0.35rem; column-gap: 0.6rem; }
  .row .row-main { flex-basis: 100%; order: -1; }
  .row .btn { margin-left: auto; }
}

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 0.5rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; white-space: nowrap; letter-spacing: 0.01em; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warn { color: var(--warn); background: var(--warn-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.badge.info { color: var(--info); background: var(--info-bg); }
.badge.neutral { color: var(--ink-2); background: var(--neutral-bg); }
h1 .badge { font-size: 0.75rem; letter-spacing: 0; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  min-height: 38px; padding: 0 0.95rem; border-radius: 7px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: color-mix(in srgb, var(--ink-2) 45%, var(--line-2)); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--ink)); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn.sm { min-height: 32px; padding: 0 0.7rem; font-size: 0.85rem; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.link { border: 0; background: none; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
@media (max-width: 719px) { .btn { min-height: var(--tap); } .btn.sm { min-height: 38px; } }

/* ---------- Formularios ---------- */
.form { display: grid; gap: 1.5rem; max-width: 720px; }
.form.narrow { max-width: 420px; grid-template-columns: 1fr; gap: 1rem; margin-top: 1rem; }
fieldset { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0.9rem 1rem; }
legend { font-weight: 600; font-size: 0.95rem; padding: 0; margin-bottom: 0.6rem; }
label { display: grid; gap: 0.3rem; font-size: 0.85rem; color: var(--ink-2); font-weight: 500; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 0.5rem 0.7rem;
  border: 1px solid var(--line-2); border-radius: 7px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 1rem; caret-color: var(--accent);
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input[type="file"] { padding: 0.45rem; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder, textarea::placeholder { color: color-mix(in srgb, var(--ink-2) 80%, transparent); }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; justify-content: space-between; }
.wide { grid-column: 1 / -1; }

.filters { display: flex; gap: 0.75rem; flex-wrap: wrap; align-items: flex-end; margin: 1rem 0; }
.filters label { min-width: 180px; flex: 1; max-width: 280px; }

/* ---------- Detalle ---------- */
.details { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem 1.5rem; margin: 1.25rem 0 0; padding: 1.1rem 1.2rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.details dt { font-size: 0.8rem; color: var(--ink-2); }
.details dd { margin: 0.1rem 0 0; overflow-wrap: anywhere; }
.details dd.big { font-size: 1.25rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.notes { white-space: pre-wrap; margin: 0; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.account { margin-top: 1rem; }
.segmented { display: inline-flex; padding: 3px; gap: 2px; background: var(--neutral-bg); border-radius: 9px; }
.segmented label { display: block; color: var(--ink-2); font-size: 0.9rem; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input) { min-height: 36px; padding: 0.4rem 0.9rem; border-radius: 7px; cursor: pointer; display: flex; align-items: center; }
.segmented label:has(:checked) { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.segmented label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 1px; }
.segmented + p { margin: 0.5rem 0 0; }
.account p { margin: 0 0 0.75rem; }

/* ---------- Vacío / login ---------- */
.empty { padding: 2.5rem 1.5rem; text-align: center; background: var(--surface); border: 1px dashed var(--line-2); border-radius: var(--radius); margin-top: 1rem; }
.empty-title { font-weight: 600; margin: 0 0 0.25rem; }
.empty .muted { margin: 0 auto 1.25rem; max-width: 42ch; }
.auth { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 1rem; }
.auth h1 { margin: 0; }
.auth p { margin: -0.5rem 0 0.25rem; }

/* ---------- Aviso flotante ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom)); z-index: 20;
  max-width: min(92vw, 440px); padding: 0.7rem 1rem; border-radius: var(--radius);
  background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-size: 0.9rem;
  opacity: 0; transform: translate(-50%, 8px); pointer-events: none;
  transition: opacity 0.2s, transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }
@media (max-width: 719px) { #toast { bottom: calc(5.25rem + env(safe-area-inset-bottom)); } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- Gastos, contrato, aumento, anulación ---------- */
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.amount.voided { text-decoration: line-through; color: var(--ink-2); }
.btn.primary.danger { background: var(--bad); border-color: var(--bad); color: var(--surface); }
.btn.primary.danger:hover { background: color-mix(in srgb, var(--bad) 88%, var(--ink)); }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: 2.25rem 0 0.6rem; }
.section-head h2 { margin: 0.35rem 0 0; }
details.add { flex: 0 1 auto; }
details.add > summary { list-style: none; }
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] { flex-basis: 100%; }
details.add[open] > summary { margin-bottom: 0.75rem; }
.form.inline { padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.9rem 1rem; max-width: none; }
.form.inline .form-actions, .form.inline .wide { grid-column: 1 / -1; }
.form.inline p { margin: 0; }
details.void { margin-top: 1.5rem; }
.contract { display: grid; gap: 0.9rem; }
.contract .actions { margin: 0; }
.upload { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.upload label { flex: 1 1 240px; }
.checks { grid-template-columns: 1fr; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.checks legend { margin-bottom: 0.6rem; }
.check { display: flex; flex-direction: row; align-items: center; gap: 0.75rem; min-height: 56px; padding: 0.5rem 1rem; color: var(--ink); cursor: pointer; }
.check + .check { border-top: 1px solid var(--line); }
.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); flex: none; }
.check .sub { font-variant-numeric: tabular-nums; }

/* ---------- Íconos de proyecto ---------- */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 36px; height: 36px; border-radius: 9px; object-fit: cover;
  background: var(--accent-soft); color: var(--accent); font-weight: 650; font-size: 0.95rem;
  box-shadow: inset 0 0 0 1px var(--line);
}
.avatar.lg { width: 44px; height: 44px; border-radius: 11px; font-size: 1.15rem; }
.row-main.has-avatar { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 0.75rem; align-items: center; }
.has-avatar .avatar { grid-row: span 2; }
.icon-field { display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.icon-field > label:not(.check-inline) { flex: 1 1 200px; }
.check-inline { display: flex; flex-direction: row; align-items: center; gap: 0.45rem; min-height: 40px; color: var(--ink); }
.check-inline input { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); }

/* ---------- Dólar MEP (barra superior, a la derecha) ---------- */
.mep {
  margin-left: auto; display: grid; grid-template-columns: auto auto; column-gap: 0.5rem; align-items: baseline;
  padding: 0.3rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  color: var(--ink); font: inherit; text-align: left; cursor: pointer;
}
.mep:hover { border-color: var(--line-2); }
.mep-label { font-size: 0.72rem; color: var(--ink-2); font-weight: 500; }
.mep-value { font-weight: 650; font-variant-numeric: tabular-nums; }
.mep-sub { grid-column: 1 / -1; font-size: 0.7rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mep.loading .mep-value { opacity: 0.45; }
@media (max-width: 719px) { .mep { padding: 0.2rem 0.6rem; } .mep-sub { display: none; } }

/* ---------- Por hacer (tareas del proyecto) ---------- */
.task-add { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.task-add input { flex: 1; min-width: 0; }
.tasks .row { min-height: 48px; padding-block: 0.25rem; }
.tasks .check-inline { flex: 1; min-width: 0; cursor: pointer; font-size: 0.95rem; font-weight: 400; }
.tasks .check-inline span { overflow-wrap: anywhere; }
.tasks .done .check-inline span { color: var(--ink-2); text-decoration: line-through; }
@media (max-width: 559px) { .tasks .row { flex-wrap: nowrap; } .tasks .row .btn { margin-left: 0; } }
@media (max-width: 719px) { .tabs a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } }

/* ---------- Botón Paneles (barra superior) ---------- */
.links { margin-left: auto; min-height: 36px; padding: 0 0.7rem; font-size: 0.9rem; }
.links + .mep { margin-left: 0; }
.links svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 959px) { .links span { display: none; } }
@media (max-width: 719px) { .links { min-height: 40px; padding: 0 0.6rem; } .top { gap: 0.5rem; } }

/* Lista de paneles cuando el navegador bloquea pestañas */
.links-menu {
  width: min(92vw, 440px); padding: 1.25rem; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow);
}
.links-menu::backdrop { background: rgb(0 0 0 / 0.4); }
.links-menu h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }
.links-menu p { margin: 0 0 0.75rem; }
.links-menu .list { margin-bottom: 0.9rem; }
.links-menu .row { min-height: 48px; }
.links-menu .opened .title { color: var(--ink-2); text-decoration: line-through; }
.links-menu form { display: flex; justify-content: flex-end; margin: 0; }
