/* ─── Variables ─────────────────────────────────────────────── */
:root {
  --azul: #395477;
  --verde: #98D650;
  --celeste: #4CE5D8;
  --navy: #2B3F5C;
  --fondo: #F3F6F9;
  --blanco: #FFFFFF;
  --gris: #7A8A9A;
  --gris-claro: #E4EAF0;
  --texto: #1C2B3A;
  --radio: 14px;
  --sombra: 0 2px 12px rgba(57,84,119,0.10);
  --sombra-fab: 0 4px 20px rgba(152,214,80,0.40);
}

/* ─── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ─── Pantallas ─────────────────────────────────────────────── */
.screen { display: none; min-height: 100vh; flex-direction: column; }
.screen.active { display: flex; }

/* ─── Topbar ────────────────────────────────────────────────── */
.topbar {
  background: var(--navy);
  color: var(--blanco);
  padding: 14px 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 { font-size: 1.05rem; font-weight: 700; letter-spacing: 0.01em; }
.topbar .badge-notif {
  background: var(--verde);
  color: #fff;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 0.72rem;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}

/* ─── Navbar inferior ───────────────────────────────────────── */
.navbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--blanco);
  border-top: 1px solid var(--gris-claro);
  display: flex;
  z-index: 200;
  box-shadow: 0 -2px 10px rgba(22,35,74,0.08);
}
.navbar button {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 12px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--gris);
  font-size: 0.68rem;
  font-weight: 500;
  transition: color 0.15s;
}
.navbar button.active { color: var(--azul); }
.navbar button svg { width: 22px; height: 22px; }

/* ─── FAB ───────────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 80px; right: 18px;
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--verde);
  color: #fff;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  box-shadow: var(--sombra-fab);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.93); }

.fab-menu {
  position: fixed;
  bottom: 150px; right: 18px;
  display: none; flex-direction: column; gap: 10px;
  z-index: 299;
  align-items: flex-end;
}
.fab-menu.open { display: flex; }
.fab-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--blanco);
  border: none;
  border-radius: 24px;
  padding: 10px 16px;
  box-shadow: var(--sombra);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--texto);
  white-space: nowrap;
}
.fab-item:active { transform: scale(0.97); }
.fab-item .dot {
  width: 10px; height: 10px; border-radius: 50%;
}
.fab-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 298;
  background: rgba(22,35,74,0.18);
}
.fab-overlay.open { display: block; }

/* ─── Main scroll area ──────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: 90px;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--blanco);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.card-title { font-weight: 700; font-size: 0.95rem; }
.card-meta { color: var(--gris); font-size: 0.78rem; margin-top: 2px; }
.card-body { font-size: 0.88rem; color: #3a4560; }

/* ─── Badges de estado ──────────────────────────────────────── */
.badge {
  font-size: 0.72rem; font-weight: 700;
  padding: 3px 9px; border-radius: 20px;
  white-space: nowrap;
}
.badge-pendiente { background: #FFF3CD; color: #856404; }
.badge-cobrado   { background: #D1FAE5; color: #065F46; }
.badge-anulado   { background: #FEE2E2; color: #991B1B; }
.badge-aprobado  { background: #DBEAFE; color: #1E40AF; }
.badge-pagado    { background: #D1FAE5; color: #065F46; }
.badge-rechazado { background: #FEE2E2; color: #991B1B; }
.badge-abierta   { background: #FEF3C7; color: #92400E; }
.badge-cerrada   { background: #E5E7EB; color: #6B7280; }
.badge-nueva     { background: #EDE9FE; color: #5B21B6; }
.badge-en_revision { background: #DBEAFE; color: #1E40AF; }
.badge-gestionada  { background: #D1FAE5; color: #065F46; }

.prioridad-Alta   { border-left: 4px solid #EF4444; }
.prioridad-Media  { border-left: 4px solid #F59E0B; }
.prioridad-Baja   { border-left: 4px solid #10B981; }

/* ─── Formularios ───────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 0.82rem;
  font-weight: 600; color: var(--gris);
  margin-bottom: 5px; text-transform: uppercase; letter-spacing: 0.04em;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gris-claro);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
  color: var(--texto);
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--azul);
}
.form-group textarea { resize: vertical; min-height: 80px; }

/* Autocomplete */
.autocomplete-list {
  background: #fff;
  border: 1.5px solid var(--gris-claro);
  border-top: none;
  border-radius: 0 0 10px 10px;
  max-height: 160px; overflow-y: auto;
  display: none;
  z-index: 500;
}
.autocomplete-list.open { display: block; }
.autocomplete-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.9rem;
}
.autocomplete-item:hover { background: var(--fondo); }

/* ─── Botones ───────────────────────────────────────────────── */
.btn {
  padding: 13px 20px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
  width: 100%;
}
.btn:active { transform: scale(0.98); opacity: 0.85; }
.btn-primary { background: var(--azul); color: #fff; }
.btn-success { background: #10B981; color: #fff; }
.btn-danger  { background: #EF4444; color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--azul);
  color: var(--azul);
}
.btn-sm {
  padding: 7px 14px;
  font-size: 0.82rem;
  width: auto;
  border-radius: 8px;
}
.btn-wa {
  background: #25D366; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

/* ─── Modal / Bottom Sheet ──────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(22,35,74,0.5);
  z-index: 400;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 20px 20px 0 0;
  width: 100%; max-width: 540px;
  padding: 20px 20px 36px;
  max-height: 92vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp {
  from { transform: translateY(100px); opacity: 0; }
  to   { transform: translateY(0);     opacity: 1; }
}
.modal-handle {
  width: 40px; height: 4px;
  background: var(--gris-claro);
  border-radius: 2px;
  margin: 0 auto 18px;
}
.modal-title {
  font-size: 1.1rem; font-weight: 800;
  margin-bottom: 18px; color: var(--navy);
}

/* ─── Toast ─────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--navy); color: #fff;
  padding: 12px 22px; border-radius: 24px;
  font-size: 0.9rem; font-weight: 600;
  z-index: 9999;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
  white-space: nowrap;
  box-shadow: var(--sombra);
}
#toast.show { opacity: 1; }

/* ─── Login ─────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 32px 24px;
  background: linear-gradient(160deg, #1C2B3A 0%, var(--azul) 100%);
}
.login-logo {
  margin-bottom: 32px;
  text-align: center;
}
.login-logo h1 { color: #fff; font-size: 1.5rem; font-weight: 800; }
.login-logo p  { color: rgba(255,255,255,0.7); font-size: 0.88rem; margin-top: 4px; }
.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%; max-width: 380px;
  box-shadow: 0 8px 40px rgba(57,84,119,0.25);
}
.login-card h2 { font-size: 1.15rem; font-weight: 800; color: var(--navy); margin-bottom: 20px; }
.error-msg {
  background: #FEE2E2; color: #991B1B;
  border-radius: 8px; padding: 10px 12px;
  font-size: 0.85rem; margin-bottom: 12px; display: none;
}
.error-msg.show { display: block; }

/* ─── Feed / Evento items ───────────────────────────────────── */
.evento-item {
  display: flex; gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gris-claro);
}
.evento-item:last-child { border-bottom: none; }
.evento-icon {
  width: 38px; height: 38px; border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.evento-icon.cobro    { background: #D6E9F8; }
.evento-icon.pago     { background: #E2F5C8; }
.evento-icon.alerta   { background: #FEF3C7; }
.evento-icon.solicitud{ background: #D6F5F3; }
.evento-body { flex: 1; min-width: 0; }
.evento-resumen { font-weight: 600; font-size: 0.9rem; }
.evento-tiempo { color: var(--gris); font-size: 0.76rem; margin-top: 2px; }

/* ─── Resumen / Indicadores ─────────────────────────────────── */
.kpi-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  margin-bottom: 16px;
}
.kpi-card {
  background: #fff; border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 16px;
  text-align: center;
}
.kpi-valor { font-size: 1.6rem; font-weight: 800; color: var(--azul); }
.kpi-label { font-size: 0.75rem; color: var(--gris); margin-top: 2px; }

/* ─── Empty / loading states ────────────────────────────────── */
.empty-state {
  text-align: center; padding: 48px 16px; color: var(--gris);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-state p { font-size: 0.9rem; }

.loading-state {
  text-align: center; padding: 32px 16px; color: var(--gris);
}

/* ─── Detail view ───────────────────────────────────────────── */
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

/* ─── Filtros ───────────────────────────────────────────────── */
.filtros {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 8px; margin-bottom: 4px;
  scrollbar-width: none;
}
.filtro-btn {
  background: var(--blanco);
  border: 1.5px solid var(--gris-claro);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.82rem; font-weight: 600;
  cursor: pointer; white-space: nowrap; color: var(--gris);
  transition: all 0.15s;
}
.filtro-btn.active {
  background: var(--azul); border-color: var(--azul); color: #fff;
}

/* ─── Install banner ────────────────────────────────────────── */
#install-banner {
  display: none;
  position: fixed; bottom: 72px; left: 12px; right: 12px;
  background: var(--navy); color: #fff;
  border-radius: 14px; padding: 14px 16px;
  z-index: 350;
  box-shadow: var(--sombra);
}
#install-banner.show { display: flex; align-items: center; gap: 12px; }
#install-banner p { flex: 1; font-size: 0.85rem; }
#install-banner button { background: var(--verde); color: #fff; border: none; border-radius: 8px; padding: 8px 14px; font-weight: 700; cursor: pointer; font-size: 0.85rem; }

/* ─── Historial estados ─────────────────────────────────────── */
.historial { font-size: 0.78rem; color: var(--gris); margin-top: 10px; }
.historial li { margin-bottom: 2px; }

/* ─── Sección título ────────────────────────────────────────── */
.section-title {
  font-size: 0.78rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--gris);
  margin: 16px 0 8px;
}

/* ─── Separadores de fecha en feed ─────────────────────────── */
.fecha-sep {
  text-align: center; font-size: 0.76rem; color: var(--gris);
  margin: 10px 0; position: relative;
}
.fecha-sep::before {
  content: ''; position: absolute;
  left: 0; right: 0; top: 50%;
  height: 1px; background: var(--gris-claro);
  z-index: 0;
}
.fecha-sep span {
  background: var(--fondo); padding: 0 10px; position: relative; z-index: 1;
}

/* ─── Comentarios ───────────────────────────────────────────── */
.comentario {
  background: var(--fondo); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 8px;
}
.comentario .autor { font-weight: 700; font-size: 0.8rem; color: var(--azul); }
.comentario .texto { font-size: 0.88rem; margin-top: 3px; }
.comentario .tiempo { font-size: 0.74rem; color: var(--gris); margin-top: 3px; }

/* ─── Tablet/desktop ajuste ─────────────────────────────────── */
@media (min-width: 540px) {
  .screen { max-width: 540px; margin: 0 auto; }
  .navbar { max-width: 540px; left: 50%; transform: translateX(-50%); }
  .fab { right: calc(50% - 270px + 18px); }
  .fab-menu { right: calc(50% - 270px + 18px); }
}
