:root {
  --sidebar-bg: #17181f;
  --sidebar-text: #b7b9c6;
  --sidebar-text-active: #ffffff;
  --accent: #2563eb;
  --accent-light: #eaf0fe;
  --bg: #f4f5f8;
  --card-bg: #ffffff;
  --border: #e6e7ec;
  --text: #1f2230;
  --text-muted: #7c7f8e;
  --green-bg: #e6f7ec; --green-text: #166534;
  --red-bg: #fdeaea; --red-text: #991b1b;
  --yellow-bg: #fff6e0; --yellow-text: #92710b;
  --blue-bg: #eaf0fe; --blue-text: #1d4ed8;
  --purple-bg: #f2ebfc; --purple-text: #6d28d9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  padding: 6px 10px 22px;
}

.sidebar-brand-logo {
  display: block;
  width: 100%;
  max-width: 180px;
  filter: invert(1);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.sidebar-nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
}

.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }

.sidebar-nav a.active {
  background: rgba(255,255,255,0.1);
  color: var(--sidebar-text-active);
}

.sidebar-footer a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  font-size: 14px;
  display: block;
}

.sidebar-footer a:hover { color: #fff; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-title { font-weight: 700; font-size: 16px; }

.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar-user-name { font-weight: 600; }
.topbar-user-email { color: var(--text-muted); }

.content { padding: 28px; }

/* ---------- Card ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 20px;
}

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

.card-header h2 { margin: 0; font-size: 16px; }

.card-header-actions { display: flex; align-items: center; gap: 10px; }

.search-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  width: 240px;
}
.search-input:focus { outline: none; border-color: var(--accent); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }

.btn-secondary { background: #f1f2f6; color: var(--text); }
.btn-secondary:hover { background: #e6e7ec; }

.btn-danger { background: var(--red-text); color: #fff; }
.btn-danger:hover { background: #7f1d1d; }

.btn-green { background: var(--green-bg); color: var(--green-text); }
.btn-green:hover { filter: brightness(0.96); }

.btn-blue { background: var(--blue-bg); color: var(--blue-text); }
.btn-blue:hover { filter: brightness(0.96); }

.btn-purple { background: var(--purple-bg); color: var(--purple-text); }
.btn-purple:hover { filter: brightness(0.96); }

.btn-amber { background: var(--yellow-bg); color: var(--yellow-text); }
.btn-amber:hover { filter: brightness(0.96); }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  padding: 4px 8px;
}
.btn-icon:hover { color: var(--text); }

.row-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: none;
  border-radius: 999px;
  padding: 5px 11px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: filter .15s;
}
.pill-btn:hover { filter: brightness(0.95); }
.pill-btn svg { width: 13px; height: 13px; flex-shrink: 0; }

.pill-btn-blue { background: var(--blue-bg); color: var(--blue-text); }
.pill-btn-green { background: var(--green-bg); color: var(--green-text); }
.pill-btn-amber { background: var(--yellow-bg); color: var(--yellow-text); }

/* ---------- Action button (círculo con ícono superpuesto sobre pill de color suave) ---------- */
.action-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  border: none;
  border-radius: 999px;
  height: 34px;
  padding: 0 16px 0 32px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.action-btn:hover { filter: brightness(0.97); }
.action-btn .action-btn-icon {
  position: absolute;
  left: -6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.action-btn .action-btn-icon svg { width: 14px; height: 14px; }

.action-btn-green { background: var(--green-bg); color: var(--green-text); }
.action-btn-green .action-btn-icon svg { color: var(--green-text); }
.action-btn-blue { background: var(--blue-bg); color: var(--blue-text); }
.action-btn-blue .action-btn-icon svg { color: var(--blue-text); }
.action-btn-purple { background: var(--purple-bg); color: var(--purple-text); }
.action-btn-purple .action-btn-icon svg { color: var(--purple-text); }
.action-btn-red { background: var(--red-bg); color: var(--red-text); }
.action-btn-red .action-btn-icon svg { color: var(--red-text); }

/* ---------- Chip select (selector de cuota estilo "skills") ---------- */
.chip-select { position: relative; }
.chip-select-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
}
.chip-select.open .chip-select-field { border-color: var(--accent); }
.chip-select-empty { color: var(--text-muted); }
.chip-select-caret { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; transition: transform .15s; }
.chip-select.open .chip-select-caret { transform: rotate(180deg); }

.chip-select-tag {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--accent);
  border-radius: 14px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  max-width: 100%;
  line-height: 1.4;
}

.chip-select-panel {
  display: none;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 30;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border);
  box-shadow: 0 10px 30px rgba(15,16,22,0.12);
  max-height: 240px;
  overflow-y: auto;
}
.chip-select.open .chip-select-panel { display: block; }

.chip-select-option {
  padding: 12px 16px;
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.chip-select-option:last-child { border-bottom: none; }
.chip-select-option:hover { background: var(--bg); }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .02em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

td { padding: 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-activo { background: var(--green-bg); color: var(--green-text); }
.badge-inactivo { background: var(--red-bg); color: var(--red-text); }
.badge-vencido, .badge-vencida { background: var(--yellow-bg); color: var(--yellow-text); }
.badge-pendiente { background: var(--yellow-bg); color: var(--yellow-text); }
.badge-pagada, .badge-exitoso { background: var(--green-bg); color: var(--green-text); }
.badge-rechazado { background: var(--red-bg); color: var(--red-text); }
.badge-rol-administrador { background: var(--blue-bg); color: var(--blue-text); }
.badge-rol-usuario, .badge-rol-cliente { background: #f1f2f6; color: var(--text-muted); }

/* ---------- Stat cards (dashboard) ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}

.stat-card .label { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,16,22,0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.open { display: flex; }

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 380px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
}

.modal h3 { margin: 0 0 16px; font-size: 16px; }

.modal-lg { width: 640px; }

.form-field { margin-bottom: 14px; }
.form-field label { display: block; font-size: 13px; margin-bottom: 5px; color: #444; }
.form-field input, .form-field select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 16px;
}

.form-grid .form-field.full,
.form-grid .modal-actions {
  grid-column: 1 / -1;
}

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Lightbox de fotos ---------- */
.lightbox-modal {
  position: relative;
  width: auto;
  max-width: 90vw;
  background: #14151c;
  padding: 16px;
}
.lightbox-body { position: relative; display: flex; align-items: center; justify-content: center; }
.lightbox-body img { max-width: 80vw; max-height: 78vh; border-radius: 8px; display: block; }
.lightbox-close {
  position: absolute; top: 8px; right: 12px;
  background: none; border: none; color: #fff; font-size: 26px; line-height: 1; cursor: pointer;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(255,255,255,0.15); color: #fff; border: none; border-radius: 50%;
  width: 40px; height: 40px; font-size: 22px; cursor: pointer;
}
.lightbox-nav:hover { background: rgba(255,255,255,0.3); }
.lightbox-nav:disabled { opacity: 0; pointer-events: none; }
.lightbox-prev { left: 6px; }
.lightbox-next { right: 6px; }
.lightbox-counter { text-align: center; color: #cfd0da; font-size: 13px; margin-top: 10px; }

/* ---------- Credencial (ver cliente) ---------- */
.credencial { width: 340px; padding: 0; overflow: hidden; }

.credencial-header {
  background: linear-gradient(135deg, var(--sidebar-bg), #2a2c3a);
  color: #fff;
  padding: 28px 24px 20px;
  text-align: center;
  position: relative;
}

.credencial-cerrar {
  position: absolute;
  top: 10px;
  right: 12px;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
}
.credencial-cerrar:hover { background: rgba(255,255,255,0.22); }

.credencial-foto {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(255,255,255,0.85);
  background: #fff;
  margin-bottom: 12px;
}

.credencial-foto-placeholder {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.85);
  background: rgba(255,255,255,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-size: 30px;
  font-weight: 700;
}

.credencial-header h3 { margin: 0 0 8px; font-size: 17px; }

.credencial-body { padding: 20px 24px 24px; }

.credencial-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.credencial-row:last-child { border-bottom: none; }

.credencial-row svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-muted); }

.credencial-row .valor { color: var(--text); font-weight: 500; word-break: break-word; }
.credencial-row .valor-vacio { color: var(--text-muted); font-weight: 400; font-style: italic; }

/* ---------- Login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.login-box {
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--border);
  padding: 36px 32px;
  width: 340px;
}

.login-logo { display: block; width: 100%; max-width: 260px; margin: 0 auto 18px; }

.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box p.subtitle { font-size: 13px; color: var(--text-muted); margin: 0 0 22px; }

.login-box .btn-primary { width: 100%; margin-top: 6px; }

/* ---------- Alerts / empty state ---------- */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--red-bg); color: var(--red-text); }
.alert-success { background: var(--green-bg); color: var(--green-text); }

.empty-state { padding: 30px; text-align: center; color: var(--text-muted); font-size: 14px; }

/* ---------- Impresión (cotizador y similares) ---------- */
.only-print { display: none; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .app-shell, .app-main { display: block; width: 100%; }
  .content { padding: 0; }
  body { background: #fff; }
  .card { border: none; padding: 0; margin-bottom: 18px; }
  .only-print { display: block; }
}

/* ---------- Diálogos de estado (éxito / error / confirmación) ---------- */
.modal.dialogo {
  width: 360px;
  text-align: center;
  padding: 44px 26px 26px;
  position: relative;
  overflow: visible;
}

.dialogo-icono {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: -36px;
  left: 50%;
  transform: translateX(-50%);
  box-shadow: 0 6px 16px rgba(15,16,22,0.18);
}
.dialogo-icono svg { width: 34px; height: 34px; }

.dialogo-icono-exito { background: #16a34a; color: #fff; }
.dialogo-icono-error { background: #ef4444; color: #fff; }

.dialogo-titulo { font-size: 19px; font-weight: 700; margin: 6px 0 10px; }
.dialogo-mensaje { font-size: 14px; color: var(--text-muted); margin: 0 0 20px; line-height: 1.5; }
.dialogo-divisor { border-top: 1px solid var(--border); margin: 0 -26px 18px; }
.dialogo-acciones { display: flex; justify-content: center; gap: 10px; }
.dialogo-acciones .btn { min-width: 96px; }
