:root {
  --bg: #f5f6f8; --panel: #ffffff; --text: #16181d; --muted: #6b7280; --line: #e5e7eb;
  --accent: #16a34a; --accent-ink: #ffffff; --accent-soft: #dcfce7;
  --danger: #dc2626; --danger-soft: #fee2e2; --warn: #b45309; --warn-soft: #fef3c7; --info-soft: #e0e7ff;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115; --panel: #171a21; --text: #e7e9ee; --muted: #9aa1ad; --line: #272b35;
    --accent: #22c55e; --accent-ink: #06260f; --accent-soft: #12321e;
    --danger: #f87171; --danger-soft: #3a1717; --warn: #fbbf24; --warn-soft: #3a2a0c; --info-soft: #1e2440;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 12px; } h3 { font-size: 15px; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

/* Layout */
.top { position: sticky; top: 0; z-index: 10; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-in { max-width: 1200px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.brand i { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); display: inline-block; }
nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
nav a { text-decoration: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); white-space: nowrap; }
nav a.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; } .grow { flex: 1; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.split { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.split > * { min-width: 0; }
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; }
  .top-in { gap: 8px 10px; }
  .top-in nav { order: 3; flex-basis: 100%; }
  .brand { flex: 1; }
  main { padding-top: 14px; }
}

/* Controles */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.pri { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.dan { color: var(--danger); } .btn.dan.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  border: 1px solid var(--line); background: var(--bg); padding: 7px 10px; border-radius: 8px; width: 100%; min-width: 0;
}
textarea { min-height: 110px; resize: vertical; }
label.f { display: block; margin-bottom: 12px; } label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }

/* Chips y estados */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 13px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--accent); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--danger); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.t-tiene { background: var(--accent-soft); } .t-no { background: var(--danger-soft); } .t-rev { background: var(--warn-soft); }
.t-enviado { background: var(--accent-soft); } .t-saltado { background: var(--bg); border: 1px solid var(--line); } .t-error { background: var(--danger-soft); }
.cats { display: flex; flex-direction: column; gap: 4px; }
.cat { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; cursor: pointer; border: 1px solid transparent; }
.cat:hover { background: var(--bg); } .cat.on { background: var(--accent-soft); font-weight: 600; }
.cat .n { margin-left: auto; color: var(--muted); font-size: 13px; }
@media (max-width: 760px) { .cats { flex-direction: row; overflow-x: auto; } .cat { white-space: nowrap; } }

/* Tablas */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--bg); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.off td { opacity: .5; }
td.wrap { max-width: 360px; white-space: normal; word-break: break-word; }
td.nw { white-space: nowrap; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.stat { background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.stat b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 10px 0; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

/* Log */
.log:empty::before { content: 'Sin actividad todavía. Aquí verás en vivo lo que hace el bot.'; color: #6b7280; }
.log { background: #0b0d10; color: #d7dbe2; font: 12.5px/1.5 ui-monospace, Menlo, monospace; border-radius: 8px; padding: 10px 12px; height: 320px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }
.log .error { color: #fca5a5; } .log .ok { color: #86efac; } .log .salto { color: #9ca3af; } .log .aviso { color: #fcd34d; } .log .pausa { color: #93c5fd; } .log .fin { color: #fff; font-weight: 700; } .log .wa { color: #c4b5fd; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }

/* QR */
.qr { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px; }
.qr img { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 10px; }

/* Modal / toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 50; overflow-y: auto; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border-radius: 12px; padding: 20px; width: 100%; max-width: 560px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-box.wide { max-width: 860px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: calc(100% - 32px); }
.toast.err { background: var(--danger); color: #fff; }

/* Login */
.login { max-width: 360px; margin: 12vh auto; }

.ejemplo { background: var(--accent-soft); border-radius: 10px 10px 2px 10px; padding: 8px 12px; margin: 6px 0; white-space: pre-wrap; max-width: 520px; }
.hint { font-size: 13px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 8px 10px; }

/* Sugerencias de zona sacadas del historial de chat */
.sug { margin-top: 4px; padding: 4px 6px; border-radius: 6px; background: #fef9c322; border: 1px dashed #ca8a04; font-size: 12px; }
.sug .ev { margin-top: 2px; font-style: italic; white-space: normal; max-width: 260px; }
.btn.xs { padding: 0 6px; font-size: 12px; line-height: 18px; min-height: 0; }

/* Respuestas como listado: 2 líneas por fila, clic para ver completo (un mensaje por línea) */
td.resp { min-width: 340px; max-width: 520px; cursor: pointer; }
td.resp .clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; white-space: normal; word-break: break-word; }
td.resp .sep { color: var(--muted); }
td.resp.abierto .clamp { display: block; }
td.resp.abierto .m { display: block; padding: 2px 0; border-bottom: 1px dashed var(--line); }
td.resp.abierto .sep { display: none; }
tr[data-r] td { vertical-align: middle; }
tr[data-r] td:first-child { white-space: nowrap; }
