:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaf0;
  --muted: #9097a6;
  --accent: #ff6a2b;
  --accent-ink: #1a0d06;
  --ok: #35c27a;
  --warn: #f2b33d;
  --err: #ef5350;
  --info: #5aa2ff;
  --wa: #25d366;
  --mail: #5aa2ff;
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f0f2f5; --line: #e2e5ea; --text: #161a22; --muted: #5d6576;
    --accent-ink: #fff; color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: inherit; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); min-height: 1em; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 28px; display: grid; gap: 14px; text-align: center; justify-items: center; }
.login-card input { width: 100%; }

/* ---------- layout ---------- */
.shell { min-height: 100%; }
.view { padding: 18px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 980px; margin: 0 auto; }
.nav { position: fixed; z-index: 10; bottom: 0; left: 0; right: 0; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(12px); border-top: 1px solid var(--line); display: flex; }
.nav .brand, .nav .desk { display: none; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; position: relative; }
.nav a i { font-style: normal; font-size: 20px; line-height: 1; }
.nav a.active { color: var(--accent); }
.badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--err); color: #fff; font-size: 10px; font-weight: 700; border-radius: 10px; padding: 1px 6px; min-width: 18px; text-align: center; }
.badge:empty { display: none; }
@media (min-width: 900px) {
  .nav { top: 0; right: auto; width: 220px; height: auto; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding: 16px 10px; gap: 2px; }
  .nav .brand { display: flex; gap: 10px; align-items: center; font-weight: 700; padding: 6px 10px 18px; }
  .nav .desk { display: flex; }
  .nav .mob { display: none; }
  .nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; font-size: 14px; padding: 10px 12px; border-radius: 10px; }
  .nav a.active { background: var(--panel-2); }
  .nav a i { font-size: 17px; width: 20px; text-align: center; }
  .badge { position: static; margin-left: auto; }
  .view { margin-left: 220px; padding: 28px 32px 40px; max-width: 1060px; }
}

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
a.card { text-decoration: none; color: inherit; }
.grid { display: grid; gap: 10px; }
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { display: grid; gap: 2px; text-decoration: none; }
.kpi .v { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.alert .v { color: var(--warn); }
.status { display: grid; gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .status { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.warn { background: var(--warn); }
.dot.err { background: var(--err); }
.bar { height: 8px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

.btn { appearance: none; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #06210f; }
.btn.danger { color: var(--err); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.mic { width: 44px; height: 44px; padding: 0; justify-content: center; border-radius: 50%; font-size: 18px; flex: none; }
.btn.mic.rec { background: var(--err); border-color: var(--err); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--err) 25%, transparent); } }

input, textarea, select { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; }
textarea { resize: vertical; min-height: 90px; }
input:focus, textarea:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent) 50%, transparent); border-color: var(--accent); }
label.field { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
label.check { display: flex; gap: 10px; align-items: center; }
label.check input { width: auto; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.tab { white-space: nowrap; border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 20px; padding: 6px 12px; font: inherit; font-size: 13px; cursor: pointer; }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }

.list { display: grid; gap: 8px; }
.item { display: grid; gap: 6px; text-decoration: none; border-left: 4px solid var(--line); cursor: pointer; }
.item.u-alta { border-left-color: var(--err); }
.item.u-media { border-left-color: var(--warn); }
.item .top { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.item .who { color: var(--text); font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .q { color: var(--warn); }
.chip { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.ch { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; }
.ch.whatsapp { background: color-mix(in srgb, var(--wa) 20%, transparent); color: var(--wa); }
.ch.email { background: color-mix(in srgb, var(--mail) 20%, transparent); color: var(--mail); }
.ch.test { background: var(--panel-2); color: var(--muted); }

/* ---------- conversación ---------- */
.convo { display: flex; flex-direction: column; gap: 6px; max-height: 46vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 85%; padding: 8px 11px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.msg.in { background: var(--panel-2); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: color-mix(in srgb, var(--accent) 18%, var(--panel)); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .t { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; }
.qbox { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 40%, transparent); border-radius: 12px; padding: 12px; }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100dvh - var(--nav-h) - 70px - env(safe-area-inset-bottom)); }
@media (min-width: 900px) { .chat-wrap { height: calc(100dvh - 80px); } }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 2px 12px; }
.chat-log .msg { max-width: 88%; }
.chat-log .msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.chat-log .msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.chat-log .msg.user .t { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding-top: 8px; border-top: 1px solid var(--line); }
.composer textarea { resize: none; min-height: 44px; max-height: 140px; height: 44px; border-radius: 22px; padding: 11px 16px; }
.typing { color: var(--muted); font-size: 13px; padding: 4px 6px; }
.ref { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---------- actividad ---------- */
.ev { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 14px; }
.ev .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; grid-column: 2; }
.ev .dot { margin-top: 6px; }
.ev.info .dot { background: var(--info); }
.ev.ok .dot { background: var(--ok); }
.ev.warn .dot { background: var(--warn); }
.ev.error .dot { background: var(--err); }

/* ---------- consumo ---------- */
.chart { width: 100%; height: 180px; display: block; }
.chart rect { fill: var(--accent); }
.chart rect:hover { fill: var(--warn); }
.chart text { fill: var(--muted); font-size: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.qr { background: #fff; padding: 10px; border-radius: 12px; width: 240px; max-width: 100%; }
.steps { padding-left: 20px; margin: 6px 0 12px; color: var(--muted); font-size: 14px; }
.steps li { margin: 4px 0; }
.form { display: grid; gap: 12px; }
.form-2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.more-links { display: grid; gap: 8px; }
.more-links a { display: flex; gap: 12px; align-items: center; text-decoration: none; padding: 16px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.head h1 { flex: 1; }
.back { text-decoration: none; font-size: 22px; padding: 0 6px; }
