:root {
  --bg: #0B0E11;
  --surface: #151A21;
  --surface-2: #1D242E;
  --surface-3: #26303D;
  --border: #2B3644;
  --text: #F0F4F8;
  --text-muted: #8292A6;
  --teal: #10B981;
  --teal-glow: rgba(16, 185, 129, 0.15);
  --amber: #F59E0B;
  --red: #EF4444;
  --blue: #3B82F6;
  --radius: 12px;
  --shadow: 0 10px 30px -10px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

.mono, .brand, input, textarea, select, .session-id, .status-label, .count, #qrSessionId, code {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
}

/* ---------- Topbar & Navigation ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(21, 26, 33, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.brand-mark { color: var(--teal); }
.brand-rest { color: var(--text-muted); }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge.beta {
  background: var(--teal-glow);
  color: var(--teal);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.nav-tabs {
  display: flex;
  background: var(--surface-2);
  padding: 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  gap: 4px;
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  background: var(--surface-3);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  color: var(--teal);
  background: var(--teal-glow);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 6px 12px;
  border-radius: 999px;
  font-family: 'IBM Plex Mono', monospace;
}
.status-dot {
  width: 8px;
  height: 8px;
  background: var(--teal);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--teal);
  animation: pulseDot 2s infinite ease-in-out;
}
@keyframes pulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

/* ---------- Layout & Tabs ---------- */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.tab-content {
  display: none;
  animation: fadeIn 0.25s ease-in-out;
}
.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text);
}

.panel-sub {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.panel-head.align-center { align-items: center; }

.count {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}

/* ---------- Form Controls ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.field-row {
  display: flex;
  align-items: center;
}
.gap-12 { gap: 12px; }

.label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.optional { color: #5B6A7D; font-weight: 400; }

input, textarea, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 13px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
input::placeholder, textarea::placeholder { color: #5B6A7D; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-glow);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%8292A6' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
}
.checkbox-label input[type="checkbox"] {
  accent-color: var(--teal);
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Inter', sans-serif;
}
.btn.primary {
  background: var(--teal);
  color: #051912;
}
.btn.primary:hover { background: #34D399; box-shadow: 0 0 15px var(--teal-glow); }

.btn.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--text-muted); background: var(--surface-2); }

.btn.danger {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: var(--red);
}
.btn.danger:hover { background: var(--red); color: #fff; }

.btn.small { padding: 6px 12px; font-size: 12px; }
.btn.large { padding: 14px 24px; font-size: 14px; }
.w-full { width: 100%; }

.error { color: var(--red); font-size: 12px; margin-top: 8px; }
.muted { color: var(--text-muted); }
.micro { font-size: 11px; }
.text-teal { color: var(--teal); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.mt-4 { margin-top: 4px; }
.mt-6 { margin-top: 6px; }
.mt-12 { margin-top: 12px; }
.mt-14 { margin-top: 14px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.py-20 { padding-top: 20px; padding-bottom: 20px; }
.text-center { text-align: center; }

/* ---------- Session Cards ---------- */

#newSessionForm {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
}

.session-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.session-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.session-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.session-id { font-size: 14px; font-weight: 600; }

.signal {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}
.signal .bar {
  width: 4px;
  background: var(--border);
  border-radius: 1px;
  transition: background 0.3s ease;
}
.signal .bar:nth-child(1) { height: 4px; }
.signal .bar:nth-child(2) { height: 8px; }
.signal .bar:nth-child(3) { height: 12px; }
.signal .bar:nth-child(4) { height: 16px; }

.signal[data-status="connected"] .bar { background: var(--teal); }
.signal[data-status="qr_pending"] .bar:nth-child(1),
.signal[data-status="qr_pending"] .bar:nth-child(2) { background: var(--amber); }

.status-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }
.status-label[data-status="connected"] { color: var(--teal); }
.status-label[data-status="qr_pending"] { color: var(--amber); }

.session-actions { display: flex; gap: 8px; margin-top: auto; }

/* ---------- Bulk Studio Layout ---------- */

.studio-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 900px) {
  .studio-grid { grid-template-columns: 1fr; }
}

/* Sessions Checkbox Selector */
.session-selector-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 160px;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
}
.session-checkbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface-3);
  font-size: 13px;
}

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: all 0.2s ease;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--teal);
  background: rgba(16, 185, 129, 0.05);
}
.dropzone svg { color: var(--text-muted); margin-bottom: 8px; }
.dropzone p { margin: 0; font-size: 13px; font-weight: 500; }
.link-text { color: var(--teal); text-decoration: underline; }

/* Contacts Summary */
.contacts-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-top: 14px;
}
.contacts-summary.hidden { display: none; }
.summary-metric { display: flex; flex-direction: column; }
.metric-val { font-size: 18px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; }
.metric-lbl { font-size: 11px; color: var(--text-muted); }

/* Anti-Ban Safeguards */
.risk-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
}
.risk-badge.low { background: var(--teal-glow); color: var(--teal); border: 1px solid rgba(16,185,129,0.3); }
.risk-badge.medium { background: rgba(245,158,11,0.15); color: var(--amber); border: 1px solid rgba(245,158,11,0.3); }
.risk-badge.high { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }

.range-inputs {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}
.range-inputs input[type="range"] {
  flex: 1;
  accent-color: var(--teal);
  cursor: pointer;
}

/* Variable Chips */
.variable-chips-container { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chips-list { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--teal);
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.chip:hover { background: var(--teal); color: #000; }

.spintax-hint {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}
.spintax-hint code { background: var(--surface-3); padding: 1px 4px; border-radius: 3px; color: var(--teal); }

/* WhatsApp Chat Preview Bubble */
.wa-chat-window {
  background: #0B141A;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-top: 12px;
}
.wa-chat-header {
  background: #202C33;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.wa-avatar {
  width: 32px;
  height: 32px;
  background: #00A884;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}
.wa-chat-info { display: flex; flex-direction: column; }
.wa-chat-name { font-size: 13px; font-weight: 600; color: #E9EDEF; }
.wa-chat-number { font-size: 11px; color: #8696A0; }

.wa-chat-body {
  padding: 16px;
  background-image: radial-gradient(rgba(255,255,255,0.03) 1px, transparent 0);
  background-size: 16px 16px;
  min-height: 120px;
}
.wa-bubble {
  background: #005C4B;
  color: #E9EDEF;
  padding: 8px 12px;
  border-radius: 8px 0px 8px 8px;
  max-width: 85%;
  margin-left: auto;
  font-size: 13px;
  line-height: 1.4;
  position: relative;
}
.wa-bubble-text { margin: 0; white-space: pre-wrap; word-break: break-word; }
.wa-time { font-size: 10px; color: #8696A0; float: right; margin-top: 4px; margin-left: 12px; }
.wa-ticks { color: #53BDEB; }

.wa-media-preview {
  margin-bottom: 6px;
  padding: 6px;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  font-size: 11px;
}
.wa-media-preview.hidden { display: none; }

/* ---------- Live Monitor ---------- */

.monitor-header-panel { background: var(--surface-2); }

.progress-bar-container { display: flex; flex-direction: column; gap: 8px; }
.progress-info { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; }
.progress-track {
  height: 10px;
  background: var(--surface-3);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10B981, #34D399);
  transition: width 0.3s ease;
  box-shadow: 0 0 10px var(--teal-glow);
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.metric-card {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.metric-title { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.metric-num { font-size: 22px; font-weight: 700; font-family: 'IBM Plex Mono', monospace; }

/* Table */
.table-responsive { overflow-x: auto; }
.activity-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}
.activity-table th {
  background: var(--surface-2);
  padding: 10px 14px;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
.activity-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.activity-table tr:hover td { background: var(--surface-2); }

.badge-status {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}
.badge-status.sent { background: rgba(16,185,129,0.15); color: var(--teal); }
.badge-status.failed { background: rgba(239,68,68,0.15); color: var(--red); }
.badge-status.pending { background: rgba(245,158,11,0.15); color: var(--amber); }

/* QR Modal */
.overlay {
  position: fixed; inset: 0;
  background: rgba(8, 11, 13, 0.85);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.qr-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 320px;
  text-align: center;
}
.qr-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.qr-body { min-height: 220px; display: flex; align-items: center; justify-content: center; }
.qr-body img { width: 220px; height: 220px; border-radius: 8px; background: #fff; padding: 8px; }

/* Code Blocks for CRM API Docs */
.code-block {
  background: #0B0E11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  overflow-x: auto;
  margin: 10px 0 0;
}
.code-block code {
  color: var(--teal);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.ml-8 { margin-left: 8px; }
.mt-8 { margin-top: 8px; }
.mt-10 { margin-top: 10px; }
.text-left { text-align: left; }
.hidden { display: none !important; }

.auth-modal {
  width: 360px;
  padding: 28px;
}
.auth-modal-head h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 700;
}

@media (max-width: 600px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 12px; }
  .nav-tabs { width: 100%; justify-content: center; }
  .key-field input { width: 100%; }
}
