/* =========================================================
   Condo App — Tokens de diseño
   Paleta: fachada nocturna de edificio, ventanas encendidas
   como indicador de estado de pago. Tema oscuro por defecto,
   con tema claro alternativo vía [data-theme="light"].
   ========================================================= */
:root,
[data-theme="dark"] {
  --bg: #0F1720;
  --bg-elevated: #16212C;
  --card: #1A2733;
  --card-hover: #1F2E3B;
  --border: #263544;
  --border-soft: #1E2C38;

  --text: #EAF0F4;
  --text-muted: #8697A5;
  --text-dim: #5C6B79;

  --accent: #2FBF71;       /* verde: fondos disponibles / pagado */
  --accent-dim: #1D8A50;
  --accent-soft: rgba(47, 191, 113, 0.14);

  --warn: #F5A623;         /* ambar: gas / parcial */
  --warn-soft: rgba(245, 166, 35, 0.14);

  --danger: #E5484D;       /* rojo: pendiente / egresos */
  --danger-soft: rgba(229, 72, 77, 0.14);

  --info: #5B9DF5;
  --info-soft: rgba(91, 157, 245, 0.14);

  --shadow-color: rgba(0,0,0,.4);

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 20px;
}

[data-theme="light"] {
  --bg: #F5F7F9;
  --bg-elevated: #FFFFFF;
  --card: #FFFFFF;
  --card-hover: #F1F4F7;
  --border: #E1E7EC;
  --border-soft: #EAEEF2;

  --text: #16212C;
  --text-muted: #5C6B79;
  --text-dim: #8697A5;

  --accent: #1C9D5B;
  --accent-dim: #167A45;
  --accent-soft: rgba(28, 157, 91, 0.12);

  --warn: #B8790F;
  --warn-soft: rgba(184, 121, 15, 0.12);

  --danger: #D1373D;
  --danger-soft: rgba(209, 55, 61, 0.10);

  --info: #3576D9;
  --info-soft: rgba(53, 118, 217, 0.10);

  --shadow-color: rgba(20,30,40,.10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; }

a { color: inherit; }

::selection { background: var(--accent-soft); }

/* Scrollbar sutil */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* =========================================================
   Layout general
   ========================================================= */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* El backdrop solo existe visualmente en móvil (ver media query abajo).
   Debe quedar display:none de forma incondicional aquí — si no, en
   desktop este div vacío ocupa una celda del grid y descuadra todo
   el layout (empuja el sidebar real a la derecha y el contenido abajo). */
.sidebar-backdrop { display: none; }

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .22s ease;
    box-shadow: 0 0 40px var(--shadow-color);
  }
  .sidebar.open { transform: translateX(0); }

  .sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(6,10,14,.55);
    z-index: 55;
  }
  .sidebar-backdrop.open { display: block; }

  .sidebar-close-btn { display: flex; }
}

.sidebar-close-btn {
  display: none;
  margin-left: auto;
  background: transparent; border: none; color: var(--text-muted);
  padding: 6px; border-radius: 6px; cursor: pointer;
}
.sidebar-close-btn svg { width: 18px; height: 18px; }

.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-soft);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  padding: 0 10px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: linear-gradient(160deg, var(--accent), var(--accent-dim));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 16px; height: 16px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-s);
  color: var(--text-muted);
  font-size: 14.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid var(--border-soft);
  padding-top: 16px;
}
.theme-toggle {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px; margin-bottom: 10px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-s); color: var(--text-muted);
  font-size: 13px; font-weight: 500; cursor: pointer;
  transition: color .15s, border-color .15s;
}
.theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.theme-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 13px;
  color: var(--accent);
}
.user-meta { font-size: 12.5px; line-height: 1.3; }
.user-meta .name { font-weight: 600; color: var(--text); }
.user-meta .role { color: var(--text-dim); text-transform: capitalize; }
.logout-btn {
  margin-top: 12px; width: 100%; padding: 8px;
  background: transparent; border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-s);
  font-size: 12.5px; cursor: pointer;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); }

/* =========================================================
   Main content
   ========================================================= */
.main {
  padding: 28px 34px 60px;
  max-width: 1180px;
  width: 100%;
}
@media (max-width: 640px) { .main { padding: 18px 16px 50px; } }

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px; left: 16px;
  z-index: 40;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  padding: 9px;
  color: var(--text);
  box-shadow: 0 4px 14px var(--shadow-color);
}
@media (max-width: 860px) {
  .mobile-menu-btn { display: flex; }
  .main { padding-top: 68px; }
  .nav-item { padding: 13px 12px; font-size: 15px; }
  .btn { padding: 12px 18px; }
  .btn-sm { padding: 9px 14px; }
  .window { min-height: 56px; }
}

.main > #pageContent > h1,
.section-header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
@media (max-width: 640px) {
  .main > #pageContent > h1, .section-header h1 { font-size: 19px; }
}

/* =========================================================
   Cards / grids
   ========================================================= */
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 860px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-m);
  padding: 20px;
}
.card h3 {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card .value {
  font-family: var(--font-mono);
  font-size: 30px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.stat-card.positive .value { color: var(--accent); }
.stat-card.warn .value { color: var(--warn); }
.stat-card.info .value { color: var(--info); }
.stat-card .hint { color: var(--text-dim); font-size: 12.5px; margin-top: 6px; }

.stat-card-top { display: flex; align-items: flex-start; justify-content: space-between; }
.stat-icon {
  width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 16px; height: 16px; }
.stat-icon.accent { background: var(--accent-soft); color: var(--accent); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-icon.warn { background: var(--warn-soft); color: var(--warn); }

.trend-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600; margin-top: 6px;
  padding: 2px 8px; border-radius: 100px;
}
.trend-up { background: var(--accent-soft); color: var(--accent); }
.trend-down { background: var(--danger-soft); color: var(--danger); }

.cat-bar-row { margin-bottom: 16px; }
.cat-bar-row:last-child { margin-bottom: 0; }
.cat-bar-label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13.5px; font-weight: 500; margin-bottom: 6px;
}
.cat-bar-track {
  height: 8px; border-radius: 100px; background: var(--bg-elevated);
  overflow: hidden; margin-bottom: 5px;
}
.cat-bar-fill {
  height: 100%; border-radius: 100px;
  background: linear-gradient(90deg, var(--accent-dim), var(--accent));
  transition: width .3s ease;
}

/* =========================================================
   Fachada del edificio — elemento distintivo del dashboard
   ========================================================= */
.facade-card { padding: 24px; }
.facade-legend { display: flex; gap: 18px; margin-bottom: 18px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-muted); }
.legend-dot { width: 9px; height: 9px; border-radius: 3px; }

.facade-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 10px;
}

.window {
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: transform .12s;
  font-size: 11px;
}
.window:hover { transform: translateY(-2px); }
.window .lbl { font-family: var(--font-mono); font-weight: 600; font-size: 11.5px; }
.window .icon { font-size: 13px; }

.window.status-paid { background: var(--accent-soft); border-color: rgba(47,191,113,.35); color: var(--accent); }
.window.status-partial { background: var(--warn-soft); border-color: rgba(245,166,35,.35); color: var(--warn); }
.window.status-pending { background: var(--danger-soft); border-color: rgba(229,72,77,.3); color: var(--danger); }
.window.status-none { background: var(--bg-elevated); border-color: var(--border); color: var(--text-dim); }

/* =========================================================
   Tablas
   ========================================================= */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  text-align: left; color: var(--text-dim); font-weight: 600;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 12px; border-bottom: 1px solid var(--border-soft);
}
tbody td { padding: 12px; border-bottom: 1px solid var(--border-soft); }
tbody tr:hover { background: var(--card-hover); }
.amount { font-family: var(--font-mono); font-weight: 600; }
.amount.pos { color: var(--accent); }
.amount.neg { color: var(--danger); }

.badge {
  display: inline-block; padding: 3px 9px; border-radius: 100px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.badge.verificado, .badge.resuelto { background: var(--accent-soft); color: var(--accent); }
.badge.pendiente, .badge.abierto { background: var(--warn-soft); color: var(--warn); }
.badge.rechazado, .badge.descartado { background: var(--danger-soft); color: var(--danger); }
.badge.en_votacion, .badge.en_progreso { background: var(--info-soft); color: var(--info); }

/* =========================================================
   Formularios
   ========================================================= */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.field input, .field select, .field textarea {
  width: 100%; padding: 11px 12px;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-s); color: var(--text); font-size: 16px;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: var(--radius-s);
  font-size: 14px; font-weight: 600; cursor: pointer; border: none;
  transition: opacity .15s;
}
.btn:hover { opacity: 0.88; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #06140C; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; }

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}

.tabs { display: flex; gap: 6px; margin-bottom: 20px; border-bottom: 1px solid var(--border-soft); }
.tab {
  padding: 10px 4px; margin-right: 18px; background: none; border: none;
  color: var(--text-muted); font-size: 14px; font-weight: 500; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--text); border-color: var(--accent); }

.empty-state {
  text-align: center; padding: 50px 20px; color: var(--text-dim);
}
.empty-state .icon { font-size: 32px; margin-bottom: 10px; }

/* =========================================================
   Modal
   ========================================================= */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(6,10,14,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-l); padding: 26px;
  width: 100%; max-width: 460px;
  max-height: 88vh; overflow-y: auto;
}
.modal h3 { font-family: var(--font-display); font-size: 17px; margin: 0 0 18px; }
.modal-close { float: right; background: none; border: none; color: var(--text-dim); font-size: 18px; cursor: pointer; }

/* =========================================================
   Voting / Issues
   ========================================================= */
.issue-card {
  background: var(--card); border: 1px solid var(--border-soft);
  border-radius: var(--radius-m); padding: 18px; margin-bottom: 12px;
  display: flex; gap: 16px; align-items: flex-start;
}
.vote-box {
  flex-shrink: 0; width: 58px; text-align: center;
  border: 1px solid var(--border); border-radius: var(--radius-s);
  padding: 8px 6px; cursor: pointer; background: var(--bg-elevated);
  transition: background .15s, border-color .15s;
}
.vote-box.voted { background: var(--accent-soft); border-color: var(--accent); }
.vote-box .count { font-family: var(--font-mono); font-weight: 700; font-size: 18px; display: block; }
.vote-box .lbl { font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; }
.issue-body { flex: 1; }
.issue-body .title { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
.issue-body .desc { color: var(--text-muted); font-size: 13.5px; line-height: 1.5; margin-bottom: 8px; }
.issue-meta { display: flex; gap: 10px; align-items: center; font-size: 12px; color: var(--text-dim); flex-wrap: wrap; }

/* =========================================================
   Login
   ========================================================= */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative;
  background:
    radial-gradient(circle at 20% 20%, rgba(47,191,113,.08), transparent 40%),
    radial-gradient(circle at 80% 80%, rgba(91,157,245,.06), transparent 40%),
    var(--bg);
}
.login-theme-toggle {
  position: absolute; top: 20px; right: 20px;
  width: auto; margin-bottom: 0;
}
.login-box { width: 100%; max-width: 380px; }
.login-brand {
  display: flex; align-items: center; gap: 12px; justify-content: center;
  margin-bottom: 28px;
}
.login-brand .brand-mark { width: 40px; height: 40px; border-radius: 11px; }
.login-brand .brand-mark svg { width: 22px; height: 22px; }
.login-brand span { font-family: var(--font-display); font-weight: 700; font-size: 22px; }

.login-card {
  background: var(--card); border: 1px solid var(--border-soft);
  border-radius: var(--radius-l); padding: 30px;
}
.login-card h2 { font-family: var(--font-display); font-size: 19px; margin: 0 0 4px; }
.login-card .sub { color: var(--text-muted); font-size: 13.5px; margin-bottom: 22px; }
.login-error {
  background: var(--danger-soft); color: var(--danger); font-size: 13px;
  padding: 10px 12px; border-radius: var(--radius-s); margin-bottom: 16px;
}

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  padding: 12px 18px; border-radius: var(--radius-s); font-size: 13.5px;
  z-index: 200; box-shadow: 0 8px 24px var(--shadow-color);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--accent); color: var(--accent); }

.receipt-link {
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--info); font-size: 12.5px; text-decoration: none;
}
.receipt-link:hover { text-decoration: underline; }

.text-muted { color: var(--text-muted); }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
