:root {
  --bg: #f5f6f8; --card: #fff; --ink: #1d2330; --muted: #6b7280; --line: #e5e7eb;
  --brand: #2563eb; --brand-ink: #fff; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --A: #16a34a; --B: #2563eb; --C: #9ca3af; --D: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1218; --card: #171b24; --ink: #e5e7eb; --muted: #9aa3b2; --line: #2a303c; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; } .brand span { color: var(--muted); font-weight: 400; font-size: 13px; }
nav { display: flex; gap: 4px; }
nav button { background: none; border: 0; padding: 8px 14px; border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 14px; }
nav button.active { background: var(--brand); color: var(--brand-ink); }
.health { margin-left: auto; display: flex; gap: 8px; font-size: 12px; }
.pill { padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); }
.pill.on { color: var(--ok); border-color: var(--ok); } .pill.off { color: var(--bad); border-color: var(--bad); }
main { padding: 20px; max-width: 1300px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
h3 { margin: 0 0 10px; font-size: 15px; }
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; }
label.chk { flex-direction: row; align-items: center; gap: 6px; flex: none; font-size: 13px; color: var(--ink); }
label.chk input { width: auto; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row.opts { margin-top: 12px; align-items: center; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 12px; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:disabled { opacity: .6; }
.search-card .primary { margin-left: auto; padding: 9px 18px; }
.job { margin-top: 14px; } .hidden { display: none !important; }
.bar { height: 6px; background: var(--line); border-radius: 9px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--brand); transition: width .4s; }
pre { white-space: pre-wrap; font-size: 12px; color: var(--muted); max-height: 180px; overflow: auto; margin: 8px 0 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; } .filters input, .filters select { width: auto; flex: 1 1 140px; }
.muted { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.list { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 12px; }
.pcard { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.pcard:hover { border-color: var(--brand); }
.ptop { display: flex; gap: 10px; align-items: flex-start; }
.score { min-width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 15px; }
.score.A { background: var(--A); } .score.B { background: var(--B); } .score.C { background: var(--C); } .score.D { background: var(--D); }
.pname { font-weight: 600; } .psub { color: var(--muted); font-size: 12px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); }
.tag.st { color: var(--brand); border-color: var(--brand); }
.acts { display: flex; gap: 6px; flex-wrap: wrap; }
.acts a, .btnlink { font-size: 12px; text-decoration: none; padding: 4px 9px; border-radius: 7px; border: 1px solid var(--line); color: var(--ink); background: var(--bg); }
.acts a.wa { color: #fff; background: #25d366; border-color: #25d366; }
.acts a.tel { color: #fff; background: var(--brand); border-color: var(--brand); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl td, .tbl th { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover { background: var(--bg); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.kpi b { display: block; font-size: 24px; } .kpi span { color: var(--muted); font-size: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.mini .it { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.mini .it:hover { color: var(--brand); } .mini .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tips { margin: 0; padding-left: 18px; } .tips li { margin-bottom: 6px; }
.overlay { position: fixed; inset: 0; background: #0006; z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(680px, 100%); background: var(--card); z-index: 10; overflow: auto; padding: 20px 22px; border-left: 1px solid var(--line); }
.drawer .close { position: absolute; right: 14px; top: 12px; font-size: 20px; border: 0; background: none; }
.drawer h2 { margin: 0 30px 4px 0; font-size: 20px; }
.sec { margin-top: 16px; } .sec h4 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 13px; } .kv div:nth-child(odd) { color: var(--muted); }
.pros li { color: var(--ok); } .cons li { color: var(--warn); } .pros, .cons { margin: 0; padding-left: 18px; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.timeline { border-left: 2px solid var(--line); padding-left: 12px; }
.timeline .ev { margin-bottom: 8px; font-size: 13px; } .timeline .ev small { color: var(--muted); }
.ai { background: var(--bg); border-radius: 10px; padding: 12px; font-size: 13px; }
.ai p { margin: 4px 0 10px; } .ai .copy { float: right; font-size: 11px; padding: 2px 8px; }
.ai blockquote { margin: 4px 0 10px; padding: 8px 10px; border-left: 3px solid #25d366; background: var(--card); white-space: pre-wrap; }
dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); width: min(440px, 95vw); }
.addform { display: flex; flex-direction: column; gap: 8px; } .addform .row { justify-content: flex-end; }
@media (max-width: 600px) { main { padding: 12px; } .grid2 { grid-template-columns: 1fr; } .form2 { grid-template-columns: 1fr; } }
.related { margin: 12px 0 4px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; font-size: 13px; }
.related b { margin-right: 4px; }
.chip { font-size: 12px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--brand); color: var(--brand); background: var(--card); }
.chip:hover { background: var(--brand); color: var(--brand-ink); }
.chip.done { border-color: var(--line); color: var(--muted); }
.filters label { flex: 1 1 200px; }
.profile-pill { margin-left: auto; font-size: 12px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--brand); color: var(--brand); background: var(--card); }
.profile-pill + .health { margin-left: 8px; }
.profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.prof { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; background: var(--bg); }
.prof:hover, .prof.sel { border-color: var(--brand); }
.prof.active { box-shadow: inset 4px 0 0 var(--ok); }
.prof b { display: block; } .prof small { color: var(--muted); }
pre.preview { max-height: 360px; background: var(--bg); padding: 10px; border-radius: 8px; color: var(--ink); }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }
.loc-wrap { position: relative; display: flex; gap: 6px; }
.loc-wrap input { flex: 1; }
.loc-wrap button { white-space: nowrap; }
.suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 20; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px #0002; overflow: hidden; }
.suggest .opt { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; color: var(--ink); font-size: 13px; }
.suggest .opt:hover, .suggest .opt.hl { background: var(--bg); }
.suggest .opt small { color: var(--muted); }
.suggest .kind { font-size: 11px; color: var(--brand); white-space: nowrap; }
.dist { font-size: 11px; color: var(--muted); }
.usermenu { display: flex; gap: 6px; align-items: center; }
.usermenu button { font-size: 12px; padding: 4px 10px; }
h4.sub { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--line); white-space: nowrap; }
.badge.own { color: var(--ok); border-color: var(--ok); } .badge.sys { color: var(--muted); } .badge.off { color: var(--bad); border-color: var(--bad); }
.tests { margin-top: 10px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.tests .ok { color: var(--ok); } .tests .bad { color: var(--bad); }
tr.inactive td { opacity: .5; }

button.danger { background: var(--bad); color: #fff; border-color: var(--bad); }
button.danger:disabled { opacity: .45; cursor: not-allowed; }
button.del-search { color: var(--bad); margin-left: 4px; }
.ds-box { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.6; }


/* ==================== Celulares y tablets ==================== */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
#searches td:nth-child(2) { min-width: 180px; }
#searches td:last-child { white-space: nowrap; }
#users-table td, #perf td, #locs td { white-space: nowrap; }
.list { grid-template-columns: repeat(auto-fill, minmax(min(330px, 100%), 1fr)); }
.grid2 { grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); }
.profiles { grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.kpis { grid-template-columns: repeat(auto-fit, minmax(min(130px, 45%), 1fr)); }
.filters input, .filters select, .row > *, label { min-width: 0; }
select { max-width: 100%; text-overflow: ellipsis; }
.pname, .psub, .kv div, .ai, .ai blockquote, .timeline .ev, .tbl td, .ds-box, #acc-info, .prof b { overflow-wrap: anywhere; }
pre, img { max-width: 100%; }
dialog { max-height: 90vh; overflow: auto; }

@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  /* Encabezado compacto, no fijo (antes tapaba media pantalla) */
  header { position: static; padding: 10px 12px; gap: 8px 10px; }
  .brand { order: 0; font-size: 17px; }
  .brand span { display: none; }
  .usermenu { order: 1; margin-left: auto; }
  .usermenu button { padding: 6px 10px; }
  #btn-account { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  nav { order: 2; width: calc(100% + 24px); margin: 0 -12px; padding: 0 12px 2px; overflow-x: auto; flex-wrap: nowrap;
        scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  nav::-webkit-scrollbar { display: none; }
  nav button { flex: none; padding: 8px 12px; }
  .profile-pill { order: 3; margin-left: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .health { order: 4; margin-left: 0; flex-wrap: wrap; gap: 4px; }
  .pill { font-size: 11px; }

  main { padding: 10px; }
  .card { padding: 12px; border-radius: 10px; margin-bottom: 12px; }
  /* iOS hace zoom en campos con letra menor a 16px */
  input, select, textarea { font-size: 16px; }

  /* Buscar: campos uno debajo de otro */
  .search-card > .row:first-child { flex-direction: column; align-items: stretch; }
  .loc-wrap { flex-wrap: wrap; }
  .loc-wrap input { flex: 1 1 100%; }
  .loc-wrap button { flex: 1 1 auto; }
  .row.opts { gap: 10px 14px; }
  label.chk { flex-wrap: wrap; }
  .search-card .primary { margin-left: 0; width: 100%; padding: 12px; }

  /* Prospectos: filtros en 2 columnas */
  .filters { gap: 6px; }
  .filters > * { flex: 1 1 calc(50% - 6px); }
  .filters #f-search, .filters #f-q { flex-basis: 100%; }
  .filters button { padding: 9px 10px; }

  /* Botones de contacto más fáciles de tocar */
  .acts a, .btnlink { padding: 7px 11px; font-size: 13px; }

  /* Detalle del prospecto */
  .drawer { padding: 14px 14px 30px; }
  .drawer h2 { font-size: 18px; }
  .kv { grid-template-columns: 1fr; gap: 0 0; }
  .kv div:nth-child(odd) { margin-top: 8px; font-size: 12px; }
  .drawer .row { flex-wrap: wrap; }

  .grid2 { gap: 12px; }
  dialog { width: calc(100vw - 20px); padding: 14px; }
  .tbl { font-size: 12.5px; }
}
/* Casillas y selectores con texto largo: que se acomoden en varias líneas */
label.chk { max-width: 100%; flex-wrap: wrap; }
label.chk select { min-width: 0; max-width: 100%; }
#sys-info, .muted { overflow-wrap: anywhere; }
@media (max-width: 760px) {
  label.chk { flex: 1 1 auto; white-space: normal; }
  label.chk input[type=checkbox] { flex: none; }
  .row.opts label.chk:has(select) { flex: 1 1 100%; justify-content: space-between; }
}
/* Selectores dentro de etiquetas en las barras de filtros: altura normal */
.filters label select, .filters label input { flex: none; width: 100%; }
/* Casilla + texto en la misma línea (el texto se acomoda en varias líneas si es largo) */
label.chk:not(:has(select)) { flex-wrap: nowrap; align-items: flex-start; }
label.chk:not(:has(select)) input[type=checkbox] { margin-top: 3px; }
