:root {
  --bg: #f0f2f5; --surface: #ffffff; --surface-2: #f7f8fa; --border: #e1e0d9; --grid: #e1e0d9;
  --text: #0b0b0b; --text-2: #52514e; --muted: #898781;
  --accent: #128c7e; --accent-strong: #075e54; --accent-soft: #dcf8c6;
  --bubble-in: #ffffff; --bubble-out: #d9fdd3;
  --s1: #2a78d6; --s2: #eb6834; --good: #0ca30c; --warn: #fab219; --bad: #d03b3b;
  --unread: #25d366;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --border: #2c2c2a; --grid: #2c2c2a;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #898781;
    --accent: #00a884; --accent-strong: #00c49a; --accent-soft: #005c4b;
    --bubble-in: #232322; --bubble-out: #005c4b;
    --s1: #3987e5; --s2: #d95926;
  }
}
:root[data-theme="dark"] {
  --bg: #0d0d0d; --surface: #1a1a19; --surface-2: #232322; --border: #2c2c2a; --grid: #2c2c2a;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #898781;
  --accent: #00a884; --accent-strong: #00c49a; --accent-soft: #005c4b;
  --bubble-in: #232322; --bubble-out: #005c4b;
  --s1: #3987e5; --s2: #d95926;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1.2em; margin: 6px 0 0; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; }
.row.right { justify-content: flex-end; }
h1, h3 { margin: 0 0 8px; }
label { display: block; font-size: 12px; color: var(--text-2); margin: 8px 0; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
.check { display: flex; align-items: center; gap: 6px; margin: 0; white-space: nowrap; }
.check input { width: auto; }
.btn { padding: 8px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.badge { background: var(--unread); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 600; padding: 1px 7px; min-width: 18px; text-align: center; display: inline-block; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.pill.st-nuevo { border-color: var(--s1); color: var(--s1); }
.pill.st-seguimiento { border-color: var(--warn); color: #a36f00; }
.pill.st-cotizado { border-color: var(--s2); color: var(--s2); }
.pill.st-vendido { border-color: var(--good); color: var(--good); }
.pill.st-perdido { border-color: var(--muted); color: var(--muted); }
.acc-tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px; color: #fff; white-space: nowrap; }

/* ----- login ----- */
.login { height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; margin-top: 12px; }

/* ----- layout ----- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--accent-strong); color: #fff; }
.brand { font-weight: 700; font-size: 16px; }
#nav { display: flex; gap: 4px; flex: 1; }
#nav button { background: transparent; border: 0; color: #fff; opacity: .8; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
#nav button.active, #nav button:hover { opacity: 1; background: rgba(255,255,255,.15); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-right .btn { color: #fff; }
.topbar-right .muted { color: rgba(255,255,255,.75); }
.view { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.view.inbox { padding: 0; display: flex; overflow: hidden; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; background: var(--muted); }
.dot.conectado { background: var(--good); } .dot.qr { background: var(--warn); } .dot.reconectando, .dot.iniciando { background: var(--s2); }

/* ----- columnas (un WhatsApp Web por vendedor) ----- */
.view.board { padding: 0; overflow-x: auto; overflow-y: hidden; display: flex; flex-direction: column; }
.columns { display: flex; flex: 1; min-height: 0; min-width: max-content; }
.column { width: 400px; flex-shrink: 0; height: 100%; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); }
.col-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; color: #fff; }
.col-head b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-head .phone { opacity: .85; font-size: 11px; white-space: nowrap; }
.col-head .badge { background: #fff; color: var(--text); }
.col-head .dot { background: rgba(255,255,255,.45); }
.col-head .dot.conectado { background: #7CFC9A; }
.col-head .dot.qr { background: #ffd54f; }
.col-list-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.col-list-wrap .col-search { border-radius: 0; border-width: 0 0 1px; padding: 7px 12px; }
.col-list { flex: 1; overflow-y: auto; }
.col-list .chat { padding: 8px 12px; }
.col-list .avatar { width: 34px; height: 34px; font-size: 12px; }
.col-conv { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.col-conv .conv-header { padding: 8px 10px; }
.col-conv .conv-header::before { content: none; }
.col-conv .messages { padding: 12px; }
.col-conv .msg { max-width: 85%; }
.col-conv .composer { padding: 8px 10px; }
.col-conv .msg img { max-width: 240px; max-height: 240px; }
.col-empty { padding: 30px 16px; color: var(--muted); text-align: center; }
.col-mode { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 6px; padding: 2px 8px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.col-mode:hover, .col-mode.on { background: #fff; color: var(--text); }
.col-lists { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.lists-bar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 10px; background: var(--surface); border-bottom: 1px solid var(--border); }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 2px 9px; font-size: 12px; cursor: pointer; color: var(--text-2); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip b { font-weight: 600; }
.col-cards { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.ccard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.ccard .head { display: flex; gap: 6px; align-items: center; margin-bottom: 4px; }
.ccard .head .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard .resumen { color: var(--text-2); margin: 4px 0; }
.ccard .accion { margin: 4px 0; padding: 6px 8px; background: var(--surface-2); border-radius: 6px; }
.ccard .accion b { color: var(--accent); }
.ccard .prods { font-size: 12px; color: var(--muted); }
.ccard .foot { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.ccard .foot select { width: auto; padding: 3px 6px; font-size: 12px; }
.ccard.seguido { opacity: .65; }
.pill.pr-alta { border-color: var(--bad); color: var(--bad); }
.pill.pr-media { border-color: var(--warn); color: #a36f00; }
.pill.pr-baja { border-color: var(--muted); color: var(--muted); }
.pill.cat-comprador { border-color: var(--good); color: var(--good); }
.pill.cat-cotizo { border-color: var(--s2); color: var(--s2); }
.pill.cat-interesado { border-color: var(--s1); color: var(--s1); }
.pill.cat-frio, .pill.cat-no_cliente { border-color: var(--muted); color: var(--muted); }
.due-hoy { color: var(--bad); font-weight: 600; }
@media (max-width: 900px) {
  .columns { scroll-snap-type: x mandatory; }
  .column { width: 100vw; scroll-snap-align: start; }
}

/* ----- embudo (kanban por tipo de cliente) ----- */
.view.funnel { padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.funnel-bar { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.funnel-bar select, .funnel-bar input { width: auto; min-width: 160px; }
.funnel-cols { flex: 1; min-height: 0; display: flex; gap: 10px; padding: 12px; overflow-x: auto; }
.fcol { width: 290px; flex-shrink: 0; display: flex; flex-direction: column; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; min-height: 0; }
.fcol.over { outline: 2px dashed var(--accent); outline-offset: -2px; }
.fcol-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); font-weight: 600; border-top: 4px solid var(--fcol-color, var(--muted)); border-radius: 12px 12px 0 0; }
.fcol-head .n { font-weight: 400; color: var(--muted); }
.fcol-head input { width: auto; margin: 0; }
.fcol-body { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.fcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; cursor: grab; display: flex; gap: 8px; align-items: flex-start; }
.fcard:hover { border-color: var(--accent); }
.fcard.dragging { opacity: .4; }
.fcard.sel { background: var(--accent-soft); border-color: var(--accent); }
.fcard input { width: auto; margin: 3px 0 0; cursor: pointer; }
.fcard .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fcard .sum { color: var(--text-2); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fcard .meta { display: flex; gap: 4px; align-items: center; margin-top: 4px; flex-wrap: wrap; }
.fcard.seguido { opacity: .6; }
.fcol-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 8px; }
.fcol.pending .fcol-body { align-items: stretch; }
.pending-acc { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.modal-card.wide { max-width: 760px; }
.drafts { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow-y: auto; }
.draft { display: grid; grid-template-columns: 170px 1fr auto; gap: 8px; align-items: start; font-size: 13px; }
.draft textarea { font-size: 13px; }
.draft .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.camp-log { max-height: 40vh; overflow-y: auto; font-size: 13px; }
.camp-log div { padding: 4px 0; border-bottom: 1px solid var(--border); }
.camp-log .ok { color: var(--good); } .camp-log .err { color: var(--bad); }
.radio { display: flex; gap: 14px; margin: 8px 0; }
.radio label { display: flex; gap: 6px; align-items: center; margin: 0; }
.radio input { width: auto; }
.preview-img { max-height: 120px; border-radius: 8px; display: block; margin-top: 6px; }
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin: 8px 0; }
.progress i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* ----- lista de chats ----- */
.chatlist { width: 340px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.filters { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.filters .row > * { flex: 1; }
.chats { overflow-y: auto; flex: 1; }
.chat { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.chat:hover { background: var(--surface-2); }
.chat.active { background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.chat .top { display: flex; justify-content: space-between; gap: 6px; align-items: baseline; }
.chat .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.chat .preview { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.chat .meta { display: flex; gap: 6px; align-items: center; margin-top: 3px; }
.chat.unanswered .preview::before { content: "● "; color: var(--s2); }

/* ----- conversacion ----- */
.conversation { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
.empty { flex: 1; display: grid; place-items: center; color: var(--muted); }
.conv { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.conv-header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.conv-header .name { font-weight: 600; }
.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; font-size: 11px; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 2px 10px; margin: 8px 0; }
.msg { max-width: 70%; padding: 6px 10px; border-radius: 10px; background: var(--bubble-in); align-self: flex-start; box-shadow: 0 1px 1px rgba(0,0,0,.08); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg .foot { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 10px; color: var(--muted); margin-top: 2px; }
.msg .by { font-size: 10px; color: var(--accent); font-weight: 600; }
.msg img { max-width: 320px; max-height: 320px; border-radius: 8px; display: block; cursor: zoom-in; }
.msg audio { max-width: 280px; display: block; }
.msg .file { display: inline-block; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.msg .media-btn { font-size: 12px; }
.ticks.read { color: #53bdeb; }
.composer { display: flex; gap: 8px; padding: 10px 16px; background: var(--surface); border-top: 1px solid var(--border); }
.composer textarea { max-height: 140px; overflow-y: hidden; }
.loadmore { align-self: center; }

/* ----- panel info ----- */
.info { width: 300px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--surface); padding: 16px; overflow-y: auto; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; margin: 0 0 10px; }
.info dt { color: var(--muted); } .info dd { margin: 0; }

/* ----- analiticas ----- */
.filters-row { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.filters-row select { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 700; line-height: 1.1; }
.kpi .l { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.kpi.alert .v { color: var(--bad); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 12px; margin-bottom: 16px; }
figure { margin: 0; }
figcaption { font-weight: 600; margin-bottom: 8px; }
.chart svg { width: 100%; height: auto; display: block; }
.chart .bar { transition: opacity .1s; }
.chart .bar:hover { opacity: .8; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .label { fill: var(--text-2); font-weight: 600; }
.chart line.grid { stroke: var(--grid); }
.chart line.axis { stroke: var(--border); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.tip { position: fixed; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 4px 12px rgba(0,0,0,.15); z-index: 50; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; font-size: 12px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.link { cursor: pointer; } tr.link:hover { background: var(--surface-2); }
.analytics .card { margin-bottom: 16px; }

/* ----- cuentas / usuarios ----- */
.account-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; margin-top: 16px; }
.account-card .qr { width: 100%; max-width: 260px; display: block; margin: 8px auto; border-radius: 8px; background: #fff; }
.account-card .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }
.accounts form.row input { flex: 1; }

/* ----- modal / toast ----- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-card { width: 100%; max-width: 480px; max-height: 90vh; overflow: auto; }
.modal-card.wide { max-width: 760px; }
.modal-card img.full { max-width: 100%; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 60; }

/* ----- movil ----- */
@media (max-width: 900px) {
  .info { display: none; }
  .info.show { display: block; position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -4px 0 16px rgba(0,0,0,.2); }
  .chatlist { width: 100%; }
  .inbox.has-chat .chatlist { display: none; }
  .inbox:not(.has-chat) .conversation { display: none; }
  .conv-header::before { content: "‹"; font-size: 24px; cursor: pointer; padding: 0 6px; }
  .topbar { flex-wrap: wrap; gap: 8px; }
  .msg { max-width: 88%; }
  .view { padding: 12px; }
}
