/* CRM de seguros */
:root {
  color-scheme: light;
  --bg:          #f4f3ef;
  --surface:     #fcfcfb;
  --surface-2:   #f0efec;
  --border:      #e2e0da;
  --text:        #0b0b0b;
  --text-2:      #52514e;
  --text-3:      #7a7975;
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --good:        #1a7f37;
  --good-bg:     #e6f4ea;
  --critical:    #c4312f;
  --critical-bg: #fbe9e8;
  --warning:     #8a5a00;
  --warning-bg:  #fff4d6;
  /* un color por estado del pipeline */
  --st-nuevo:      #2a78d6;
  --st-contactado: #7c5cd6;
  --st-cotizando:  #c98500;
  --st-propuesta:  #d9682b;
  --st-ganado:     #1a7f37;
  --st-perdido:    #8a8984;
  --shadow:      0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --radius:      14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #24241f; --border: #33332e;
    --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
    --good: #4cc26a; --good-bg: #16301d; --critical: #ef7472; --critical-bg: #3a1c1b;
    --warning: #f0c45a; --warning-bg: #3a2e10;
    --st-nuevo: #3987e5; --st-contactado: #9b82ec; --st-cotizando: #e0a20a;
    --st-propuesta: #ea7f45; --st-ganado: #3fae5c; --st-perdido: #8f8e86;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #24241f; --border: #33332e;
  --text: #ffffff; --text-2: #c3c2b7; --text-3: #8f8e86; --accent: #3987e5;
  --good: #4cc26a; --good-bg: #16301d; --critical: #ef7472; --critical-bg: #3a1c1b;
  --warning: #f0c45a; --warning-bg: #3a2e10;
  --st-nuevo: #3987e5; --st-contactado: #9b82ec; --st-cotizando: #e0a20a;
  --st-propuesta: #ea7f45; --st-ganado: #3fae5c; --st-perdido: #8f8e86;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 1.05rem; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Botones e inputs ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  border: 1px solid var(--border); background: var(--surface);
  padding: .55rem 1rem; border-radius: 10px; cursor: pointer; font-weight: 500;
  text-decoration: none; display: inline-flex; align-items: center; gap: .35rem;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-sm { padding: .3rem .65rem; font-size: .85rem; }
.btn-wa { background: #1f9d55; border-color: #1f9d55; color: #fff; }
.btn-wa:hover { background: #1f9d55; filter: brightness(1.08); }
.btn-peligro { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 40%, var(--border)); }
.btn-peligro:hover { background: var(--critical-bg); }
.btn:disabled { opacity: .6; cursor: default; }
.btn-icon {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-3); padding: .25rem .45rem; border-radius: 6px; font-size: 1rem;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: .3rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number],
input[type=search], input[type=datetime-local], select, textarea {
  width: 100%; padding: .6rem .75rem; border: 1px solid var(--border);
  border-radius: 10px; background: var(--surface); outline: none;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.campo { margin-bottom: .9rem; }
.fila { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
@media (max-width: 520px) { .fila { grid-template-columns: 1fr; } }

.alerta { padding: .65rem .85rem; border-radius: 10px; font-size: .9rem; margin-bottom: .9rem; }
.alerta-error { background: var(--critical-bg); color: var(--critical); }
.alerta-aviso { background: var(--warning-bg); color: var(--warning); }

/* ---------- Login ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow);
}
.marca { display: flex; align-items: center; gap: .55rem; font-weight: 700; font-size: 1.1rem; }
.marca-logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent);
  display: grid; place-items: center; color: #fff; flex: none;
}
.auth-card .marca { margin-bottom: .4rem; }
.auth-card p.lead { color: var(--text-2); margin: 0 0 1.4rem; font-size: .92rem; }
.auth-card .btn-primary { width: 100%; padding: .7rem; justify-content: center; }
.auth-legal { text-align: center; font-size: .8rem; margin: 1rem 0 0; }
.auth-legal a { color: var(--text-2); }

/* Páginas de texto (política de privacidad) */
.doc { max-width: 720px; margin: 0 auto; padding: 32px 16px 64px; line-height: 1.65; }
.doc .marca { margin-bottom: 1.75rem; }
.doc h1 { font-size: 1.8rem; margin-bottom: .25rem; }
.doc h2 { font-size: 1.1rem; margin: 2rem 0 .5rem; }
.doc ul { padding-left: 1.25rem; }
.doc li { margin: .35rem 0; }
.doc a { color: var(--accent); }

/* ---------- Estructura de la app ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.topbar-in {
  max-width: 1280px; margin: 0 auto; padding: .7rem 16px;
  display: flex; align-items: center; gap: 1rem;
}
.nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.nav button {
  border: none; background: transparent; padding: .45rem .8rem; border-radius: 8px;
  cursor: pointer; color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.nav button:hover { background: var(--surface-2); }
.nav button.activo { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.badge {
  display: inline-block; min-width: 1.3em; padding: 0 .4em; margin-left: .25rem;
  border-radius: 999px; background: var(--critical); color: #fff;
  font-size: .72rem; line-height: 1.45em; text-align: center; font-weight: 600;
}
.topbar-user { display: flex; align-items: center; gap: .5rem; color: var(--text-2); font-size: .9rem; }
@media (max-width: 720px) {
  .topbar-in { flex-wrap: wrap; gap: .5rem; }
  .nav { order: 3; flex-basis: 100%; }
  .topbar-user { margin-left: auto; }
  .topbar-user .nombre { display: none; }
  .marca .texto { display: none; }
}

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 48px; }
.vista-cab { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.vista-cab h1 { font-size: 1.35rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }

/* KPIs de la bandeja */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpi { padding: .9rem 1rem; }
.kpi .valor { font-size: 1.6rem; font-weight: 700; }
.kpi .etiqueta { font-size: .82rem; color: var(--text-2); }
.kpi.alerta-kpi .valor { color: var(--critical); }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.filtros { display: flex; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.filtros input[type=search] { flex: 1; min-width: 180px; }
.filtros select { width: auto; }

/* Lista de leads */
.lista { list-style: none; margin: 0; padding: 0; }
.lista li {
  display: grid; grid-template-columns: 1fr auto; gap: .25rem 1rem; align-items: center;
  padding: .8rem 1rem; border-bottom: 1px solid var(--border); cursor: pointer;
}
.lista li:last-child { border-bottom: none; }
.lista li:hover { background: var(--surface-2); }
.lista .nom { font-weight: 600; }
.lista .meta { font-size: .82rem; color: var(--text-2); display: flex; gap: .6rem; flex-wrap: wrap; }
.lista .der { text-align: right; display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
.vacio { padding: 2.5rem 1rem; text-align: center; color: var(--text-2); }

.chip-estado {
  display: inline-flex; align-items: center; gap: .35rem; font-size: .78rem; font-weight: 600;
  padding: .1rem .55rem; border-radius: 999px; white-space: nowrap;
  color: var(--st); background: color-mix(in srgb, var(--st) 14%, transparent);
}
.chip-estado::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--st); }
[data-estado=nuevo]      { --st: var(--st-nuevo); }
[data-estado=contactado] { --st: var(--st-contactado); }
[data-estado=cotizando]  { --st: var(--st-cotizando); }
[data-estado=propuesta]  { --st: var(--st-propuesta); }
[data-estado=ganado]     { --st: var(--st-ganado); }
[data-estado=perdido]    { --st: var(--st-perdido); }
.tag-fuente { font-size: .75rem; padding: .05rem .45rem; border-radius: 6px; background: var(--surface-2); color: var(--text-2); }
.urgente { color: var(--critical); font-weight: 600; }

/* ---------- Pipeline (kanban) ---------- */
.kanban { display: grid; grid-template-columns: repeat(6, minmax(220px, 1fr)); gap: .75rem; overflow-x: auto; padding-bottom: .5rem; }
.columna { background: var(--surface-2); border-radius: var(--radius); padding: .6rem; min-height: 200px; display: flex; flex-direction: column; }
.columna.sobre { outline: 2px dashed var(--accent); outline-offset: -2px; }
.columna-cab { display: flex; justify-content: space-between; align-items: center; padding: .2rem .3rem .6rem; font-weight: 600; font-size: .9rem; }
.columna-cab .n { color: var(--text-3); font-weight: 500; }
.tarjeta {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--st);
  border-radius: 10px; padding: .6rem .7rem; margin-bottom: .5rem; cursor: grab; font-size: .88rem;
}
.tarjeta:active { cursor: grabbing; }
.tarjeta .nom { font-weight: 600; }
.tarjeta .meta { color: var(--text-2); font-size: .8rem; }

/* ---------- Tareas y campañas ---------- */
.tarea { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border); }
.tarea:last-child { border-bottom: none; }
.tarea input[type=checkbox] { width: 18px; height: 18px; flex: none; accent-color: var(--accent); }
.tarea .cuerpo { flex: 1; min-width: 0; }
.tarea .cuando { font-size: .82rem; color: var(--text-2); }
.tarea.vencida .cuando { color: var(--critical); font-weight: 600; }
.grupo-titulo { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); margin: 1.2rem 0 .4rem; font-weight: 600; }

.tabla-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .65rem .9rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .78rem; color: var(--text-2); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
td.num, th.num { text-align: right; }
tr:last-child td { border-bottom: none; }
td input[type=number] { width: 110px; padding: .3rem .5rem; text-align: right; }

/* ---------- Panel lateral del lead y modales ---------- */
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); z-index: 31;
  background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto;
  padding: 20px; box-shadow: -8px 0 30px rgba(0,0,0,.12);
}
.panel-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; margin-bottom: .75rem; }
.panel-cab h2 { font-size: 1.3rem; }
.acciones-rapidas { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0 1rem; }
.datos { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; font-size: .9rem; margin: 0 0 1rem; }
.datos dt { color: var(--text-2); }
.datos dd { margin: 0; word-break: break-word; }
.seccion { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }
.seccion h3 { font-size: .95rem; margin-bottom: .6rem; }
.estados { display: flex; gap: .35rem; flex-wrap: wrap; }
.estados button {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: .25rem .7rem; font-size: .82rem; cursor: pointer; color: var(--text-2);
}
.estados button.activo { background: var(--st); border-color: var(--st); color: #fff; font-weight: 600; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .55rem 0 .55rem .9rem; border-left: 2px solid var(--border); position: relative; font-size: .88rem; }
.timeline li::before {
  content: ""; position: absolute; left: -5px; top: .85rem; width: 8px; height: 8px;
  border-radius: 50%; background: var(--text-3);
}
.timeline .cuando { font-size: .78rem; color: var(--text-3); }
.timeline .tipo { font-weight: 600; }
.form-actividad { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; margin-bottom: .75rem; }
.form-actividad select { width: auto; }
@media (max-width: 520px) { .form-actividad { grid-template-columns: 1fr; } }
.respuestas { font-size: .85rem; background: var(--surface-2); border-radius: 10px; padding: .6rem .8rem; }
.respuestas div { padding: .15rem 0; }
.respuestas b { font-weight: 600; color: var(--text-2); }

dialog {
  border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface);
  color: var(--text); width: min(520px, calc(100% - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.35); }
.modal-in { padding: 22px; }
.modal-in h2 { margin-bottom: 1rem; }
.modal-acciones { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; font-size: .9rem;
}
