/* =====================================================================
   SONET · Bitácora de Clientes — estilos
   Portado del design system aprobado en reference/bitacora-clientes-sonet.html.
   Paleta y componentes iguales; se quitan los que dependían de PIN/CSV
   (pin-input, sync-zone, export-card) y se agregan los de magic link y
   envío a Zoho vía Edge Function.
   ===================================================================== */

:root {
  --sonet-1: #4ba3db;
  --sonet-2: #2176bc;
  --sonet-3: #1a67ac;
  --sonet-4: #153f72;
  --sonet-5: #0f4a67;

  --ink: #153f72;
  --ink-soft: #5b7290;
  --paper: #F2F6FA;
  --surface: #FFFFFF;
  --line: #D9E3EF;
  --brand: #2176bc;
  --brand-ink: #153f72;
  --brand-soft: #E6F1FA;
  --ok: #1F9D55;
  --ok-soft: #E4F6EB;
  --warn: #D98C0F;
  --warn-soft: #FBEDD8;
  --bad: #D64545;
  --bad-soft: #FBE7E7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(21,63,114,0.06), 0 10px 26px -14px rgba(21,63,114,0.30);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

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

body {
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

.loading-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--ink-soft);
  text-align: center;
  padding: 0 24px;
}

.spinner {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--sonet-2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: linear-gradient(120deg, var(--sonet-4) 0%, var(--sonet-3) 55%, var(--sonet-2) 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar.brand {
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  display: block;
}
.brand-band {
  padding: max(26px, calc(env(safe-area-inset-top) + 12px)) 20px 22px;
  text-align: center;
}
.brand-logo { width: 190px; max-width: 62%; height: auto; display: block; margin: 0 auto; }
.brand-rule { height: 4px; background: linear-gradient(90deg, var(--sonet-4), var(--sonet-3), var(--sonet-2), var(--sonet-1)); }
.brand-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 10px; letter-spacing: .06em; text-transform: uppercase; font-weight: 600; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-title strong { font-size: 16px; }
.topbar-title span { font-size: 12px; color: rgba(255,255,255,0.80); }
.icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-btn:active { background: rgba(255,255,255,0.30); }

.progress-rail { height: 5px; background: var(--sonet-4); }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--sonet-1), #7fc3ea); transition: width 0.4s ease; }

/* ---------- screen ---------- */
.screen { flex: 1; padding: 18px 16px 32px; }

.q { font-size: 22px; margin: 4px 0 4px; letter-spacing: -0.01em; }
.hint { color: var(--ink-soft); font-size: 14px; margin: 0 0 18px; }

.email-input {
  font-size: 17px;
  padding: 15px 14px;
  margin-bottom: 6px;
}

.center-screen {
  min-height: calc(100vh - 64px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 32px 24px;
}
.center-screen .big-icon { font-size: 40px; margin-bottom: 4px; }
.center-screen h1 { font-size: 19px; margin: 0; }
.center-screen p { color: var(--ink-soft); font-size: 14.5px; margin: 0; line-height: 1.5; }

/* ---------- search / list ---------- */
.search {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  margin-bottom: 14px;
}

.client-list { display: flex; flex-direction: column; gap: 8px; }
.client-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
}
.client-row:active { background: var(--brand-soft); }
.client-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.client-name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.client-sub { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.chev { color: var(--ink-soft); font-size: 18px; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

.chip {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 7px;
  border-radius: 999px;
  flex-shrink: 0;
}
.chip-edit { background: var(--warn-soft); color: var(--warn); }
.chip-new { background: var(--brand-soft); color: var(--brand); }
.chip-exported { background: var(--line); color: var(--ink-soft); }
.chip-inactive { background: var(--bad-soft); color: var(--bad); }
.chip-done { background: var(--ok-soft); color: var(--ok); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-dept { background: var(--brand-soft); color: var(--brand); }

.mt { margin-top: 10px; }

/* --- bloques de contacto (acordeón) --- */
.block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  margin-bottom: 10px;
  overflow: hidden;
}
.block.open { border-color: var(--sonet-1); box-shadow: var(--shadow); }
.block.block-err { border-color: var(--bad); }
.block-head {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 13px 14px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
}
.block-head:active { background: var(--brand-soft); }
.block-icon {
  width: 24px; height: 24px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  background: var(--warn-soft); color: var(--warn);
}
.block-icon.ok { background: var(--ok-soft); color: var(--ok); }
/* bloque opcional sin tocar: ni listo ni pendiente — no debe alarmar */
.block-icon.neutro { background: var(--line); color: var(--ink-soft); }
.block-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.block-title { font-size: 14.5px; font-weight: 700; color: var(--ink); }
.block-sub { font-size: 12px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.block-chev { color: var(--ink-soft); font-size: 14px; flex-shrink: 0; }
.block-body { padding: 4px 14px 16px; border-top: 1px solid var(--line); }
.block-body .form-fields, .block-body .field { margin-top: 14px; }

/* --- validación --- */
.input.err { border-color: var(--bad); background: var(--bad-soft); }
.field.has-error .field-label { color: var(--bad); }
.field-error { font-size: 11.5px; color: var(--bad); margin: 5px 0 0; font-weight: 600; }
.opt { font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--ink-soft); opacity: .8; }
.error-text.center, .fineprint.center { text-align: center; }

textarea.input { resize: vertical; min-height: 60px; font-family: var(--sans); line-height: 1.4; }

.sub-title { font-size: 13px; font-weight: 700; color: var(--ink); margin: 18px 0 8px; }

.legend {
  background: var(--brand-soft);
  border-left: 3px solid var(--brand);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 11px 13px;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--brand-ink);
  margin-bottom: 12px;
}
.alert {
  background: var(--bad-soft);
  border-left: 3px solid var(--bad);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 13px;
  font-size: 12.5px;
  color: var(--bad);
  margin-bottom: 12px;
  font-weight: 600;
}

.save-zone { margin-top: 26px; padding-top: 18px; border-top: 2px solid var(--line); }
.btn-lg { padding: 16px 18px; font-size: 16px; }

/* --- envío a Zoho (admin) --- */
.send-zone {
  margin: 8px 0 4px;
  padding: 12px 13px;
  background: var(--brand-soft);
  border-radius: var(--radius);
  border: 1px dashed var(--sonet-1);
}
.batch-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  margin-bottom: 8px;
  cursor: pointer;
}
.batch-row input { width: 19px; height: 19px; margin-top: 2px; flex-shrink: 0; }

/* --- vista verificar (admin) --- */
.verify-list { display: flex; flex-direction: column; gap: 8px; }
.verify-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}
.verify-row:active { background: var(--brand-soft); }
.toggle {
  flex-shrink: 0;
  /* ancho fijo: "Marcar" y "Quitar" no miden lo mismo, y al ir alineados a la
     derecha el borde izquierdo bailaba de fila en fila */
  min-width: 76px;
  text-align: center;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.toggle.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.hint.small, .empty.small { font-size: 12.5px; margin-bottom: 10px; padding: 12px 0; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.tab {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }

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

/* ---------- client form ---------- */
.ref-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}
.ref-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; font-size: 13px; }
.ref-row span { color: var(--ink-soft); }
.ref-row strong { text-align: right; font-weight: 600; }

.form-fields { display: flex; flex-direction: column; gap: 14px; margin-bottom: 20px; }
.field-label { display: block; font-size: 12.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); margin-bottom: 6px; }
.field-hint { font-size: 12px; color: var(--warn); margin: 5px 0 0; }

.input {
  width: 100%;
  padding: 12px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 15px;
  color: var(--ink);
  font-family: var(--sans);
}
select.input { font-family: var(--sans); }

.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkbox-row input { width: 20px; height: 20px; }

/* ---------- buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-ink); }
.btn-ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--bad); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- exit overlay ---------- */
.exit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20,35,43,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}
.exit-card {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  border-radius: 18px 18px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}
.exit-card p { margin: 0 0 14px; font-size: 14.5px; }
.exit-actions { display: flex; flex-direction: column; gap: 8px; }

.btn-text { background: none; border: none; color: var(--ink-soft); font-size: 13px; text-decoration: underline; cursor: pointer; }

/* ---------- admin ---------- */
.error-text { color: var(--bad); font-size: 13px; margin: -8px 0 12px; }
.fineprint { font-size: 11.5px; color: var(--ink-soft); margin-top: 8px; line-height: 1.5; }

.stat-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-card.ok { background: var(--ok-soft); border-color: transparent; }
.stat-card.bad { background: var(--bad-soft); border-color: transparent; }
.stat-num { font-size: 24px; font-weight: 800; font-family: var(--mono); }
.stat-label { font-size: 12px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }

.section-title { font-size: 14px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); margin: 22px 0 10px; }

.vendor-stats { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.vendor-stat-row { display: flex; align-items: center; gap: 10px; }
.vendor-stat-name { width: 110px; flex-shrink: 0; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vendor-stat-bar { flex: 1; height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.vendor-stat-fill { height: 100%; background: linear-gradient(90deg, var(--sonet-3), var(--sonet-1)); }
.vendor-stat-num { width: 52px; text-align: right; font-family: var(--mono); font-size: 12.5px; color: var(--ink-soft); }

.pending-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.pending-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.pending-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
.pending-meta { font-size: 12px; color: var(--ink-soft); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  background: var(--sonet-4);
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 40;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--bad); }

@media (min-width: 640px) {
  body { background: #DCE7F2; }
  #app { margin: 24px auto; min-height: calc(100vh - 48px); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow); }
}

/* --- barra "Copiar datos de" --- */
.copy-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 9px 11px;
  background: var(--brand-soft);
  border-radius: var(--radius-sm);
  border: 1px dashed var(--sonet-1);
}
.copy-label {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--sonet-5);
  flex-shrink: 0;
}
.copy-select {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  background: var(--surface);
  border-color: var(--sonet-1);
  min-width: 0;
}


.client-sub.sub-bad { color: var(--bad); font-weight: 600; }
.client-sub.sub-ok  { color: var(--ok); font-weight: 600; }
.toggle.locked { opacity: .55; }

/* La fila de la cola de envio pasa de <label> a <div> para poder llevar el
   boton "Quitar" fuera del label (dentro, alternaria la casilla). */
.batch-main { display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.batch-row.incompleto { border-color: var(--bad); background: var(--bad-soft); }
.btn-quitar {
  flex-shrink: 0; align-self: center; min-width: 76px; text-align: center;
  border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-soft); border-radius: 8px;
  padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-quitar:hover { border-color: var(--bad); color: var(--bad); }

/* Contador dentro de las pestañas del panel. Fondo translucido para que se lea
   igual sobre el blanco de la pestaña inactiva y sobre el azul de la activa. */
.tab-n {
  background: rgba(0, 0, 0, .08); color: inherit;
  border-radius: 999px; padding: 1px 7px;
  font-size: 11.5px; font-weight: 700; line-height: 1.6;
}
.tab.active .tab-n { background: rgba(255, 255, 255, .26); }
