:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-2: #eef3f1;
  --text: #13201c;
  --muted: #5d6f69;
  --line: #dde6e2;
  --brand: #128c7e;
  --brand-2: #0b6b60;
  --brand-soft: #dcf3ee;
  --accent: #25d366;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --chat-bg: #efeae2;
  --shadow: 0 1px 2px rgba(16, 40, 32, .06), 0 8px 24px rgba(16, 40, 32, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1513; --surface: #16201d; --surface-2: #1d2a26; --text: #e6efec; --muted: #93a8a1;
    --line: #26352f; --brand: #25b39f; --brand-2: #1c9483; --brand-soft: #173c35; --danger-soft: #3a1d1a;
    --bubble-in: #1f2c28; --bubble-out: #0f4a3f; --chat-bg: #0b1210; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1513; --surface: #16201d; --surface-2: #1d2a26; --text: #e6efec; --muted: #93a8a1;
  --line: #26352f; --brand: #25b39f; --brand-2: #1c9483; --brand-soft: #173c35; --danger-soft: #3a1d1a;
  --bubble-in: #1f2c28; --bubble-out: #0f4a3f; --chat-bg: #0b1210; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
.hidden { display: none !important; }
h2 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.01em; }
h3 { margin: 0 0 8px; font-size: 16px; }
.muted { color: var(--muted); }
small { font-size: 12.5px; }
code { background: var(--surface-2); padding: 3px 8px; border-radius: 6px; font-size: 13px; word-break: break-all; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; }
.brand.big { font-size: 24px; justify-content: center; }
.logo {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--brand)); color: #fff; font-weight: 800;
}

/* ---------- botones ---------- */
.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 16px; border-radius: 10px; font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--brand); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.link { background: none; border: 0; color: var(--brand); font: inherit; font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

/* ---------- formularios ---------- */
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
input, textarea, select {
  width: 100%; font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; align-items: end; }
.input-btn { display: flex; gap: 6px; }
.error { color: var(--danger); min-height: 1em; margin: 4px 0; font-size: 14px; }

.toggle { flex-direction: row !important; align-items: center; gap: 10px !important; cursor: pointer; font-weight: 500 !important; }
.toggle input, .bot-switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; flex: none; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s;
}
input:checked + .switch { background: var(--accent); }
input:checked + .switch::after { transform: translateX(18px); }
input:focus-visible + .switch { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- entrar ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: var(--shadow); text-align: center; }
.auth-card form { text-align: left; margin-top: 18px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; margin-bottom: 12px; }

/* ---------- cabecera ---------- */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-right: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #a0aca8; }
.status.on .dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(37, 211, 102, .18); }
.bot-switch { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; position: relative; }

.tabs { display: flex; gap: 4px; padding: 10px 24px 0; overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--surface); }
.tabs button {
  border: 0; background: none; font: inherit; font-weight: 600; color: var(--muted);
  padding: 10px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

main { max-width: 1080px; margin: 0 auto; padding: 24px 24px 120px; }
.section-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.section-head p { margin: 0; max-width: 620px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin-top: 16px; box-shadow: var(--shadow); }

/* ---------- respuestas ---------- */
.rules { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.rule {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; cursor: pointer; transition: border-color .15s, transform .15s;
}
.rule:hover { border-color: var(--brand); transform: translateY(-1px); }
.rule img { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--surface-2); }
.rule .body { padding: 14px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--brand-soft); color: var(--brand-2); padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; }
.reply-preview { white-space: pre-wrap; font-size: 14px; color: var(--text); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.rule .foot { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--muted); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); border: 2px dashed var(--line); border-radius: 14px; }

/* ---------- editor ---------- */
dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 20, 18, .45); }
dialog form { padding: 22px; max-height: calc(100vh - 48px); overflow: auto; }
.drop {
  border: 2px dashed var(--line); border-radius: 12px; padding: 16px; text-align: center; margin-bottom: 14px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; transition: border-color .15s, background .15s;
}
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop img { max-width: 100%; max-height: 260px; border-radius: 10px; }

/* ---------- probar ---------- */
.chat { background: var(--chat-bg); border-radius: 14px 14px 0 0; border: 1px solid var(--line); border-bottom: 0;
  min-height: 320px; max-height: 60vh; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; box-shadow: 0 1px 1px rgba(0,0,0,.08); font-size: 14.5px; }
.bubble.in { align-self: flex-end; background: var(--bubble-out); }
.bubble.out { align-self: flex-start; background: var(--bubble-in); }
.bubble img { display: block; max-width: 280px; width: 100%; border-radius: 8px; margin-bottom: 6px; }
.bubble .src { display: block; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.chat-input { display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 0 0 14px 14px; padding: 10px; }

/* ---------- registro ---------- */
.logs { display: flex; flex-direction: column; gap: 10px; }
.log { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; }
.log .who { font-weight: 700; }
.log .when, .log .status { font-size: 12.5px; color: var(--muted); }
.log .msg, .log .rep { white-space: pre-wrap; font-size: 14px; }
.log .rep { color: var(--muted); }

.kv { display: flex; align-items: center; gap: 10px; margin: 8px 0; flex-wrap: wrap; }
.kv span { min-width: 150px; color: var(--muted); }
.user-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }

/* ---------- barra guardar / toast ---------- */
.savebar {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 10px 12px 10px 20px; border-radius: 14px;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 12px 30px rgba(0,0,0,.25); width: max-content; max-width: calc(100vw - 32px);
}
.savebar .btn.ghost { color: var(--bg); }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 30; background: var(--brand); color: #fff; padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; }
.toast.err { background: var(--danger); }

@media (max-width: 720px) {
  .top { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .status { order: 3; width: 100%; }
  .tabs { padding: 6px 8px 0; }
  main { padding: 16px 16px 120px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .log { grid-template-columns: 1fr; }
  .savebar { left: 16px; right: 16px; transform: none; width: auto; flex-wrap: wrap; }
  .bubble { max-width: 90%; }
}

/* ---------- planes ---------- */
.plan-banner { max-width: 1080px; margin: 16px auto 0; padding: 10px 16px; border-radius: 12px; background: var(--brand-soft); color: var(--brand-2); font-weight: 600; font-size: 14px; }
.plan-banner.warn { background: #fff4d6; color: #7a5200; }
.plan-banner.expired { background: var(--danger-soft); color: var(--danger); }
.users .user-row { align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 0; }
.small { font-size: 12.5px; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; }
.pill.ok { background: var(--brand-soft); color: var(--brand-2); }
.pill.warn { background: #fff4d6; color: #7a5200; }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.grid-user { display: grid; grid-template-columns: 1.2fr 1.2fr .6fr 1.4fr auto; gap: 10px; align-items: end; }
@media (max-width: 720px) { .grid-user { grid-template-columns: 1fr 1fr; } .plan-banner { margin: 12px 16px 0; } }
.plan-banner.as { background: #e8e4ff; color: #3b2a8f; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .plan-banner.as { background: #2a2350; color: #d9d2ff; } }
.apps { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 4px 16px; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
details.adv { border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-bottom: 10px; }
details.adv summary { cursor: pointer; font-weight: 700; }
details.adv[open] summary { margin-bottom: 10px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.days label { flex-direction: row !important; align-items: center; gap: 4px !important; margin: 0 !important; border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.days input { width: auto; }
pre.code { background: var(--surface-2); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: 13px; white-space: pre; }
.help { display: block; margin-top: 6px; font-weight: 400; font-size: 12.5px; line-height: 1.45; color: var(--brand-2); background: var(--brand-soft); border-radius: 8px; padding: 6px 10px; }
.pill.new { background: #e8e4ff; color: #3b2a8f; }
.center { text-align: center; }

/* Pasos de una respuesta */
#steps-wrap { margin-bottom: 12px; }
.steps-head { margin-bottom: 8px; }
.step { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface-2); }
.step.over { border-color: var(--brand); }
.step-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.step-top .kind { font-weight: 700; margin-right: auto; }
.step-top label { display: inline-flex; flex-direction: row; align-items: center; gap: 6px; margin: 0; font-size: 13px; color: var(--muted); white-space: nowrap; }
.step-top input[type=number] { width: 64px; padding: 4px 6px; }
.step textarea { width: 100%; }
.step img, .step video { max-width: 100%; max-height: 220px; border-radius: 10px; display: block; margin-bottom: 8px; }
.step audio { width: 100%; margin-bottom: 4px; }
.step .file { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface); border-radius: 10px; margin-bottom: 4px; word-break: break-all; }
.step-add { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 8px; }
.rule .media-note { font-size: 13px; color: var(--muted); margin-top: 4px; }

.hist { margin-top: 10px; }
.hist-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.hist-row .small { font-size: 13px; }

/* Contactos (CRM) */
.ct-bar { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; margin: 10px 0 6px; }
.ct-bar input, .ct-bar select { padding: 8px 10px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { background: var(--surface); border: 0; padding: 8px 12px; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.active { background: var(--brand); color: #fff; }
.ct-list { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.ct-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.ct-row b[contenteditable] { outline: none; border-bottom: 1px dashed transparent; }
.ct-row b[contenteditable]:focus { border-bottom-color: var(--brand); }
.ct-side { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.ct-side select { padding: 5px 8px; }
.ct-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.ct-tags .chip { display: inline-flex; align-items: center; gap: 4px; }
.ct-tags .x { background: none; border: 0; cursor: pointer; color: inherit; font-size: 14px; padding: 0 2px; line-height: 1; }
.ct-tags input { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 2px 8px; font-size: 12.5px; }
.ct-notes { grid-column: 1 / -1; width: 100%; }
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr); gap: 10px; overflow-x: auto; padding: 10px 0; }
.kcol { background: var(--surface-2); border-radius: 14px; padding: 10px; min-height: 120px; }
.kcol h4 { margin: 0 0 8px; font-size: 14px; }
.kcard { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 8px; display: flex; flex-direction: column; gap: 4px; }
.kcard select { padding: 4px 6px; font-size: 13px; }
.tagsline { display: flex; flex-wrap: wrap; gap: 4px; }
@media (max-width: 720px) { .ct-bar { grid-template-columns: 1fr 1fr; } .ct-row { grid-template-columns: 1fr; } }
.kw-box { min-height: 0; line-height: 1.5; }

/* estadisticas del registro */
.stats { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 20px; margin: 12px 0 16px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; } .stat span { color: var(--muted); font-size: 12px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 70px; margin: 14px 4px 4px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar i { display: block; width: 100%; max-width: 36px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 3px; }
.bar em { font-style: normal; font-size: 11px; color: var(--muted); margin-top: 4px; }
.stats h4 { margin: 16px 0 8px; }
.miss-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--line); }
.miss-row span { flex: 1; } .miss-row b { color: var(--muted); }

/* embudo de ventas */
.funnel { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 6px 0 4px; }
.fstep { background: var(--surface-2); border-radius: 10px; padding: 8px 14px; text-align: center; min-width: 96px; }
.fstep b { display: block; font-size: 20px; } .fstep span { font-size: 12px; color: var(--muted); }
.funnel i { font-style: normal; color: var(--muted); font-size: 13px; }

/* conversacion de un cliente en el registro */
.conv { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; font-size: 14px; border: 1px solid var(--line); }
.bubble.them { align-self: flex-start; background: var(--surface); }
.bubble.me { align-self: flex-end; background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.bubble.note { align-self: center; font-size: 12px; color: var(--muted); background: transparent; border: 0; }
.bubble .when { font-size: 11.5px; color: var(--muted); margin-left: 6px; }
.log .who[data-name] { cursor: pointer; text-decoration: underline dotted; }

.cli-row { display: grid; grid-template-columns: 120px 150px 1fr 150px; gap: 10px; align-items: start; padding: 7px 0; border-top: 1px solid var(--line); font-size: 14px; }
.cli-row .when { font-size: 12px; color: var(--muted); } .cli-row .who { cursor: pointer; }
.cli-row .cli-msg { white-space: pre-wrap; } .cli-row .cli-st { font-size: 12px; color: var(--muted); text-align: right; } .cli-row .cli-st.bad { color: #e0a000; }
@media (max-width: 720px) { .cli-row { grid-template-columns: 1fr; gap: 2px; } .cli-row .cli-st { text-align: left; } }
