/*
 * Profrakt Toolbox.
 *
 * ── WHERE THE COLOURS COME FROM ───────────────────────────────────────────
 *
 * Profrakt's own brand, read off the `profrakt-custom-theme-v2` HubSpot theme
 * the marketing site and the help centre both run on — not the portal app's
 * `#634df5`, which is a previous design generation and belongs to that app,
 * not to the brand:
 *
 *   purple #250932 · purple-mid #4a2068 · violet #AC92FF · lavender #F4F2FF
 *
 * The pairing that makes a page read as Profrakt at a glance is violet on
 * purple — a lavender fill with dark-purple text — so that, and not a purple
 * fill with white text, is what `.btn-primary` is.
 *
 * The portal's design system has no dark tokens and neither does the theme;
 * the dark set below is this tool's own, derived from the same hues. A
 * developer tool is read at night, and one that ignores that is one people
 * stop opening.
 *
 * ── THE ONE NETWORK REQUEST ───────────────────────────────────────────────
 *
 * MD Nichrome is Profrakt's display face and the reason a heading looks like
 * theirs. It is licensed, so the files are not copied here — the `@font-face`
 * below points at the copy Profrakt already publishes from their own CDN
 * (`access-control-allow-origin: *`), exactly as the help centre does, and the
 * page's CSP names that host under `font-src`.
 *
 * `@font-face` is lazy and `font-display: swap` is set, so the tool still
 * works whole from a static bucket on a laptop with no route to that CDN: the
 * headings render in the system stack instead. Everything else — body text,
 * icons, the whole UI — is local. Icons stay inline SVG in the markup.
 */

@font-face {
  font-family: "MD Nichrome";
  src: url("https://27067591.fs1.hubspotusercontent-eu1.net/hubfs/27067591/raw_assets/profrakt-custom-theme-v2/25/js_client_assets/assets/MDNichrome-Regular-Cnxpmd4P.woff")
    format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "MD Nichrome";
  src: url("https://27067591.fs1.hubspotusercontent-eu1.net/hubfs/27067591/raw_assets/profrakt-custom-theme-v2/25/js_client_assets/assets/MDNichrome-Bold-CBcrt1O5.woff")
    format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Profrakt's four brand colours, verbatim. */
  --purple: #250932;
  --purple-mid: #4a2068;
  --violet: #ac92ff;
  --lavender: #f4f2ff;

  --brand: #4a2068;
  --brand-ink: #ffffff;
  --brand-soft: #f4f2ff;
  --brand-line: #ded5f7;

  /* The brand's primary action: violet fill, purple text. */
  --accent: #ac92ff;
  --accent-ink: #250932;
  --accent-hover: #9d7fff;

  --bg: #fbfaff;
  --surface: #ffffff;
  --surface-2: #f6f4fc;
  --border: #e7e3f0;
  --border-strong: #d3cce3;

  --text: #250932;
  --text-muted: #6c6377;
  --text-faint: #948da1;

  --ok: #2f7a3b;
  --ok-soft: #e8faeb;
  --warn: #8a5a00;
  --warn-soft: #fff8e0;
  --danger: #af010d;
  --danger-soft: #fdecec;
  --info: #4a2068;
  --info-soft: #f0ebfb;

  /*
   * The HTTP method colours are NOT the brand, on purpose. In a contents rail
   * of 33 endpoints, GET and POST have to be told apart faster than a colour
   * can be recognised as ours, so they stay on the conventional
   * blue/green/amber/red that every API tool has used for twenty years.
   */
  --get: #1a47b8;
  --get-soft: #e4ecfd;
  --post: #2f7a3b;
  --post-soft: #e8faeb;
  --put: #8a5a00;
  --put-soft: #fff8e0;
  --delete: #af010d;
  --delete-soft: #fdecec;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --rail-w: 244px;
  --sidebar-w: 292px;
  --header-h: 60px;
  --display: "MD Nichrome", ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
  --shadow-sm: 0 1px 2px rgb(37 9 50 / 0.06);
  --shadow: 0 2px 6px rgb(37 9 50 / 0.05), 0 12px 28px rgb(37 9 50 / 0.07);
}

@media (prefers-color-scheme: dark) {
  :root {
    /*
     * Violet carries the brand into the dark set. `--brand` lifts off #4a2068,
     * which is too close to the background to be a link colour, to the violet
     * the brand already owns.
     */
    --brand: #c3adff;
    --brand-ink: #1c0d26;
    --brand-soft: #2b1d3d;
    --brand-line: #3d2c54;

    --accent: #ac92ff;
    --accent-ink: #1c0d26;
    --accent-hover: #bda6ff;

    --bg: #140b1b;
    --surface: #1d1327;
    --surface-2: #261a33;
    --border: #33253f;
    --border-strong: #453352;

    --text: #f0eaf5;
    --text-muted: #a99ab6;
    --text-faint: #82758e;

    --ok: #6cd07f;
    --ok-soft: #16301c;
    --warn: #e5b64b;
    --warn-soft: #322709;
    --danger: #ff7b7b;
    --danger-soft: #331414;
    --info: #c3adff;
    --info-soft: #2b1d3d;

    --get: #8fb0ff;
    --get-soft: #16213f;
    --post: #6cd07f;
    --post-soft: #16301c;
    --put: #e5b64b;
    --put-soft: #322709;
    --delete: #ff7b7b;
    --delete-soft: #331414;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow: 0 2px 6px rgb(0 0 0 / 0.3), 0 12px 28px rgb(0 0 0 / 0.45);
  }
}

* {
  box-sizing: border-box;
}

/* `hidden` has to beat the layout rules. Half the elements in here are flex or
   grid containers, and `display: flex` silently wins over the attribute's own
   `display: none` — which is how a hidden picker ends up visible. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}

/*
 * The display face is for the page's own voice — the hero, the panel titles,
 * the dialog — and NOT for data. An endpoint path, a price or a JSON key
 * rendered in a display face reads as decoration; those stay in Inter and the
 * mono stack. MD Nichrome runs tight, so the tracking comes back in a little.
 */
.display {
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

p {
  margin: 0 0 10px;
}

a {
  color: var(--brand);
}

code,
kbd,
pre {
  font-family: var(--mono);
  font-size: 12.5px;
}

/* ── Top bar ──────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: var(--text);
}

/*
 * Sized by height, never by width: the mark's own 305:69 ratio does the rest,
 * and a width would stretch it the first time the suffix changes length.
 */
.wordmark-logo {
  display: block;
  height: 19px;
  width: auto;
  color: var(--purple);
}

@media (prefers-color-scheme: dark) {
  .wordmark-logo {
    color: var(--text);
  }
}

/* A hairline, not a slash: the suffix is a sibling of the mark, not part of
   it, and the logo must not read as "Profrakt Toolbox" set in one face. */
.wordmark-sep {
  width: 1px;
  height: 18px;
  background: var(--border-strong);
}

.wordmark-suffix {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  white-space: nowrap;
}

.wordmark:hover .wordmark-suffix {
  color: var(--text);
}

.env-chip {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.env-chip[data-env="production"] {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}

.env-chip[data-env="sandbox"] {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 35%, transparent);
}

.sender-picker {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.sender-picker select {
  max-width: 220px;
}

/* ── Buttons and form controls ────────────────────────────────────────── */

/* `.btn` is on anchors as well as buttons now — every call to action on the
   front page is a real link — so the anchor defaults have to be turned off
   here rather than at each call site. */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  text-decoration: none;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-soft);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/*
 * Violet fill, purple text — Profrakt's own primary button, not a purple fill
 * with white text. `filter: brightness()` is deliberately not used: on a light
 * fill it washes the button out instead of deepening it, so the hover state is
 * a real colour.
 */
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--accent-ink);
}

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

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(1.08);
  color: #fff;
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12.5px;
}

.count {
  min-width: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

textarea {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  resize: vertical;
}

.field {
  display: block;
  margin-bottom: 12px;
}

.field > span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.check {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-bottom: 12px;
  font-size: 13px;
}

.check input {
  margin-top: 3px;
}

.check small {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
}


/* ── Page-wide bits the reference brought with it ─────────────────────── */

html {
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

/*
 * Inline code inside prose. Scoped to prose contexts on purpose: a `<code>` in
 * a table of headers or inside the JSON viewer is already in a bordered box,
 * and a second border around it reads as a nested control.
 */
p code,
li code,
td code {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0 4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#search {
  width: min(320px, 30vw);
  padding: 8px 13px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

#search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 30%, transparent);
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ── The two views ────────────────────────────────────────────────────── */

/*
 * The reference reads and the toolbox works, and they were tuned at different
 * densities before they shared a page. The body carries the reference's
 * reading size; the toolbox takes its own back here, so every control inside
 * it — all `font: inherit` — is the size it was designed at.
 */
#view-toolbox {
  font-size: 14px;
  line-height: 1.45;
}

/* Switching views is a route change, not a scroll. */
.view[hidden] {
  display: none !important;
}

/* ── The view switch ──────────────────────────────────────────────────── */

/*
 * A segmented control in the top bar. It sits beside the wordmark rather than
 * centred, because it is navigation and not a mode toggle: "Reference" and
 * "Toolbox" are two places, and the reader should read them left to right with
 * the brand, not hunt for them in the middle of the bar.
 */
.viewswitch {
  display: flex;
  gap: 2px;
  margin-left: 6px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
}

.viewswitch a {
  padding: 5px 14px;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.viewswitch a:hover {
  color: var(--text);
}

.viewswitch a[aria-current="true"] {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 720px) {
  .viewswitch {
    margin-left: 0;
  }
}

/*
 * The environment chip and the sender picker are the toolbox's connection
 * state, and they have no meaning anywhere else.
 *
 * Written as "not the toolbox" rather than naming the reference: when the
 * front page and the guides were added, the old rule left a PRODUCTION chip
 * and a sender dropdown sitting in the top bar of a marketing page for anyone
 * who had connected once.
 *
 * Hidden in CSS and not by setting `hidden` from the router, on purpose: the
 * toolbox's own `renderHeader()` owns that attribute — it is what decides
 * whether you are connected at all — and two writers on one attribute is a
 * race that shows up as a chip flickering back on after a reconnect. A
 * display rule keyed off the view cannot fight it: the toolbox stays the only
 * thing that decides whether these exist, and the view decides whether they
 * are on screen.
 */
body:not([data-view="toolbox"]) #env-chip,
body:not([data-view="toolbox"]) #sender-picker {
  display: none !important;
}

/* ── The footer ───────────────────────────────────────────────────────── */

/*
 * The reading views end; the toolbox does not. It is an application with a
 * fixed-height rail and a log drawer, and a column of links under it would be
 * the only thing on the page that scrolls.
 */
body[data-view="toolbox"] .sitefoot {
  display: none;
}

.sitefoot {
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.sitefoot-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 20px;
}

.sitefoot-brand b {
  display: block;
  font-size: 13.5px;
}

.sitefoot-brand span {
  font-size: 12.5px;
  color: var(--text-muted);
}

.sitefoot-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
}

.sitefoot-links a {
  font-size: 13px;
  font-weight: 550;
  color: var(--text-muted);
  text-decoration: none;
}

.sitefoot-links a:hover {
  color: var(--brand);
  text-decoration: underline;
}

/* ── The top bar on a narrow screen ───────────────────────────────────── */

/*
 * Below 900px the bar ran off the side: the wordmark, a four-item switch and a
 * search field do not fit in 375px, and nothing wrapped — the "Toolbox" tab was
 * simply off-screen with no way to reach it. It becomes two rows instead, and
 * `--header-h` grows with it so every `scroll-margin-top` computed from it
 * still clears the bar.
 */
@media (max-width: 900px) {
  :root {
    --header-h: 104px;
  }

  /*
   * Two rows: the wordmark and the search field, then the view switch across
   * the full width underneath.
   *
   * `display: contents` on the two wrappers is what makes that possible — it
   * dissolves them so the bar's flex layout sees the wordmark, the search and
   * the switch directly and can order them independently. Without it the
   * switch is stuck inside `.topbar-left` with the wordmark, which is how the
   * fourth tab ended up off-screen with no way to reach it: 341px of tabs in
   * 253px of room, on the one view switch the whole site navigates by.
   */
  .topbar {
    height: auto;
    min-height: var(--header-h);
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
  }

  .topbar-left,
  .topbar-right {
    display: contents;
  }

  .wordmark {
    order: 1;
  }

  #search {
    order: 2;
    flex: 1 1 140px;
    width: auto;
    min-width: 0;
  }

  #log-button,
  #connect-button {
    order: 2;
  }

  .viewswitch {
    order: 3;
    flex: 1 0 100%;
    margin: 0;
    /* Still scrollable, as a backstop for a 320px screen or a longer label —
       but it should not need to be at any width we design for. */
    overflow-x: auto;
    scrollbar-width: none;
  }

  .viewswitch::-webkit-scrollbar {
    display: none;
  }

  .viewswitch a {
    flex: 1 1 auto;
    padding: 5px 10px;
    text-align: center;
  }

  .topbar-cta {
    display: none;
  }
}

@media (max-width: 460px) {
  /* The suffix is the first thing to go: "Profrakt" alone still says where you
     are, and the switch below it says what you are looking at. */
  .wordmark-sep,
  .wordmark-suffix {
    display: none;
  }
}
