/* CRM Neopindec — estilos PWA */
:root {
  color-scheme: light;
  --brand: #1f3a5f;
  --brand-2: #2a78d6;
  --surface-1: #fcfcfb;
  --page: #f3f4f2;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 25, 40, .08), 0 4px 14px rgba(15, 25, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19; --page: #0d0d0d;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --border: rgba(255, 255, 255, 0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --good-text: #0ca30c;
    --brand: #23415f;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19; --page: #0d0d0d;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --border: rgba(255, 255, 255, 0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good-text: #0ca30c;
  --brand: #23415f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--ink); font-size: 15px;
}
h1, h2, h3 { margin: 0 0 .4em; }
a { color: var(--s1); }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface-1);
  border: 1px solid var(--grid); border-radius: 8px; padding: 9px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--s1); outline-offset: 1px; }
label { font-size: 12.5px; color: var(--ink-2); display: block; margin: 10px 0 4px; font-weight: 600; }

/* ---- Layout ---- */
#app { display: flex; min-height: 100dvh; }
.sidebar {
  width: 232px; background: var(--brand); color: #fff; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100dvh;
}
.sidebar .logo { padding: 18px 16px 10px; font-weight: 800; font-size: 18px; letter-spacing: .5px; }
.sidebar .logo small { display: block; font-weight: 400; font-size: 11px; opacity: .75; }
.nav { flex: 1; overflow-y: auto; padding: 6px 8px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin: 2px 0;
  color: #ffffffd9; text-decoration: none; border-radius: 8px; font-size: 14px;
}
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, .14); color: #fff; }
.nav a .ico { width: 20px; text-align: center; }
.sidebar .userbox { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.15); font-size: 13px; }
.sidebar .userbox b { display: block; }
.sidebar .userbox button {
  margin-top: 8px; background: rgba(255,255,255,.15); color: #fff; border: 0;
  padding: 6px 10px; border-radius: 7px; font-size: 12.5px;
}
main { flex: 1; padding: 22px 26px 90px; max-width: 1280px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.topbar h1 { font-size: 22px; margin: 0; }

/* bottom nav móvil */
.bottomnav { display: none; }
@media (max-width: 860px) {
  .sidebar { display: none; }
  main { padding: 14px 14px 84px; }
  .bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--brand); justify-content: space-around;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottomnav a {
    color: #ffffffcc; text-decoration: none; font-size: 10.5px; text-align: center;
    padding: 4px 6px; border-radius: 8px; min-width: 52px;
  }
  .bottomnav a .ico { display: block; font-size: 19px; }
  .bottomnav a.active { color: #fff; background: rgba(255,255,255,.16); }
}

/* ---- Componentes ---- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.grid { display: grid; gap: 14px; }
.tiles { grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .t-label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.tile .t-value { font-size: 25px; font-weight: 750; margin-top: 3px; }
.tile .t-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.two-col { grid-template-columns: 1fr 1fr; }
@media (max-width: 980px) { .two-col { grid-template-columns: 1fr; } }

.btn {
  background: var(--s1); border: 0; color: #fff; border-radius: 8px;
  padding: 9px 14px; font-weight: 600; font-size: 14px;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { filter: brightness(1.08); }
.btn.secondary { background: transparent; color: var(--ink); border: 1px solid var(--grid); }
.btn.danger { background: var(--critical); }
.btn.small { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; color: var(--ink-2); font-size: 12px; border-bottom: 2px solid var(--grid); padding: 7px 8px; white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.tbl tr:hover td { background: color-mix(in srgb, var(--s1) 5%, transparent); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 650; white-space: nowrap; }
.badge.stage-nuevo { background: #2a78d61f; color: var(--s1); }
.badge.stage-contactado { background: #4a3aa71f; color: var(--s7); }
.badge.stage-calificado { background: #eda1002a; color: #8a6100; }
.badge.stage-propuesta { background: #eb68342a; color: var(--s2); }
.badge.stage-negociacion { background: #e87ba42a; color: #b03e6b; }
.badge.stage-ganado { background: #0ca30c22; color: var(--good-text); }
.badge.stage-perdido { background: #d03b3b22; color: var(--critical); }
.badge.gray { background: var(--grid); color: var(--ink-2); }
.badge.prio-alta { background: #d03b3b22; color: var(--critical); }
.badge.prio-media { background: #eda1002a; color: #8a6100; }
.badge.prio-baja { background: var(--grid); color: var(--ink-2); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 120px; padding: 7px 9px; font-size: 13.5px; }

/* Kanban — ocupa toda la altura disponible de la pantalla */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.kb-col { min-width: 235px; width: 235px; flex-shrink: 0; background: color-mix(in srgb, var(--surface-1) 60%, var(--page)); border: 1px solid var(--border); border-radius: 10px; padding: 8px; overflow-y: auto; }
.kb-col h4 { margin: 0 0 8px; padding: 4px; font-size: 12.5px; color: var(--ink-2); display: flex; justify-content: space-between; position: sticky; top: -8px; background: inherit; z-index: 2; }
@media (min-width: 861px) {
  .kanban { height: calc(100dvh - 218px); min-height: 340px; }
}
@media (max-width: 860px) {
  .kanban { height: calc(100dvh - 300px); min-height: 300px; }
}
.kb-card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 9px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); cursor: pointer; }
.kb-card .t { font-weight: 650; font-size: 13px; line-height: 1.25; }
.kb-card .m { font-size: 12px; color: var(--ink-2); margin-top: 4px; display: flex; justify-content: space-between; gap: 6px; }

/* Progreso KPI */
.pbar { height: 8px; background: var(--grid); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.pbar > i { display: block; height: 100%; border-radius: 99px; background: var(--s1); }
.pbar > i.ok { background: var(--good); }
.pbar > i.warn { background: var(--warning); }
.pbar > i.bad { background: var(--critical); }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 14px; }
.modal { background: var(--surface-1); border-radius: 14px; max-width: 640px; width: 100%; max-height: 92dvh; overflow-y: auto; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal h3 { display: flex; justify-content: space-between; align-items: center; }
.modal .x { background: none; border: 0; font-size: 20px; color: var(--muted); }
.mrow { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 560px) { .mrow { grid-template-columns: 1fr; } }
.mact { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toast */
#toasts { position: fixed; top: 14px; right: 14px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--ink); color: var(--page); padding: 11px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px; animation: pop .18s ease; }
.toast.err { background: var(--critical); color: #fff; }
@keyframes pop { from { transform: translateY(-6px); opacity: 0; } }

/* Login */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; background: linear-gradient(150deg, var(--brand) 0%, #0e1c30 100%); padding: 16px; }
.login-card { background: var(--surface-1); border-radius: 16px; padding: 30px 28px; width: 100%; max-width: 380px; box-shadow: 0 12px 50px rgba(0,0,0,.35); }
.login-card .logo { font-size: 24px; font-weight: 800; color: var(--brand-2); }
.login-card .logo small { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

/* Chat IA */
.chat { display: flex; flex-direction: column; height: calc(100dvh - 200px); min-height: 380px; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 8px 2px; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 14px; margin-bottom: 10px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: break-word; }
.msg.user { background: var(--s1); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.assistant { background: color-mix(in srgb, var(--surface-1) 50%, var(--page)); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.assistant b { color: var(--s1); }
.chat-in { display: flex; gap: 8px; padding-top: 10px; }
.chat-in textarea { resize: none; height: 52px; }
.suggestions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.suggestions button { background: color-mix(in srgb, var(--s1) 10%, transparent); border: 1px solid color-mix(in srgb, var(--s1) 30%, transparent); color: var(--s1); border-radius: 99px; padding: 5px 12px; font-size: 12.5px; }

/* Mapa */
#map { height: 430px; border-radius: var(--radius); z-index: 1; }
.loc-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.loc-fresh { background: var(--good); }
.loc-old { background: var(--warning); }
.loc-none { background: var(--muted); }

/* Visita en curso */
.visit-live { border: 2px solid var(--good); background: #0ca30c14; }
.pulse { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: var(--good); animation: pulse 1.4s infinite; margin-right: 8px; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #0ca30c66; } 70% { box-shadow: 0 0 0 9px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.route-stop { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.route-stop .ord { width: 26px; height: 26px; border-radius: 50%; background: var(--s1); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0; }
.route-stop.done .ord { background: var(--good); }
.route-stop.skipped .ord { background: var(--muted); }

/* Página de lead */
.lead-grid { grid-template-columns: 380px 1fr; align-items: start; }
@media (max-width: 1020px) { .lead-grid { grid-template-columns: 1fr; } }
.info-tbl { width: 100%; font-size: 13.5px; border-collapse: collapse; }
.info-tbl td { padding: 5px 4px; border-bottom: 1px solid var(--grid); }
.info-tbl td:first-child { color: var(--ink-2); width: 34%; font-size: 12.5px; }
.stepper-card { padding: 12px 16px; }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; }
.step {
  border: 1px solid var(--grid); background: var(--surface-1); color: var(--ink-2);
  padding: 7px 13px; border-radius: 99px; font-size: 12.5px; font-weight: 600;
}
.step.past { background: color-mix(in srgb, var(--s1) 14%, var(--surface-1)); border-color: color-mix(in srgb, var(--s1) 40%, transparent); color: var(--s1); }
.step.now { background: var(--s1); color: #fff; border-color: var(--s1); }
.step.win.now { background: var(--good); border-color: var(--good); }
.step.lose.now { background: var(--critical); border-color: var(--critical); }
.step:hover { filter: brightness(1.05); }

/* Actividades */
.act-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px 2px; border-bottom: 1px solid var(--grid); font-size: 13.5px; }
.act-row:last-child { border-bottom: 0; }
.act-row.completada { opacity: .6; }
.act-row.overdue b:first-child { color: var(--critical); }

/* Cotizaciones */
.quote-row { display: flex; gap: 10px; align-items: flex-start; padding: 11px 2px; border-bottom: 1px solid var(--grid); font-size: 13.5px; flex-wrap: wrap; }
.quote-row:last-child { border-bottom: 0; }
.q-status-sel { width: auto; padding: 4px 6px; font-size: 12px; margin: 4px 0; }

/* Adjuntos */
.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.att-item { position: relative; border: 1px solid var(--grid); border-radius: 9px; overflow: hidden;
  cursor: pointer; background: color-mix(in srgb, var(--surface-1) 70%, var(--page)); }
.att-item img { width: 100%; height: 86px; object-fit: cover; display: block; background: var(--grid); }
.att-doc { height: 86px; display: flex; align-items: center; justify-content: center; font-size: 34px; }
.att-name { font-size: 10.5px; padding: 4px 6px; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; color: var(--ink-2); }
.att-del { position: absolute; top: 4px; right: 4px; background: rgba(0,0,0,.55); color: #fff;
  border: 0; border-radius: 50%; width: 22px; height: 22px; font-size: 11px; line-height: 1; }

/* Calendario */
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px;
  font-size: 12px; color: var(--ink-2); font-weight: 700; text-align: center; margin-bottom: 4px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-day { min-height: 98px; border: 1px solid var(--grid); border-radius: 8px; padding: 4px;
  background: color-mix(in srgb, var(--surface-1) 70%, var(--page)); overflow: hidden; }
.cal-day.off { background: transparent; border-color: transparent; }
.cal-day.today { border: 2px solid var(--s1); }
.cal-num { font-size: 11.5px; font-weight: 700; color: var(--ink-2); margin-bottom: 3px; }
.cal-day.today .cal-num { color: var(--s1); }
.cal-chip { font-size: 10.5px; line-height: 1.25; padding: 2px 5px; border-radius: 5px;
  margin-bottom: 2px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-chip.pend { background: #2a78d61f; color: var(--s1); }
.cal-chip.done { background: var(--grid); color: var(--ink-2); text-decoration: line-through; }
.cal-chip.overdue { background: #d03b3b22; color: var(--critical); font-weight: 700; }
.cal-chip.route { background: #1baf7a22; color: #0d7a52; }
.cal-more { font-size: 10px; color: var(--muted); }
@media (max-width: 860px) {
  .cal-day { min-height: 64px; }
  .cal-chip { font-size: 9px; }
}

/* Lead score */
.score { display: inline-flex; align-items: center; gap: 3px; padding: 1px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 750; white-space: nowrap; }
.score-hot { background: #d03b3b1f; color: var(--critical); }
.score-warm { background: #eda1002a; color: #8a6100; }
.score-cold { background: #2a78d61a; color: var(--s1); }

.muted { color: var(--muted); font-size: 12.5px; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.chartbox { position: relative; height: 250px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.section-title { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.hr { border: 0; border-top: 1px solid var(--grid); margin: 14px 0; }

/* ---------- Medidores KPI (gauges de mínimos de actividad) ---------- */
.meter-row { display: flex; flex-wrap: wrap; gap: 18px; }
.meter { text-align: center; flex: 0 0 auto; width: 108px; }
.meter-ring {
  width: 84px; height: 84px; border-radius: 50%; margin: 0 auto;
  display: flex; align-items: center; justify-content: center;
}
.meter-hole {
  width: 62px; height: 62px; border-radius: 50%; background: var(--card, #fff);
  display: flex; align-items: center; justify-content: center; flex-direction: row;
  font-size: 17px; gap: 1px;
}
.meter-hole small { color: #898781; font-size: 11px; }
.meter-label { font-size: 11.5px; color: #4c4a45; margin-top: 6px; line-height: 1.25; }
.meter-pct { font-size: 12px; font-weight: 700; margin-top: 2px; }

/* ---------- Ayuda: bot sin IA + manual ---------- */
.help-grid { display: grid; grid-template-columns: minmax(320px, 44%) 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .help-grid { grid-template-columns: 1fr; } }
.hb-panel { position: sticky; top: 10px; }
.hb-chat { max-height: 46vh; min-height: 180px; overflow-y: auto; padding: 4px 2px;
  display: flex; flex-direction: column; gap: 8px; }
.hb-msg { border-radius: 10px; padding: 8px 12px; font-size: 13.5px; line-height: 1.45; max-width: 95%; }
.hb-msg p { margin: 4px 0; }
.hb-bot { background: #f0f4fa; border: 1px solid #dfe7f2; align-self: flex-start; }
.hb-user { background: #1f3a5f; color: #fff; align-self: flex-end; }
.hb-title { font-size: 14px; }
.hb-sugs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.hb-input { display: flex; gap: 8px; }
.hb-input input { flex: 1; }
.hb-index a { white-space: nowrap; }
.hb-sec { padding: 8px 0 2px; scroll-margin-top: 12px; }
.hb-sec h3 { margin: 10px 0 4px; color: #1f3a5f; }
.hb-sec p { margin: 5px 0; font-size: 13.5px; line-height: 1.5; }
.hb-flash { animation: hbflash 1.5s ease; }
@keyframes hbflash { 0% { background: #fff3d6; } 100% { background: transparent; } }

/* capturas y diagramas del manual */
.hb-shot { width: 100%; max-width: 720px; border: 1px solid #d9d7d2; border-radius: 8px;
  box-shadow: 0 2px 8px rgba(31,58,95,.10); display: block; margin-top: 8px; }
.hb-imglink { display: inline-block; position: relative; text-decoration: none; }
.hb-imglink .hb-zoom { display: block; font-size: 11px; color: #898781; margin: 3px 0 6px; }
.hb-imglink:hover .hb-shot { box-shadow: 0 4px 14px rgba(31,58,95,.22); }
.hb-svg { width: 100%; max-width: 760px; height: auto; margin: 6px 0 2px; }
.hb-tbl { font-size: 12.5px; margin: 6px 0; }
.hb-tbl td, .hb-tbl th { padding: 5px 8px; }
