:root {
  --bg: #f6f3ee;
  --panel: #ffffff;
  --text: #2a2522;
  --muted: #7a716a;
  --line: #e4ddd3;
  --accent: #b5432a;
  --accent-soft: #f6e2db;
  --menu-w: 240px;
  --st-potencial: #8a8178;
  --st-contactado: #2f6fb0;
  --st-seguimiento: #c28a00;
  --st-cliente: #2e8b4e;
  --st-descartado: #6b6b6b;
  --st-cerrado: #b03030;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1a18; --panel: #262320; --text: #eee8e1; --muted: #a59b91;
    --line: #3a3530; --accent: #e0694d; --accent-soft: #3d2a24;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px;
  background: var(--accent); color: #fff;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contador { font-size: 13px; opacity: .9; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 24px; padding: 4px 8px; cursor: pointer; }

.menu {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--menu-w); z-index: 40;
  background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: calc(env(safe-area-inset-top) + 12px) 0 24px;
  transform: translateX(-100%); transition: transform .2s ease;
}
.menu.abierto { transform: none; }
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; display: none; }
.velo.visible { display: block; }
.menu-brand { font-weight: 700; font-size: 17px; padding: 4px 18px 12px; color: var(--accent); }
.menu-sep { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 16px 18px 6px; }
.nav-item {
  display: flex; width: 100%; align-items: center; gap: 8px;
  background: none; border: 0; text-align: left; cursor: pointer;
  padding: 10px 18px; font-size: 15px;
}
.nav-item:hover { background: var(--accent-soft); }
.nav-item.activo { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .n { margin-left: auto; font-size: 12px; color: var(--muted); }
.punto { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }

.contenido { padding: 12px 16px 40px; }
.buscador { display: flex; gap: 8px; margin-bottom: 12px; }
.buscador input, .buscador select {
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
}
.buscador input { flex: 1; min-width: 0; }
.buscador select { max-width: 40%; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 900px) {
  .menu { transform: none; }
  .velo, #btnMenu { display: none !important; }
  .topbar, .contenido { margin-left: var(--menu-w); }
  .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
}

.card {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--st-potencial);
  border-radius: 10px; padding: 8px 10px; cursor: pointer; text-align: left; width: 100%;
  display: flex; flex-direction: column; gap: 2px; min-height: 78px;
}
.card:active { transform: scale(.98); }
.card .nom { font-weight: 600; font-size: 14px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .pie { display: flex; justify-content: space-between; align-items: center; margin-top: auto; font-size: 11px; }
.pill { padding: 1px 7px; border-radius: 99px; color: #fff; font-size: 11px; white-space: nowrap; }
.alerta { color: var(--accent); font-weight: 600; }

.vacio { text-align: center; color: var(--muted); padding: 40px 0; }

dialog {
  border: 0; padding: 0; background: var(--panel); color: var(--text);
  width: min(560px, 100vw); max-width: 100vw; max-height: 92vh; border-radius: 16px;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
@media (max-width: 599px) {
  dialog { margin: auto 0 0; width: 100vw; border-radius: 16px 16px 0 0; max-height: 94vh; }
}
.f-cab { position: sticky; top: 0; background: var(--panel); padding: 14px 16px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: flex-start; z-index: 1; }
.f-cab h2 { margin: 0; font-size: 18px; flex: 1; }
.f-cab .sub { font-size: 13px; color: var(--muted); }
.f-cuerpo { padding: 12px 16px 20px; overflow-y: auto; }
.f-sec { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.estados { display: flex; flex-wrap: wrap; gap: 6px; }
.estados button { border: 1px solid var(--line); background: var(--panel); border-radius: 99px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.estados button.sel { color: #fff; border-color: transparent; }
.acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px; cursor: pointer; font-size: 14px; text-align: center; text-decoration: none; color: var(--text); }
.btn.prim { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.peligro { color: var(--st-cerrado); }
.campo { display: block; margin-bottom: 10px; }
.campo span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.campo input, .campo textarea, .campo select { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.campo textarea { min-height: 70px; resize: vertical; }
.dato { font-size: 14px; margin: 3px 0; word-break: break-word; }
.dato a { color: var(--accent); }
.hist { list-style: none; padding: 0; margin: 0; }
.hist li { border-left: 2px solid var(--line); padding: 4px 0 8px 10px; font-size: 13px; }
.hist li b { font-weight: 600; }
.hist .fecha { color: var(--muted); font-size: 12px; }
.fuente { font-size: 12px; color: var(--muted); margin-top: 16px; word-break: break-all; }

.aviso {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: #2a2522; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; display: flex; gap: 12px; align-items: center;
}
.aviso.visible { opacity: 1; pointer-events: auto; }
.aviso button { background: none; border: 0; color: #ffb39f; font-weight: 600; cursor: pointer; }

/* ---------- voz y login (modo servidor) ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 50;
  background: var(--accent); color: #fff; border: 0; border-radius: 99px; padding: 14px 20px;
  font-size: 17px; font-weight: 600; box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}
.fab[hidden] { display: none; }
.contenido { padding-bottom: 90px; }
.hablar-mini { padding: 6px 10px; font-size: 14px; white-space: nowrap; }
.btn.grande { padding: 14px; font-size: 16px; }
.btn.on { background: var(--st-cerrado); color: #fff; border-color: var(--st-cerrado); }
.btn:disabled { opacity: .5; }
.ayuda { color: var(--muted); font-size: 13px; }
#vozTexto {
  width: 100%; min-height: 84px; padding: 10px; margin: 8px 0 10px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--text); resize: vertical;
}
#vozRes { margin-top: 12px; }
.propuesta { border: 1px solid var(--line); border-left: 4px solid var(--st-cliente); border-radius: 10px; padding: 10px 12px; background: var(--bg); }
.propuesta.peligro { border-left-color: var(--st-cerrado); }
.propuesta p { margin: 4px 0 8px; }
.propuesta ul { margin: 0 0 10px; padding-left: 18px; font-size: 14px; }
.opciones { display: grid; gap: 8px; margin-top: 8px; }
.opciones .btn { text-align: left; }
.error { color: var(--st-cerrado); font-size: 14px; margin: 6px 0; }
.error[hidden] { display: none; }
.login { padding: 24px 20px 28px; }
.login h2 { margin: 0 0 16px; font-size: 20px; }
.login .btn { width: 100%; padding: 13px; font-size: 16px; }
.login input { font-size: 16px; }
#login::backdrop { background: var(--bg); }
