:root {
  --bg: #070c0e;
  --surface: #0f171a;
  --surface-2: #152126;
  --border: rgba(255, 255, 255, 0.09);
  --text: #f3f7f6;
  --muted: #98aba6;
  --accent: #10b981;
  --accent-bright: #22c55e;
  --warn: #f59e0b;
  --error: #ef4444;
  --radius: 14px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

.app-container {
  width: 100%;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 20px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(7, 12, 14, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.app-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 64px;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}
.app-brand-mark { width: 34px; height: 34px; flex: none; }
.app-brand-text span { color: var(--accent-bright); }

.app-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.ws-select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
  max-width: 260px;
}

.app-main { padding-top: 28px; padding-bottom: 60px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-width: 0;
}

.auth-wrap {
  display: flex;
  justify-content: center;
  padding: 36px 0;
}
.auth-card { width: 100%; max-width: 480px; }
.auth-card h1 { margin: 8px 0 10px; font-size: 1.65rem; letter-spacing: -0.025em; line-height: 1.2; }
.auth-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent-bright);
  margin: 0;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-bright);
  display: inline-block;
}

.muted { color: var(--muted); margin: 0; }
.small { font-size: 0.84rem; }

.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-size: 0.84rem; font-weight: 600; color: #d3e1dd; }
.field input, .field select {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.94rem;
  font-family: inherit;
}
.field input:focus, .field select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, opacity 0.12s ease, background 0.12s ease;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 7px 12px; font-size: 0.84rem; }
.btn-block { width: 100%; }
.btn-primary {
  background: linear-gradient(135deg, #10b981, #22c55e);
  color: #04150e;
  font-weight: 700;
}
.btn-primary:hover:not(:disabled) { opacity: 0.92; }
.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: rgba(255, 255, 255, 0.1); }

.alert {
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  background: rgba(16, 185, 129, 0.12);
  color: #b7f5d8;
}
.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fecaca;
}
.alert-warn {
  background: rgba(245, 158, 11, 0.14);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fde68a;
}

.dash-wrap { display: flex; flex-direction: column; gap: 20px; }

.dash-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.ws-title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ws-title-row h1 { margin: 0; font-size: 1.6rem; letter-spacing: -0.025em; }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-live { background: rgba(16, 185, 129, 0.18); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.35); }
.badge-demo { background: rgba(245, 158, 11, 0.18); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.35); }
.badge-warn { background: rgba(239, 68, 68, 0.18); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35); }

.dash-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.pill-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.pill-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.84rem;
  font-weight: 700;
  cursor: pointer;
}
.pill-btn.active { background: var(--accent); color: #04150e; }

.margin-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 0.84rem;
  font-weight: 600;
  color: #d3e1dd;
}
.margin-control input {
  width: 60px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: right;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.kpi-card { display: flex; flex-direction: column; gap: 4px; }
.kpi-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; }
.kpi-accent { color: var(--accent-bright); }
.kpi-sub { font-size: 0.82rem; color: var(--muted); }
.kpi-warn { border-color: rgba(245, 158, 11, 0.35); }

.advisor-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(15, 23, 26, 0.96));
  border-color: rgba(16, 185, 129, 0.28);
}
.advisor-main { flex: 1 1 360px; }
.advisor-main h2 { margin: 6px 0 4px; font-size: 1.15rem; }
.advisor-counts { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.adv-stat {
  background: rgba(7, 12, 14, 0.65);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  min-width: 84px;
}
.adv-stat span { display: block; font-size: 1.25rem; font-weight: 800; color: var(--accent-bright); }
.adv-stat small { font-size: 0.74rem; color: var(--muted); }

.ops-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0 0 4px; font-size: 1.12rem; }

.copy-row { display: flex; gap: 8px; flex-wrap: wrap; }
.copy-row input { flex: 1 1 180px; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.82rem; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field-full { grid-column: 1 / -1; }
.action-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
.data-table th { color: var(--muted); font-size: 0.76rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.wrap-cell { white-space: normal; min-width: 200px; }
.data-table a { color: var(--accent-bright); text-decoration: none; font-weight: 600; }
.data-table a:hover { text-decoration: underline; }

.tabs-bar { display: flex; gap: 8px; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 10px; flex-wrap: wrap; }
.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.tab-btn.active { background: var(--surface-2); color: var(--text); border-color: var(--border); }

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card { width: 100%; max-width: 520px; }

@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ops-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 600px) {
  .app-container { padding: 0 14px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .ws-select { max-width: 100%; width: 100%; }
}

.code-snippet {
  margin: 0;
  padding: 12px;
  border-radius: 10px;
  background: #0a1114;
  border: 1px solid var(--border);
  color: #a7f3d0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  overflow-x: auto;
  max-width: 100%;
  white-space: pre-wrap;
  word-break: break-word;
}

.event-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.event-chip {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #a7f3d0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.76rem;
  font-weight: 600;
}

.source-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.08);
  color: #d3e1dd;
  margin-right: 6px;
}
.source-pill.stripe {
  background: rgba(99, 91, 255, 0.22);
  color: #c7d2fe;
}
