/* Craggy Studio: the harness's Graphite tokens, Shell B (docs/ui/style.md). */
:root {
  --rail: #0F0F11; --sidebar: #141416; --workspace: #18181B; --surface: #232326; --raised: #2A2A2E;
  --field: #111113; --fieldBorder: #2E2E33; --rim: #36363C; --border: #2A2A2F;
  --text: #E8E8EC; --muted: #A3A3AD; --faint: #86868F;
  --accent: #FF9A3C; --accentSoft: rgba(255,154,60,.14); --onAccent: #1A1207;
  --success: #3DDC97; --warning: #FFC857; --danger: #FF6B6B; --info: #5AA9FF; --link: #8DB4FF;
  --sans: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--workspace); color: var(--text); font: 14px/1.5 var(--sans); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 23px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 24px 0 10px; }
h3 { font-size: 14px; font-weight: 600; margin: 0; }
p { margin: 6px 0; }
.hidden { display: none !important; }

/* Top bar */
.top { position: sticky; top: 0; z-index: 20; height: 52px; background: var(--rail); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 0 24px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); margin-right: 18px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); flex: none; }
.nav { display: flex; height: 52px; }
.nav a { display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }
.nav a.on { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.gap { flex: 1; }
.search { width: 220px; height: 32px; display: flex; align-items: center; justify-content: space-between; padding: 0 10px;
  background: var(--field); border: 1px solid var(--fieldBorder); border-radius: 6px; color: var(--faint); cursor: pointer; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--rim); border-radius: 4px; padding: 0 5px; }
.balance { color: var(--accent); font-weight: 600; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--raised); display: grid; place-items: center; font-weight: 600; font-size: 12px; }
.account { position: relative; }
button.avatar { border: 1px solid var(--rim); color: var(--text); font: inherit; font-weight: 600; font-size: 12px; padding: 0; cursor: pointer; }
button.avatar.in { background: var(--accent); border-color: var(--accent); color: var(--onAccent); }
button.avatar:hover, button.avatar[aria-expanded=true] { filter: brightness(1.1); }
.account .menu { position: absolute; top: calc(100% + 8px); right: 0; min-width: 220px; max-width: min(300px, calc(100vw - 32px)); z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 18px 50px rgba(0,0,0,.45); padding: 6px; }
.account .menu[hidden] { display: none; }
.account .who { padding: 8px 10px 10px; border-bottom: 1px solid var(--border); margin-bottom: 6px; line-height: 1.5; }
.account .who strong, .account .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account .who span { color: var(--muted); font-size: 12px; }
.account .item { display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 5px; background: none; color: var(--text);
  font: inherit; font-weight: 500; text-align: left; cursor: pointer; }
.account .item:hover { background: var(--raised); color: var(--accent); text-decoration: none; }
.account .item:disabled { opacity: .6; cursor: default; }

/* Page */
main { max-width: 1100px; margin: 0 auto; padding: 20px 24px 80px; }
main.flowpage { max-width: 1100px; }
.crumbs { color: var(--faint); font-size: 13px; margin-bottom: 2px; }
.crumbs a { color: var(--faint); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 -24px 20px; padding: 0 24px; overflow-x: auto; }
.tabs a { height: 40px; display: flex; align-items: center; gap: 6px; padding: 0 14px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.on { color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }
.meta { color: var(--faint); font-size: 13px; }
.muted { color: var(--muted); }
.line { color: var(--muted); margin: 4px 0 16px; }
.narrow { max-width: 960px; margin: 0 auto; }

/* Controls */
.btn { height: 32px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--rim); background: #2A2A2F; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; color: var(--text); }
.btn:hover { background: #323237; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--onAccent); font-weight: 600; }
.btn.primary:hover { background: #ffa955; }
.btn.outline { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.small { height: 26px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { color: var(--muted); font-size: 13px; }
.field small { color: var(--faint); font-size: 12px; }
input[type=text], input[type=number], input[type=password], select, textarea {
  background: var(--field); border: 1px solid var(--fieldBorder); border-radius: 6px; padding: 0 10px; height: 32px; outline: none; width: 100%; }
textarea { padding: 8px 10px; height: auto; min-height: 120px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5; resize: vertical; }
textarea.code { min-height: 420px; tab-size: 4; white-space: pre; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: inline-flex; padding: 2px; border: 1px solid var(--rim); border-radius: 6px; }
.seg button { height: 26px; padding: 0 12px; border: 0; background: transparent; color: var(--muted); border-radius: 4px; cursor: pointer; }
.seg button.on { background: #2A2A2F; color: var(--text); }

/* Chips */
.chip { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 4px; font-size: 12px; font-weight: 600;
  background: var(--raised); color: var(--muted); white-space: nowrap; }
.chip.info { background: rgba(90,169,255,.14); color: var(--info); }
.chip.accent { background: var(--accentSoft); color: var(--accent); }
.chip.success { background: rgba(61,220,151,.14); color: var(--success); }
.chip.warning { background: rgba(255,200,87,.14); color: var(--warning); }
.chip.danger { background: rgba(255,107,107,.14); color: var(--danger); }
.chip.kind { width: 84px; justify-content: center; flex: none; }
.pill { font-family: var(--mono); font-size: 12.5px; background: var(--field); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; }

/* Cards, rows, tables */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.card.pad { padding: 16px; }
.rows > * { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 40px; border-top: 1px solid var(--border); color: var(--text); }
.rows > *:first-child { border-top: 0; }
.rows > a:hover { background: var(--raised); text-decoration: none; }
.rows .grow { flex: 1; min-width: 0; }
.rows .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 18px; color: var(--faint); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding: 8px 12px; }
td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
tr.link { cursor: pointer; }
tr.link:hover td { background: var(--raised); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
pre.block { background: var(--field); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow: auto; font-family: var(--mono);
  font-size: 12.5px; margin: 6px 0; max-height: 420px; white-space: pre-wrap; word-break: break-word; }
.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.banner.info { background: rgba(90,169,255,.07); border: 1px solid rgba(90,169,255,.25); }
.banner.warning { background: rgba(255,200,87,.07); border: 1px solid rgba(255,200,87,.25); }
.banner.danger { background: rgba(255,107,107,.07); border: 1px solid rgba(255,107,107,.25); }
.banner.success { background: rgba(61,220,151,.07); border: 1px solid rgba(61,220,151,.25); }
.banner .grow { flex: 1; }
.progress { height: 6px; border-radius: 3px; background: #2A2A2F; overflow: hidden; }
.progress > div { height: 100%; background: var(--info); width: 0; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.tile { background: var(--workspace); border: 1px solid var(--border); border-radius: 10px; padding: 12px; cursor: pointer; text-align: left; color: var(--text); }
.tile:hover { border-color: var(--rim); background: var(--raised); }
.tile.on { border-color: var(--accent); }
.tile p { margin: 8px 0 2px; font-weight: 500; }
.tile .meta { font-size: 12.5px; }
.tile .meta.mono { font-family: var(--mono); font-size: 12px; }
.problems li { color: var(--warning); margin: 3px 0; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--rim);
  border-radius: 8px; padding: 10px 16px; z-index: 60; box-shadow: 0 10px 30px rgba(0,0,0,.5); max-width: 90vw; }
.toast.error { border-color: var(--danger); }

/* Flow */
.flowbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.wire { width: 2px; height: 14px; background: var(--rim); margin-left: 58px; }
.wire.lit { background: var(--info); }
.step { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 16px; display: flex; gap: 14px; align-items: center; cursor: pointer; }
.step:hover { border-color: var(--rim); }
.step.open { border-color: var(--accent); cursor: default; display: block; }
.step.glow { border-color: rgba(255,154,60,.55); box-shadow: 0 0 0 3px rgba(255,154,60,.1); }
.step .say { flex: 1; min-width: 0; }
.step .say .out { color: var(--faint); font-size: 13px; margin-top: 2px; }
.step .cost { color: var(--faint); font-size: 13px; white-space: nowrap; }
.loop { border: 1px dashed var(--rim); border-radius: 12px; padding: 12px; }
.loop > .loophead { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; cursor: pointer; }
.stepform { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.addstep { margin-top: 14px; padding: 14px; }
.graph { background: var(--sidebar); border: 1px solid var(--border); border-radius: 10px; overflow: auto; padding: 10px; }
.graph svg text { font: 12px var(--sans); }
.graph svg text:not(.k) { fill: var(--text); }
.graph svg text.k { font-weight: 600; font-size: 11px; }

/* Drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: 480px; max-width: 100vw; background: var(--sidebar); border-left: 1px solid var(--rim);
  box-shadow: -20px 0 40px rgba(0,0,0,.4); z-index: 50; display: flex; flex-direction: column; }
.drawer header { height: 52px; display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--border); }
.drawer header select { width: auto; max-width: 220px; min-width: 0; flex: 0 1 auto; }
.drawer header .btn { flex: none; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.you { align-self: flex-end; background: #2A2A2F; border-radius: 12px 12px 4px 12px; padding: 8px 12px; max-width: 85%; white-space: pre-wrap; }
.reply { white-space: pre-wrap; }
.reply .cost { color: var(--faint); font-size: 12px; margin-top: 4px; }
.toolline { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.toolline .mono { color: var(--faint); font-size: 11.5px; }
.cardmsg { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.cardmsg.approval { border-color: var(--accent); }
.cardmsg .big { font-size: 20px; font-weight: 600; }
.composer { border-top: 1px solid var(--border); padding: 12px 14px; }
.composer textarea { min-height: 64px; font-family: var(--sans); font-size: 14px; }
.composer .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; gap: 8px; }
.typing { color: var(--faint); font-style: italic; }

/* Popover */
.pop { position: fixed; top: 80px; left: 50%; transform: translateX(-50%); width: 560px; max-width: calc(100vw - 32px); background: var(--surface);
  border: 1px solid var(--rim); border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,.6); z-index: 55; padding: 16px; max-height: calc(100vh - 120px); overflow: auto; }
.pop .results a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; color: var(--text); }
.pop .results a.on, .pop .results a:hover { background: var(--raised); text-decoration: none; }

.bottomnav { display: none; }

@media (max-width: 760px) {
  html, body { font-size: 15px; }
  .top { padding: 0 16px; }
  .nav, div.avatar, .brand span:not(.logo), .search .kbd { display: none; }
  .search { width: auto; flex: 0 0 auto; }
  main { padding: 16px 16px 90px; }
  .tabs { margin: 0 -16px 16px; padding: 0 16px; }
  .btn { height: 40px; }
  .row2 { grid-template-columns: 1fr; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 60px; background: var(--rail); border-top: 1px solid var(--border); z-index: 30; }
  .bottomnav a { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
  .bottomnav a.on { color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
  .drawer { width: 100vw; border-left: 0; }
  .drawer header .gap { display: none; }
  .drawer header select { flex: 1 1 auto; max-width: none; }
  .step > .actions { flex-wrap: wrap; gap: 6px 10px; }
  .step > .actions > .say { flex: 1 1 100%; order: 1; }
  .step > .actions > .cost { order: 2; }
  .wire { margin-left: 30px; }
  table.stack thead { display: none; }
  table.stack tr { display: block; border-top: 1px solid var(--border); padding: 6px 0; }
  table.stack td { display: block; border: 0; padding: 2px 12px; }
  .cardmsg.approval .btn { flex: 1; justify-content: center; }
}
.formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-top: 10px; }
.formgrid .field:has(textarea) { grid-column: 1 / -1; }
.bignum { font-size: 28px; font-weight: 600; }
.bigline { font-size: 18px; margin: 4px 0 8px; }
.scrollx { overflow-x: auto; }
@media (max-width: 760px) { .formgrid { grid-template-columns: 1fr; } }
