/* ============================================================
   Gestión de Alquileres — "Libro mayor de finca" · dark editorial
   Verde bosque + latón · tipografía Fraunces / Outfit / JetBrains Mono
   ============================================================ */

:root {
  /* Controles nativos (date picker, select, scrollbars) en oscuro */
  color-scheme: dark;

  /* Fondos */
  --bg: #0b0f0d;
  --bg-2: #101613;
  --surface: rgba(20, 27, 23, 0.9);
  --surface-glass: rgba(22, 30, 26, 0.88);
  --surface-strong: rgba(14, 20, 17, 0.97);
  --border: rgba(238, 226, 197, 0.11);
  --border-strong: rgba(238, 226, 197, 0.22);

  /* Texto */
  --text: #f3efe4;
  --text-muted: #a4b2a4;

  /* Acentos */
  --brass: #e0b155;
  --brass-deep: #c8923a;
  --sage: #8fc07a;
  --forest: #4a7c59;
  --accent: var(--brass);
  --accent-2: var(--sage);
  --accent-grad: linear-gradient(135deg, #e6bd63 0%, #8fc07a 100%);
  --brass-grad: linear-gradient(135deg, #f0cd7a 0%, #c8923a 100%);
  --success: #6fd39a;
  --success-bg: rgba(111, 211, 154, 0.14);
  --warning: #f2c14e;
  --warning-bg: rgba(242, 193, 78, 0.14);
  --danger: #ef7d6b;
  --danger-bg: rgba(239, 125, 107, 0.14);
  --ink: #12160f;

  /* Formas */
  --radius: 20px;
  --radius-sm: 12px;
  --radius-pill: 999px;

  /* Sombras */
  --shadow-soft: 0 14px 40px rgba(0, 0, 0, 0.42);
  --shadow-glow: 0 0 0 1px var(--border-strong), 0 26px 60px rgba(0, 0, 0, 0.55);

  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
  --spring: 460ms cubic-bezier(0.34, 1.56, 0.64, 1);

  --font-display: 'Fraunces', Georgia, serif;
  --font-ui: 'Outfit', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* El atributo `hidden` debe ganar siempre a display: grid/flex/etc. */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }
html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  /* Color sólido de base; los gradientes viven en .backdrop (capa fija).
     background-attachment: fixed provocaba glitches de repintado al hacer scroll. */
  background: #0c100e;
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Capa de fondo fija: gradientes + cuadrícula. Al ser un elemento fijo
   (no background-attachment: fixed) el navegador la composita sin fallos. */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(1200px 800px at 12% -8%, #16241b 0%, transparent 55%),
    radial-gradient(1100px 760px at 108% 4%, #1a2419 0%, transparent 52%),
    linear-gradient(160deg, #0c110e 0%, #131c16 46%, #0a0e0c 100%);
  transform: translateZ(0);
}
.backdrop::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(rgba(240, 232, 210, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(240, 232, 210, 0.018) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), transparent 84%);
  -webkit-mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.85), transparent 84%);
}

/* Grano de película para textura */
.grain {
  position: fixed;
  inset: -50%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  animation: grainShift 8s steps(6) infinite;
}
@keyframes grainShift {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4%, 3%); }
  40% { transform: translate(3%, -2%); }
  60% { transform: translate(-2%, -3%); }
  80% { transform: translate(2%, 4%); }
}

/* Aurora de fondo animada. Sin filter: blur() — los propios gradientes ya son
   suaves y el blur forzaba repintados costosos que ensuciaban el scroll. */
.aurora {
  position: fixed;
  inset: -12%;
  background:
    radial-gradient(52% 42% at 22% 12%, rgba(143, 192, 122, 0.17), transparent 72%),
    radial-gradient(46% 40% at 78% 16%, rgba(224, 177, 85, 0.12), transparent 70%),
    radial-gradient(42% 36% at 48% 92%, rgba(74, 124, 89, 0.16), transparent 74%);
  z-index: 0;
  pointer-events: none;
  will-change: transform;
  animation: float 20s ease-in-out infinite alternate;
}
@keyframes float {
  from { transform: translate3d(0, 0, 0) scale(1); }
  to   { transform: translate3d(0, 26px, 0) scale(1.05); }
}

/* "Glass" sin backdrop-filter: el filtro sobre capas fijas/animadas provocaba
   glitches de compositing (zonas negras) al hacer scroll. La superficie
   semiopaca + borde consigue el mismo efecto de forma estable. */
.glass {
  background: var(--surface-glass);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.muted { color: var(--text-muted); font-size: 0.85rem; }
.user-badge { margin-top: 0.2rem; }

.ti {
  width: 1.1em;
  height: 1.1em;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

/* ---------- Scroll ---------- */
html {
  scrollbar-width: thin;
  scrollbar-color: rgba(224, 177, 85, 0.3) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(224, 177, 85, 0.28);
  border-radius: 8px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(224, 177, 85, 0.5); }
::-webkit-scrollbar-corner { background: transparent; }

/* ---------- Animaciones de entrada ---------- */
.reveal {
  opacity: 0;
  transform: translateY(18px);
  animation: revealUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
  animation-delay: calc(var(--d, 0) * 90ms + 60ms);
}
@keyframes revealUp {
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .reveal { animation: none; opacity: 1; transform: none; }
  .aurora, .grain { animation: none; }
}

/* ---------- Botones ---------- */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  border: 1px solid var(--border);
  background: rgba(240, 232, 210, 0.04);
  border-radius: var(--radius-pill);
  padding: 0.55rem 1.05rem;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition), box-shadow var(--transition), border-color var(--transition);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-2px); border-color: var(--border-strong); background: rgba(240, 232, 210, 0.09); }
.btn:active { transform: translateY(0); }
.btn-primary {
  background: var(--brass-grad);
  border-color: transparent;
  color: var(--ink);
  font-weight: 700;
  box-shadow: 0 8px 22px rgba(200, 146, 58, 0.32);
}
.btn-primary:hover { box-shadow: 0 12px 30px rgba(200, 146, 58, 0.5); }
.btn-ghost { background: rgba(240, 232, 210, 0.03); }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.82rem; }
.btn-block { width: 100%; justify-content: center; margin-top: 0.5rem; }
.btn-icon {
  width: 32px; height: 32px; padding: 0; justify-content: center;
  border-radius: 10px; font-size: 0.95rem; line-height: 1;
}
.btn-icon .ti { width: 17px; height: 17px; }
.btn-icon.has-notes { color: var(--brass); border-color: rgba(224, 177, 85, 0.4); background: rgba(224, 177, 85, 0.14); }

/* ---------- Login ---------- */
.login-body { display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  position: relative; z-index: 1;
  width: 100%; max-width: 420px;
  padding: 2.4rem 2.2rem;
  border-radius: var(--radius);
  text-align: center;
  animation: revealUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.login-brand { margin-bottom: 1.6rem; }
.login-brand h1 { font-family: var(--font-display); font-size: 2rem; font-weight: 600; letter-spacing: -0.01em; }
.logo-badge {
  display: inline-grid; place-items: center;
  width: 56px; height: 56px; margin-bottom: 0.7rem;
  font-size: 1.6rem; border-radius: 16px;
  color: var(--ink);
  background: var(--brass-grad);
  box-shadow: 0 12px 28px rgba(200, 146, 58, 0.35);
}
.logo-badge .ti { width: 30px; height: 30px; stroke-width: 1.9; }
#login-form { text-align: left; }
#login-form label { display: block; font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.4rem; margin-top: 0.9rem; }
#login-form label:first-child { margin-top: 0; }
input, select {
  width: 100%;
  font-family: inherit; font-size: 0.95rem; color: var(--text);
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.72rem 0.85rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(224, 177, 85, 0.22);
}
select option { background: #14201a; color: var(--text); }
.password-field { position: relative; }
.password-field input { padding-right: 3.4rem; }
.password-toggle {
  position: absolute;
  top: 50%;
  right: 0.45rem;
  transform: translateY(-50%);
  min-width: 44px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(240, 232, 210, 0.05);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 800;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.password-toggle:hover { background: rgba(240, 232, 210, 0.1); border-color: var(--border-strong); }
.error-msg { color: var(--danger); font-size: 0.85rem; margin-top: 0.8rem; text-align: center; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap;
  padding: 0.9rem 1.5rem;
  border-radius: 0 0 var(--radius) var(--radius);
  border-top: none;
}
.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand .logo-badge { width: 46px; height: 46px; font-size: 1.2rem; margin: 0; }
.brand .logo-badge .ti { width: 24px; height: 24px; }
.brand h1 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 600; letter-spacing: -0.01em; line-height: 1.05; }
.topbar-actions { display: flex; gap: 0.55rem; flex-wrap: wrap; }

/* ---------- Layout ---------- */
.container { position: relative; z-index: 1; max-width: 1240px; margin: 0 auto; padding: 1.8rem 1.5rem 3.5rem; }

/* Selector de meses (agrupado por año) */
.month-selector { display: flex; flex-direction: column; gap: 0.55rem; padding: 0.3rem 0.1rem 1rem; margin-bottom: 0.4rem; }
.year-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.year-tab {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.32rem 0.85rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.year-tab:hover { color: var(--text); border-color: var(--border-strong); }
.year-tab.active { color: var(--ink); background: var(--sage); border-color: transparent; }
.month-pills-row { display: flex; gap: 0.6rem; overflow-x: auto; padding: 0.1rem 0.1rem 0.5rem; }
.month-pill {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--surface-glass);
  border-radius: 14px;
  padding: 0.65rem 1.05rem;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), background var(--transition), box-shadow var(--transition);
  min-width: 100px; text-align: left;
  color: var(--text);
}
.month-pill:hover { transform: translateY(-3px); border-color: var(--border-strong); }
.month-pill.active {
  border-color: transparent;
  background: var(--brass-grad);
  color: var(--ink);
  box-shadow: 0 12px 26px rgba(200, 146, 58, 0.32);
}
.month-pill .mp-name { display: block; font-weight: 700; font-size: 0.98rem; }
.month-pill .mp-sub { display: block; font-family: var(--font-mono); font-size: 0.72rem; opacity: 0.78; }

.month-pill-wrap { position: relative; flex: 0 0 auto; }
.month-pill-del {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; padding: 0;
  display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border-strong);
  background: var(--surface-strong); color: var(--danger);
  opacity: 0; transform: scale(0.85);
  transition: opacity var(--transition), transform var(--transition), background var(--transition);
  cursor: pointer;
}
.month-pill-del .ti { width: 11px; height: 11px; }
.month-pill-wrap:hover .month-pill-del { opacity: 1; transform: scale(1); }
.month-pill-del:hover { background: var(--danger-bg); }

/* Cards resumen */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.card {
  position: relative; overflow: hidden;
  border-radius: 16px;
  padding: 1.3rem 1.35rem 1.2rem;
  min-height: 148px;
  display: flex; flex-direction: column; gap: 0.3rem;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.card:hover { transform: translateY(-5px); box-shadow: var(--shadow-glow); border-color: var(--border-strong); }
.card::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--brass-grad); opacity: 0.95;
}
.card::after {
  content: ''; position: absolute; right: -40px; top: -40px;
  width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(circle, rgba(224, 177, 85, 0.1), transparent 70%);
  pointer-events: none;
}
.card[data-kind="beneficio"]::before { background: linear-gradient(135deg, #6fd39a, #8fc07a); }
.card[data-kind="gastos"]::before { background: linear-gradient(135deg, #ef7d6b, #f2c14e); }
.card[data-kind="pendiente"]::before { background: linear-gradient(135deg, #f2c14e, #ef7d6b); }
.card[data-kind="reparto"]::before { background: linear-gradient(135deg, #4a7c59, #e0b155); }
.card-icon {
  display: inline-grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  background: rgba(240, 232, 210, 0.06);
  color: var(--brass);
  margin-bottom: 0.5rem;
}
.card-icon .ti { width: 19px; height: 19px; }
.card[data-kind="beneficio"] .card-icon { color: var(--sage); }
.card[data-kind="gastos"] .card-icon { color: var(--danger); }
.card[data-kind="pendiente"] .card-icon { color: var(--warning); }
.card-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.card-value {
  font-family: var(--font-mono);
  font-size: 1.85rem; font-weight: 700; letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.card-foot { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); }
.card-value.pos { color: var(--success); }
.card-value.neg { color: var(--danger); }

/* ---------- Gastos de edificio (propietarios) ---------- */
.owners-panel { margin-bottom: 1.4rem; }
.owners-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.9rem;
}
.owner-card {
  border-radius: 14px;
  padding: 0.9rem 1.05rem;
  background: rgba(240, 232, 210, 0.04);
  border: 1px solid var(--border);
  transition: border-color var(--transition), background var(--transition);
}
.owner-card.mine { border-color: rgba(224, 177, 85, 0.45); background: rgba(224, 177, 85, 0.08); }
.owner-name { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 0.4rem; }
.owner-tag {
  font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 0.1rem 0.4rem; border-radius: var(--radius-pill);
  background: var(--brass-grad); color: var(--ink);
}
.owner-pisos { font-size: 0.74rem; color: var(--text-muted); margin: 0.15rem 0 0.5rem; }
.owner-amount { font-family: var(--font-mono); font-size: 1.3rem; font-weight: 700; }

.owner-consumo {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.7rem;
}
.owner-consumo-label { flex: 1 0 100%; font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.owner-consumo-item { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text); font-weight: 600; }
.owner-amount-label { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.1rem; }

.owner-real {
  margin-top: 0.65rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.6rem;
}
.owner-real-label { flex: 1 0 100%; font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.owner-real-value { font-family: var(--font-mono); font-size: 1rem; font-weight: 700; }
.owner-real-value.pos { color: var(--success); }
.owner-real-value.neg { color: var(--danger); }
.owner-real-detail { flex: 1 0 100%; font-size: 0.72rem; color: var(--text-muted); }

.owners-balance {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  border-radius: 12px;
  font-size: 0.88rem; font-weight: 600;
  margin-bottom: 0.9rem;
}
.owners-balance .ti { width: 16px; height: 16px; flex: 0 0 auto; }
.owners-balance.ok { background: rgba(143, 192, 122, 0.12); color: var(--sage); }
.owners-balance.debe { background: rgba(224, 177, 85, 0.14); color: var(--brass); }
.owners-balance strong { font-weight: 800; }

/* ---------- Analítica ---------- */
.analytics-grid {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 1.2rem;
  margin-bottom: 1.4rem;
}
.chart-panel { border-radius: var(--radius); padding: 1.3rem 1.4rem 1.4rem; min-width: 0; }
.panel-sub { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; align-items: center; }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--text-muted); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }
.chart-host { position: relative; width: 100%; margin-top: 0.4rem; }
.chart-host svg { width: 100%; height: auto; display: block; overflow: visible; }

/* Líneas del gráfico de evolución */
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-line-draw {
  stroke-dasharray: var(--len);
  stroke-dashoffset: var(--len);
  animation: drawLine 1.4s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes drawLine { to { stroke-dashoffset: 0; } }
.chart-area { opacity: 0; animation: fadeArea 1.2s ease forwards 0.4s; }
@keyframes fadeArea { to { opacity: 1; } }
.chart-dot { transition: r var(--transition); cursor: pointer; }
.chart-grid-line { stroke: rgba(240, 232, 210, 0.07); stroke-width: 1; }
.chart-axis-label { font-family: var(--font-mono); font-size: 10px; fill: var(--text-muted); }
.chart-guide { stroke: rgba(224, 177, 85, 0.5); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; transition: opacity var(--transition); }

.chart-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.5rem 0.7rem;
  font-size: 0.78rem;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translate(-50%, -120%);
  transition: opacity 0.14s ease;
  white-space: nowrap;
}
.chart-tooltip strong { font-family: var(--font-display); font-weight: 600; display: block; margin-bottom: 0.25rem; font-size: 0.82rem; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 0.4rem; font-family: var(--font-mono); font-size: 0.72rem; }
.chart-tooltip .tt-row span.dot { width: 8px; height: 8px; border-radius: 2px; }
.chart-empty { text-align: center; color: var(--text-muted); font-size: 0.88rem; padding: 3rem 0; }

/* Donut */
.donut-host { display: flex; align-items: center; gap: 1.4rem; margin-top: 0.6rem; flex-wrap: wrap; }
.donut-chart { position: relative; width: 168px; height: 168px; flex: 0 0 auto; }
.donut-chart svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-seg { transition: stroke-width var(--transition); }
.donut-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.donut-center .dc-value { font-family: var(--font-mono); font-size: 1.15rem; font-weight: 700; }
.donut-center .dc-label { font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.donut-legend { display: grid; gap: 0.5rem; flex: 1 1 140px; min-width: 140px; }
.donut-legend .dl-item { display: flex; align-items: center; gap: 0.55rem; font-size: 0.82rem; }
.donut-legend .dl-dot { width: 11px; height: 11px; border-radius: 3px; flex: 0 0 auto; }
.donut-legend .dl-name { flex: 1; color: var(--text-muted); }
.donut-legend .dl-val { font-family: var(--font-mono); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Paneles / tablas */
/* Inquilinos y Gastos apilados a ancho completo: la tabla de Gastos tiene
   muchas columnas (fecha, recibo, tipo, proveedor, descripción, importe,
   reparto, estado...) y a media anchura obligaba a scroll horizontal
   constante. A ancho completo caben todas sin recortarse. */
.tables-grid { display: grid; grid-template-columns: 1fr; gap: 1.2rem; }
/* min-width: 0 es necesario en los hijos de un grid: sin él, un elemento
   ancho dentro (como la tabla de gastos) fuerza la columna a crecer en vez
   de activar el scroll interno de .table-wrap, y empuja toda la página. */
.panel { border-radius: var(--radius); padding: 1.2rem 1.3rem 1.4rem; min-width: 0; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 0.9rem; }
.panel-head-actions { display: flex; align-items: center; gap: 0.7rem; flex: 0 0 auto; }
.panel-head h2 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 600; letter-spacing: -0.01em; }
.panel-note { margin-top: 0.9rem; font-size: 0.8rem; color: var(--text-muted); }
.table-wrap { overflow-x: auto; max-width: 100%; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th {
  text-align: left; font-weight: 600; font-size: 0.7rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 0.68rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: rgba(240, 232, 210, 0.04); }
.num { text-align: right; }
.center { text-align: center; }
td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.piso-tag { font-weight: 700; }
.date-fallback { color: var(--text-muted); font-size: 0.82rem; }

/* Estado pagado/pendiente */
.status-toggle {
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0.3rem 0.72rem;
  font-size: 0.76rem; font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex; align-items: center; gap: 0.35rem;
}
.status-toggle .ti { width: 14px; height: 14px; }
.status-toggle.pagado { background: var(--success-bg); color: var(--success); border-color: rgba(111, 211, 154, 0.35); }
.status-toggle.pendiente { background: var(--warning-bg); color: var(--warning); border-color: rgba(242, 193, 78, 0.35); }
.status-toggle:hover { transform: translateY(-1px); filter: brightness(1.15); }

.row-actions { display: inline-flex; gap: 0.35rem; }

/* Stepper de ocupantes */
.ocupantes-control { display: inline-flex; align-items: center; gap: 0.4rem; }
.ocup-num {
  font-family: var(--font-mono); font-weight: 700; font-size: 0.92rem;
  min-width: 1.1ch; text-align: center;
}
.ocup-btn {
  width: 24px; height: 24px; padding: 0; line-height: 1;
  display: inline-grid; place-items: center;
  border: 1px solid var(--border); border-radius: 8px;
  background: rgba(240, 232, 210, 0.05); color: var(--text);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.ocup-btn:hover { background: rgba(224, 177, 85, 0.16); border-color: var(--border-strong); transform: translateY(-1px); }

/* Badge de método de reparto */
.reparto-badge {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.72rem; font-weight: 600;
  padding: 0.2rem 0.5rem; border-radius: var(--radius-pill);
  white-space: nowrap;
}
.reparto-badge.personas { background: rgba(143, 192, 122, 0.15); color: var(--sage); }
.reparto-badge.igual { background: rgba(224, 177, 85, 0.15); color: var(--brass); }

.reparto-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}
.ambito-badge {
  display: inline-block;
  font-size: 0.6rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 0.12rem 0.38rem; border-radius: var(--radius-pill);
  white-space: nowrap;
}
.ambito-badge.edificio { background: rgba(239, 125, 107, 0.16); color: var(--danger); }
.ambito-badge.inquilinos { background: rgba(92, 198, 208, 0.16); color: #5cc6d0; }

.reparto-note {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.62rem; font-weight: 600;
  color: var(--muted);
  border-bottom: 1px dashed var(--border-strong);
  cursor: help;
  white-space: nowrap;
}

.note-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; margin-left: 0.3rem;
  border-radius: 5px; color: var(--brass);
  background: rgba(224, 177, 85, 0.16);
  cursor: help; vertical-align: middle;
}
.note-badge .ti { width: 10px; height: 10px; }

.doc-link-slot { display: inline-block; }
.doc-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; margin-left: 0.35rem;
  border-radius: 7px; color: var(--brass);
  background: rgba(224, 177, 85, 0.12);
  vertical-align: middle;
}
.doc-link .ti { width: 13px; height: 13px; }
.doc-link:hover { background: rgba(224, 177, 85, 0.22); }

.empty { text-align: center; color: var(--text-muted); padding: 1.8rem 0; font-size: 0.9rem; }
.read-only-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  background: rgba(240, 232, 210, 0.06);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
}

/* Resumen por vivienda */
.tenant-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}
.tenant-card {
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.tenant-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-glow); border-color: var(--border-strong); }
.tenant-card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(135deg, #4a7c59, #e0b155);
}
.tenant-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}
.tenant-pill {
  border-radius: var(--radius-pill);
  padding: 0.32rem 0.72rem;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: rgba(240, 232, 210, 0.08);
}
.tenant-status { font-size: 0.72rem; font-weight: 700; }
.tenant-status.ok { color: var(--success); }
.tenant-status.warn { color: var(--warning); }
.tenant-card h3 { font-family: var(--font-display); font-weight: 600; font-size: 1.05rem; margin-bottom: 0.9rem; }
.tenant-metrics { display: grid; gap: 0.55rem; }
.tenant-metrics div { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.88rem; }
.tenant-metrics dt { color: var(--text-muted); }
.tenant-metrics dd { font-family: var(--font-mono); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Documentos ---------- */
.docs-section { margin-top: 0.4rem; }
.section-heading { margin-bottom: 1rem; }
.section-heading h2 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 600; letter-spacing: -0.01em; }

.doc-list { list-style: none; display: grid; gap: 0.55rem; }
.doc-item {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(240, 232, 210, 0.03);
  transition: border-color var(--transition), background var(--transition), transform var(--transition);
}
.doc-item:hover { border-color: var(--border-strong); background: rgba(240, 232, 210, 0.06); transform: translateX(2px); }
.doc-thumb {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 9px; flex: 0 0 auto;
  background: rgba(224, 177, 85, 0.12); color: var(--brass);
}
.doc-thumb .ti { width: 20px; height: 20px; }
.doc-meta { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-sub { font-family: var(--font-mono); font-size: 0.72rem; color: var(--text-muted); }
.doc-actions { display: inline-flex; gap: 0.4rem; flex: 0 0 auto; }
.doc-cat {
  font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 0.15rem 0.45rem; border-radius: var(--radius-pill);
  background: rgba(143, 192, 122, 0.14); color: var(--sage);
}
.doc-empty { text-align: center; color: var(--text-muted); font-size: 0.88rem; padding: 1.6rem 0; }
.doc-email {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}
.doc-email.missing { color: var(--warning); font-family: var(--font-ui); font-style: italic; }

/* ---------- Recibos y contratos (sección propia) ---------- */
.recibos-section { margin-top: 1.6rem; }
.recibos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.recibo-card {
  padding: 1.15rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.recibo-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-glow); border-color: var(--border-strong); }
.recibo-card-head { display: flex; align-items: flex-start; gap: 0.7rem; }
.recibo-card-titles { flex: 1; min-width: 0; }
.recibo-card-titles h3 {
  font-family: var(--font-display); font-weight: 600; font-size: 1.02rem;
  margin: 0.05rem 0 0.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recibo-card-total {
  font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem;
  color: var(--brass); white-space: nowrap; flex: 0 0 auto;
}
.tipo-pills { display: flex; gap: 0.4rem; }
.tipo-pill {
  flex: 1;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  padding: 0.3rem 0.4rem;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}
.tipo-pill:hover { color: var(--text); border-color: var(--border-strong); }
.tipo-pill.active { background: var(--sage); color: var(--ink); border-color: transparent; }
.recibo-actions-row, .recibo-send-row { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.recibo-send-row { padding-top: 0.6rem; border-top: 1px dashed var(--border); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center; padding: 1.5rem;
  background: rgba(5, 8, 6, 0.78);
  animation: fade 180ms ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; max-width: 460px; max-height: calc(100vh - 3rem);
  border-radius: var(--radius); padding: 1.7rem;
  display: flex; flex-direction: column;
  animation: modalPop 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modalPop { from { opacity: 0; transform: translateY(16px) scale(0.96); } to { opacity: 1; transform: none; } }
.modal h3 { flex: 0 0 auto; font-family: var(--font-display); font-size: 1.3rem; font-weight: 600; margin-bottom: 1.2rem; }
#modal-form {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  padding-right: 0.6rem;
  margin-right: -0.6rem;
}
.modal-form-row { margin-bottom: 0.9rem; }
.modal-form-row label { display: block; font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.35rem; }
.modal-actions { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.3rem; padding-top: 0.9rem; border-top: 1px solid var(--border); }
.checkbox-row { display: flex; align-items: center; gap: 0.6rem; }
.checkbox-row input { width: auto; }
.modal-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.2rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 1.6rem; left: 50%; transform: translateX(-50%);
  z-index: 60;
  background: var(--surface-strong);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-pill);
  padding: 0.75rem 1.4rem; font-size: 0.88rem; font-weight: 600;
  box-shadow: var(--shadow-soft);
  animation: toastIn 260ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.error { border-color: rgba(239, 125, 107, 0.5); color: var(--danger); }
.toast.success { border-color: rgba(111, 211, 154, 0.5); color: var(--success); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- Balance anual: botón flotante + modal ---------- */
.balance-fab {
  position: fixed; top: 5.5rem; right: 1.3rem; z-index: 40;
  display: inline-flex; align-items: center; gap: 0.5rem;
  border: 1px solid var(--border-strong);
  background: var(--surface-strong);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 0.6rem 1.05rem;
  font-size: 0.85rem; font-weight: 700;
  font-family: var(--font-mono);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
}
.balance-fab:hover { transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.balance-fab .ti { width: 16px; height: 16px; color: var(--brass); }
.balance-fab.ok .ti { color: var(--sage); }
.balance-fab.debe { border-color: rgba(224, 177, 85, 0.5); }

.balance-modal { max-width: 620px; }
.balance-year-tabs { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }

.balance-totales { display: flex; gap: 1rem; margin-bottom: 1.5rem; }
.balance-totales-item {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; display: flex; flex-direction: column; gap: 0.25rem;
}
.balance-totales-label { font-size: 0.8rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.balance-totales-value { font-size: 1.6rem; font-weight: 700; font-family: var(--font-mono); color: var(--text); }
.balance-totales-value.pos { color: var(--sage); }
.balance-totales-value.neg { color: var(--danger); }

.balance-summary {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.65rem 0.9rem; border-radius: 12px;
  font-size: 0.88rem; font-weight: 600; margin-bottom: 1rem;
}
.balance-summary.ok { background: rgba(143, 192, 122, 0.12); color: var(--sage); }
.balance-summary.debe { background: rgba(224, 177, 85, 0.14); color: var(--brass); }
.balance-chart-host { margin-bottom: 1.1rem; }
.balance-rows { display: grid; gap: 0.55rem; max-height: 320px; overflow-y: auto; padding-right: 0.3rem; }
.balance-row {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(240, 232, 210, 0.03);
}
.balance-row-mes { font-family: var(--font-mono); font-size: 0.78rem; color: var(--text-muted); width: 76px; flex: 0 0 auto; }
.balance-row-detalle { flex: 1; font-size: 0.86rem; }
.balance-row-detalle.ok { color: var(--text-muted); }
.balance-row.pagado { opacity: 0.55; }

/* ---------- Responsive ---------- */
/* Portátiles (13"-16": 1366-1536px de ancho) — todo más compacto para que
   quepa sin scroll excesivo, sin tocar el espaciado holgado de monitores grandes. */
@media (max-width: 1550px) {
  .container { padding: 1.15rem 1.3rem 2rem; }
  .topbar { padding: 0.7rem 1.3rem; }
  .month-selector { padding: 0.25rem 0.1rem 0.7rem; }
  .card { min-height: 104px; padding: 0.9rem 1rem 0.85rem; }
  .card-value { font-size: 1.5rem; }
  .card-icon { width: 28px; height: 28px; margin-bottom: 0.3rem; }
  .summary-grid { gap: 0.75rem; margin-bottom: 1rem; }
  .analytics-grid { gap: 0.9rem; margin-bottom: 1rem; }
  .chart-panel { padding: 1rem 1.1rem 1.05rem; }
  .panel { padding: 0.9rem 1.05rem 1.05rem; }
  .panel-head { margin-bottom: 0.6rem; }
  .tenant-summary-grid { gap: 0.75rem; margin-bottom: 1rem; }
  .tenant-card { padding: 0.8rem 0.9rem; }
  .tenant-card-head { margin-bottom: 0.6rem; }
  .tables-grid, .recibos-grid { gap: 0.9rem; }
  .owners-panel { margin-bottom: 1rem; }
  .owner-card { padding: 0.75rem 0.9rem; }
  .owner-amount { font-size: 1.15rem; }
  .brand h1 { font-size: 1.3rem; }
  .section-heading { margin-bottom: 0.7rem; }
  .section-heading h2 { font-size: 1.2rem; }
}

@media (max-width: 1000px) {
  .analytics-grid { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .tables-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .summary-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0.8rem 1rem; }
  .brand h1 { font-size: 1.25rem; }
  .btn { font-size: 0.82rem; padding: 0.5rem 0.85rem; }
  .donut-host { justify-content: center; }
}
