/*
  CondoPilot portal — siempre oscuro, móvil primero (spec §14).
  Una sola paleta: azul de la marca (#0063ff, del logo) como relleno con texto
  blanco, y su versión clara (#5b9bff) para texto e íconos sobre oscuro.
  Los estados (debes / al día / por revisar) tienen colores propios y distintos
  del acento. Todos los pares de texto se verifican en test_assets.py.
*/

:root {
  --bg: #0f1218;
  --surface: #181c25;
  --text: #eef1f7;
  --hint: #9fa8ba;
  --brand: #0063ff;
  --on-brand: #ffffff;
  --accent: #5b9bff;
  --tint: rgba(0, 99, 255, 0.22);
  --tint-warn: rgba(240, 184, 74, 0.16);
  --tint-ok: rgba(93, 214, 138, 0.16);
  --tint-bad: rgba(255, 102, 112, 0.16);
  --on-fill: rgba(255, 255, 255, 0.18);
  --sep: rgba(255, 255, 255, 0.09);
  --track: rgba(255, 255, 255, 0.12);
  --debt: #ff6670;
  --ok: #5dd68a;
  --warn: #f0b84a;
  --debt-bg: #c62833;
  --ok-bg: #1b6a3a;
  --on-state: #ffffff;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(8px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px))
    max(32px, env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px));
}

h1, h2, h3, p, ul { margin: 0; padding: 0; }

h1 { font-size: 24px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; text-wrap: balance; }

h2 {
  margin: 20px 4px 6px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--hint);
}

.muted { color: var(--hint); font-size: 15px; }

.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;
}

.ic {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}

/* ---- saludo y cambio de unidad o condominio ---- */

.greet { margin: 4px 4px 14px; }
.greet p { margin-top: 2px; font-size: 15px; color: var(--hint); }

.pick {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; margin-top: 12px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--sep); border-radius: 12px;
  color: var(--text); font-weight: 600; text-decoration: none;
}
.pick .ic:first-child { color: var(--accent); }
.pick .end { margin-left: auto; width: 20px; height: 20px; color: var(--hint); }
.pick:active { background: var(--track); }

/* ---- dato principal: botón-tarjeta con ícono ---- */

.herobtn {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 16px;
  background: var(--brand); color: var(--on-brand);
}
.herobtn.debt { background: var(--debt-bg); color: var(--on-state); }
.herobtn.ok { background: var(--ok-bg); color: var(--on-state); }

.herobtn .tile-ic {
  width: 48px; height: 48px; flex: none; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: var(--on-fill);
}
.herobtn .tile-ic .ic { width: 26px; height: 26px; }

.herobtn .tx { display: flex; flex-direction: column; min-width: 0; }
.herobtn .amt { font-size: 28px; font-weight: 700; line-height: 1.1; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.herobtn .lbl { font-size: 15px; font-weight: 600; }
.herobtn .sb { margin-top: 3px; font-size: 13px; font-weight: 400; opacity: 0.92; }

/* ---- indicadores con ícono: el monto usa todo el ancho de la tarjeta ---- */

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }

.kpi {
  display: flex; flex-direction: column; gap: 6px; min-width: 0;
  padding: 12px; background: var(--surface); border-radius: var(--radius);
}

.kpi .head { display: flex; align-items: center; gap: 8px; min-width: 0; }

.kpi .tile-ic {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--tint); color: var(--accent);
}
.kpi .tile-ic .ic { width: 16px; height: 16px; }
.kpi.attn .tile-ic { background: var(--tint-warn); color: var(--warn); }
.kpi.ok .tile-ic { background: var(--tint-ok); color: var(--ok); }
.kpi.bad .tile-ic { background: var(--tint-bad); color: var(--debt); }

.kpi .label { font-size: 13px; line-height: 1.2; color: var(--hint); }

/* Nunca se parte en dos líneas: el tamaño baja con el ancho de la pantalla. */
.kpi .value {
  font-size: clamp(16px, 5vw, 22px); line-height: 1.1; font-weight: 700;
  letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.kpi.attn .value { color: var(--warn); }
.kpi.ok .value { color: var(--ok); }
.kpi.bad .value { color: var(--debt); }
.kpi .meta { padding: 0; font-size: 13px; }
.kpi progress { margin-top: 2px; }

/* ---- tarjetas y filas ---- */

.card, .notice { background: var(--surface); border-radius: var(--radius); }
.card { padding: 2px 16px; }
.notice { padding: 16px; margin-top: 12px; }

.rows { list-style: none; }

.rows li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 16px;
  min-height: 44px; padding: 11px 0;
  border-top: 1px solid var(--sep);
}
.rows li:first-child { border-top: 0; }
.rows li > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.rows li > span:last-child { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.meta { display: block; padding-bottom: 12px; font-size: 13px; color: var(--hint); }

/* ---- tarjetas de cobranza: título, barra de avance y líneas Pagado/Pendiente ---- */

.mcard { --bar: var(--ok); padding: 10px 14px 12px; border-radius: var(--radius); background: var(--surface); }
.mcard + .mcard { margin-top: 10px; }
.mbody .mcard { background: rgba(255, 255, 255, 0.05); }
.mbody .mcard:first-child { margin-top: 10px; }

/* Si el monto no cabe junto al título, baja de línea: nunca se corta. */
.mhead { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 12px; }
.mt { font-size: 12px; font-weight: 600; letter-spacing: 0.07em; text-transform: uppercase; color: var(--accent); }
.mt.gap { display: block; margin-top: 12px; }
.nm { min-width: 0; overflow-wrap: anywhere; font-size: 16px; font-weight: 600; }
.mtot { margin-left: auto; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mtot small { margin-left: 4px; font-size: 12px; font-weight: 400; color: var(--hint); }
.hint { display: block; font-size: 13px; color: var(--hint); }
.mcard progress { margin: 8px 0 6px; }

.mline { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; font-size: 15px; }
.mline > span:first-child { min-width: 0; color: var(--hint); }
.mline small { font-size: 12px; }
.mline > span:last-child { white-space: nowrap; font-weight: 600; font-variant-numeric: tabular-nums; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.stats > div { padding: 6px 8px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); }
.stats b { display: block; font-size: 18px; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.stats span { display: block; font-size: 12px; line-height: 1.2; color: var(--hint); }

/* ---- selector de unidades / condominios ---- */

.cards { list-style: none; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.cards li + li { border-top: 1px solid var(--sep); }
.cards a {
  display: flex; flex-direction: column; justify-content: center; gap: 2px;
  position: relative; min-height: 56px; padding: 10px 40px 10px 16px;
  color: var(--text); text-decoration: none;
}
.cards a::after {
  content: "\203A"; position: absolute; right: 16px; top: 50%;
  transform: translateY(-50%); font-size: 24px; color: var(--hint);
}
.cards a:active { background: var(--track); }
.cards a strong { font-weight: 600; }
.cards a span { font-size: 15px; color: var(--hint); }

/* ---- barra de avance ---- */

progress {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border: 0; border-radius: 3px; overflow: hidden;
  background: var(--track); color: var(--bar, var(--accent));
}
progress::-webkit-progress-bar { background: var(--track); }
progress::-webkit-progress-value { background: var(--bar, var(--accent)); border-radius: 3px; }
progress::-moz-progress-bar { background: var(--bar, var(--accent)); border-radius: 3px; }
.kpi.ok { --bar: var(--ok); }
.kpi.bad { --bar: var(--debt); }

/* ---- desplegables nativos (sin JavaScript): el detalle solo si se pide ---- */

details summary {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 44px; cursor: pointer; list-style: none;
  color: var(--accent); font-weight: 600;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "\203A"; font-size: 22px; color: var(--hint); transform: rotate(90deg); }
details[open] > summary::after { transform: rotate(-90deg); }
.card > details { border-top: 1px solid var(--sep); }
details.card { margin-top: 12px; }
details .rows li:first-child { border-top: 1px solid var(--sep); }
.month .mbody { padding-bottom: 12px; }

/* ---- estados de carga ---- */

.skeleton { display: block; border-radius: var(--radius); background: var(--track); }
.skeleton.hero-sk { height: 76px; }
.skeleton.row-sk { height: 64px; margin-top: 12px; }
.skeleton.title-sk { height: 32px; width: 60%; margin: 8px 4px 20px; border-radius: 8px; }

@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: pulse 1.4s ease-in-out infinite; }
  @keyframes pulse { 50% { opacity: 0.5; } }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
}

a:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- pantallas anchas (computadora): mismo diseño, más aire ---- */

@media (min-width: 900px) {
  #app { max-width: 880px; padding-top: 32px; }
}
