:root {
  --bg: #070b16;
  --bg-2: #0c1222;
  --card: rgba(18, 25, 45, 0.72);
  --card-solid: #121a2e;
  --input: #0b1120;
  --text: #e8edf7;
  --muted: #8b97b3;
  --border: rgba(148, 163, 214, 0.14);
  --border-strong: rgba(148, 163, 214, 0.26);
  --primary: #22c55e;
  --primary-2: #06b6d4;
  --accent: #8b5cf6;
  --grad: linear-gradient(135deg, #22c55e 0%, #06b6d4 55%, #8b5cf6 100%);
  --primary-text: #04130a;
  --danger: #f87171;
  --warn: #fbbf24;
  --ok: #4ade80;
  --pill: rgba(34, 197, 94, 0.12);
  --pill-text: #86efac;
  --pill-alt: rgba(139, 92, 246, 0.16);
  --pill-alt-text: #c4b5fd;
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, 0.7);
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 100% -10%, rgba(6, 182, 212, 0.10), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(139, 92, 246, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
svg { width: 18px; height: 18px; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
.ok { color: var(--ok); }
.nowrap { white-space: nowrap; }
h1, h2, h3 { margin: 0 0 12px; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 700; }
h3 { font-size: 18px; font-weight: 700; }
.grad { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- Controles ---------- */
button {
  font: inherit; font-weight: 500; display: inline-flex; align-items: center; gap: 8px; justify-content: center;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.03); color: var(--text); cursor: pointer;
  transition: transform 0.15s, background 0.15s, border-color 0.15s, box-shadow 0.15s, filter 0.15s;
}
button:hover { background: rgba(255, 255, 255, 0.07); border-color: rgba(148, 163, 214, 0.4); }
button:active { transform: translateY(1px); }
button.primary {
  background: var(--grad); border: none; color: #fff; font-weight: 600;
  box-shadow: 0 8px 24px -8px rgba(6, 182, 212, 0.6);
}
button.primary:hover { filter: brightness(1.08); box-shadow: 0 10px 28px -8px rgba(6, 182, 212, 0.8); }
button.big { width: 100%; padding: 12px 16px; font-size: 15px; border-radius: 12px; }
button.danger { color: var(--danger); border-color: rgba(248, 113, 113, 0.3); }
button.danger:hover { background: rgba(248, 113, 113, 0.1); }
button.ghost { background: transparent; border-color: transparent; }

input, textarea, select {
  font: inherit; width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--input); color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder, textarea::placeholder { color: #5b6684; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.18);
}
input[type='checkbox'], input[type='radio'] { width: 16px; height: 16px; margin-top: 0; flex: none; accent-color: var(--primary); }
textarea { resize: vertical; }
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13px; color: #c9d2e6; }
label > input, label > textarea, label > select, label > .input-icon { margin-top: 6px; font-weight: 400; }
label small { font-weight: 400; }
label.inline { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; margin-right: 14px; color: var(--text); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
.row > label { flex: 1 1 160px; }
.row > label.small { flex: 0 0 90px; }
.input-icon { position: relative; display: block; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.input-icon input { padding-left: 40px; margin: 0; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px;
  backdrop-filter: blur(14px); box-shadow: var(--shadow);
}
.card.center { text-align: center; max-width: 520px; margin: 0 auto; }
.card.narrow { max-width: 760px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.login-glow {
  position: absolute; inset: auto; width: 720px; height: 720px; border-radius: 50%;
  background: conic-gradient(from 90deg, rgba(34, 197, 94, 0.35), rgba(6, 182, 212, 0.35), rgba(139, 92, 246, 0.35), rgba(34, 197, 94, 0.35));
  filter: blur(120px); opacity: 0.55; animation: spin 18s linear infinite; pointer-events: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-wrap {
  position: relative; display: grid; grid-template-columns: 1.1fr 1fr; gap: 0; width: 100%; max-width: 940px;
  border: 1px solid var(--border); border-radius: 24px; overflow: hidden; box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.85);
  background: rgba(10, 15, 30, 0.75); backdrop-filter: blur(18px);
}
.login-brand {
  padding: 48px 44px; position: relative;
  background:
    radial-gradient(600px 300px at 0% 0%, rgba(34, 197, 94, 0.18), transparent 60%),
    radial-gradient(500px 300px at 100% 100%, rgba(139, 92, 246, 0.22), transparent 60%),
    rgba(255, 255, 255, 0.015);
  border-right: 1px solid var(--border);
}
.login-brand h1 { font-size: 38px; font-weight: 800; line-height: 1.1; margin: 22px 0 12px; }
.login-brand > p { color: var(--muted); font-size: 15px; max-width: 380px; margin: 0 0 28px; }
.features { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.features li { display: flex; gap: 12px; align-items: flex-start; color: var(--muted); }
.features li svg { color: var(--primary-2); margin-top: 2px; padding: 7px; width: 32px; height: 32px; border-radius: 10px; background: rgba(6, 182, 212, 0.12); }
.features b { display: block; color: var(--text); font-weight: 600; }
.login-card { padding: 48px 40px; display: flex; flex-direction: column; justify-content: center; }
.login-card h2 { font-size: 24px; margin-bottom: 4px; }
.login-card > p.muted { margin: 0 0 26px; }
.login-card button { margin-top: 8px; }
.logo {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff;
  background: var(--grad); box-shadow: 0 10px 30px -8px rgba(6, 182, 212, 0.7);
}
.logo svg { width: 24px; height: 24px; }

/* ---------- Estructura del panel ---------- */
#app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; padding: 22px 16px;
  background: rgba(9, 13, 26, 0.85); border-right: 1px solid var(--border); backdrop-filter: blur(16px);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 6px; }
.brand .logo { width: 40px; height: 40px; border-radius: 12px; }
.brand strong { display: block; font-size: 15px; font-weight: 700; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
#tabs { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#tabs button {
  justify-content: flex-start; gap: 12px; width: 100%; padding: 11px 12px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-weight: 500; border-radius: 12px;
}
#tabs button:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
#tabs button.active {
  color: var(--text); font-weight: 600; border-color: rgba(6, 182, 212, 0.25);
  background: linear-gradient(90deg, rgba(34, 197, 94, 0.16), rgba(6, 182, 212, 0.08));
  box-shadow: inset 3px 0 0 var(--primary);
}
#tabs button.active svg { color: var(--primary); }
.logout { justify-content: flex-start; gap: 12px; color: var(--muted); padding: 11px 12px; }
.logout:hover { color: var(--danger); background: rgba(248, 113, 113, 0.08); }

main { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.topbar h1 { font-size: 26px; font-weight: 800; margin: 0; }
.topbar p { margin: 2px 0 0; }
.chip {
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border-strong); background: rgba(255, 255, 255, 0.03);
}
.chip::before, .badge::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
[data-state='conectado'] { color: var(--ok); }
[data-state='conectado']::before { background: var(--ok); box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.18); animation: pulse 2s infinite; }
[data-state='esperando_qr'] { color: var(--warn); }
[data-state='esperando_qr']::before { background: var(--warn); }
[data-state='desconectado'] { color: var(--danger); }
[data-state='desconectado']::before { background: var(--danger); }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px rgba(74, 222, 128, 0); } }

/* ---------- Inicio ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
  display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow); backdrop-filter: blur(14px);
  transition: transform 0.2s, border-color 0.2s;
}
.stat:hover { transform: translateY(-2px); border-color: var(--border-strong); }
.stat b { display: block; font-size: 28px; font-weight: 800; line-height: 1.1; }
.stat small { color: var(--muted); }
.stat-ico { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; }
.stat-ico svg { width: 22px; height: 22px; }
.c1 { background: rgba(34, 197, 94, 0.14); color: #4ade80; }
.c2 { background: rgba(6, 182, 212, 0.14); color: #22d3ee; }
.c3 { background: rgba(139, 92, 246, 0.16); color: #a78bfa; }
.c4 { background: rgba(251, 191, 36, 0.14); color: #fbbf24; }
.wa-card { max-width: 560px; }
.badge { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.qr { width: 270px; height: 270px; margin: 14px auto; display: block; background: #fff; padding: 12px; border-radius: 18px; box-shadow: 0 0 0 6px rgba(6, 182, 212, 0.15), 0 20px 40px -10px rgba(6, 182, 212, 0.45); }

/* ---------- Tablas ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar h2 { margin: 0; flex: 1; }
.toolbar input { max-width: 320px; }
.table-wrap {
  overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); backdrop-filter: blur(14px);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: rgba(255, 255, 255, 0.02); }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
tr:last-child td { border-bottom: none; }
td button { padding: 6px 12px; font-size: 13px; }
.pill { display: inline-block; background: var(--pill); color: var(--pill-text); border-radius: 999px; padding: 2px 10px; margin: 2px 0; font-size: 12px; font-weight: 500; }
.pill.alt { background: var(--pill-alt); color: var(--pill-alt-text); }

/* ---------- Diálogos ---------- */
dialog {
  border: 1px solid var(--border-strong); border-radius: 20px; background: var(--card-solid); color: var(--text);
  width: min(660px, calc(100vw - 32px)); padding: 26px; box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.9);
}
dialog[open] { animation: pop 0.18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
dialog::backdrop { background: rgba(3, 6, 14, 0.7); backdrop-filter: blur(4px); }
fieldset { border: 1px solid var(--border); border-radius: 14px; margin: 0 0 14px; padding: 12px 16px; background: rgba(255, 255, 255, 0.015); }
legend { padding: 0 6px; font-weight: 600; font-size: 13px; color: #c9d2e6; }
.checks label { margin: 6px 0; display: flex; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 6px; }

/* ---------- Simulador ---------- */
.chat {
  white-space: pre-wrap; padding: 14px 16px; border-radius: 4px 16px 16px 16px; min-height: 44px; font: inherit; margin-top: 16px;
  background: #1f2c34; border: 1px solid rgba(37, 211, 102, 0.18); color: #e9edef; max-width: 520px;
}

/* ---------- Ajustes ---------- */
fieldset.access { padding: 14px 16px; margin-bottom: 18px; }
label.option { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; padding: 12px; border-radius: 12px; border: 1px solid transparent; color: var(--text); }
label.option:has(input:checked) { background: rgba(34, 197, 94, 0.08); border-color: rgba(34, 197, 94, 0.3); }
label.option input { margin-top: 3px; }
#publicOptions { border-top: 1px solid var(--border); margin-top: 10px; padding-top: 14px; }
p.label { font-weight: 600; font-size: 13px; color: #c9d2e6; margin: 14px 0 6px; }
.preview { white-space: pre-wrap; display: block; max-height: 4.5em; overflow: hidden; }

/* ---------- Responsivo ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .login-wrap { grid-template-columns: 1fr; max-width: 460px; }
  .login-brand { border-right: none; border-bottom: 1px solid var(--border); padding: 32px 28px; }
  .login-brand h1 { font-size: 30px; }
  .features { display: none; }
  .login-card { padding: 32px 28px; }
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 5; height: auto; flex-direction: row; align-items: center; gap: 10px; padding: 10px 12px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand > div:not(.logo) { display: none; }
  .brand .logo { width: 34px; height: 34px; border-radius: 10px; }
  #tabs { min-width: 0; }
  #tabs { flex-direction: row; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  #tabs button { width: auto; white-space: nowrap; padding: 9px 12px; }
  #tabs button.active { box-shadow: inset 0 -2px 0 var(--primary); }
  .logout span { display: none; }
  main { padding: 20px 16px 40px; }
  .topbar h1 { font-size: 22px; }
}
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; gap: 10px; }
  .stat b { font-size: 22px; }
  .stat-ico { width: 38px; height: 38px; }
  #tabs button span { display: none; }
}

/* ---------- Canales (WhatsApp / Telegram) ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
[data-state='apagado'] { color: var(--muted); }
[data-state='apagado']::before { background: #5b6684; }
[data-state='conectando'] { color: var(--warn); }
[data-state='conectando']::before { background: var(--warn); }
[data-state='error'] { color: var(--danger); }
[data-state='error']::before { background: var(--danger); }
.channels { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.channel { text-align: left; max-width: none; }
.channel-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.channel-head > div { flex: 1; min-width: 0; }
.channel-head h2 { margin: 0 0 2px; }
.channel-logo { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: #fff; flex: none; }
.channel-logo .brand-ico { width: 26px; height: 26px; }
.channel-logo.wa { background: linear-gradient(135deg, #25d366, #128c7e); box-shadow: 0 10px 26px -10px rgba(37, 211, 102, 0.8); }
.channel-logo.tg { background: linear-gradient(135deg, #37aee2, #1e96c8); box-shadow: 0 10px 26px -10px rgba(55, 174, 226, 0.8); }
.channel p { margin: 6px 0; }
.channel .qr { margin: 14px auto; }
#tgMe a { color: #5cc8f5; font-weight: 600; text-decoration: none; }
#tgMe a:hover { text-decoration: underline; }
.tg-form { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-top: 8px; }
.tg-form label { flex: 1 1 220px; margin: 0; }
.tg-help { margin-top: 14px; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: rgba(255, 255, 255, 0.015); }
.tg-help summary { cursor: pointer; font-weight: 600; color: #c9d2e6; }
.tg-help ol { margin: 10px 0 2px; padding-left: 20px; color: var(--muted); display: grid; gap: 6px; }
.tg-help b, .tg-help i { color: var(--text); }
code { background: rgba(255, 255, 255, 0.07); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }

/* Interruptor */
.switch { position: relative; display: inline-block; width: 50px; height: 28px; margin: 0; flex: none; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px; background: #2a3350; border: 1px solid var(--border-strong);
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.switch span::before {
  content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; border-radius: 50%;
  background: #cbd5e1; transition: transform 0.2s, background 0.2s; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}
.switch input:checked + span { background: var(--grad); border-color: transparent; box-shadow: 0 6px 18px -6px rgba(6, 182, 212, 0.7); }
.switch input:checked + span::before { transform: translateX(22px); background: #fff; }
.switch input:focus-visible + span { outline: 2px solid var(--primary-2); outline-offset: 2px; }

@media (max-width: 1000px) {
  .channels { grid-template-columns: minmax(0, 1fr); }
}

.tg-mode { margin: 4px 0 10px; }
p.hint { margin: -6px 0 12px; font-size: 12.5px; }
