/* ==========================================================================
   The Builder panel — js/builder-panel/panel.js — in the console's own
   tokens: navy ground and champagne hairlines in the dark scheme, pearl
   and navy in the light, claret only for a refusal or a stop. Quiet glass;
   monospace for every fact a machine said (paths, counts), the serif for
   the one word that names the thing. Phone-first: laid out for 375 wide,
   the desk inherits it; hard phone rules at the end.
   ========================================================================== */

.asgb {
  --asgb-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --asgb-line: var(--border);
  --asgb-field: color-mix(in srgb, var(--bg-elevated) 70%, transparent);
  --asgb-add: 26, 122, 74;
  --asgb-del: 142, 27, 46;
  position: relative;
  display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0;
  gap: 10px; padding: 8px 10px 10px;
  color: var(--text);
}
.asgb[hidden] { display: none; }
.asgb svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* the working light: a hairline down the panel's inner edge that carries a
   pulse only while a build is going — light, never geometry */
.asgb::before {
  content: ""; position: absolute; right: 0; top: 0; bottom: 0; width: 1px; pointer-events: none;
  background: linear-gradient(to bottom, transparent, rgba(var(--glow-rgb), .45) 50%, transparent); opacity: .5;
}
.asgb.asgb-running::before {
  opacity: 1; width: 2px;
  background: linear-gradient(to bottom, transparent 0%, var(--accent) 50%, transparent 100%);
  background-size: 100% 46%; background-repeat: no-repeat;
  animation: asgbScan 1.9s linear infinite;
}
@keyframes asgbScan { from { background-position: 0 -60%; } to { background-position: 0 160%; } }

/* ── head ── */
.asgb-head { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; min-height: 34px; flex: none; }
.asgb-mark { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  box-shadow: 0 0 14px rgba(var(--glow-rgb), .25), inset 0 0 8px rgba(var(--glow-rgb), .18); }
.asgb-mark i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.asgb-running .asgb-mark i { animation: asgbBeat 1.1s ease-in-out infinite; }
@keyframes asgbBeat { 50% { opacity: .35; } }
.asgb-ttl { min-width: 0; flex: 1 1 0; display: flex; flex-direction: column; line-height: 1.15; }
.asgb-ttl b { font: 600 17px/1.15 var(--asgb-serif); color: var(--accent); letter-spacing: .01em; }
.asgb-ttl span { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* the panel is a narrow column at every size (260px on a desk), so the usage
   line always goes UNDER the title, never beside it */
.asgb-usage { order: 5; flex: 1 1 100%; padding-left: 36px; font: 500 10.5px/1.3 var(--font-mono); color: var(--text-faint); letter-spacing: .02em; }
.asgb-usage:empty { display: none; }
.asgb-state { flex: none; font: 700 9.5px/1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--text-muted);
  padding: 6px 9px; border-radius: var(--radius-pill); border: 1px solid var(--asgb-line); }
.asgb-running .asgb-state { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 55%, transparent); }

/* ── what it has its hands on ── */
.asgb-now { flex: none; display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 8px 11px; border-radius: var(--radius-sm);
  border: 1px solid var(--asgb-line); background: var(--asgb-field); }
.asgb-now small { flex: none; font: 700 9px/1 var(--font-mono); letter-spacing: .18em; text-transform: uppercase; color: var(--text-faint); min-width: 62px; }
.asgb-now b { min-width: 0; font: 600 12px/1.3 var(--font-mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asgb-now.asgb-now-write { border-color: color-mix(in srgb, var(--accent) 70%, transparent); box-shadow: 0 0 0 1px rgba(var(--glow-rgb), .25), 0 0 22px -6px rgba(var(--glow-rgb), .5); }

/* ── the safety line ── */
.asgb-line { flex: none; margin: 0; display: flex; gap: 8px; align-items: flex-start; font-size: 11.5px; line-height: 1.45; color: var(--text-muted); }
.asgb-line svg { flex: none; width: 15px; height: 15px; margin-top: 1px; color: var(--accent); }
.asgb-line code { font-family: var(--font-mono); font-size: 10.5px; color: var(--text); }

/* ── ready prompts ── */
.asgb-quick { flex: none; display: flex; gap: 6px; overflow-x: auto; overscroll-behavior-x: contain; padding-bottom: 2px; scrollbar-width: none; }
.asgb-quick::-webkit-scrollbar { display: none; }
.asgb-chip { flex: none; min-height: 32px; padding: 0 11px; border-radius: var(--radius-pill); cursor: pointer; white-space: nowrap;
  border: 1px solid var(--asgb-line); background: var(--asgb-field); color: var(--text); font-size: 12px; font-weight: 500; position: relative; }
.asgb-chip::before { content: ""; position: absolute; left: 0; right: 0; top: -6px; bottom: -6px; }   /* a 44px hand */
.asgb-chip:hover, .asgb-chip:focus-visible { border-color: var(--accent); color: var(--accent); }
.asgb-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── the thread ── */
.asgb-thread { flex: 1 1 auto; min-height: 140px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 10px; padding: 2px 1px; }
.asgb-note { font-size: 12px; line-height: 1.5; color: var(--text-muted); padding: 8px 10px; border: 1px dashed var(--asgb-line); border-radius: var(--radius-sm); }
.asgb-fail { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 50%, transparent); border-style: solid; }
.asgb-me { align-self: flex-end; max-width: 92%; padding: 8px 11px; border-radius: 13px 13px 3px 13px; white-space: pre-wrap; overflow-wrap: anywhere;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); font-size: 13px; line-height: 1.45; }
.asgb-ai, .asgb-doc { display: flex; flex-direction: column; gap: 7px; }
.asgb-say { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }
.asgb-say > :first-child { margin-top: 0; } .asgb-say > :last-child { margin-bottom: 0; }
.asgb-say p, .asgb-say ul, .asgb-say ol { margin: 0 0 8px; }
.asgb-say ul, .asgb-say ol { padding-left: 18px; }
.asgb-say h4 { margin: 4px 0 6px; font: 600 14px/1.3 var(--asgb-serif); color: var(--accent); }
.asgb-say pre { padding: 9px; border-radius: var(--radius-sm); background: var(--asgb-field); border: 1px solid var(--asgb-line); overflow: auto; font: 500 11.5px/1.5 var(--font-mono); }
.asgb-say code { font-family: var(--font-mono); font-size: .92em; background: var(--bg-sunken); padding: 1px 4px; border-radius: 4px; }
.asgb-say pre code { background: none; padding: 0; }

/* a tool call: one line of trace, folded; the turning mark stays until it answers */
.asgb-tool { border-left: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); padding-left: 9px; }
.asgb-tool.asgb-refused { border-left-color: var(--danger); }
.asgb-tool summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 7px; min-height: 28px; color: var(--text-muted); font: 500 11.5px/1.3 var(--font-mono); }
.asgb-tool summary::-webkit-details-marker { display: none; }
.asgb-tool summary svg { flex: none; width: 12px; height: 12px; color: var(--accent); }
.asgb-refused summary svg { color: var(--danger); }
.asgb-tool summary b { flex: none; color: var(--text); font-weight: 600; }
.asgb-tool summary span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.asgb-tool pre { margin: 5px 0 3px; padding: 8px; border-radius: var(--radius-sm); background: var(--asgb-field); border: 1px solid var(--asgb-line); max-height: 220px; overflow: auto;
  font: 500 11px/1.5 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text-muted); }
.asgb-tool .asgb-out { color: var(--text); }
.asgb-refusal { margin: 5px 0 3px; padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); background: var(--danger-soft);
  display: flex; flex-direction: column; gap: 3px; font-size: 12px; line-height: 1.45; color: var(--text); overflow-wrap: anywhere; }
.asgb-refusal small { font: 700 9px/1 var(--font-mono); letter-spacing: .16em; text-transform: uppercase; color: var(--danger); }
.asgb-spin { flex: none; margin-left: auto; width: 10px; height: 10px; border-radius: 50%; border: 1.5px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent); animation: asgbTurn .8s linear infinite; }
@keyframes asgbTurn { to { transform: rotate(360deg); } }
.asgb-meta { font: 500 10.5px/1.4 var(--font-mono); color: var(--text-faint); letter-spacing: .02em; }

/* ── a change card: the file, the diff, Accept / Undo ── */
.asgb-card { border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: var(--radius-md); background: var(--panel);
  backdrop-filter: blur(10px) saturate(1.1); -webkit-backdrop-filter: blur(10px) saturate(1.1);
  box-shadow: inset 0 1px 0 rgba(var(--glow-rgb), .10), var(--shadow-sm); padding: 10px 11px; display: flex; flex-direction: column; gap: 7px; position: relative; }
.asgb-card::after { content: ""; position: absolute; left: 14px; right: 14px; top: -1px; height: 1px; background: linear-gradient(90deg, transparent, rgba(var(--glow-rgb), .6), transparent); pointer-events: none; }
.asgb-card-accepted { border-color: color-mix(in srgb, rgb(var(--asgb-add)) 60%, transparent); }
.asgb-card-undone { border-color: var(--asgb-line); opacity: .8; }
.asgb-card-err { border-color: var(--danger); }
.asgb-card-head { display: flex; align-items: center; gap: 7px; min-width: 0; flex-wrap: wrap; }
.asgb-card-head svg { flex: none; width: 13px; height: 13px; color: var(--accent); }
.asgb-card-head b { min-width: 0; flex: 1 1 auto; font: 600 12.5px/1.3 var(--font-mono); color: var(--text); overflow-wrap: anywhere; }
.asgb-kind, .asgb-badge { flex: none; font: 700 9px/1 var(--font-mono); letter-spacing: .14em; text-transform: uppercase; padding: 5px 7px; border-radius: var(--radius-pill); border: 1px solid var(--asgb-line); color: var(--text-muted); }
.asgb-badge { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 50%, transparent); }
.asgb-card-accepted .asgb-badge { color: rgb(var(--asgb-add)); border-color: color-mix(in srgb, rgb(var(--asgb-add)) 60%, transparent); }
.asgb-card-undone .asgb-badge { color: var(--text-faint); border-color: var(--asgb-line); }
.asgb-card-note { margin: 0; font-size: 12px; line-height: 1.45; color: var(--text-muted); }
.asgb-card-stat { font: 500 10.5px/1 var(--font-mono); color: var(--text-faint); }
.asgb-card-stat:empty { display: none; }
.asgb-diff { margin: 0; padding: 8px 0; border-radius: var(--radius-sm); background: var(--asgb-field); border: 1px solid var(--asgb-line); max-height: 320px; overflow: auto;
  font: 500 11px/1.5 var(--font-mono); display: flex; flex-direction: column; }
.asgb-diff span { display: block; padding: 0 9px; white-space: pre-wrap; overflow-wrap: anywhere; }
.asgb-d-add { background: rgba(var(--asgb-add), .14); color: var(--text); }
.asgb-d-del { background: rgba(var(--asgb-del), .14); color: var(--text); text-decoration: line-through; text-decoration-color: rgba(var(--asgb-del), .6); }
.asgb-d-ctx { color: var(--text-faint); }
.asgb-d-skip { color: var(--text-faint); font-style: italic; padding: 2px 9px; }
.asgb-card-acts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; min-height: 36px; }
.asgb-card-said { font: 500 10.5px/1.3 var(--font-mono); color: var(--text-faint); min-width: 0; overflow-wrap: anywhere; }
.asgb-card-err .asgb-card-said { color: var(--danger); }
.asgb-accept { border-color: color-mix(in srgb, rgb(var(--asgb-add)) 60%, transparent); background: rgba(var(--asgb-add), .12); color: var(--text); }
.asgb-accept:hover:not(:disabled) { background: rgba(var(--asgb-add), .22); }
.asgb-undo { border-color: var(--asgb-line); }

/* ── history ── */
.asgb-hist { position: absolute; inset: 44px 10px auto; max-height: min(70%, 520px); z-index: 3; display: flex; flex-direction: column; gap: 6px; padding: 10px;
  border-radius: var(--radius-md); border: 1px solid var(--asgb-line); background: color-mix(in srgb, var(--bg-elevated) 94%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); box-shadow: var(--shadow-lg); }
.asgb-hist[hidden] { display: none; }
.asgb-hist-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.asgb-hist-head b { font: 600 15px/1.2 var(--asgb-serif); color: var(--accent); }
.asgb-hist-body { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.asgb-hist-row { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; text-align: left; min-height: 44px; padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--text); }
.asgb-hist-row:hover, .asgb-hist-row:focus-visible { border-color: var(--asgb-line); background: var(--asgb-field); }
.asgb-hist-row b { font-size: 12.5px; font-weight: 500; line-height: 1.35; overflow-wrap: anywhere; }
.asgb-hist-row small { font: 500 10px/1.3 var(--font-mono); color: var(--text-faint); }

/* ── the prompt box at the foot ── */
.asgb-form { flex: none; border: 1px solid var(--asgb-line); border-radius: 16px; background: var(--asgb-field); padding: 8px 10px;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, box-shadow .15s; }
.asgb-form:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); box-shadow: 0 0 0 1px rgba(var(--glow-rgb), .25), 0 10px 40px -14px rgba(var(--glow-rgb), .45); }
.asgb-form textarea { display: block; width: 100%; min-height: 44px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font-size: 14px; line-height: 1.45; padding: 6px 2px; }
.asgb-form textarea::placeholder { color: var(--text-faint); }
.asgb-row { display: flex; align-items: center; gap: 6px; }
.asgb-sp { flex: 1 1 auto; }
.asgb-btn, .asgb-go { position: relative; flex: none; min-height: 36px; display: inline-flex; align-items: center; gap: 6px; padding: 0 11px; border-radius: var(--radius-pill); cursor: pointer;
  border: 1px solid var(--asgb-line); background: var(--asgb-field); color: var(--text); font-size: 12.5px; font-weight: 600; }
.asgb-btn::before, .asgb-go::before { content: ""; position: absolute; left: 0; right: 0; top: -4px; bottom: -4px; }   /* a 44px hand */
.asgb-btn svg, .asgb-go svg { width: 13px; height: 13px; }
.asgb-btn:hover:not(:disabled), .asgb-btn:focus-visible { border-color: var(--accent); color: var(--accent); }
/* THE FOOT ROW IS ICONS ONLY (the panel is a 260px column on a desk): New and
   History keep their word in the title and aria-label; Send, Accept and Undo
   keep theirs on the face, because they are the decision. */
.asgb-row .asgb-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.asgb-row .asgb-btn { width: 44px; min-height: 44px; padding: 0; justify-content: center; }
.asgb-row .asgb-btn svg { width: 16px; height: 16px; }
.asgb-round { width: 36px; padding: 0; justify-content: center; }
.asgb-go { border-color: color-mix(in srgb, var(--accent) 60%, transparent); background: var(--accent-soft); color: var(--accent); }
.asgb-go.asgb-stop { border-color: var(--danger); background: var(--danger-soft); color: var(--danger); }
.asgb-go.asgb-stop svg { fill: currentColor; stroke: none; }
.asgb-btn:disabled, .asgb-go:disabled { opacity: .45; cursor: not-allowed; }
.asgb-btn:focus-visible, .asgb-go:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── a word in passing ── */
.asgb-toast { position: absolute; left: 10px; right: 10px; bottom: 76px; z-index: 4; padding: 8px 11px; border-radius: var(--radius-sm); pointer-events: none;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); background: color-mix(in srgb, var(--bg-elevated) 94%, transparent); color: var(--text);
  font-size: 12.5px; line-height: 1.4; box-shadow: var(--shadow-md); opacity: 0; transform: translateY(4px); transition: opacity .18s, transform .18s; }
.asgb-toast.on { opacity: 1; transform: none; }

@media (prefers-reduced-motion: reduce) {
  .asgb.asgb-running::before, .asgb-running .asgb-mark i, .asgb-spin { animation: none; }
}

/* ── the phone: measured at 375×812; the panel is the whole sidebar ── */
@media (max-width: 600px) {
  .asgb { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)) !important; gap: 8px !important; }
  .asgb-line { display: none; }                       /* said in the title's tooltip; the thread needs the height */
  .asgb-now small { min-width: 0; }
  .asgb-thread { min-height: 120px; }
  .asgb-diff { max-height: 240px; }
  .asgb-hist { inset: 40px 8px auto; }
  .asgb-go { min-height: 44px; }
  .asgb-toast { bottom: calc(100px + env(safe-area-inset-bottom)); }
}
