:root {
  --bg: #0a0e1a;
  --surface: #121a2c;
  --surface-2: #16203a;
  --surface-hover: #182544;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.16);
  --primary: #2f8fef;
  --primary-dark: #1c63c4;
  --primary-soft: rgba(47,143,239,0.14);
  --primary-glow: rgba(47,143,239,0.45);
  --text: #f3f6fb;
  --muted: #8b95ac;
  --muted-2: #59637a;
  --danger: #f0475c;
  --danger-bg: rgba(240,71,92,0.14);
  --warn: #f5a524;
  --warn-bg: rgba(245,165,36,0.14);
  --ok: #2bc47b;
  --ok-bg: rgba(43,196,123,0.14);
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 10px 24px rgba(0,0,0,0.30);
  --shadow-lg: 0 20px 50px rgba(0,0,0,0.45);
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg);
  background-image:
    radial-gradient(1100px 550px at 12% -10%, rgba(47,143,239,0.16), transparent 60%),
    radial-gradient(800px 460px at 100% 0%, rgba(99,102,241,0.10), transparent 55%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif; letter-spacing: -0.01em; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-2); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- Iconos ---------- */
.icon { width: 20px; height: 20px; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.icon.xs { width: 14px; height: 14px; }
.icon.sm { width: 16px; height: 16px; }
.icon.lg { width: 28px; height: 28px; }

.icon-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: 0 0 0 1px rgba(47,143,239,0.18), 0 0 22px -4px var(--primary-glow);
  flex-shrink: 0;
}
.icon-circle.sm { width: 34px; height: 34px; }
.icon-circle.sm .icon { width: 16px; height: 16px; }
.icon-circle.lg { width: 64px; height: 64px; }
.icon-circle.lg .icon { width: 28px; height: 28px; }
.icon-circle.muted { background: rgba(255,255,255,0.06); color: var(--muted); box-shadow: none; }
.icon-circle.danger { background: var(--danger-bg); color: var(--danger); box-shadow: 0 0 0 1px rgba(240,71,92,0.18), 0 0 22px -4px rgba(240,71,92,0.4); }
.icon-circle.ok { background: var(--ok-bg); color: var(--ok); box-shadow: 0 0 0 1px rgba(43,196,123,0.18), 0 0 22px -4px rgba(43,196,123,0.4); }

.avatar {
  border-radius: 50%;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.sm { width: 40px; height: 40px; }
.avatar.md { width: 64px; height: 64px; }
.avatar.lg { width: 96px; height: 96px; }
.avatar.sm .icon { width: 18px; height: 18px; }
.avatar.md .icon { width: 26px; height: 26px; }
.avatar.lg .icon { width: 38px; height: 38px; }

.collector-block { margin-bottom: 10px; }
.collector-clients { margin-top: -4px; }
.collector-clients .list-item {
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  margin-bottom: 0;
  padding: 10px 2px;
}
.collector-clients .list-item:last-child { border-bottom: none; }
.toggle-ico { transition: transform 0.15s ease; margin-left: 2px; }
.toggle-ico.rotated { transform: rotate(90deg); }

/* ---------- Layout ---------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  background: rgba(18,26,44,0.85);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  color: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 40px; height: 40px; object-fit: contain; flex-shrink: 0; }
.topbar h1 { font-size: 17px; font-weight: 700; }
.topbar .sub { font-size: 12px; color: var(--muted); }
.topbar button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
}

.content {
  flex: 1;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

/* Navegación inferior (móvil) / lateral implícita */
.bottomnav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(18,26,44,0.92);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 6px 4px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.bottomnav button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  min-width: 60px;
  transition: color .15s, background .15s;
}
.bottomnav button .icon { width: 20px; height: 20px; }
.bottomnav button.active { color: var(--primary); font-weight: 600; background: var(--primary-soft); }

@media (min-width: 768px) {
  .content { padding: 28px; }
  .bottomnav {
    top: 0;
    bottom: auto;
    left: auto;
    right: 20px;
    background: transparent;
    border: none;
    backdrop-filter: none;
    padding: 14px 0;
    justify-content: flex-end;
    gap: 6px;
    max-width: none;
  }
  .bottomnav button { flex-direction: row; color: var(--muted); font-size: 13px; padding: 9px 14px; }
  .bottomnav button .icon { width: 17px; height: 17px; }
  .bottomnav button.active { color: #fff; background: var(--primary); box-shadow: 0 6px 20px -4px var(--primary-glow); }
  .content { padding-bottom: 28px; }
}

/* ---------- Componentes ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 18px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: transform .15s ease, border-color .15s ease;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--primary); box-shadow: 0 0 0 1px rgba(47,143,239,0.2); }
.stat.clickable:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.stat .stat-top { margin-bottom: 10px; display: flex; align-items: flex-start; justify-content: space-between; }
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.stat.danger .value { color: var(--danger); }
.stat.ok .value { color: var(--ok); }
.stat-eye {
  color: var(--muted);
  opacity: 0.55;
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}
.stat-eye .icon { width: 15px; height: 15px; }
.stat-eye:hover { opacity: 1; color: var(--text); background: rgba(255,255,255,0.06); }

h2.section {
  font-size: 13px;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  scroll-margin-top: 84px;
}

.report-section { margin-bottom: 8px; }
.report-section:first-of-type h2.section { margin-top: 0; }
h2.section .icon { color: var(--primary); width: 16px; height: 16px; }

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.list-item:hover { background: var(--surface-hover); border-color: var(--border-strong); }
.list-item:active { background: var(--surface-2); }
.list-item .info { min-width: 0; flex: 1; }
.list-item .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.list-item .meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 4px; }
.list-item .right { text-align: right; flex-shrink: 0; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.list-item .amount { font-weight: 700; font-size: 15px; color: var(--text); }
.list-item .chev { color: var(--muted-2); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 99px;
  margin-top: 5px;
}
.badge .icon { width: 12px; height: 12px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: rgba(255,255,255,0.06); color: var(--muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  width: 100%;
  box-shadow: 0 8px 20px -6px var(--primary-glow);
  transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease, background .12s ease;
  text-decoration: none;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 10px 26px -6px var(--primary-glow); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.55; box-shadow: none; transform: none; }
.btn.secondary { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); box-shadow: none; }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.danger { background: linear-gradient(135deg, var(--danger), #c23349); box-shadow: 0 8px 20px -6px rgba(240,71,92,0.4); }
.btn.small { width: auto; padding: 9px 14px; font-size: 13px; }
.btn.ghost { background: var(--surface-2); color: var(--text); box-shadow: none; border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-hover); }
.btn .icon { width: 17px; height: 17px; }

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(80px + env(safe-area-inset-bottom));
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  border: none;
  box-shadow: 0 10px 30px -6px var(--primary-glow), 0 0 0 1px rgba(255,255,255,0.06) inset;
  z-index: 15;
  transition: transform .15s ease;
}
.fab:hover { transform: translateY(-2px) scale(1.03); }
.fab .icon { width: 24px; height: 24px; }
@media (min-width: 768px) { .fab { bottom: 28px; } }

/* ---------- Formularios ---------- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  color-scheme: dark;
}
.field input::placeholder, .field textarea::placeholder { color: var(--muted-2); }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .hint { font-size: 12px; color: var(--muted-2); margin-top: 5px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 15px; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--primary); }
.checkbox-row label { font-size: 14px; color: var(--text); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 500px at 18% 0%, rgba(47,143,239,0.22), transparent 60%),
    radial-gradient(700px 420px at 100% 100%, rgba(99,102,241,0.14), transparent 55%);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 34px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-card .logo { display: flex; justify-content: center; margin-bottom: 6px; }
.login-logo { width: 190px; max-width: 100%; height: auto; }
.login-card h1 { font-size: 21px; text-align: center; margin-bottom: 6px; font-weight: 800; }
.login-card p { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,7,15,0.7);
  backdrop-filter: blur(2px);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
@media (min-width: 640px) { .modal-overlay { align-items: center; } }
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 22px;
  padding-bottom: calc(22px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow-lg);
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal h3 { font-size: 17px; margin-bottom: 18px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ---------- Tabla cronograma ---------- */
.table-wrap { overflow-x: auto; }
table.sched { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.sched th, table.sched td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.sched th { color: var(--muted); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; }
table.sched tr:last-child td { border-bottom: none; }
table.sched tr.done td { color: var(--ok); }
table.sched tr.late td { color: var(--danger); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: calc(92px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 90vw;
}
.toast-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.25s ease;
}
.toast-msg .icon { color: var(--ok); width: 18px; height: 18px; }
.toast-msg.error { border-color: rgba(240,71,92,0.35); }
.toast-msg.error .icon { color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; } }

/* ---------- Barras de avance de cobro ---------- */
.progress-item { padding: 12px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.progress-item:first-child { padding-top: 0; }
.progress-item:last-child { border-bottom: none; padding-bottom: 0; }
.progress-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.progress-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.progress-name small { color: var(--muted); font-weight: 400; }
.progress-pct { font-size: 13px; font-weight: 700; color: var(--primary); flex-shrink: 0; }
.progress-pct.late { color: var(--danger); }
.progress-bar { height: 8px; background: rgba(255,255,255,0.06); border-radius: 99px; margin: 8px 0 4px; overflow: hidden; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #6aa9f5); border-radius: 99px; transition: width 0.3s; }
.progress-fill.late { background: linear-gradient(90deg, var(--danger), #ff7d8c); }
.progress-meta { font-size: 12px; color: var(--muted); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 44px 16px;
  font-size: 14px;
}
.empty .icon-circle { margin: 0 auto 14px; }

.searchbar { margin-bottom: 12px; position: relative; }
.searchbar .search-ico {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
  display: flex;
}
.searchbar input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 99px;
  padding: 12px 16px 12px 42px;
  background: var(--surface-2);
  color: var(--text);
}
.searchbar input::placeholder { color: var(--muted-2); }
.searchbar input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.autocomplete-wrap { position: relative; }
.autocomplete-results {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  box-shadow: var(--shadow-lg);
}
.autocomplete-results .ac-item { padding: 11px 14px; cursor: pointer; font-size: 14px; }
.autocomplete-results .ac-item:hover, .autocomplete-results .ac-item.active { background: var(--surface-hover); }
.autocomplete-results .ac-empty { padding: 11px 14px; color: var(--muted); font-size: 13px; }

.filter-chips { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filter-chips button {
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  border-radius: 99px;
  padding: 8px 15px;
  font-size: 13px;
  color: var(--muted);
  transition: all .15s;
}
.filter-chips button:hover { border-color: var(--border-strong); color: var(--text); }
.filter-chips button.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.detail-rows { font-size: 14px; }
.detail-rows .row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.detail-rows .row:last-child { border-bottom: none; }
.detail-rows .row .k { color: var(--muted); }
.detail-rows .row .v { font-weight: 600; text-align: right; color: var(--text); }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 14px;
  font-weight: 600;
  padding: 0 0 14px;
}
.back-link .icon { width: 16px; height: 16px; }
