:root {
  --asfalto: #24272c;
  --hormigon: #e4e6e8;
  --card: #ffffff;
  --ink: #1d2025;
  --muted: #687079;
  --line: #d3d6da;
  --senal: #ffc72c;
  --ok: #1d8a4e;
  --warn: #b86e00;
  --bad: #cc3a2f;
  --wa: #168a52;
  --radius: 14px;
  --font: 'Barlow', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --display: 'Barlow Condensed', 'Arial Narrow', system-ui, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --hormigon: #15171a;
    --card: #1f2226;
    --ink: #ebedef;
    --muted: #9aa1a9;
    --line: #33373d;
    --ok: #3cb675;
    --warn: #e39a2a;
    --bad: #ef6a5f;
    --wa: #3cb675;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.4;
  background: var(--hormigon); color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--display); font-weight: 700; letter-spacing: .01em; margin: 0; }
small, .muted { color: var(--muted); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--senal); outline-offset: 2px; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: var(--asfalto); color: #fff;
}
.topbar h1 { font-size: 26px; }
#view { padding: 16px 14px calc(110px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; text-decoration: none; font-size: 22px;
}
.icon-btn svg { width: 24px; height: 24px; }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
  border-top: 3px solid transparent;
}
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a.active { color: var(--ink); border-top-color: var(--senal); }
.fab {
  position: fixed; right: 18px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 11;
  width: 58px; height: 58px; border-radius: 16px; border: 2px solid var(--asfalto);
  background: var(--senal); color: #1d2025; font-size: 32px; font-weight: 600; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.25); cursor: pointer;
}

/* ---------- Marca de plaza: el elemento distintivo ---------- */
.plate {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 58px; padding: 4px 8px; flex-shrink: 0;
  font-family: var(--display); font-weight: 700; font-size: 17px; line-height: 1.1; text-align: center;
  color: #1d2025; background: var(--senal);
  border: 2px solid #1d2025; border-radius: 6px;
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- Panel principal ---------- */
.hero {
  position: relative; overflow: hidden;
  background: var(--asfalto); color: #fff; border-radius: var(--radius);
  padding: 22px 18px 18px; margin-bottom: 8px;
}
.hero::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px;
  background: repeating-linear-gradient(90deg, var(--senal) 0 22px, transparent 22px 36px);
}
.hero-mes { font-family: var(--display); font-size: 30px; font-weight: 700; }
.hero-sub { color: #b9bec5; margin-top: 2px; }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.kpis small { color: #b9bec5; display: block; }
.kpis b { font-family: var(--display); font-size: clamp(15px, 4.7vw, 22px); font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpis b.ok { color: #6ee3a0; }
.kpis b.warn { color: var(--senal); }
.progress { height: 8px; border-radius: 4px; background: #3a3e45; margin-top: 14px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--senal); border-radius: 4px; transition: width .4s ease; }
.cta-row { margin-top: 14px; }

.sec { font-size: 21px; margin: 22px 2px 8px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.sec small { font-family: var(--font); font-size: 14px; font-weight: 500; }
.sec.bad-t { color: var(--bad); }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card); border-radius: var(--radius); margin-bottom: 10px;
  border: 1px solid var(--line); overflow: hidden;
}
.card-main { display: flex; align-items: center; gap: 12px; padding: 12px; cursor: pointer; }
.card-main .grow { flex: 1; min-width: 0; }
.card-main .grow b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-main .grow small { display: block; }
.card-main .right { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.card-main .right b { font-variant-numeric: tabular-nums; font-weight: 600; }
.card-actions {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 9px 12px; border-top: 1px dashed var(--line);
}
.card-actions small { flex: 1; min-width: 120px; }
.card-note { padding: 7px 12px; font-size: 14px; font-weight: 600; border-top: 1px dashed var(--line); }
.card-note.bad { color: var(--bad); }
.card-note.ok { color: var(--ok); }
.card-note.warn { color: var(--warn); }
.card.atrasado { border-left: 5px solid var(--bad); }
.card.vence { border-left: 5px solid var(--senal); }

.chip { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; white-space: nowrap; }
.chip.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.chip.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.chip.neutral { background: color-mix(in srgb, var(--muted) 16%, transparent); color: var(--ink); }
.chip.muted { background: transparent; color: var(--muted); border: 1px solid var(--line); }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 11px; border: 1px solid transparent;
  font-weight: 600; text-decoration: none; cursor: pointer; background: transparent; color: inherit;
}
.btn svg { width: 18px; height: 18px; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14.5px; }
.btn.wide { width: 100%; margin-top: 10px; }
.btn.primary { background: var(--asfalto); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { background: var(--senal); color: #1d2025; } }
.btn.ghost { border-color: var(--line); background: var(--card); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); background: transparent; }
.btn.wa { background: var(--wa); color: #fff; }
.btn.wa-o { color: var(--wa); border-color: color-mix(in srgb, var(--wa) 45%, transparent); background: transparent; }
.btn.senal { background: var(--senal); color: #1d2025; border-color: #1d2025; border-width: 2px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
.actions.start { justify-content: flex-start; }
.actions .btn { flex: 1 1 auto; }

/* ---------- Navegación de cobros ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.month-nav b { font-family: var(--display); font-size: 26px; }
.month-nav .icon-btn { background: var(--card); border: 1px solid var(--line); font-size: 26px; }
.mini { text-align: center; color: var(--muted); margin-bottom: 12px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; padding: 8px 0; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--asfalto); color: #fff; }
.summary { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin: 0 2px 10px; }

/* ---------- Hoja inferior ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-bg { position: absolute; inset: 0; background: rgba(10,12,15,.5); opacity: 0; transition: opacity .2s; }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 92vh; overflow-y: auto;
  background: var(--card); border-radius: 20px 20px 0 0;
  padding: 8px 18px calc(22px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .22s ease-out;
  max-width: 640px; margin: 0 auto;
}
.sheet.open .sheet-bg { opacity: 1; }
.sheet.open .sheet-panel { transform: none; }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 14px; }
.sheet h2 { font-size: 25px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.sheet .sub { color: var(--muted); margin: 4px 0 12px; }
@media (prefers-reduced-motion: reduce) { .sheet-panel, .sheet-bg, .progress i { transition: none; } }

/* ---------- Formularios ---------- */
form.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
form.grid .field { grid-column: 1 / -1; }
form.grid .field.half { grid-column: span 1; }
form.grid .actions, form.grid .check { grid-column: 1 / -1; }
.field { display: block; margin-top: 12px; }
.field > span { display: block; font-weight: 600; font-size: 14.5px; margin-bottom: 5px; }
.field small { display: block; margin-top: 4px; font-size: 13px; }
.field input, .field select, .field textarea, textarea.msg {
  width: 100%; font-size: 16px; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--hormigon);
}
.field textarea, textarea.msg { resize: vertical; line-height: 1.45; }
.check { display: flex; gap: 10px; align-items: flex-start; margin-top: 14px; font-size: 15px; }
.check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--asfalto); }
.form-sec { grid-column: 1 / -1; margin: 22px 0 0; font-size: 19px; }
.form-help { grid-column: 1 / -1; margin: 2px 0 0; font-size: 14px; }
.err { color: var(--bad); min-height: 1.2em; font-weight: 500; }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 14px 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.dl dd.bad-t { color: var(--bad); }
.bad-t { color: var(--bad); }
.row small { color: var(--muted); }
.notes { background: var(--hormigon); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; }
.row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; font-variant-numeric: tabular-nums;
}
details.more { margin-top: 14px; }
details.more summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 6px 0; }
.ok-mark { display: grid; place-items: center; width: 64px; height: 64px; margin: 8px auto 10px; border-radius: 50%; background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); font-size: 34px; }
.center { text-align: center; }

/* ---------- Ajustes ---------- */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.panel h3 { font-size: 21px; }
.vars { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 4px; }
.vars code { font-size: 13px; background: var(--hormigon); padding: 2px 6px; border-radius: 6px; }
.tpl { border-top: 1px dashed var(--line); padding-top: 4px; margin-top: 14px; }
.tpl .actions { margin-top: 8px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--asfalto); }
.login-box { width: 100%; max-width: 360px; background: var(--card); border-radius: 18px; padding: 26px 22px; }
.login-box h1 { font-size: 32px; }
.login-mark {
  width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 12px;
  font-family: var(--display); font-size: 44px; font-weight: 700; color: #1d2025;
  background: var(--senal); border: 3px solid #1d2025; border-radius: 12px;
}

/* ---------- Aviso ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(150px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 60; background: var(--ink); color: var(--card); padding: 10px 16px; border-radius: 10px;
  font-weight: 500; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ---------- Indicadores ---------- */
.seg.seg2 { grid-template-columns: 1fr 1fr; }
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 560px) { .kpi-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi {
  display: flex; flex-direction: column; gap: 3px; min-height: 112px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 11px; color: inherit; text-decoration: none; position: relative;
}
.kpi small { color: var(--muted); font-weight: 500; font-size: 13.5px; }
.kpi b { font-family: var(--display); font-size: clamp(20px, 6.4vw, 27px); line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12.5px; line-height: 1.3; }
.kpi.mal { border-left: 5px solid var(--bad); }
.kpi.mal b { color: var(--bad); }
.kpi.bien b { color: var(--ok); }
.kpi.aviso { border-left: 5px solid var(--senal); }
.minibar { display: block; height: 6px; border-radius: 3px; background: var(--hormigon); overflow: hidden; margin: 3px 0 1px; }
.minibar i { display: block; height: 100%; background: var(--senal); border-radius: 3px; }
.grafico-box { padding: 12px 10px 8px; }
.grafico { width: 100%; height: auto; display: block; }
.g-ing { fill: var(--ok); }
.g-gas { fill: var(--muted); opacity: .55; }
.g-cero { stroke: var(--line); stroke-width: 1; }
.g-neto { fill: none; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.g-neto-p { fill: var(--senal); stroke: var(--ink); stroke-width: 1.2; }
.g-lab { font-size: 10px; fill: var(--muted); text-anchor: middle; font-family: var(--font); }
.leyenda { display: flex; gap: 14px; justify-content: center; font-size: 13px; color: var(--muted); margin-top: 4px; }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.leyenda i.g-ing { background: var(--ok); }
.leyenda i.g-gas { background: var(--muted); opacity: .55; }
.leyenda i.g-neto-l { background: var(--senal); border: 1.5px solid var(--ink); border-radius: 50%; }
.lista-kpi { padding: 2px 12px; }
.lista-kpi .row { color: inherit; text-decoration: none; }
.lista-kpi .row:last-child { border-bottom: 0; }
.row.rank { grid-template-columns: auto 1fr auto; }
.rank-bar { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.rank-bar i { display: block; height: 8px; border-radius: 4px; background: var(--ok); min-width: 3px; }
.rank-bar i.neg { background: var(--bad); }
@media (prefers-color-scheme: dark) { .seg button.on { background: var(--senal); color: #1d2025; } }
.minibar.grande { height: 10px; border-radius: 5px; }

/* ---------- Informe para la Renta ---------- */
.renta-card summary { list-style: none; }
.renta-card summary::-webkit-details-marker { display: none; }
.renta-card[open] summary { border-bottom: 1px dashed var(--line); }
.renta-body { padding: 6px 14px 12px; }
.renta-body .row { font-variant-numeric: tabular-nums; }
.renta-body .row.tot { border-bottom: 1.5px solid var(--ink); }
.avisos { background: color-mix(in srgb, var(--senal) 16%, transparent); border-radius: 10px; padding: 10px 12px 10px 28px; margin: 12px 0 4px; font-size: 14px; }
.avisos li { margin: 3px 0; }
.aviso-box { background: color-mix(in srgb, var(--senal) 16%, transparent); border-radius: 10px; padding: 10px 12px; font-size: 14px; }

/* ---------- Revisión UX ---------- */
.fab { width: auto; min-width: 58px; padding: 0 20px 0 16px; display: inline-flex; align-items: center; gap: 6px; font-size: 17px; font-weight: 700; font-family: var(--font); }
.fab span { font-size: 28px; line-height: 1; margin-top: -2px; }
.sheet-x {
  position: absolute; top: 10px; right: 12px; width: 40px; height: 40px; border-radius: 50%;
  border: 0; background: var(--hormigon); color: var(--ink); font-size: 26px; line-height: 1; cursor: pointer;
}
.sheet-panel > h2 { padding-right: 44px; }
.card.hecho { opacity: .78; }
.card.hecho .card-main { padding-top: 9px; padding-bottom: 9px; }
.seg a { display: grid; place-items: center; padding: 8px 0; border-radius: 9px; font-weight: 600; color: var(--muted); text-decoration: none; }
.seg a.on { background: var(--asfalto); color: #fff; }
@media (prefers-color-scheme: dark) { .seg a.on { background: var(--senal); color: #1d2025; } }
.seg.seg2 { margin-bottom: 14px; }
.row.paso { grid-template-columns: auto 1fr auto; padding: 14px 2px; }
.paso-n { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--senal); color: #1d2025; font-weight: 700; border: 2px solid #1d2025; }
.paso-n.ok { background: var(--ok); color: #fff; border-color: var(--ok); }

/* ---------- Deshacer, apartados plegables ---------- */
.toast { display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap; justify-content: center; }
.toast button { border: 0; background: transparent; color: #ffd65c; font: 700 15px var(--font); padding: 6px 4px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
@media (prefers-color-scheme: dark) { .toast button { color: #6b4500; } }
details.acordeon { padding: 0; }
details.acordeon > summary { list-style: none; cursor: pointer; padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
details.acordeon > summary::-webkit-details-marker, .form-grupo > summary::-webkit-details-marker { display: none; }
details.acordeon > summary::after, .form-grupo > summary::after { content: '›'; font-size: 24px; color: var(--muted); transition: transform .15s; }
details.acordeon[open] > summary::after, .form-grupo[open] > summary::after { transform: rotate(90deg); }
details.acordeon > summary small { display: block; color: var(--muted); }
details.acordeon[open] > summary { border-bottom: 1px dashed var(--line); }
details.acordeon > :not(summary) { margin-left: 16px; margin-right: 16px; }
details.acordeon > :last-child { margin-bottom: 16px; }
.form-grupo { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 12px; margin-top: 14px; padding: 0 12px; background: var(--card); }
.form-grupo > summary { list-style: none; cursor: pointer; padding: 12px 0; display: flex; align-items: center; gap: 10px; }
.form-grupo > summary > span:first-child { flex: 1; }
.form-grupo > summary small { display: block; color: var(--muted); font-size: 13px; }
.form-grupo-in { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; padding-bottom: 12px; }
