:root {
  --bg: #14161A;
  --surface: #1B1E24;
  --surface-hi: #22262D;
  --border: #2A2E36;
  --border-soft: #22252B;
  --text: #EDEEF1;
  --text-dim: #9297A1;
  --text-faint: #7B8290;
  --teal: #2FD9AC;
  --red: #F2545B;
  --amber: #FFB020;
  --violet: #A78BFA;
  --blue: #4C8CFF;
  --gray: #6B7280;

  /* Tonos suaves/intensos usados por theme.js */
  --green-muted: #3FBF87;
  --orange: #FF8A3D;
  --graphite: #454B56;   /* el "negro" de los chips: negro puro no se lee sobre fondo oscuro */
  --red-bright: #FF4D57;
  --red-muted: #C2565C;
  --yellow-muted: #E0A83C;

  /* Intensidad del tinte de fila (theme.js las sobrescribe) */
  --row-tint-alpha: 10%;
  --row-tint-alpha-hover: 18%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
}

::placeholder { color: var(--text-faint); }

.wrap { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }

.eyebrow {
  font-size: 11.5px; font-weight: 700; letter-spacing: 1.5px;
  color: var(--text-faint); text-transform: uppercase; margin-bottom: 6px;
}

h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 26px; font-weight: 600; margin: 0;
}

.topbar {
  display: flex; flex-wrap: wrap; gap: 16px;
   justify-content: space-between;
  margin-bottom: 22px;
}
.topbar-actions { display: flex; align-items: center; gap: 12px; }

.total-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 16px; text-align: center;
}
.total-count {
  font-family: 'JetBrains Mono', monospace; font-size: 22px;
  font-weight: 600; line-height: 1; color: var(--teal);
}
.total-label {
  font-size: 10px; letter-spacing: 1px; color: var(--text-faint);
  text-transform: uppercase; margin-top: 3px;
}

.btn {
  padding: 12px 18px; border-radius: 10px; border: none;
  font-weight: 700; font-size: 14px; cursor: pointer; font-family: inherit;
}
.btn-primary { background: var(--teal); color: #0A0B0D; }
.btn-ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--border); font-weight: 600; padding: 10px 14px; font-size: 13px; }
.btn-ghost:hover { color: var(--text); border-color: var(--border-soft); background: var(--surface-hi); }

.error-banner {
  margin-bottom: 16px; padding: 10px 14px; border-radius: 9px;
  background: rgba(242,84,91,.08); border: 1px solid rgba(242,84,91,.3);
  color: var(--red); font-size: 13px;
}

.chip-group { margin-bottom: 12px; }
.chip-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 0;
}
.chip {
  flex: 0 0 auto; display: flex; align-items: center; gap: 7px;
  padding: 7px 13px; border-radius: 99px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); white-space: nowrap; font-family: inherit;
}
.chip .count { opacity: .6; font-family: 'JetBrains Mono', monospace; font-size: 11.5px; }
.dot { width: 7px; height: 7px; border-radius: 99px; display: inline-block; flex: 0 0 auto; }

.search-row { display: flex; gap: 10px; margin-bottom: 18px; align-items: center; }
.input {
  width: 100%; max-width: 420px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; color: var(--text); font-size: 14px;
  font-family: inherit; outline: none;
}
.input:focus { border-color: var(--teal); }

.loading, .empty { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty { border: 1px dashed var(--border); border-radius: 14px; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-sub { font-size: 13.5px; margin-bottom: 18px; }

.table-wrap { overflow-x: hidden; border: 1px solid var(--border); border-radius: 14px; cursor: grab; }
.table-wrap.dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.table-wrap.dragging tbody tr:hover { background: transparent; }
table { border-collapse: collapse; width: 100%; }
thead tr { background: var(--surface); }
th {
  text-align: left; padding: 11px 14px; font-size: 11px; letter-spacing: .6px;
  text-transform: uppercase; color: var(--text-faint); font-weight: 700;
  border-bottom: 1px solid var(--border);
}
td { padding: 12px 14px; vertical-align: top; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-hi); }

/* Tinte "neon" por fila según el color de la calificación: apenas un
   10% del color de fondo (no pastel sólido) + una línea de acento al color
   completo sobre el borde izquierdo para que se lea bien sin saturar. */
tbody tr.row-tinted {
  background: color-mix(in srgb, var(--row-tint) var(--row-tint-alpha), transparent);
  box-shadow: inset 3px 0 0 0 var(--row-tint);
}
tbody tr.row-tinted:hover {
  background: color-mix(in srgb, var(--row-tint) var(--row-tint-alpha-hover), transparent);
}

.lead-name { font-weight: 600; font-size: 13.5px; }
.lead-name.muted { color: var(--text-faint); font-weight: 500; }
.lead-phone { font-family: 'JetBrains Mono', monospace; font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

.tags { display: flex; flex-wrap: wrap; gap: 4px; max-width: 190px; }
.tag { font-size: 11px; padding: 2px 7px; border-radius: 6px; background: var(--surface-hi); color: var(--text-dim); white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px 3px 7px;
  border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap;
}

.icon-btn {
  width: 30px; height: 30px; display: inline-grid; place-items: center;
  border-radius: 8px; border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); cursor: pointer; font-size: 13px;
}
.icon-btn:hover { background: var(--surface-hi); color: var(--text); border-color: var(--border-soft); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: rgba(242,84,91,.1); border-color: rgba(242,84,91,.35); }

.cards { display: none; flex-direction: column; gap: 10px; }
.card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; background: var(--surface); cursor: pointer; }
.card.row-tinted {
  background: color-mix(in srgb, var(--row-tint) var(--row-tint-alpha), var(--surface));
  box-shadow: inset 3px 0 0 0 var(--row-tint);
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; font-size: 12.5px; color: var(--text-dim); }

.footer-count { margin-top: 18px; font-size: 12px; color: var(--text-faint); text-align: center; }

/* Drawer */
.overlay { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.overlay-bg { position: absolute; inset: 0; background: rgba(10,11,13,.8); backdrop-filter: blur(2px); }
.drawer {
  position: relative; width: min(440px, 100vw); height: 100%; background: var(--surface);
  border-left: 1px solid var(--border); display: flex; flex-direction: column;
  animation: slideIn .2s ease-out;
}
@keyframes slideIn { from { transform: translateX(24px); opacity: 0 } to { transform: translateX(0); opacity: 1 } }
.drawer-head {
  padding: 20px 22px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-title { font-family: 'Space Grotesk', sans-serif; font-size: 18px; font-weight: 600; }
.drawer-sub { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }
.drawer-body { padding: 20px 22px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 16px; }
.drawer-foot { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; }

.field-label {
  font-size: 11.5px; font-weight: 600; color: var(--text-dim); letter-spacing: .3px;
  text-transform: uppercase; display: block; margin-bottom: 6px;
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
textarea, select { width: 100%; box-sizing: border-box; }
textarea { min-height: 70px; resize: vertical; line-height: 1.5; }

.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-option {
  padding: 6px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: transparent;
  color: var(--text-dim); font-family: inherit;
}
.tag-option.active { border-color: var(--teal); background: rgba(47,217,172,.12); color: var(--teal); }

.toggle-row { display: flex; gap: 6px; }
.toggle-btn {
  flex: 1; padding: 9px 0; border-radius: 9px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--text-dim);
  font-family: inherit;
}
.toggle-btn.active { border-color: var(--blue); background: rgba(76,140,255,.12); color: var(--blue); }

.btn-delete { padding: 10px 14px; border-radius: 9px; border: 1px solid rgba(242,84,91,.3); background: transparent; color: var(--red); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.btn-save { flex: 1; padding: 10px 14px; border-radius: 9px; border: none; background: var(--teal); color: #0A0B0D; font-weight: 700; font-size: 13.5px; cursor: pointer; }

/* Confirm modal */
.modal-overlay { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-box {
  position: relative; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 22px; width: min(360px, 100%);
}
.modal-title { font-weight: 600; font-size: 15.5px; margin-bottom: 6px; }
.modal-sub { font-size: 13.5px; color: var(--text-dim); margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; }
.btn-cancel { flex: 1; padding: 9px 0; border-radius: 9px; border: 1px solid var(--border); background: transparent; color: var(--text-dim); font-weight: 600; font-size: 13.5px; cursor: pointer; }
.btn-confirm-delete { flex: 1; padding: 9px 0; border-radius: 9px; border: none; background: var(--red); color: #fff; font-weight: 700; font-size: 13.5px; cursor: pointer; }

/* Configuración de opciones (catálogos editables) */
.settings-section { padding-bottom: 18px; margin-bottom: 18px; border-bottom: 1px solid var(--border-soft); }
.settings-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.option-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.option-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 10px; border-radius: 8px; background: var(--surface-hi); border: 1px solid var(--border-soft);
}
.option-row-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.option-row .icon-btn { width: 26px; height: 26px; font-size: 11px; }
.option-add-row { display: flex; gap: 8px; }
.option-add-row .input { max-width: none; }
.option-add-row .btn { white-space: nowrap; }
.field-form {
  display: flex; flex-direction: column; gap: 14px; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-hi); margin-bottom: 10px;
}

.scrollbar::-webkit-scrollbar { height: 8px; width: 8px; }
.scrollbar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ---------------- Pestañas: Tabla / Dashboard ---------------- */
.view-tabs { display: flex; gap: 6px; margin-bottom: 18px; }
.view-tab {
  padding: 8px 16px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-dim); font-weight: 600; font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.view-tab:hover { color: var(--text); border-color: var(--border-soft); }
.view-tab.active { background: var(--surface-hi); color: var(--text); border-color: var(--teal); }

/* ---------------- Dashboard de métricas ---------------- */
.dash-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.dash-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; display: flex; flex-direction: column;
}
.dash-card-wide { grid-column: span 3; }
.dash-card-head { margin-bottom: 14px; }
.dash-card-title { font-family: 'Space Grotesk', sans-serif; font-size: 14.5px; font-weight: 600; color: var(--text); }
.dash-card-sub { font-size: 12px; color: var(--text-faint); margin-top: 3px; line-height: 1.45; }
.dash-card-body { position: relative; height: 240px; }
.dash-card-wide .dash-card-body { height: 260px; }
.dash-card-empty {
  height: 100%; display: grid; place-items: center; text-align: center;
  color: var(--text-faint); font-size: 12.5px; border: 1px dashed var(--border); border-radius: 10px;
}
.dash-insight {
  margin-top: 12px; padding: 10px 12px; border-radius: 9px;
  background: var(--surface-hi); border: 1px solid var(--border-soft);
  font-size: 12.5px; color: var(--text-dim); line-height: 1.5;
}
.dash-insight strong { color: var(--text); }
.dash-insight:empty { display: none; }

.kpi-card { align-items: center; text-align: center; }
.kpi-ring-wrap { position: relative; width: 168px; height: 168px; margin: 6px auto 2px; }
.kpi-ring-wrap canvas { width: 100% !important; height: 100% !important; }
.kpi-ring-value {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-family: 'Space Grotesk', sans-serif; font-size: 30px; font-weight: 700; color: var(--teal);
}

@media (max-width: 980px) {
  .dash-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-card-wide { grid-column: span 2; }
}
@media (max-width: 640px) {
  .dash-grid { grid-template-columns: 1fr; }
  .dash-card-wide { grid-column: span 1; }
}

@media (max-width: 860px) {
  .table-wrap { display: none !important; }
  .cards { display: flex !important; }
  .field-row { grid-template-columns: 1fr; }
}
/* ---------------- Usuario logueado (topbar) ---------------- */
.user-box {
  display: flex; flex-direction: column; justify-content: center;
  padding: 4px 12px; border-left: 1px solid var(--border); line-height: 1.25;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role {
  font-size: 10px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-faint); margin-top: 1px;
}

/* ---------------- Caja: ingresos y gastos ---------------- */
.caja-kpis {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 12px; margin-bottom: 18px;
}
.caja-kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.caja-kpi-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: 6px;
}
.caja-kpi-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 20px; font-weight: 600; line-height: 1.1;
}
.caja-sub { font-size: 12px; color: var(--text-faint); margin-top: 2px; }
.caja-mes { max-width: 190px; flex: 0 0 auto; }
#view-caja .search-row { flex-wrap: wrap; }

@media (max-width: 640px) {
  .caja-kpis { grid-template-columns: 1fr; }
  .caja-mes { max-width: none; }
}

/* Caja: sub-pestañas, vínculo con clientes */
.caja-subtabs { display: flex; gap: 6px; margin-bottom: 16px; }
.caja-kpi-hint { font-size: 11px; color: var(--text-faint); margin-top: 5px; line-height: 1.4; }
.caja-hint { font-size: 11.5px; color: var(--text-faint); margin-top: 6px; line-height: 1.4; }
.caja-tag-general { background: transparent; border: 1px dashed var(--border); color: var(--text-faint); }

/* ---------------- Estados de carga ---------------- */

/* Esqueletos: mismo alto que el contenido real, así el bloque no salta
   cuando llegan los datos. */
.skeleton {
  background: linear-gradient(90deg, var(--surface-hi) 25%, var(--border) 37%, var(--surface-hi) 63%);
  background-size: 400% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
  border-radius: 6px;
}
.skeleton-line { height: 13px; width: 100%; }
.skeleton-row td { padding: 14px; }
.skeleton-row td:first-child .skeleton-line { width: 70%; }
.skeleton-row td:last-child .skeleton-line { width: 40%; margin-left: auto; }

@keyframes skeleton-shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* Aparición suave del contenido real, para que no entre de golpe. */
.fade-in { animation: fade-in .22s ease-out both; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Botones con carga: spinner + bloqueo para evitar el doble submit. */
.spinner {
  display: inline-block; width: 13px; height: 13px; margin-right: 8px;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; vertical-align: -2px;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.is-loading { cursor: progress; opacity: .85; }
button[disabled] { cursor: not-allowed; }

@media (prefers-reduced-motion: reduce) {
  .skeleton, .spinner, .fade-in { animation-duration: .01ms; animation-iteration-count: 1; }
}

/* En botones de ícono el spinner va solo, sin margen de texto. */
.icon-btn .spinner { margin-right: 0; width: 12px; height: 12px; }

/* KPI de conversión: vistas adicionales bajo el anillo principal */
.kpi-extra { width: 100%; margin-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.kpi-extra:empty { display: none; }
.kpi-extra-row { text-align: left; }
.kpi-extra-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.kpi-extra-label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.kpi-extra-pct { font-family: 'JetBrains Mono', monospace; font-size: 13px; font-weight: 600; color: var(--teal); }
.kpi-extra-bar { height: 5px; border-radius: 99px; background: var(--border); margin-top: 5px; overflow: hidden; }
.kpi-extra-bar span { display: block; height: 100%; border-radius: 99px; background: var(--teal); }
.kpi-extra-detail { font-size: 11px; color: var(--text-faint); margin-top: 4px; }