:root {
  color-scheme: dark;
  --bg: #0d1117; --panel: #151b23; --panel-2: #1c242e; --line: #2a3441; --line-hover: #3d4b5c;
  --text: #e6edf3; --muted: #8b98a8;
  --red: #ff282d; --amber: #ffb020; --green: #3fb950; --blue: #58a6ff; --cyan: #6fd3f2;
  --logo-end: #ff6b3d;
  --warn-bg: #3d2410; --warn-line: #5c3a18; --warn-bg2: #3a2a10; --warn-text: #ffc65c;
  --active-bg: #1f2d3d; --bad-bg: #3a1416; --bad-text: #ff8b8e; --ok-bg: #12301c; --ok-text: #7ee39a;
  --user-bg: #1f3a5f; --blocked-bg: #2d1214; --fw-bg: #0f2a33; --fw-line: #2ea9d4; --refused-bg: #33260d;
  --pre-text: #c8d4e0;
  --inj-line: #5c2427; --inj-text: #ff9b9d; --jb-line: #5c4018; --obf-line: #2a4a5c; --obf-text: #8fd0e8;
  --abuse-line: #1f4a5c; --abuse-text: #7fd3ff; --ctl-line: #1f4a2b;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #ffffff; --panel: #f6f8fa; --panel-2: #eef1f5; --line: #d0d7de; --line-hover: #a8b3c0;
  --text: #1f2328; --muted: #59636e;
  --red: #d1242f; --amber: #9a6700; --green: #1a7f37; --blue: #0969da; --cyan: #0a7ea4;
  --logo-end: #f26a3d;
  --warn-bg: #fff4d6; --warn-line: #e8cf8a; --warn-bg2: #fff1cc; --warn-text: #7d4e00;
  --active-bg: #ddf0ff; --bad-bg: #ffebe9; --bad-text: #a40e26; --ok-bg: #dafbe1; --ok-text: #116329;
  --user-bg: #d6e8ff; --blocked-bg: #ffebe9; --fw-bg: #e0f4fb; --fw-line: #4bb3d6; --refused-bg: #fff1cc;
  --pre-text: #2f3a46;
  --inj-line: #f0a3a8; --inj-text: #a40e26; --jb-line: #e5c06a; --obf-line: #8ccbe0; --obf-text: #0a6182;
  --abuse-line: #7fc4e6; --abuse-text: #0a5f8f; --ctl-line: #7fcf96;
}
* { box-sizing: border-box; }

/* The whole app is a fixed shell: the page itself never scrolls, so the tray
   and composer can never be pushed off the bottom. Only the transcript and the
   inspector body scroll. */
html, body { height: 100%; }
body {
  margin: 0; height: 100dvh; overflow: hidden;
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, sans-serif;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- header ---------- */
.topbar {
  flex: none; display: flex; justify-content: space-between; align-items: center;
  padding: 9px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; gap: 10px; align-items: center; }
.logo { width: 26px; height: 26px; border-radius: 6px; flex: none;
  background: linear-gradient(135deg, var(--red), var(--logo-end)); }
.topbar h1 { margin: 0; font-size: 15px; font-weight: 650; }
.sub { margin: 0; font-size: 11px; color: var(--muted); }
.endpoint { display: flex; gap: 7px; align-items: center; }
.endpoint code { font-family: var(--mono); font-size: 11px; color: var(--blue); }
.label { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }

.warning { flex: none; padding: 8px 16px; background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-line); color: var(--amber); font-size: 12px; }
.warning code { font-family: var(--mono); }

/* ---------- key switcher: one row, scrolls sideways rather than wrapping ---------- */
.keybar {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; background: var(--panel-2); border-bottom: 1px solid var(--line);
}
.bar-label { font-size: 10px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); flex: none; }
.keys { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 1px; }
.keys::-webkit-scrollbar { height: 4px; }
.keys::-webkit-scrollbar-thumb { background: var(--line); border-radius: 2px; }
.keycard {
  flex: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; text-align: left;
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  font: inherit; transition: border-color .12s, background .12s;
}
.keycard:hover { border-color: var(--line-hover); }
.keycard .name { font-family: var(--mono); font-size: 11.5px; font-weight: 600; }
.keycard .cfg { font-size: 9.5px; color: var(--muted); margin-top: 1px;
  max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.keycard.active { background: var(--active-bg); border-color: var(--blue); }
.keycard.active.danger { background: var(--bad-bg); border-color: var(--red); }
.keycard.active.warn   { background: var(--warn-bg2); border-color: var(--amber); }
.keycard.active.ok     { background: var(--ok-bg); border-color: var(--green); }

/* ---------- controls ---------- */
.controls {
  flex: none; display: flex; gap: 14px; align-items: center;
  padding: 7px 16px; border-bottom: 1px solid var(--line);
}
.controls label { display: flex; gap: 6px; align-items: center;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
select { background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 7px; font: inherit; font-size: 12px; text-transform: none;
  max-width: 230px; }
.model-count { font-size: 10px; color: var(--muted); text-transform: none; letter-spacing: 0; }
.toggle { cursor: pointer; }
.toggle input { accent-color: var(--red); }
.stream-warning { font-size: 10.5px; color: var(--amber); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
button.ghost:hover { color: var(--text); border-color: var(--line-hover); }
button.ghost.danger { color: var(--red); border-color: var(--inj-line); }
button.ghost.danger:hover { color: #fff; background: var(--red); border-color: var(--red); }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr 420px; }
.chat-pane { display: flex; flex-direction: column; min-height: 0;
  border-right: 1px solid var(--line); }
.transcript { flex: 1; min-height: 0; overflow-y: auto;
  padding: 16px; display: flex; flex-direction: column; gap: 11px; }

/* ---------- messages ---------- */
.msg { max-width: 78%; padding: 9px 12px; border-radius: 11px;
  white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--user-bg); border-bottom-right-radius: 3px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border-bottom-left-radius: 3px; }
.msg.blocked, .msg.firewall, .msg.refused { align-self: stretch; max-width: 100%; font-size: 12.5px; }
.msg.blocked { background: var(--blocked-bg); border: 1px solid var(--red); font-family: var(--mono); }
.msg.firewall { background: var(--fw-bg); border: 1px solid var(--fw-line); }
.msg.refused { background: var(--refused-bg); border: 1px solid var(--amber); }
.msg .bt { font-weight: 700; margin-bottom: 4px; font-family: var(--mono); letter-spacing: .04em; }
.msg.blocked .bt { color: var(--red); }
.msg.firewall .bt { color: var(--cyan); }
.msg.refused .bt { color: var(--amber); }
.msg .leak { margin-top: 7px; padding: 6px 9px; border-radius: 5px;
  background: var(--bad-bg); border: 1px solid var(--red);
  font-size: 11px; color: var(--bad-text); font-family: var(--mono); }
.msg .meta { margin-top: 6px; font-size: 10px; color: var(--muted); font-family: var(--mono); }

/* ---------- attack tray: pinned above the composer, collapsible ---------- */
.tray { flex: none; border-top: 1px solid var(--line); background: var(--panel-2); }
.tray-head {
  display: flex; align-items: center; gap: 7px; width: 100%;
  padding: 7px 16px; background: none; border: 0; cursor: pointer; font: inherit; text-align: left;
}
.tray-head:hover .bar-label { color: var(--text); }
.chev { color: var(--muted); font-size: 10px; transition: transform .15s; }
.tray.collapsed .chev { transform: rotate(-90deg); }
.tray.collapsed .tray-body { display: none; }
.tray-hint { font-size: 10px; color: var(--muted); }
.tray-body { padding: 0 16px 10px; max-height: 27vh; overflow-y: auto; scrollbar-width: thin; }
.attack-group + .attack-group { margin-top: 8px; }
.group-label { font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-bottom: 5px; }
.group-label.blocked { color: var(--cyan); }
.group-label.leak { color: var(--red); }
.attacks { display: flex; gap: 6px; flex-wrap: wrap; }
.attack { padding: 4px 10px; border-radius: 14px; cursor: pointer; font: inherit; font-size: 11.5px;
  background: var(--panel); border: 1px solid var(--line); color: var(--text); white-space: nowrap; }
.attack:hover { border-color: var(--line-hover); }
.attack .mark { margin-right: 4px; opacity: .85; }
.attack.injection   { border-color: var(--inj-line); color: var(--inj-text); }
.attack.jailbreak   { border-color: var(--jb-line); color: var(--warn-text); }
.attack.obfuscation { border-color: var(--obf-line); color: var(--obf-text); }
.attack.abuse       { border-color: var(--abuse-line); color: var(--abuse-text); }
.attack.control     { border-color: var(--ctl-line); color: var(--ok-text); }

/* ---------- composer, always at the bottom edge ---------- */
.composer { flex: none; display: flex; gap: 8px; padding: 10px 16px;
  border-top: 1px solid var(--line); background: var(--panel); }
textarea { flex: 1; resize: none; background: var(--bg); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; font: inherit;
  max-height: 120px; }
textarea:focus { outline: none; border-color: var(--blue); }
#send { background: var(--red); color: #fff; border: 0; border-radius: 8px;
  padding: 0 20px; font: inherit; font-weight: 600; cursor: pointer; }
#send:disabled { opacity: .5; cursor: default; }

/* ---------- inspector ---------- */
.inspector { display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.metrics { flex: none; display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 1px; background: var(--line); border-bottom: 1px solid var(--line); }
.metric { background: var(--panel); padding: 7px 4px; text-align: center; }
.metric .v { font-family: var(--mono); font-size: 14px; font-weight: 650; }
.metric .k { font-size: 8.5px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); margin-top: 1px; }
.metric.firewall .v { color: var(--cyan); }
.metric.rejected .v { color: var(--red); }
.metric.refused .v  { color: var(--amber); }
.inspector-head { flex: none; padding: 10px 14px 0; }
.inspector-head h2 { margin: 0 0 8px; font-size: 12.5px; font-weight: 600; }
.tabs { display: flex; gap: 2px; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 4px 9px; font: inherit; font-size: 12px; cursor: pointer; }
.tab.active { color: var(--text); border-bottom-color: var(--red); }
.inspector-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 14px 18px; }
.empty { color: var(--muted); font-size: 13px; }
.inspector-body pre { margin: 0; font-family: var(--mono); font-size: 11px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; color: var(--pre-text); }
.row { display: flex; justify-content: space-between; gap: 12px;
  padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.row:last-child { border-bottom: 0; }
.row .k { color: var(--muted); }
.row .v { font-family: var(--mono); text-align: right; word-break: break-all; }
.v.ok { color: var(--green); } .v.bad { color: var(--red); } .v.warn { color: var(--amber); }
.verdict { padding: 8px 11px; border-radius: 7px; margin-bottom: 11px; font-size: 12px; font-weight: 600; }
.verdict.ok { background: var(--ok-bg); border: 1px solid var(--green); color: var(--ok-text); }
.verdict.bad { background: var(--bad-bg); border: 1px solid var(--red); color: var(--bad-text); }
.verdict.warn { background: var(--warn-bg2); border: 1px solid var(--amber); color: var(--warn-text); }
.burst { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin-top: 10px; }
.burst div { padding: 5px 0; text-align: center; border-radius: 4px;
  font-family: var(--mono); font-size: 10px; }
.burst .pass { background: var(--ok-bg); color: var(--ok-text); }
.burst .fail { background: var(--bad-bg); color: var(--bad-text); }

/* ---------- narrow: stack, and let the page scroll again ---------- */
@media (max-width: 1080px) {
  body { height: auto; overflow: auto; }
  main { grid-template-columns: 1fr; }
  .chat-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .transcript { min-height: 46vh; }
}

/* ---------- theme toggle ---------- */
.theme-toggle { margin-left: 14px; padding: 4px 9px; line-height: 1; font-size: 14px; }

/* ---------- auth: user + sign out in the header ---------- */
.logout-form { display: inline; margin: 0 0 0 6px; }
.burst-summary { margin-top: 14px; }

/* ---------- login page ---------- */
body.login-page { height: auto; min-height: 100dvh; overflow: auto;
  align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { flex: none; display: block; width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.login-card .brand { margin-bottom: 20px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 5px;
  font-size: 12px; color: var(--muted); }
.login-form input { background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 9px 11px; font: inherit; font-size: 14px; }
.login-form input:focus { outline: none; border-color: var(--blue); }
.login-form button { margin-top: 4px; background: var(--red); color: #fff; border: 0;
  border-radius: 8px; padding: 10px; font: inherit; font-weight: 600; cursor: pointer; }
.login-form button:focus-visible, .login-form input:focus-visible { outline: 2px solid var(--blue); outline-offset: 1px; }
.login-error { margin: 0 0 16px; padding: 8px 11px; border-radius: 8px; font-size: 12.5px;
  background: var(--bad-bg); color: var(--bad-text); border: 1px solid var(--inj-line); }
.login-foot { margin: 18px 0 0; font-size: 11.5px; color: var(--muted); }
.login-notice { margin: 0 0 16px; padding: 8px 11px; border-radius: 8px; font-size: 12.5px;
  background: var(--ok-bg); color: var(--ok-text); border: 1px solid var(--ctl-line); }

/* ---------- Fastly bot challenge (login page) ----------
   Fastly's script runs the challenge inside .fastly-challenge and reports
   progress in data-challenge-status. By default only a CAPTCHA is visible;
   these rules show every state as a status line above the Sign in button.
   Fastly's docs name the element both ways, so both selectors are covered. */
.fastly-challenge, fastly-challenge {
  display: flex; align-items: center; flex-wrap: wrap; gap: 9px;
  min-height: 34px; padding: 7px 11px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg);
  font-size: 12.5px; color: var(--muted);
}
.fastly-challenge::before, fastly-challenge::before {
  content: ""; flex: none; width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid var(--line); box-sizing: border-box;
}
.fastly-challenge::after, fastly-challenge::after {
  content: "Fastly Bot Management is checking your browser…"; flex: 1 1 0; min-width: 0;
}

.fastly-challenge[data-challenge-status="started"]::before,
fastly-challenge[data-challenge-status="started"]::before,
.fastly-challenge[data-challenge-status="processing"]::before,
fastly-challenge[data-challenge-status="processing"]::before {
  border-color: var(--line); border-top-color: var(--blue);
  animation: challenge-spin .9s linear infinite;
}
.fastly-challenge[data-challenge-status="processing"]::after,
fastly-challenge[data-challenge-status="processing"]::after { content: "Verifying with Fastly Bot Management…"; }

.fastly-challenge[data-challenge-status="complete"],
fastly-challenge[data-challenge-status="complete"] {
  /* No box once verified: just bold green text, lined up with the fields.
     The border stays (transparent) so the height doesn't jump. */
  border-color: transparent; background: transparent; padding-left: 0;
  color: var(--green); font-weight: 650;
}
.fastly-challenge[data-challenge-status="complete"]::before,
fastly-challenge[data-challenge-status="complete"]::before {
  border: 0; background: var(--green) center / 10px no-repeat
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='20 6 9 17 4 12'/%3E%3C/svg%3E");
}
.fastly-challenge[data-challenge-status="complete"]::after,
fastly-challenge[data-challenge-status="complete"]::after {
  content: "Verified by Fastly Bot Management";
  /* Fastly logo after the text: hug the text so it sits right beside it. */
  flex: 0 1 auto; padding-right: 21px;
  background: url("/fastly-logo.png") right center / 15px 15px no-repeat;
}

.fastly-challenge[data-challenge-status="error"],
fastly-challenge[data-challenge-status="error"] {
  border-color: var(--inj-line); background: var(--bad-bg); color: var(--bad-text);
}
.fastly-challenge[data-challenge-status="error"]::before,
fastly-challenge[data-challenge-status="error"]::before { border: 0; background: var(--red); }
.fastly-challenge[data-challenge-status="error"]::after,
fastly-challenge[data-challenge-status="error"]::after {
  content: "Fastly Bot Management couldn't verify this browser. Reload the page, or turn off ad blockers and try again.";
}

/* CAPTCHA: Fastly draws it inside its own frame, which the page's CSS can't
   reach (its input and button ignore .login-form's styles). So the box around
   it is styled like the login form's own fields -- same surface, border and
   radius -- with the Fastly mark and a plain label above, and the frame is
   given matching corners so it reads as part of the card. */
.fastly-challenge[data-challenge-status="captcha_prompted"],
fastly-challenge[data-challenge-status="captcha_prompted"] {
  gap: 10px 9px; padding: 11px 12px;
  border-color: var(--line); background: var(--bg); color: var(--text);
}
.fastly-challenge[data-challenge-status="captcha_prompted"]::before,
fastly-challenge[data-challenge-status="captcha_prompted"]::before {
  order: -2; border: 0; border-radius: 0;
  background: url("/fastly-logo.png") center / 14px 14px no-repeat;
}
.fastly-challenge[data-challenge-status="captcha_prompted"]::after,
fastly-challenge[data-challenge-status="captcha_prompted"]::after {
  content: "Fastly Bot Management: type the characters shown to continue";
  order: -1; flex-basis: calc(100% - 30px); font-weight: 500;
}
.fastly-challenge[data-challenge-status="captcha_prompted"] > *,
fastly-challenge[data-challenge-status="captcha_prompted"] > * {
  flex-basis: 100%; max-width: 100%;
}
.fastly-challenge iframe, fastly-challenge iframe {
  display: block; max-width: 100%; border: 1px solid var(--line); border-radius: 6px;
  /* Fastly's frame is light-themed. Paint it white behind its content so it
     stays a readable white card in dark mode too, rather than going
     transparent over the dark box with dark text. */
  color-scheme: light; background: #fff;
}

@keyframes challenge-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .fastly-challenge::before, fastly-challenge::before { animation: none !important; }
}
