/* ---------- theme tokens ----------
   Dark is the default, so the base :root block is the dark palette and
   [data-theme="light"] overrides it. index.html stamps the attribute before
   first paint. */
:root {
  color-scheme: dark;

  --sidebar-bg: #07111f;
  --sidebar-bg-2: #040b16;
  --sidebar-text: #9db1c9;
  --sidebar-text-dim: #66799180;
  --sidebar-border: rgba(255, 255, 255, .07);
  --sidebar-hover: rgba(255, 255, 255, .06);

  --bg: #0c1521;
  --surface: #121d2b;
  --surface-sunken: #0e1825;
  --input-bg: #0d1826;
  --border: #1e2c3e;
  --border-strong: #2b3c51;
  --border-hover: #3a4d66;

  --text: #e7eef6;
  --text-soft: #b6c4d4;
  --text-muted: #7e8fa4;
  --placeholder: #5d6f86;

  --primary: #3b82f6;
  --primary-hover: #2f72e0;
  --primary-ring: rgba(59, 130, 246, .26);
  --primary-soft: rgba(59, 130, 246, .14);
  --primary-soft-border: rgba(59, 130, 246, .3);
  --primary-soft-text: #9cc4fb;

  --success: #4ade80;
  --success-bg: rgba(34, 197, 94, .11);
  --success-border: rgba(74, 222, 128, .28);
  --success-text: #a7e9c1;
  --error: #f87171;
  --error-bg: rgba(248, 113, 113, .1);
  --error-border: rgba(248, 113, 113, .3);
  --error-text: #fbb4b4;
  --error-ring: rgba(248, 113, 113, .2);
  --warn: #fbbf24;
  --warn-bg: rgba(251, 191, 36, .1);
  --warn-border: rgba(251, 191, 36, .3);
  --info-bg: rgba(59, 130, 246, .1);
  --info-border: rgba(59, 130, 246, .26);
  --info-text: #b8d3f8;

  --env-key: #7fb99a;
  --env-value: #cdeadd;

  --code-bg: #08111d;
  --code-fg: #c6d3e3;
  --code-border: #1a2939;

  --btn-disabled-bg: #26364a;
  --btn-disabled-fg: #63768c;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 10px 26px -12px rgba(0, 0, 0, .7);
  --primary-glow: 0 4px 14px -5px rgba(59, 130, 246, .8);

  --radius-lg: 14px;
  --radius: 11px;
  --radius-sm: 9px;
  --sidebar-w: 292px;

  --font: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:root[data-theme="light"] {
  color-scheme: light;

  --sidebar-bg: #0a1b30;
  --sidebar-bg-2: #061120;
  --sidebar-text: #a9bdd4;
  --sidebar-text-dim: #6d86a3;
  --sidebar-border: rgba(255, 255, 255, .06);
  --sidebar-hover: rgba(255, 255, 255, .055);

  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-sunken: #f8fafc;
  --input-bg: #ffffff;
  --border: #e7ecf3;
  --border-strong: #d5dde8;
  --border-hover: #c2cddc;

  --text: #101a29;
  --text-soft: #445168;
  --text-muted: #77869c;
  --placeholder: #a3aebe;

  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-ring: rgba(37, 99, 235, .14);
  --primary-soft: #eef4ff;
  --primary-soft-border: #dce8fd;
  --primary-soft-text: #1c3f7a;

  --success: #0f7a48;
  --success-bg: #edfaf3;
  --success-border: #b6e5cd;
  --success-text: #0c5c37;
  --error: #c22b2b;
  --error-bg: #fdf1f1;
  --error-border: #f2c5c5;
  --error-text: #8d2020;
  --error-ring: rgba(194, 43, 43, .13);
  --warn: #8a5b06;
  --warn-bg: #fdf6e8;
  --warn-border: #eedcb0;
  --info-bg: #f0f5ff;
  --info-border: #d3e2fb;
  --info-text: #23406b;

  --env-key: #45836a;
  --env-value: #0d3d29;

  --code-bg: #0b1524;
  --code-fg: #c6d3e3;
  --code-border: #16263c;

  --btn-disabled-bg: #c3ccda;
  --btn-disabled-fg: #f4f7fb;

  --shadow-sm: 0 1px 2px rgba(15, 27, 45, .05);
  --shadow: 0 1px 3px rgba(15, 27, 45, .05), 0 8px 24px -8px rgba(15, 27, 45, .1);
  --primary-glow: 0 4px 12px -4px rgba(37, 99, 235, .6);
}

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .2s ease, color .2s ease;
}

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }

.shell { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.content { flex: 1; min-width: 0; padding: 40px 44px 72px; }

.page { max-width: 1180px; }

.page-head { margin-bottom: 26px; }
.page-title { margin: 0 0 6px; font-size: 27px; font-weight: 700; letter-spacing: -.025em; }
.page-subtitle { margin: 0; color: var(--text-muted); font-size: 14.5px; }

/* ---------- sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(175deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 18px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}
.brand-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(140deg, #3b82f6, #1d4ed8);
  color: #fff;
  box-shadow: 0 4px 14px -4px rgba(59, 130, 246, .7);
}
.brand-icon svg { width: 20px; height: 20px; stroke-width: 2.1; }
.brand-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -.015em;
  line-height: 1.3;
}

.theme-toggle {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 1px solid var(--sidebar-border);
  border-radius: 9px;
  background: rgba(255, 255, 255, .04);
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.theme-toggle:hover {
  background: rgba(255, 255, 255, .1);
  border-color: rgba(255, 255, 255, .18);
  color: #fff;
}
.theme-toggle:focus-visible { outline: 2px solid #7fb2ff; outline-offset: 2px; }

.sidebar-nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 3px; }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--sidebar-text);
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 500;
  letter-spacing: -.005em;
  text-align: left;
  cursor: pointer;
  transition: background .16s ease, color .16s ease;
}
.sidebar-item:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-item.is-active {
  background: linear-gradient(135deg, #2f7ef5, #1d4ed8);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 18px -6px rgba(37, 99, 235, .85);
}
.sidebar-item:focus-visible { outline: 2px solid #7fb2ff; outline-offset: 2px; }

.sidebar-icon { width: 19px; height: 19px; flex: 0 0 19px; color: var(--sidebar-text-dim); }
.sidebar-item.is-active .sidebar-icon,
.sidebar-item:hover .sidebar-icon { color: #fff; }
.sidebar-icon svg { width: 100%; height: 100%; }
.sidebar-label { flex: 1; }

/* ---------- topbar (mobile only) ---------- */
.topbar { display: none; }

/* ---------- cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 26px 28px;
  margin-bottom: 18px;
}
.card--success { border-left: 3px solid var(--success); }
.card--error { border-left: 3px solid var(--error); }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.card-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-soft);
}
.card-head-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- forms ---------- */
.grid { display: grid; gap: 22px 32px; }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); }

.field { min-width: 0; }
.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  letter-spacing: -.005em;
}
.field-label--mono {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
}
.req { color: var(--error); margin-left: 3px; }
.optional {
  margin-left: 7px;
  font-family: var(--font);
  font-weight: 500;
  font-size: 11.5px;
  color: var(--text-muted);
}

.input-wrap { position: relative; display: flex; }

.input {
  width: 100%;
  padding: 12px 15px;
  font-family: var(--font);
  font-size: 14.5px;
  color: var(--text);
  background: var(--input-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: border-color .16s ease, box-shadow .16s ease;
}
.input::placeholder { color: var(--placeholder); font-weight: 400; }
.input:hover:not(:focus) { border-color: var(--border-hover); }
.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3.5px var(--primary-ring);
}
.has-error .input { border-color: var(--error); }
.has-error .input:focus { box-shadow: 0 0 0 3.5px var(--error-ring); }

.field-error { margin: 7px 0 0; font-size: 12.5px; font-weight: 500; color: var(--error); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 24px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-sunken);
  cursor: pointer;
  transition: border-color .16s ease;
}
.switch-row:hover { border-color: var(--border-strong); }
.checkbox { width: 17px; height: 17px; margin-top: 2px; accent-color: var(--primary); cursor: pointer; }
.switch-text { display: flex; flex-direction: column; gap: 2px; font-size: 13.5px; }
.switch-text strong { font-weight: 600; }
.switch-hint { color: var(--text-muted); font-size: 12.5px; line-height: 1.45; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 11px 22px;
  font-family: var(--font);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -.005em;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .1s ease;
}
.btn:disabled { cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--primary-glow); }
.btn-primary:not(:disabled):hover { background: var(--primary-hover); }
.btn-primary:disabled { background: var(--btn-disabled-bg); color: var(--btn-disabled-fg); box-shadow: none; }

.btn-ghost {
  background: var(--surface);
  color: var(--text-soft);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-ghost:not(:disabled):hover { background: var(--surface-sunken); color: var(--text); }
.btn-ghost:disabled { opacity: .55; }

.link-btn {
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--primary);
  cursor: pointer;
  text-underline-offset: 3px;
  text-decoration: underline;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- icons ---------- */
.icon, .icon-sm, .alert-icon { display: inline-flex; }
.icon-sm { width: 16px; height: 16px; flex: 0 0 16px; }
.icon-sm svg { width: 100%; height: 100%; }

/* ---------- alerts ---------- */
.alert-slot:empty { display: none; }
.alert-slot { margin-top: 16px; }
.card .alert-slot { margin-top: 20px; }

.alert {
  display: flex;
  align-items: flex-start;
  gap: 13px;
  padding: 15px 18px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 16px;
}
.alert:last-child { margin-bottom: 0; }
.alert-icon { width: 19px; height: 19px; flex: 0 0 19px; margin-top: 1px; }
.alert-icon svg { width: 100%; height: 100%; }
.alert-text { flex: 1; }

.alert--info    { background: var(--info-bg);    border-color: var(--info-border);    color: var(--info-text); }
.alert--info .alert-icon { color: var(--primary); }
.alert--success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert--success .alert-icon { color: var(--success); }
.alert--error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error-text); }
.alert--error .alert-icon { color: var(--error); }
.alert--warning { background: var(--warn-bg);    border-color: var(--warn-border);    color: var(--warn); }
.alert--warning .alert-icon { color: var(--warn); }

/* ---------- environment summary ---------- */
.env-summary {
  padding: 16px 20px;
  margin-bottom: 18px;
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  border-radius: var(--radius-lg);
  color: var(--success-text);
}
.env-summary-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.env-summary-head .alert-icon { color: var(--success); }
.env-summary-title {
  flex: 1;
  font-weight: 700;
  font-size: 12.5px;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.env-summary-head .link-btn { color: var(--success); }

.env-row {
  display: flex;
  align-items: baseline;
  gap: 14px;
  padding: 6px 0;
  border-top: 1px solid var(--success-border);
}
.env-key {
  flex: 0 0 90px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--env-key);
}
.env-value {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--env-value);
  word-break: break-all;
}

/* ---------- badges & event code ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: -.005em;
  border: 1px solid;
}
.badge--success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.badge--error   { background: var(--error-bg);   border-color: var(--error-border);   color: var(--error); }
.badge--warn    { background: var(--warn-bg);    border-color: var(--warn-border);    color: var(--warn); cursor: help; }

.codes-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 13px 15px;
  margin-bottom: 26px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.code-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.code-row-label {
  flex: 0 0 82px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
}
.code-row-value {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--primary-soft-text);
  background: var(--primary-soft);
  border: 1px solid var(--primary-soft-border);
  padding: 3px 10px;
  border-radius: 6px;
}

/* ---------- code blocks ---------- */
.code {
  margin: 0;
  padding: 18px 20px;
  background: var(--code-bg);
  color: var(--code-fg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12.7px;
  line-height: 1.7;
  white-space: pre;
  tab-size: 4;
}
.tok-key  { color: #79c0ff; }
.tok-str  { color: #a5d6ff; }
.tok-num  { color: #f0b072; }
.tok-lit  { color: #ff9492; }
.tok-punc { color: #7d8da3; }
.tok-cmd  { color: #7ee787; font-weight: 500; }
.tok-flag { color: #79c0ff; }

.response-note { margin: 0; color: var(--text-muted); font-size: 14px; }
.response-hint { margin: 10px 0 0; color: var(--text-muted); font-size: 13px; line-height: 1.55; }
.response-time { font-size: 12px; font-weight: 500; color: var(--text-muted); }

.copy-status { font-size: 12.5px; font-weight: 600; }
.copy-status.is-ok { color: var(--success); }
.copy-status.is-fail { color: var(--error); }

.results:empty { display: none; }
.results > .card { animation: rise .28s ease both; }
.results > .card:nth-child(2) { animation-delay: .06s; }
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

.backdrop { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .content { padding: 24px 20px 60px; }

  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 16px;
    background: var(--sidebar-bg);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 40;
    border-bottom: 1px solid var(--sidebar-border);
  }
  .topbar-title { font-weight: 700; font-size: 15px; letter-spacing: -.015em; }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 9px;
    background: transparent;
    color: #fff;
    cursor: pointer;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: 0 0 50px rgba(0, 0, 0, .5);
  }
  .nav-open .sidebar { transform: translateX(0); }
  .nav-open .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(3, 8, 15, .6);
  }
}

@media (max-width: 560px) {
  .grid--2 { grid-template-columns: 1fr; }
  .card { padding: 20px 17px; }
  .page-title { font-size: 23px; }
  .env-row { flex-direction: column; gap: 2px; }
  .env-key { flex: none; }
  .code-row { gap: 5px; }
  .code-row-label { flex: none; }
  .form-actions .btn { flex: 1; }
}
