:root {
  /* Light is the base palette; dark overrides the same tokens below. Nothing
     outside this block should name a colour directly, or it will survive a
     theme switch and look broken in one of them. */
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --panel-2: #eef2f6;
  --line: #d6dde5;
  --text: #16202c;
  --muted: #566678;
  --accent: #0b5fd0;
  --accent-fg: #ffffff;
  --accent-dim: #b9d3f5;
  --ok: #0a7150;
  --warn: #8a5209;
  --danger: #b52424;
  --ok-line: #9ad4bb;
  --crit-line: #e8a8a8;
  --secret-bg: #eaf2ff;
  --shadow: 0 8px 24px rgba(16, 32, 56, .14);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* Dark tokens live in one place and are applied two ways: when the viewer has
   chosen dark, and when they have chosen nothing and their system prefers it. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #182029;
  --line: #243040;
  --text: #dbe4ef;
  --muted: #8b9bb0;
  --accent: #4c9aff;
  --accent-fg: #06101d;
  --accent-dim: #2a5b9e;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --ok-line: #1e5a45;
  --crit-line: #6b2a2a;
  --secret-bg: #0a1420;
  --shadow: 0 8px 24px rgba(0, 0, 0, .5);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f14;
    --panel: #121821;
    --panel-2: #182029;
    --line: #243040;
    --text: #dbe4ef;
    --muted: #8b9bb0;
    --accent: #4c9aff;
    --accent-fg: #06101d;
    --accent-dim: #2a5b9e;
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #f87171;
    --ok-line: #1e5a45;
    --crit-line: #6b2a2a;
    --secret-bg: #0a1420;
    --shadow: 0 8px 24px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: var(--accent); }
code, pre, .mono { font-family: var(--mono); }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
header h1 { font-size: 16px; margin: 0; letter-spacing: .5px; }
header h1 span { color: var(--accent); }
header .spacer { flex: 1; }
header .who { color: var(--muted); font-size: 13px; }

nav { display: flex; gap: 4px; padding: 0 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
nav button {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 14px; cursor: pointer; font-size: 14px;
}
nav button:hover { color: var(--text); }
nav button.active { color: var(--text); border-bottom-color: var(--accent); }

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

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 16px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }

.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .4px; }
input, select, textarea {
  width: 100%; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 14px; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent-dim); }
textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
input[type=range] { padding: 0; }
input[type=color] { padding: 2px; height: 36px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 18px; }
.check input { width: auto; }
.check label { margin: 0; text-transform: none; letter-spacing: 0; font-size: 13px; color: var(--text); }

button.btn {
  background: var(--accent); color: var(--accent-fg); border: none; border-radius: 6px;
  padding: 8px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
}
button.btn:hover { filter: brightness(1.1); }
button.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 400; }
button.btn.ghost:hover { border-color: var(--accent-dim); filter: none; }
button.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); font-weight: 400; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
.pill.on { color: var(--ok); border-color: var(--ok-line); }
.pill.off { color: var(--muted); }
.pill.crit { color: var(--danger); border-color: var(--crit-line); }

.secret {
  background: var(--secret-bg); border: 1px solid var(--accent-dim); border-radius: 6px;
  padding: 12px; margin-top: 12px; font-family: var(--mono); font-size: 13px; word-break: break-all;
}
.secret .warn { color: var(--warn); font-family: system-ui, sans-serif; font-size: 12px; display: block; margin-bottom: 6px; }

.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 100;
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 14px; font-size: 13px; max-width: 420px;
  box-shadow: var(--shadow);
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

.empty { color: var(--muted); font-size: 13px; padding: 12px 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* JSON tree used to build field mappings by clicking a real captured payload */
.tree { font-family: var(--mono); font-size: 12.5px; line-height: 1.7; }
.tree .k { color: var(--accent); }
.tree .v { color: var(--ok); }
.tree .leaf { cursor: pointer; border-radius: 3px; padding: 0 3px; }
.tree .leaf:hover { background: var(--accent-dim); color: var(--text); }
.tree ul { list-style: none; margin: 0; padding-left: 16px; border-left: 1px solid var(--line); }

.auth-wrap { max-width: 380px; margin: 12vh auto; }
.split { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 860px) { .split { grid-template-columns: 1fr; } }


/* ------------------------------------------------------------ theme switch */
.theme-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg);
}
.theme-switch button {
  background: none;
  border: none;
  color: var(--muted);
  padding: 5px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.2;
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] {
  background: var(--accent);
  color: var(--accent-fg);
}
.theme-switch button + button { border-left: 1px solid var(--line); }
