:root {
  --bg: #0b1020;
  --bg-2: #121a30;
  --card: #151d33;
  --line: #243049;
  --text: #e7ecf6;
  --muted: #8a97b1;
  --accent: #4f8cff;
  --emerald: #34d399;
  --amber: #fbbf24;
  --violet: #a78bfa;
  --red: #f87171;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 20px; background: var(--bg-2);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; color: var(--accent); }
.brand strong { display: block; }
.brand .sub { font-size: 12px; color: var(--muted); }
.tabs { display: flex; gap: 4px; margin-left: 8px; }
.tab {
  background: transparent; color: var(--muted); border: 0;
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab:hover { color: var(--text); background: rgba(255,255,255,.04); }
.tab.active { color: var(--text); background: rgba(79,140,255,.15); }
.env-pill {
  margin-left: auto; font-size: 12px; padding: 5px 12px; border-radius: 999px;
  background: rgba(52,211,153,.12); color: var(--emerald); border: 1px solid rgba(52,211,153,.3);
}
.env-pill.down { background: rgba(248,113,113,.12); color: var(--red); border-color: rgba(248,113,113,.3); }

main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pad { padding: 12px; }
.hidden { display: none !important; }

/* Plantillas */
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; align-self: start; }
.list-head { padding: 14px 16px; font-weight: 600; border-bottom: 1px solid var(--line); }
.tpl-item { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.tpl-item:hover { background: rgba(255,255,255,.03); }
.tpl-item.active { background: rgba(79,140,255,.12); }
.tpl-item .id { font-weight: 600; font-family: ui-monospace, monospace; font-size: 13px; }
.tpl-item .block { font-size: 11px; color: var(--muted); }
.badge { display: inline-block; font-size: 10px; padding: 2px 8px; border-radius: 999px; background: rgba(79,140,255,.15); color: var(--accent); margin-top: 4px; }

.detail { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-height: 400px; }
.detail .empty { color: var(--muted); text-align: center; padding: 80px 20px; }
.meta-grid { display: grid; grid-template-columns: 120px 1fr; gap: 6px 14px; margin: 12px 0; font-size: 13px; }
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; }
.preview-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
@media (max-width: 1000px) { .preview-row, .split { grid-template-columns: 1fr; } }
textarea, input, select {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: inherit;
}
textarea { font-family: ui-monospace, monospace; min-height: 260px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
iframe.preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.subject { font-weight: 600; margin: 8px 0; }

button {
  background: var(--accent); color: #fff; border: 0; border-radius: 8px;
  padding: 9px 16px; cursor: pointer; font-size: 13px; font-weight: 600;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--text); font-weight: 500; }
button.danger { background: transparent; border: 1px solid rgba(248,113,113,.4); color: var(--red); padding: 4px 10px; font-size: 12px; }

/* Forms */
.config-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.card.wide { grid-column: 1 / -1; }
@media (max-width: 900px) { .config-grid { grid-template-columns: 1fr; } }
.settings-form label { display: block; margin-bottom: 10px; font-size: 12px; color: var(--muted); }
.settings-form label input { margin-top: 4px; }
.emitter-rows { display: grid; gap: 10px; margin-bottom: 12px; }
.emitter-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.emitter-row .name { font-weight: 600; margin-bottom: 6px; text-transform: capitalize; }
.emitter-row .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 130px; }
.inline-form button { flex: 0; white-space: nowrap; }

/* Tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.mono, .mono { font-family: ui-monospace, monospace; font-size: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.pill.SENT, .pill.VERIFIED { background: rgba(52,211,153,.15); color: var(--emerald); }
.pill.QUEUED, .pill.PENDING { background: rgba(251,191,36,.15); color: var(--amber); }
.pill.SUPPRESSED { background: rgba(167,139,250,.15); color: var(--violet); }
.pill.FAILED { background: rgba(248,113,113,.15); color: var(--red); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.on { background: var(--emerald); } .dot.off { background: var(--line); }

/* Stats */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat .val { font-size: 26px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); }
.mon-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 900px) { .mon-grid { grid-template-columns: 1fr; } }
.funnel-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.funnel-row .name { width: 90px; font-size: 12px; color: var(--muted); }
.funnel-row .bar { height: 22px; background: var(--accent); border-radius: 5px; min-width: 2px; }
.funnel-row .n { font-size: 12px; }
.monitor-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.rangepick { font-size: 12px; color: var(--muted); }
.rangepick select { width: auto; display: inline-block; margin-left: 6px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 120px; }

/* Login */
.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: radial-gradient(1200px 600px at 50% -10%, #16203c 0%, var(--bg) 60%);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 36px 32px; width: 340px; max-width: 90vw; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.login-logo { font-size: 40px; color: var(--accent); margin-bottom: 8px; }
.login-card h2 { margin: 0 0 4px; }
.login-card input { margin: 20px 0 12px; text-align: center; }
.login-card button { width: 100%; padding: 11px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--bg-2); border: 1px solid var(--line); padding: 12px 20px; border-radius: 10px;
  transition: transform .25s; z-index: 50; max-width: 90vw;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(52,211,153,.4); }
.toast.err { border-color: rgba(248,113,113,.4); }
