/* ═══════════════════════════════════════════════════════════════════════
   KAPOZ CRM — Estilos
   Sistema de marca real de kapoz.ai:
   · Tokens oscuro (default) y claro vía html[data-theme]
   · theme.js controla auto/claro/oscuro (auto: claro 6am–6pm)
   · Plus Jakarta Sans + JetBrains Mono · gradiente firma · backdrop
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Tokens: modo OSCURO (default) ───────────────────────────────────── */
:root {
  --bg-0: #050208;
  --bg-1: #0a0612;
  --surface: #120a1f;
  --surface-2: #1a0e2e;
  --surface-3: #221836;
  --line: #2a1f40;
  --line-2: #3d2e58;
  --ink: #ffffff;
  --ink-2: #cdc4dc;
  --ink-3: #8a82a0;
  --ink-4: #5a5170;

  --grad: linear-gradient(96deg,#ffc107 0%,#ffb800 18%,#ff8a1a 36%,#ff5a3d 52%,#ff3d7a 68%,#d62cb8 82%,#7a3dc8 100%);
  --accent: #ff6b1a;
  --accent-deep: #e85a10;
  --accent-soft: rgba(255,107,26,.14);
  --good: #1ec57b;
  --warn: #ffb800;
  --bad: #ff3d7a;

  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,.35);
  --shadow-lg: 0 14px 44px rgba(0,0,0,.5);
  --overlay: rgba(5,2,8,.6);

  /* Badges de estado (versión oscuro: fondo translúcido + texto claro) */
  --b-nuevo-bg: rgba(96,165,250,.18);   --b-nuevo-fg: #93c5fd;
  --b-contact-bg: rgba(34,211,238,.16); --b-contact-fg: #67e8f9;
  --b-interes-bg: rgba(255,184,0,.16);  --b-interes-fg: #ffd166;
  --b-negoc-bg: rgba(167,139,250,.18);  --b-negoc-fg: #c4b5fd;
  --b-cliente-bg: rgba(30,197,123,.16); --b-cliente-fg: #4ade9b;
  --b-descart-bg: rgba(138,130,160,.16);--b-descart-fg: #a8a2b8;
  --b-alta-bg: var(--accent);           --b-alta-fg: #0a0612;
  --b-media-bg: rgba(255,184,0,.16);    --b-media-fg: #ffd166;
  --b-baja-bg: rgba(138,130,160,.14);   --b-baja-fg: #8a82a0;
}

/* ── Tokens: modo CLARO ──────────────────────────────────────────────── */
html[data-theme="light"] {
  --bg-0: #f7f1e9;
  --bg-1: #fbf6ef;
  --surface: #ffffff;
  --surface-2: #fbf5ee;
  --surface-3: #f1e9de;
  --line: #ece1d4;
  --line-2: #ddd0bf;
  --ink: #1d1622;
  --ink-2: #57505d;
  --ink-3: #8c8490;
  --ink-4: #b4abb7;

  --accent-soft: rgba(255,107,26,.10);
  --shadow: 0 1px 4px rgba(29,22,34,.07), 0 6px 18px rgba(29,22,34,.06);
  --shadow-lg: 0 12px 40px rgba(29,22,34,.16);
  --overlay: rgba(29,22,34,.4);

  --b-nuevo-bg: #dbeafe;   --b-nuevo-fg: #1d4ed8;
  --b-contact-bg: #cffafe; --b-contact-fg: #0e7490;
  --b-interes-bg: #fef3c7; --b-interes-fg: #b45309;
  --b-negoc-bg: #ede9fe;   --b-negoc-fg: #6d28d9;
  --b-cliente-bg: #d1fae5; --b-cliente-fg: #047857;
  --b-descart-bg: #f0eae2; --b-descart-fg: #78716c;
  --b-alta-bg: var(--accent); --b-alta-fg: #ffffff;
  --b-media-bg: #fef3c7;   --b-media-fg: #b45309;
  --b-baja-bg: #f0eae2;    --b-baja-fg: #78716c;
}

/* Durante el swap de tema, sin transiciones (theme.js pone la clase) */
html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after {
  transition: none !important;
}

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

/* El atributo [hidden] debe ganar SIEMPRE: sin esto, un `display` de clase
   (p. ej. .modal-overlay{display:grid}) anula al `hidden` y el overlay se
   muestra vacío tapando la pantalla. Aplica a #sheet/#modalOverlay/#importFile. */
[hidden] { display: none !important; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--ink);
  font-size: 14px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .25s, color .25s;
  position: relative;
}

/* Fondo oscuro: backdrop cálido de marca (mismo asset que la web) */
body::after {
  content: '';
  position: fixed; inset: 0; z-index: -1;
  background: url('backdrop.png') center / cover fixed no-repeat;
  opacity: .55;
  pointer-events: none;
  transition: opacity .25s;
}
/* Fondo claro: radiales crema cálidos (recipe de la web) */
html[data-theme="light"] body {
  background:
    radial-gradient(115% 90% at 86% 6%, #ffe7d3 0%, transparent 55%),
    radial-gradient(95% 85% at 6% 102%, #ffe1ec 0%, transparent 55%),
    linear-gradient(158deg, #f9f3ec, #f4ece2);
}
html[data-theme="light"] body::after { opacity: 0; }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; color: var(--ink); }
a { color: inherit; }

.mono { font-family: 'JetBrains Mono', monospace; }

/* ── Botones ─────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; border-radius: 11px;
  padding: 9px 16px; font-size: 13px; font-weight: 700;
  letter-spacing: -.01em;
  transition: background .15s, transform .1s, box-shadow .15s, border-color .15s, color .15s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 14px rgba(255,107,26,.35); }
.btn-primary:hover { background: var(--accent-deep); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-grad { background: var(--grad); color: #fff; box-shadow: 0 3px 16px rgba(255,90,61,.35); }
.btn-grad:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--surface); color: var(--ink-2); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: rgba(255,61,122,.12); color: var(--bad); border: 1px solid rgba(255,61,122,.3); }
.btn-danger:hover { background: rgba(255,61,122,.2); }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Toggle de tema (réplica del .k-theme-toggle de la web) ──────────── */
.k-theme-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 99px;
  color: var(--ink-2);
  font-family: 'JetBrains Mono', monospace; font-size: 10px; letter-spacing: .08em;
  transition: border-color .15s, color .15s;
}
.k-theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
.k-theme-icon { display: inline-flex; }
.k-theme-icon svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

/* ── Wordmark / marca ────────────────────────────────────────────────── */
.kw {
  background: var(--grad);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  font-weight: 800; letter-spacing: -.025em;
}
.logoimg { width: 34px; height: 34px; object-fit: contain; }

/* ── Login ───────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow-lg); padding: 42px 36px; width: 100%; max-width: 390px;
  display: flex; flex-direction: column; gap: 14px; text-align: center;
  backdrop-filter: blur(20px) saturate(140%);
}
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; }
.login-brand .kw { font-size: 34px; }
.login-sub { color: var(--ink-3); font-size: 13px; margin-bottom: 8px; }
.login-card input {
  border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px;
  background: var(--bg-1); text-align: center; color: var(--ink);
}
html[data-theme="light"] .login-card input { background: var(--surface-2); }
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-error { color: var(--bad); font-size: 12.5px; min-height: 16px; }
.login-theme { position: fixed; top: 18px; right: 18px; }

/* ── Topbar (pastilla flotante con blur, como .k-header) ─────────────── */
.topbar { position: sticky; top: 12px; z-index: 40; padding: 0 16px; }
.topbar-inner {
  max-width: 1600px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--line); border-radius: 18px;
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: -.025em; line-height: 1.1; }
.brand-title .kw { font-size: 17px; }
.brand-sub { font-size: 11px; color: var(--ink-3); }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── Main ────────────────────────────────────────────────────────────── */
.main { max-width: 1600px; margin: 0 auto; padding: 22px 16px 40px; display: flex; flex-direction: column; gap: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; display: flex; align-items: center; gap: 14px; box-shadow: var(--shadow);
}
.stat-icon { font-size: 18px; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--accent-soft); }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1; font-family: 'JetBrains Mono', monospace; letter-spacing: -.02em; }
.stat-label { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }

/* Toggle de vistas */
.view-toggle { display: inline-flex; gap: 2px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; width: fit-content; }
.view-btn {
  border: none; background: transparent; padding: 7px 16px; border-radius: 9px;
  font-size: 13px; font-weight: 700; color: var(--ink-3); transition: all .15s;
}
.view-btn:hover { color: var(--ink-2); }
.view-btn.active { background: var(--accent-soft); color: var(--accent); }

/* ── Kanban ──────────────────────────────────────────────────────────── */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kb-col { width: 280px; flex-shrink: 0; }
.kb-head {
  border-radius: 13px 13px 0 0; padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--line); border-bottom: none;
  display: flex; align-items: center; justify-content: space-between;
}
.kb-head .dot { width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; }
.kb-head-name { font-size: 13px; font-weight: 700; display: flex; align-items: center; color: var(--ink-2); }
.kb-count { font-size: 11px; color: var(--ink-3); font-family: 'JetBrains Mono', monospace; }
.kb-body {
  min-height: 130px; border: 1px solid var(--line); border-top: none;
  border-radius: 0 0 13px 13px; padding: 8px; display: flex; flex-direction: column; gap: 8px;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  transition: background .15s;
}
.kb-body.dragover { background: var(--accent-soft); }
.kb-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 13px; box-shadow: var(--shadow); cursor: grab;
  transition: box-shadow .15s, border-color .15s;
}
.kb-card:hover { border-color: var(--accent); }
.kb-card.dragging { opacity: .5; }
.kb-card-name { font-weight: 700; font-size: 13.5px; margin-bottom: 4px; letter-spacing: -.01em; }
.kb-card-meta { font-size: 11.5px; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 4px 10px; }

/* Puntos de columna */
.dot-Nuevo { background: var(--b-nuevo-fg); } .dot-Contactado { background: var(--b-contact-fg); }
.dot-Interesado { background: var(--b-interes-fg); } .dot-Negociación { background: var(--b-negoc-fg); }
.dot-Cliente { background: var(--b-cliente-fg); } .dot-Descartado { background: var(--b-descart-fg); }

/* Badges */
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 3px 9px; border-radius: 99px; white-space: nowrap; letter-spacing: .01em; }
.opp-Alta   { background: var(--b-alta-bg); color: var(--b-alta-fg); }
.opp-Media  { background: var(--b-media-bg); color: var(--b-media-fg); }
.opp-Baja   { background: var(--b-baja-bg); color: var(--b-baja-fg); }
.est-Nuevo       { background: var(--b-nuevo-bg); color: var(--b-nuevo-fg); }
.est-Contactado  { background: var(--b-contact-bg); color: var(--b-contact-fg); }
.est-Interesado  { background: var(--b-interes-bg); color: var(--b-interes-fg); }
.est-Negociación { background: var(--b-negoc-bg); color: var(--b-negoc-fg); }
.est-Cliente     { background: var(--b-cliente-bg); color: var(--b-cliente-fg); }
.est-Descartado  { background: var(--b-descart-bg); color: var(--b-descart-fg); }

/* ── Tabla ───────────────────────────────────────────────────────────── */
.table-tools { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.table-tools input, .table-tools select {
  border: 1px solid var(--line); border-radius: 11px; padding: 8px 12px; background: var(--surface); color: var(--ink);
}
.table-tools input { flex: 1; min-width: 200px; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 10.5px; font-weight: 600; color: var(--ink-3);
  font-family: 'JetBrains Mono', monospace; letter-spacing: .06em; text-transform: uppercase;
  padding: 12px 16px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
th button { border: none; background: none; font: inherit; color: inherit; display: inline-flex; align-items: center; gap: 4px; }
th button:hover { color: var(--ink); }
th .sort-ind { color: var(--accent); }
td { padding: 12px 16px; border-bottom: 1px solid var(--line); font-size: 13px; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .1s; }
tbody tr:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: none; }
.td-name { font-weight: 700; letter-spacing: -.01em; }
.td-muted { color: var(--ink-3); }
.empty { text-align: center; color: var(--ink-3); padding: 50px 20px; }

/* ── Leads GEO (Fase 2) ──────────────────────────────────────────────── */
.geo-note { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 12px; font-size: 12.5px; color: var(--ink-3); }
.geo-note .mono { color: var(--ink-2); }

/* ── Mapa ────────────────────────────────────────────────────────────── */
#map { height: 560px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); z-index: 1; }
.map-popup-name { font-weight: 700; font-family: 'Plus Jakarta Sans', sans-serif; margin-bottom: 2px; }
.map-popup-meta { font-size: 12px; color: #78716c; margin-bottom: 6px; }
.map-popup-btn {
  border: none; background: var(--accent); color: #fff; border-radius: 8px;
  padding: 5px 12px; font-size: 12px; font-weight: 700; font-family: 'Plus Jakarta Sans', sans-serif;
}

/* ── Ficha lateral (sheet) ───────────────────────────────────────────── */
.sheet-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 50; }
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw);
  background: var(--bg-1); z-index: 51; box-shadow: var(--shadow-lg);
  border-left: 1px solid var(--line);
  overflow-y: auto; padding: 26px 26px 40px;
  animation: slideIn .22s ease-out;
}
html[data-theme="light"] .sheet { background: var(--surface); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-close {
  position: absolute; top: 16px; right: 16px; border: 1px solid var(--line); background: var(--surface);
  width: 32px; height: 32px; border-radius: 10px; font-size: 14px; color: var(--ink-2);
}
.sheet-title { font-size: 21px; font-weight: 800; letter-spacing: -.025em; padding-right: 44px; }
.sheet-sector { color: var(--ink-3); font-size: 13px; margin-top: 2px; }
.sheet-badges { display: flex; gap: 6px; margin: 10px 0 16px; }
.sheet-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 22px; }

.sheet-section-title {
  font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  font-family: 'JetBrains Mono', monospace; color: var(--ink-3); margin: 20px 0 8px;
}
.field-row { display: flex; align-items: baseline; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.field-label { color: var(--ink-3); font-size: 12px; width: 96px; flex-shrink: 0; }
.field-value { color: var(--ink-2); }
.field-value a { color: var(--ink-2); }
.field-value a:hover { color: var(--accent); }

.sheet-selects { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.sheet-selects label { font-size: 11.5px; color: var(--ink-3); display: block; margin-bottom: 4px; }
.sheet-selects select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--surface); color: var(--ink); }

.notes-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; font-size: 13px; white-space: pre-wrap; color: var(--ink-2); }

/* Mensajes generados */
.msg-card { border: 1px solid var(--line); border-radius: 13px; padding: 14px; margin-bottom: 12px; background: var(--surface); }
.msg-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.msg-head-left { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; }
.msg-icon { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 13px; }
.msg-icon-mail { background: var(--accent); }
.msg-icon-ig { background: linear-gradient(135deg, #d62cb8, #7a3dc8); }
.msg-copy { border: none; background: none; font-size: 12px; font-weight: 700; color: var(--ink-3); display: inline-flex; gap: 5px; align-items: center; }
.msg-copy:hover { color: var(--accent); }
.msg-body { font-size: 12px; color: var(--ink-2); white-space: pre-wrap; line-height: 1.55; max-height: 280px; overflow-y: auto; }

/* ── Modal (formulario) ──────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 60; display: grid; place-items: center; padding: 18px; }
.modal {
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px; max-height: 90vh; overflow-y: auto; padding: 26px;
}
html[data-theme="light"] .modal { background: var(--surface); }
.modal-title { font-size: 18px; font-weight: 800; letter-spacing: -.025em; margin-bottom: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }
.form-field input, .form-field select, .form-field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 9px 12px;
  background: var(--surface); color: var(--ink);
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form-field textarea { resize: vertical; min-height: 80px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── Toasts ──────────────────────────────────────────────────────────── */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-3); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: 11px; padding: 10px 18px;
  font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease-out;
}
.toast.error { background: rgba(255,61,122,.15); border-color: var(--bad); color: var(--bad); }
html[data-theme="light"] .toast.error { background: #fde8ef; }
@keyframes toastIn { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Spinner */
.spinner-wrap { display: grid; place-items: center; padding: 90px 0; }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  .stats { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .main { padding: 16px 12px 32px; }
  .topbar { top: 8px; padding: 0 10px; }
  #map { height: 420px; }
}
