/* ==========================================================================
   studio.css — Agent Studio's tokens and layout.

   Calm and professional: graphite neutrals and one accent (a steady blue)
   that means "act here". Light and dark follow prefers-color-scheme. Text
   pairs meet WCAG AA; every control shows a visible focus ring and is at
   least 44px tall. No web fonts: the system stack, so it runs air-gapped.
   ========================================================================== */

:root {
  color-scheme: light dark;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #eef0f2;
  --ink: #1b1e22;
  --ink-2: #4a525c;            /* 7.9:1 on surface */
  --rule: #dcdfe3;
  --rule-strong: #b3bac3;
  --accent: #2b55c7;           /* 6.3:1 on white */
  --accent-ink: #ffffff;
  --accent-tint: #e8eefb;
  --ok: #1e7446;
  --ok-tint: #e5f3eb;
  --bad: #b3261e;
  --bad-tint: #fbeae9;
  --warn: #7a5200;
  --warn-tint: #fbf2dc;
  --focus: #2b55c7;
  --shadow: 0 1px 2px rgba(20, 24, 28, .06), 0 1px 3px rgba(20, 24, 28, .08);

  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --r: 8px;
  --r-lg: 12px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --side: 248px;
  --side-min: 64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111315;
    --surface: #191c1f;
    --surface-2: #22262a;
    --ink: #e6e8eb;
    --ink-2: #a8b0b9;          /* 7.6:1 on surface */
    --rule: #2d3237;
    --rule-strong: #48505a;
    --accent: #8fabff;         /* 7.9:1 on surface */
    --accent-ink: #0d1424;
    --accent-tint: #1d2740;
    --ok: #6fd19a;
    --ok-tint: #16281e;
    --bad: #ff9186;
    --bad-tint: #2e1917;
    --warn: #e7bb5a;
    --warn-tint: #2b2413;
    --focus: #8fabff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 var(--sans); }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.3; text-wrap: balance; }
h1 { margin: 0; font-size: 1.5rem; font-weight: 650; }
h2 { margin: 0 0 var(--s3); font-size: 1.05rem; font-weight: 650; }
h3 { margin: var(--s4) 0 var(--s2); font-size: .8rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-2); }
p { margin: 0 0 var(--s2); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
h1:focus, main:focus { outline: none; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .92em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.muted { color: var(--ink-2); }
.small { font-size: .85rem; }
.grow { flex: 1 1 auto; min-width: 0; }
.icon { flex: none; }

.skip { position: absolute; left: var(--s3); top: -60px; z-index: 50; padding: var(--s3) var(--s4); background: var(--surface); border-radius: var(--r); }
.skip:focus { top: var(--s3); }

/* ------------------------------------------------------------ shell */

.app { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-height: 100vh; }
.app[data-nav="collapsed"] { grid-template-columns: var(--side-min) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: var(--s2);
  background: var(--surface); border-right: 1px solid var(--rule); padding: var(--s3) var(--s2); overflow-y: auto; z-index: 20; }
.brand { display: flex; align-items: center; gap: var(--s2); padding: var(--s1) var(--s2); min-height: 48px; color: var(--accent); }
.brandtext { display: flex; flex-direction: column; min-width: 0; flex: 1; color: var(--ink); }
.product { font-weight: 700; }
.tenant { font-size: .82rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.navtoggle { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: var(--r); background: none; color: var(--ink-2); cursor: pointer; }
.navtoggle:hover { background: var(--surface-2); color: var(--ink); }
.navgroup { margin: var(--s4) var(--s3) var(--s1); font-size: .72rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
#sidenav ul { list-style: none; margin: 0; padding: 0; }
#sidenav a, .footlink { display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s3); border-radius: var(--r);
  color: var(--ink); text-decoration: none; font: inherit; width: 100%; background: none; border: 0; cursor: pointer; text-align: left; }
#sidenav a:hover, .footlink:hover { background: var(--surface-2); }
#sidenav a[aria-current="page"] { background: var(--accent-tint); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sidefoot { margin-top: auto; padding-top: var(--s3); border-top: 1px solid var(--rule); display: flex; flex-direction: column; gap: var(--s1); }
.person { display: flex; flex-direction: column; gap: 2px; padding: var(--s2) var(--s3); min-width: 0; }
.person .who { font-weight: 600; overflow-wrap: anywhere; }
.basis { align-self: flex-start; margin: var(--s1) 0; padding: 1px var(--s2); border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--rule-strong); }
.basis[data-basis="fde"], .basis[data-basis="admin"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent); }
.basis[data-basis="dev"] { background: var(--warn-tint); border-color: var(--warn); color: var(--warn); }

.app[data-nav="collapsed"] .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.app[data-nav="collapsed"] .navgroup { font-size: 0; margin: var(--s3) 0 0; border-top: 1px solid var(--rule); }
.app[data-nav="collapsed"] .brand { flex-direction: column; padding: 0; }
.app[data-nav="collapsed"] #sidenav a, .app[data-nav="collapsed"] .footlink { justify-content: center; padding: 0; }
.app[data-nav="collapsed"] .person { display: none; }

@media (max-width: 900px) {
  .app, .app[data-nav="collapsed"], .app[data-nav="expanded"] { grid-template-columns: var(--side-min) minmax(0, 1fr); }
  .app[data-nav="expanded"] .sidebar { width: var(--side); box-shadow: 0 8px 24px rgba(0, 0, 0, .25); }
}

.main { padding: var(--s5) clamp(var(--s4), 3vw, var(--s6)) var(--s6); min-width: 0; max-width: 1360px; }

/* ------------------------------------------------------------ gate screens */

.gate { min-height: 100vh; display: grid; place-items: center; padding: var(--s4); }
.gatecard { max-width: 34rem; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: var(--s6); box-shadow: var(--shadow); }
.gatecard h1 { margin-bottom: var(--s3); }
.gatecard p { color: var(--ink-2); }
.gatebrand { display: flex; align-items: center; gap: var(--s2); color: var(--accent); font-weight: 700; margin-bottom: var(--s4); }

/* ------------------------------------------------------------ page furniture */

.pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3) var(--s4); margin-bottom: var(--s5); }
.lede { margin: var(--s1) 0 0; color: var(--ink-2); max-width: 70ch; }
.listhead { margin: var(--s6) 0 var(--s1); font-size: .8rem; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-2); }
.listhead + .hint { margin-bottom: var(--s3); }
.loading { display: flex; align-items: center; gap: var(--s3); color: var(--ink-2); padding: var(--s5) 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--rule-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.empty { padding: var(--s6) var(--s5); border: 1px dashed var(--rule-strong); border-radius: var(--r-lg); background: var(--surface); max-width: 60rem; }
.empty p { color: var(--ink-2); margin: 0; }
.notice { padding: var(--s4) var(--s5); border-radius: var(--r-lg); background: var(--surface); border: 1px solid var(--rule); border-left: 4px solid var(--rule-strong); margin-bottom: var(--s4); max-width: 60rem; }
.notice[data-kind="error"] { border-left-color: var(--bad); }
.notice[data-kind="license"] { border-left-color: var(--warn); background: var(--warn-tint); }
.notice p:last-child { margin-bottom: 0; }
.flash { padding: var(--s3) var(--s4); border-radius: var(--r); margin: 0 0 var(--s4); background: var(--ok-tint); color: var(--ink); border-left: 4px solid var(--ok); max-width: 60rem; }
.flash[data-kind="error"] { background: var(--bad-tint); border-left-color: var(--bad); }
.err { color: var(--bad); font-size: .88rem; margin: var(--s2) 0 0; }
.hint { color: var(--ink-2); font-size: .85rem; margin: var(--s1) 0 0; max-width: 70ch; }
.callout { padding: var(--s3) var(--s4); border-radius: var(--r); background: var(--surface-2); border-left: 3px solid var(--rule-strong); font-size: .88rem; max-width: 72ch; margin: var(--s3) 0; }
.callout[data-kind="error"] { border-left-color: var(--bad); background: var(--bad-tint); }
.callout[data-kind="held"] { border-left-color: var(--accent); background: var(--accent-tint); }
.callout p:last-child { margin-bottom: 0; }
.statrow { display: flex; flex-wrap: wrap; gap: var(--s3); margin-bottom: var(--s5); }
.stat { display: flex; flex-direction: column; min-width: 9rem; padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r); }
.stat .n { font-size: 1.4rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .k { color: var(--ink-2); font-size: .85rem; }
.stat .sub { color: var(--ink-2); font-size: .78rem; }
.facts { display: grid; grid-template-columns: minmax(9rem, max-content) 1fr; gap: var(--s2) var(--s4); margin: 0 0 var(--s4); font-size: .92rem; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.sec { margin: 0 0 var(--s5); }
.crumbs { font-size: .88rem; margin-bottom: var(--s2); }
.crumbs a { display: inline-flex; align-items: center; min-height: 32px; }
.crumbs a::before { content: "‹"; margin-right: var(--s1); }

/* ------------------------------------------------------------ chips */

.chip { display: inline-flex; align-items: center; padding: 1px var(--s2); border-radius: 999px; border: 1px solid var(--rule-strong);
  font-size: .76rem; font-weight: 600; line-height: 1.5; white-space: nowrap; color: var(--ink-2); background: var(--surface); }
.chip[data-state="published"], .chip[data-state="pass"], .chip[data-state="completed"], .chip[data-state="connected"] { color: var(--ok); border-color: var(--ok); background: var(--ok-tint); }
.chip[data-state="retired"], .chip[data-state="fail"], .chip[data-state="failed"], .chip[data-state="stopped"], .chip[data-state="effect-irreversible"] { color: var(--bad); border-color: var(--bad); background: var(--bad-tint); }
.chip[data-state="draft"], .chip[data-state="stale"] { color: var(--warn); border-color: var(--warn); background: var(--warn-tint); }
.chip[data-state="awaiting-approval"], .chip[data-state="effect-write"], .chip[data-state="external"] { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }
.chips, .tags { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }

/* ------------------------------------------------------------ buttons */

.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r); border: 1px solid var(--rule-strong); background: var(--surface); color: var(--ink);
  font: 600 .92rem/1 var(--sans); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: none; color: var(--accent); }
.btn.quiet:hover { background: var(--accent-tint); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn[disabled] { opacity: .55; cursor: not-allowed; filter: none; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-top: var(--s4); }
.actions.end { justify-content: flex-end; margin-top: var(--s2); }

/* ------------------------------------------------------------ forms */

.field { display: flex; flex-direction: column; gap: var(--s1); margin-bottom: var(--s4); min-width: 0; }
.field label, fieldset legend { font-weight: 600; font-size: .9rem; }
.req { font-weight: 400; color: var(--ink-2); }
input[type="text"], input[type="number"], select, textarea {
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3); border-radius: var(--r); border: 1px solid var(--rule-strong);
  background: var(--surface); color: var(--ink); font: inherit; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
[aria-invalid="true"] { border-color: var(--bad) !important; }
textarea { resize: vertical; line-height: 1.55; }
textarea.code { font: 400 .85rem/1.55 var(--mono); min-height: 28rem; tab-size: 2; }
textarea.code.short { min-height: 14rem; }
select { appearance: auto; }
.check { display: flex; align-items: flex-start; gap: var(--s3); min-height: 44px; padding: var(--s2) 0; font-size: .92rem; cursor: pointer; }
.check input { flex: none; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); }
.checklist { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r); background: var(--surface); }
.checklist .check { padding: var(--s2) var(--s3); border-bottom: 1px solid var(--rule); }
.checklist .check:last-child { border-bottom: 0; }
.toolbody { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.row2 { display: grid; gap: 0 var(--s4); grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); }
.row3 { display: grid; gap: 0 var(--s4); grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.rowcard { border: 1px solid var(--rule); border-radius: var(--r-lg); padding: var(--s3) var(--s4) var(--s2); margin: 0 0 var(--s3); background: var(--surface); }
.rowcard legend { padding: 0 var(--s2); }
fieldset.inline { margin-bottom: var(--s3); }
fieldset.inline legend { margin-bottom: var(--s1); }

/* ------------------------------------------------------------ galleries */

.grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); }
.card { display: flex; flex-direction: column; gap: var(--s2); padding: var(--s4); min-height: 44px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--r-lg); text-decoration: none; box-shadow: var(--shadow); }
.card:hover { border-color: var(--accent); }
.cardhead { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.cardtitle { font-weight: 650; overflow-wrap: anywhere; }
.cardmeta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: .85rem; }
.card.starter { box-shadow: none; background: transparent; border-style: dashed; }
.cardcta { margin-top: auto; color: var(--accent); font-size: .85rem; font-weight: 600; }

.rows { display: flex; flex-direction: column; border: 1px solid var(--rule); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; }
.rowlink { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); min-height: 52px; padding: var(--s2) var(--s4); color: var(--ink);
  text-decoration: none; border-bottom: 1px solid var(--rule); }
.rowlink:last-child { border-bottom: 0; }
.rowlink:hover { background: var(--surface-2); }
.rowtitle { font-weight: 600; }
.segmented { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: var(--s4); border-radius: var(--r); background: var(--surface-2); border: 1px solid var(--rule); }
.segmented a, .segmented button { display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--s4); border-radius: 6px; border: 0;
  background: none; color: var(--ink-2); font: 600 .9rem/1 var(--sans); text-decoration: none; cursor: pointer; }
.segmented [aria-current="page"], .segmented [aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

/* ------------------------------------------------------------ focused panels (create flows) */

.focuspanel { max-width: 40rem; }
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: var(--s5); box-shadow: var(--shadow); }
.panel h1 { margin-bottom: var(--s4); font-size: 1.3rem; }

/* ------------------------------------------------------------ builder */

.topbar { position: sticky; top: 0; z-index: 10; margin: calc(-1 * var(--s5)) calc(-1 * clamp(var(--s4), 3vw, var(--s6))) var(--s4);
  padding: var(--s3) clamp(var(--s4), 3vw, var(--s6)); background: var(--bg);
  border-bottom: 1px solid var(--rule); }
.titlerow { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s3); margin-bottom: var(--s1); }
.titlerow h1 { font-size: 1.35rem; overflow-wrap: anywhere; }
.unsaved { padding: 1px var(--s2); border-radius: 999px; font-size: .78rem; font-weight: 700; color: var(--warn); background: var(--warn-tint); border: 1px solid var(--warn); }
.nexthint { margin: 0; color: var(--ink-2); font-size: .88rem; }
.retirebar { margin-top: var(--s3); padding: var(--s3) var(--s4); border: 1px solid var(--bad); border-radius: var(--r); background: var(--surface); max-width: 40rem; }
.retirebar .actions { margin-top: 0; }
.problems { padding: var(--s3) var(--s4); margin-bottom: var(--s4); border-radius: var(--r); background: var(--bad-tint); border-left: 4px solid var(--bad); }
.problems h2 { font-size: .95rem; margin-bottom: var(--s2); }
.problems ul { margin: 0; padding-left: var(--s5); font-size: .88rem; }
.builder-grid { display: grid; gap: var(--s5); align-items: start; }
@media (min-width: 1100px) { .builder-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, 400px); } }
.config .sec { padding: var(--s4) var(--s5); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); margin-bottom: var(--s3); }
.config .sec > h2 { font-size: .98rem; }
.config .sec .field:last-child { margin-bottom: 0; }
.viewtoggle { display: flex; justify-content: flex-end; margin-bottom: var(--s2); }
.testpanel { padding: var(--s4) var(--s5); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); min-width: 0; }
@media (min-width: 1100px) { .testpanel { position: sticky; top: 132px; max-height: calc(100vh - 148px); overflow-y: auto; } }
.report { margin-top: var(--s4); }
details.deploy, details.transcript { margin-top: var(--s4); padding: var(--s2) var(--s4); background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); }
details summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; }

/* ------------------------------------------------------------ tables, lists, code */

.tablewrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--r); background: var(--surface); }
.tbl { width: 100%; border-collapse: collapse; font-size: .88rem; }
.tbl th, .tbl td { text-align: left; vertical-align: top; padding: var(--s2) var(--s3); border-bottom: 1px solid var(--rule); overflow-wrap: break-word; }
.tbl td:not(.mono):not(:has(.mono)) { min-width: 9ch; }
.tbl thead th { font-weight: 650; color: var(--ink-2); background: var(--surface-2); white-space: nowrap; }
.tbl tbody th { font-weight: 600; }
.tbl tbody tr:last-child > * { border-bottom: 0; }
.steps { list-style: none; margin: 0; padding: 0; counter-reset: step; font-size: .88rem; }
.steps li { display: grid; grid-template-columns: 2.5ch 11ch 1fr; gap: var(--s2); padding: var(--s2) 0; border-bottom: 1px solid var(--rule); counter-increment: step; }
.steps li::before { content: counter(step); color: var(--ink-2); font-family: var(--mono); }
.steps .k { color: var(--ink-2); overflow-wrap: anywhere; }
.steps .s { overflow-wrap: anywhere; min-width: 0; }
.steps li[data-kind="refused"] .k, .steps li[data-kind="error"] .k, .steps li[data-kind="invalid"] .k, .steps li[data-kind="failed"] .k { color: var(--bad); }
.pre { margin: 0; padding: var(--s3); background: var(--surface-2); border-radius: var(--r); font: 400 .84rem/1.55 var(--mono);
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 28rem; overflow: auto; }
.hits { list-style: none; margin: var(--s4) 0 0; padding: 0; display: flex; flex-direction: column; gap: var(--s3); }
.hittitle { font-weight: 600; margin: 0; }
.cite { color: var(--ink-2); font-size: .85rem; margin: 0 0 var(--s1); }
.plainlist { margin: var(--s2) 0 0; padding-left: var(--s5); }
.plainlist li + li { margin-top: var(--s1); }
.turn { margin-top: var(--s2); }

@media (max-width: 600px) {
  .main { padding-top: var(--s4); }
  .topbar { margin-top: calc(-1 * var(--s4)); }
  .facts { grid-template-columns: 1fr; gap: 0; }
  .facts dd { margin-bottom: var(--s2); }
  .panel, .config .sec, .testpanel { padding: var(--s4); }
  .steps li { grid-template-columns: 2.5ch 1fr; }
  .steps li .s { grid-column: 2; }
}
