/* JENNi Partner API portal.
 *
 * Every colour, radius, shadow, spacing step, font and easing curve below comes from
 * assets/brand/jenni-tokens.css, which build.sh copies verbatim out of
 * resources/brand/tokens/. Nothing here invents a value — that is a hard rule of the
 * binding design spec (resources/brand/JENNI-DESIGN-SPEC.md §0.1).
 *
 * The token file already defines the full light palette on bare :root, redefines it under
 * prefers-color-scheme: dark guarded by :not([data-theme='light']), and redefines it again
 * under :root[data-theme='dark']. So all three theme states — explicit light, explicit
 * dark, and OS default — resolve correctly, and this file only consumes the vars.
 */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--scale-body);
  line-height: 1.6;
  letter-spacing: var(--tracking);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-blue); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------------------------------------------------------------- app frame
   One header row (brand | topbar) over ONE content area. Scalar renders its own
   sidebar inside `main`; the brand column is sized to sit over it. There is no
   portal-side nav column any more — the guides are in the document (JEN-270). */

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr);
  grid-template-rows: 57px minmax(0, 1fr);
  grid-template-areas: "brand top" "main main";
  height: 100vh;
  height: 100dvh;
}

/* -------------------------------------------------------------------- topbar */

.brandbar,
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--background));
}

.brandbar {
  grid-area: brand;
  padding: 0 var(--space-2);
  border-right: 1px solid hsl(var(--border));
  min-width: 0;
}

.topbar {
  grid-area: top;
  padding: 0 var(--space-3);
  justify-content: flex-end;
}

.brandbar__mark { width: 26px; height: 26px; flex: none; display: block; }

.brandbar__text { min-width: 0; }

.brandbar__name {
  display: block;
  font-size: var(--scale-sm);
  font-weight: 700;
  letter-spacing: var(--tracking-tight);
  line-height: 1.15;
  white-space: nowrap;
}

.brandbar__sub {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  opacity: 0.6;
  line-height: 1.4;
}

.chip {
  font-family: var(--mono);
  font-size: var(--scale-xs);
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--alpha-blue-15);
  color: var(--brand-blue);
  white-space: nowrap;
}

.chip--env {
  background: var(--alpha-navy-04);
  color: hsl(var(--muted-foreground));
}

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  flex: none;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-button);
  background: transparent;
  color: hsl(var(--foreground));
  cursor: pointer;
  transition: background var(--motion-quick) var(--ease-jenni),
              border-color var(--motion-quick) var(--ease-jenni);
}
.iconbtn:hover { background: var(--alpha-blue-08); border-color: var(--brand-blue); }
.iconbtn svg { width: 17px; height: 17px; }

/* The two glyphs swap by theme so the button always shows the state it switches TO. */
:root .iconbtn .i-sun { display: none; }
:root .iconbtn .i-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .iconbtn .i-sun { display: block; }
  :root:not([data-theme='light']) .iconbtn .i-moon { display: none; }
}
:root[data-theme='dark'] .iconbtn .i-sun { display: block; }
:root[data-theme='dark'] .iconbtn .i-moon { display: none; }

/* "Your access" — the topbar button that opens the per-partner drawer. Shows the
   current state so a narrowed view is never a surprise. */

.accessbtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 12px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-button);
  background: transparent;
  color: hsl(var(--foreground));
  font: inherit;
  font-size: var(--scale-sm);
  cursor: pointer;
  transition: background var(--motion-quick) var(--ease-jenni),
              border-color var(--motion-quick) var(--ease-jenni);
}
.accessbtn:hover { background: var(--alpha-blue-08); border-color: var(--brand-blue); }
.accessbtn[aria-expanded='true'] { border-color: var(--brand-blue); }
.accessbtn__label { font-weight: 600; white-space: nowrap; }
.accessbtn__state {
  font-family: var(--mono);
  font-size: var(--scale-xs);
  letter-spacing: var(--tracking-mono);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--alpha-navy-04);
  color: hsl(var(--muted-foreground));
  white-space: nowrap;
}
.accessbtn[data-source='preview'] .accessbtn__state,
.accessbtn[data-source='key'] .accessbtn__state {
  background: var(--alpha-blue-15);
  color: var(--brand-blue);
}


/* -------------------------------------------------------------------- access
   The per-partner control, as a drawer under the topbar (opened by .accessbtn).
   Uses the brand tokens only — no colour is written literally here, so the panel
   follows a token change. */

.access {
  position: fixed;
  top: 61px;
  right: var(--space-3);
  z-index: 15;
  width: 320px;
  max-width: calc(100vw - 2 * var(--space-2));
  max-height: calc(100vh - 70px);
  overflow-y: auto;
  padding: var(--space-2) var(--space-1) var(--space-3);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--background));
  box-shadow: var(--e3);
}
.access[hidden] { display: none; }

.access__label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  padding: 0 10px var(--space-1);
  margin: 0;
  font-weight: 400;
}

.access__source { display: grid; gap: 2px; margin-bottom: var(--space-2); }

.access__radio {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius-button);
  cursor: pointer;
  transition: background var(--motion-quick) var(--ease-jenni);
}
.access__radio:hover { background: var(--alpha-blue-08); }
.access__radio.is-on { background: var(--alpha-blue-15); }
.access__radio input { margin-top: 3px; accent-color: var(--brand-blue); flex: none; }
.access__radio strong {
  display: block;
  font-size: var(--scale-sm);
  font-weight: 600;
  line-height: 1.3;
}
.access__radio.is-on strong { color: var(--brand-blue); }
.access__radio small {
  display: block;
  font-size: var(--scale-xs);
  opacity: 0.65;
  line-height: 1.35;
  margin-top: 1px;
}
.access__radio input:disabled + span { opacity: 0.45; }

.access__badge {
  margin: 0 0 var(--space-2);
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  font-family: var(--mono);
  font-size: var(--scale-xs);
  letter-spacing: var(--tracking-mono);
  background: var(--alpha-navy-04);
  color: hsl(var(--muted-foreground));
  text-align: center;
}
.access__badge--live { background: var(--alpha-blue-15); color: var(--brand-blue); }

.access__sub {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  margin: var(--space-2) 0 6px;
  padding: 0 10px;
}

.access__set { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 10px; }

.access__chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-pill);
  font-family: var(--mono);
  font-size: var(--scale-xs);
  letter-spacing: var(--tracking-mono);
  cursor: pointer;
  transition: background var(--motion-quick) var(--ease-jenni),
              border-color var(--motion-quick) var(--ease-jenni);
}
.access__chip:hover { background: var(--alpha-blue-08); }
.access__chip.is-on {
  background: var(--alpha-blue-15);
  border-color: var(--brand-blue);
  color: var(--brand-blue);
}
.access__chip input { accent-color: var(--brand-blue); margin: 0; }

/* "Use my key" — the live half of the panel. Only rendered when the host set
   window.JENNI_PORTAL_API. The notice is visible and sits above the preview
   controls, which stay enabled: a rejected key narrows nothing and blocks nothing. */

.access__key { margin: var(--space-2) 0 var(--space-1); }

.access__keyform label.access__sub { display: block; }

.access__keyrow { display: flex; gap: 6px; padding: 0 10px; }

.access__keyinput {
  flex: 1 1 auto;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-button);
  background: hsl(var(--card));
  color: inherit;
  font-family: var(--mono);
  font-size: var(--scale-xs);
  letter-spacing: var(--tracking-mono);
}
.access__keyinput:focus-visible { outline: 2px solid var(--brand-blue); outline-offset: 1px; }

.access__keybtn,
.access__forget {
  flex: none;
  padding: 6px 10px;
  border: 1px solid var(--brand-blue);
  border-radius: var(--radius-button);
  background: var(--alpha-blue-15);
  color: var(--brand-blue);
  font: inherit;
  font-size: var(--scale-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--motion-quick) var(--ease-jenni);
}
.access__keybtn:hover,
.access__forget:hover { background: var(--alpha-blue-30); }
.access__keybtn:disabled { opacity: 0.55; cursor: progress; }
.access__forget { margin: 0 10px; }

.access__hint {
  margin: 6px 0 0;
  padding: 0 10px;
  font-size: var(--scale-xs);
  line-height: 1.35;
  opacity: 0.65;
}
.access__hint code { font-family: var(--mono); font-size: inherit; }

.access__notice {
  margin: var(--space-2) 10px 0;
  padding: 7px 10px;
  border-left: 3px solid var(--warning);
  border-radius: var(--radius-button);
  background: var(--alpha-navy-04);
  font-size: var(--scale-xs);
  line-height: 1.4;
}
.access__notice--rejected { border-left-color: var(--danger); }

/* ---------------------------------------------------------------------- main */

.main { grid-area: main; overflow-y: auto; overscroll-behavior: contain; min-width: 0; }

/* Scalar owns its own scrolling and sidebar; give it the full area. */
#reference { height: 100%; }

/* ---------------------------------------------------------------- messaging */

.notice {
  max-width: 720px;
  margin: var(--space-6) auto;
  padding: var(--space-3);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--card));
}
.notice h2 { margin-top: 0; font-size: var(--scale-h4); }
.notice p:last-child { margin-bottom: 0; }
.notice code { font-family: var(--mono); font-size: var(--scale-sm); }

.skiplink {
  position: absolute;
  left: -9999px;
  top: 8px;
  padding: 8px 14px;
  border-radius: var(--radius-button);
  background: var(--brand-blue);
  color: var(--brand-white);
  z-index: 20;
}
.skiplink:focus { left: 8px; }

/* -------------------------------------------------------------- scalar host */

/* Scalar renders its own theme. These few rules only align its shell with the
 * page frame; the reference itself keeps Scalar's own (already accessible) tokens. */
#reference .scalar-app { --scalar-font: var(--font); --scalar-font-code: var(--mono); }

/* ------------------------------------------------------------- landing cards
   content/landing.md (info.description) carries one card per reader — POS systems,
   Brands, Marketplaces & channels, Fulfillment & delivery — as plain HTML that Scalar's
   markdown sanitizer keeps: div/h3/p/code keep a class name, `a` does NOT (its schema
   allows className only on footnote back-references; measured on the vendored 1.67.0,
   2026-09-15). The card title links to the group (`#tag-group/<slug>`, measured to
   scroll), and every guide or tag named in the card is its own `#tag/<slug>` link.
   Tokens only. */

#reference .jenni-personas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-2);
  margin: var(--space-3) 0;
}

#reference .jenni-persona {
  padding: var(--space-2);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  transition: border-color 120ms ease;
}
#reference .jenni-persona:hover,
#reference .jenni-persona:focus-within { border-color: var(--brand-blue); }
#reference .jenni-persona h3 {
  margin: 0 0 var(--space-1);
  font-size: var(--scale-h4);
  line-height: 1.25;
}
#reference .jenni-persona h3 a { color: var(--brand-blue); text-decoration: none; }
#reference .jenni-persona h3 a:hover { text-decoration: underline; }
#reference .jenni-persona p {
  margin: 0 0 var(--space-1);
  font-size: var(--scale-sm);
  line-height: 1.5;
}
#reference .jenni-persona p:last-child { margin-bottom: 0; }
#reference .jenni-persona code { font-family: var(--mono); font-size: var(--scale-xs); }
#reference .jenni-persona__status {
  color: hsl(var(--muted-foreground));
  font-size: var(--scale-xs);
}

/* ----------------------------------------------------------- Reference, folded
   The `Reference` x-tagGroup starts folded in the sidebar (portal.js toggles .is-open;
   see the comment there). Scalar gives the section `data-sidebar-id` = <spec>/tag-group/
   reference, a title row (the child div classed `group/button` — its spacer siblings
   are divs too, so the class is matched, not the position) and the list (ul). */

#reference li[data-sidebar-id$="/tag-group/reference"] > div[class~="group/button"] { cursor: pointer; }
#reference li[data-sidebar-id$="/tag-group/reference"] > div[class~="group/button"]::after {
  content: '\25B8';                     /* ▸ */
  margin-left: auto;
  padding-right: var(--space-1);
  font-size: var(--scale-xs);
  opacity: 0.7;
}
#reference li[data-sidebar-id$="/tag-group/reference"].is-open > div[class~="group/button"]::after { content: '\25BE'; } /* ▾ */
#reference li[data-sidebar-id$="/tag-group/reference"]:not(.is-open) > ul { display: none; }

/* ------------------------------------------------------------------ responsive */

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 57px minmax(0, 1fr);
    grid-template-areas: "top" "main";
  }
  .brandbar {
    grid-area: top;
    border-right: 0;
    justify-content: flex-start;
  }
  .topbar { grid-area: top; background: none; border: 0; padding-right: var(--space-2); }
  /* One row, two ends: the brand text on the left must never sit under the controls.
   * The version/env chips go (the spec badge in the reference still says both), and
   * the access button keeps its STATE only — "All access" / "Preview" / "Live · key"
   * is the part that carries information; "Your access" is a label the drawer repeats. */
  .chip { display: none; }
  .accessbtn__label { display: none; }
  .access { right: var(--space-1); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; animation-duration: 1ms !important; }
}
