/* Near-black surface, large-radius cards with a hairline edge, small uppercase
   monospace labels above their values, and one neon lime used only for
   icons, key terms and state — never for large fills. The restraint is what
   makes the accent read as neon rather than as decoration. */
:root {
  --bg: #08090b;
  --panel: #101216;
  --panel-2: #15181d;
  --sunken: #0c0e11;

  --line: #1e2128;
  --line-strong: #2b2f38;

  --fg: #e9ebef;
  --muted: #8b919e;
  --dim: #767d8b;

  --accent: #a3e635;
  --accent-hover: #bef264;
  --accent-fg: #0a1003;
  --accent-soft: rgba(163, 230, 53, 0.1);
  --accent-ring: rgba(163, 230, 53, 0.26);
  --accent-glow: 0 0 14px rgba(163, 230, 53, 0.3);

  --err: #ff6b82;
  --err-soft: rgba(255, 107, 130, 0.1);

  --radius: 14px;
  --radius-sm: 9px;
  --radius-xs: 6px;

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;

  color-scheme: dark;
}

* { box-sizing: border-box; }

/* Several views and panes set their own display, which beats the attribute's
   default; hidden must always win. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  /* The page itself never scrolls — #app owns the viewport and every scrollable
     region is inside a pane. Without this, anything that overshoots by a pixel
     puts a scrollbar on the whole document. */
  overflow: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15.5px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}

/* Grid and flex children default to min-width/min-height:auto, which refuses to
   shrink below their content — that is what leaks overflow out of a pane, on
   both axes. Resetting lets every track actually hold its size. */
#app > *,
#shell > *,
.pane > *,
#codePanel > * {
  min-width: 0;
  min-height: 0;
}

::selection { background: var(--accent-ring); color: var(--fg); }

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

/* The signature label: small, uppercase, monospace, dim — always sitting
   above the thing it names. */
.field,
.brief .steps button,
.card .meta,
nav.nav .label,
.brief .nav .count {
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

/* ---------- layout ---------- */

#app {
  --chat: 42%;
  display: grid;
  grid-template-columns: var(--chat) 5px 1fr;
  height: 100vh;
  background: var(--bg);
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.pane + .pane { border-left: 1px solid var(--line); }

.splitter {
  cursor: col-resize;
  background: var(--line);
  transition: background 0.14s, box-shadow 0.14s;
}
.splitter:hover, .splitter.dragging {
  background: var(--accent);
  box-shadow: var(--accent-glow);
}
/* Widens the grab target without widening the visible line. */
.splitter::after {
  content: "";
  display: block;
  width: 13px;
  height: 100%;
  margin-left: -4px;
}
body.resizing { cursor: col-resize; user-select: none; }
/* The iframe would swallow pointer events mid-drag. */
body.resizing iframe { pointer-events: none; }

@media (max-width: 1000px) {
  #app { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .pane + .pane { border-left: 0; border-top: 1px solid var(--line); }
  .splitter { display: none; }
}

/* ---------- chrome ---------- */

header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 14px;
  height: 50px;
  flex: none;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
header h1 {
  font-size: 15px;
  margin: 0;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.sp { flex: 1; }

#title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 42%;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  flex: none;
}
.dot.on { background: var(--accent); box-shadow: var(--accent-glow); }
.dot.busy { background: #ffb84d; box-shadow: 0 0 12px rgba(255, 184, 77, 0.4); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.tabs {
  display: flex;
  gap: 3px;
  background: var(--panel);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.tab {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 3px 12px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tab:hover { color: var(--fg); }
.tab.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

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

input, textarea {
  font: inherit;
  font-family: var(--mono);
  font-size: 14px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--fg);
  width: 100%;
  text-transform: none;
  letter-spacing: normal;
}
textarea { font-family: var(--sans); font-size: 15.5px; }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
/* Vertical only: horizontal would fight the grid. */
textarea { resize: vertical; min-height: 46px; max-height: 320px; }

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

button.go {
  font: inherit;
  font-weight: 650;
  font-size: 14.5px;
  padding: 9px 17px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  cursor: pointer;
  flex: none;
}
button.go:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: var(--accent-glow);
}

button.ghost {
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  cursor: pointer;
  flex: none;
  transition: color 0.14s, border-color 0.14s;
}
button.ghost:hover { border-color: var(--accent); color: var(--accent); }

button.go[disabled], button.ghost[disabled] { opacity: 0.35; cursor: not-allowed; }
button.go[disabled]:hover { background: var(--accent); border-color: var(--accent); box-shadow: none; }
button.ghost[disabled]:hover { border-color: var(--line); color: var(--muted); }

button.wide { width: 100%; }
button.small { font-size: 13px; padding: 5px 11px; }
button.icon { font-size: 14.5px; line-height: 1; padding: 6px 9px; }
button.danger:hover { border-color: var(--err); color: var(--err); background: var(--err-soft); }

/* Interrupting a run mid-flight should read as a live action, not a quiet
   secondary button. */
button.stop {
  color: var(--err);
  border-color: var(--err);
  background: var(--err-soft);
  font-weight: 600;
}
button.stop:hover { background: var(--err); color: #0b0406; border-color: var(--err); }

/* ---------- conversation ---------- */

#log {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* Nothing in the conversation may shrink. The log is a scrolling flex column,
   and a flex item with overflow: hidden has no content-based minimum height —
   so once a long history overflowed, the details form and the brief (both
   overflow: hidden) were squeezed to a 20px sliver instead of scrolling. */
#log > * { flex-shrink: 0; }

.msg {
  max-width: 90%;
  padding: 12px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--fg);
}
.msg.bot {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
}
.msg.sys {
  align-self: center;
  color: var(--dim);
  font: 12px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  padding: 2px;
  text-align: center;
}
.msg.err {
  align-self: flex-start;
  color: var(--err);
  border: 1px solid var(--err);
  background: var(--err-soft);
}

/* One block per run: everything the agent did while working. */
.work {
  align-self: flex-start;
  width: 90%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.work > summary {
  cursor: pointer;
  list-style: none;
  padding: 9px 13px;
  font: 13.5px/1.5 var(--mono);
  color: var(--muted);
}
.work > summary::-webkit-details-marker { display: none; }
.work > summary::before { content: "▸ "; color: var(--line-strong); }
.work[open] > summary::before { content: "▾ "; }
.work > summary .label { color: var(--accent); font-weight: 600; }
.work > summary .time,
.working .time { color: var(--dim); font-variant-numeric: tabular-nums; }
.work .steps {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 4px 13px 12px;
  border-top: 1px solid var(--line);
}
/* Inside the block the tool lines take its width, not 90% of it. */
.work .steps .tool { width: 100%; }
/* The agent's narration while working: quieter than an answer. */
.msg.note {
  max-width: 100%;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 14.5px;
}

.tool {
  align-self: flex-start;
  /* A definite width, not max-width: the label's ellipsis is a percentage of
     this box, and a box sized from its own content collapsed that to a few
     characters ("Installing p…"). */
  width: 90%;
  font: 13.5px/1.6 var(--mono);
}
.tool summary {
  cursor: pointer;
  color: var(--dim);
  list-style: none;
  padding: 3px 0;
}
.tool summary::-webkit-details-marker { display: none; }
.tool summary::before { content: "▸ "; color: var(--line-strong); }
.tool[open] summary::before { content: "▾ "; }
.tool summary b { color: var(--accent); font-weight: 600; }
.tool.bad summary b { color: var(--err); }
/* One line, always. A heredoc writing a whole file would otherwise wrap into
   a wall of shell and bury the conversation. */
.tool summary span {
  display: inline-block;
  max-width: calc(100% - 5rem);
  vertical-align: bottom;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted);
}
.tool pre.cmd {
  color: var(--accent);
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin: 7px 0 0;
  padding: 10px 13px;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.tool pre.cmd + pre.out { margin-top: 5px; }
.tool pre {
  margin: 7px 0 0;
  padding: 12px 13px;
  background: var(--sunken);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  max-height: 260px;
  overflow: auto;
  /* The classic scrollbar of a box nested in the auto-scrolling log was being
     painted where the box used to be, over the next message. */
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.working {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font: 13.5px var(--mono);
  padding: 3px 0;
}
.working .spinner {
  width: 11px;
  height: 11px;
  flex: none;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .working .spinner { animation-duration: 2.5s; }
}

/* ---------- brief stepper ---------- */

.qa, .brief {
  align-self: flex-start;
  width: 100%;
  max-width: 94%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.qa { padding: 16px; }
.brief { overflow: hidden; }

.brief .steps {
  display: flex;
  gap: 3px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.brief .steps button {
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  padding: 5px 11px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
}
.brief .steps button:hover { color: var(--muted); }
.brief .steps button[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.brief .body { padding: 17px; }
.brief .body h3, .qa h3 { margin: 0 0 7px; font-size: 16px; font-weight: 650; }
.brief .body .lede { margin: 0 0 12px; font-size: 15.5px; color: var(--muted); }
.brief .body ol { margin: 0; padding-left: 1.3em; font-size: 15px; color: var(--muted); }
.brief .body ol li { margin-bottom: 7px; }
.brief .body ol li::marker { color: var(--accent); font-family: var(--mono); font-size: 13.5px; }

p.why { margin: 0 0 11px; color: var(--dim); font-size: 14px; }

.opts { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 11px; }
.opts.stacked { flex-direction: column; align-items: stretch; }
.opts button {
  font: inherit;
  font-size: 14px;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--muted);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.14s, color 0.14s;
}
.opts button:hover { border-color: var(--line-strong); color: var(--fg); }
.opts button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.brief .nav {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 17px;
  border-top: 1px solid var(--line);
}
.brief .nav .count { flex: 1; font-size: 11.5px; color: var(--dim); }
.brief.done { opacity: 0.5; }
/* A question the user skipped: kept in the list, dimmed, so it can be revisited. */
.brief .steps button.skipped { opacity: 0.45; text-decoration: line-through; }
.brief .body input + button.ghost { margin-top: 10px; }
.brief .body textarea { width: 100%; }

/* The details form reuses the brief card; only the field list is its own. */
.details .fields { display: grid; gap: 11px; }
.details .fields label { display: grid; gap: 5px; font-size: 14px; color: var(--muted); }
.details .fields input { width: 100%; }

/* ---------- composer ---------- */

footer {
  border-top: 1px solid var(--line);
  padding: 12px;
  background: var(--bg);
  flex: none;
}

/* Bottom-aligned so the button stays level with the last line as the composer
   grows, rather than drifting up to the top of a tall box. */
.row { display: flex; gap: 9px; align-items: flex-end; }
.row textarea {
  flex: 1;
  width: auto;
  min-width: 0;
}
/* Same height as the composer at rest, so the two read as one control. */
footer .row button.go { height: 46px; padding: 0 20px; }
footer .row .attachBtn { height: 46px; }
#chatAttached { justify-content: flex-start; margin: 0 0 8px; max-width: none; }
/* A file dragged over the chat or the home prompt. */
.dropping { outline: 2px dashed var(--accent); outline-offset: -2px; background: var(--accent-soft); }

/* ---------- preview and code ---------- */

.panel { flex: 1; position: relative; min-height: 0; background: var(--sunken); }

#frame { width: 100%; height: 100%; border: 0; background: #fff; }

/* Tablet and phone widths: the iframe itself narrows, so the page's own media
   queries apply as on the device. Centred, and scrollable sideways when the
   pane is narrower than the device. */
#previewPanel[hidden], .viewports[hidden] { display: none; }
#previewPanel[data-vp="tablet"], #previewPanel[data-vp="phone"] {
  display: flex; justify-content: center; overflow: auto; padding: 12px 0;
}
#previewPanel[data-vp="tablet"] #frame { flex: none; width: 768px; }
#previewPanel[data-vp="phone"] #frame { flex: none; width: 390px; }
#previewPanel[data-vp="tablet"] #frame,
#previewPanel[data-vp="phone"] #frame {
  border: 1px solid var(--line-strong); border-radius: 10px;
}
.viewports { margin-left: 8px; }
.viewports .tab { display: grid; place-items: center; padding: 3px 8px; }
.viewports svg { width: 15px; height: 15px; }
#empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--dim);
  font: 13.5px var(--mono);
  /* Opaque, so a frame still loading or blank never shows through the text. */
  background: var(--sunken);
}

#codePanel { display: flex; }
#codePanel[hidden] { display: none; }

#files {
  /* Shrinkable rather than fixed: the code panel can be dragged narrow, and a
     rigid 248px would push the viewer out of view. */
  flex: 0 1 248px;
  min-width: 128px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  padding: 10px;
  background: var(--bg);
  font: 13.5px/1.7 var(--mono);
}
#files button {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  text-align: left;
  font: inherit;
  padding: 5px 8px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  overflow-wrap: anywhere;
}
#files button:hover { background: var(--panel); color: var(--fg); }
#files svg { flex: none; width: 14px; height: 14px; opacity: 0.8; }
#files button span, .dir > summary span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* A folder: its name as a summary, its contents indented under a guide line. */
.dir > summary {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; cursor: pointer; list-style: none; color: var(--fg);
  border-radius: var(--radius-xs);
}
.dir > summary::-webkit-details-marker { display: none; }
.dir > summary:hover { background: var(--panel); }
.dir > summary svg { color: var(--accent); }
.dir > :not(summary) { margin-left: 14px; }
.dir { border-left: 1px solid transparent; }
.dir .dir, .dir > button { border-left: 1px solid var(--line); }
#files button.on { background: var(--accent-soft); color: var(--accent); }

#codeWrap { flex: 1; overflow: auto; min-width: 0; background: var(--sunken); }
#code {
  margin: 0;
  padding: 16px;
  font: 14px/1.7 var(--mono);
  white-space: pre;
  tab-size: 2;
  color: var(--muted);
}

.hint { color: var(--dim); font-family: var(--mono); font-size: 13px; }
code {
  font: 13px var(--mono);
  background: var(--panel-2);
  border: 1px solid var(--line);
  padding: 2px 6px;
  border-radius: var(--radius-xs);
  color: var(--accent);
}

/* highlight.js paints its own colours; this only sets the surface so it does
   not fight the panel behind it. */
#code.hljs, .tool pre.hljs { background: transparent; }
#code.hljs { padding: 16px; }

/* ---------- home and my apps ---------- */

#shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  height: 100vh;
}

nav.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 12px;
  border-right: 1px solid var(--line);
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 2px 8px 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.brand .mark {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--accent);
  box-shadow: var(--accent-glow);
}
#newApp { margin-bottom: 12px; }
nav.nav a {
  display: block;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  text-decoration: none;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
nav.nav a:hover { background: var(--panel); color: var(--fg); }
nav.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
nav.nav .label { margin: 18px 10px 4px; font-size: 11.5px; font-weight: 500; color: var(--dim); }
#recent a { font-size: 14px; padding: 5px 10px; }
nav.nav > .sp { min-height: 16px; }

.main { overflow-y: auto; padding: 48px 32px 64px; }
.main > section { max-width: 1000px; margin: 0 auto; }

.hero {
  margin: 6vh 0 22px;
  text-align: center;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
}
.prompt {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color 0.14s, box-shadow 0.14s;
}
.prompt:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
/* The card draws the focus ring, so the field inside it does not. */
.prompt textarea,
.prompt textarea:focus {
  min-height: 84px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  box-shadow: none;
  font-size: 16px;
  resize: none;
}
.prompt .bar { display: flex; align-items: center; gap: 9px; padding: 4px 0 0 8px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  max-width: 720px;
  margin: 14px auto 0;
}
.chips button {
  font: inherit;
  font-size: 14px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.14s, color 0.14s;
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }

.sectionHead { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; margin: 56px 0 14px; }
#appsView .sectionHead { margin-top: 0; }
.sectionHead h2 { margin: 0; font-size: 16px; font-weight: 650; }
.sectionHead a { margin-left: auto; color: var(--muted); font-size: 14px; text-decoration: none; }
.sectionHead a:hover { color: var(--accent); }
.sectionHead input { width: 220px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.grid .hint { grid-column: 1 / -1; margin: 0; }

.card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  transition: border-color 0.14s;
}
.card:hover { border-color: var(--line-strong); }
.card .open { display: flex; flex-direction: column; padding: 10px 10px 12px; color: inherit; text-decoration: none; }
/* Stands in for a screenshot until previews are captured. */
.card .thumb {
  display: grid;
  place-items: center;
  aspect-ratio: 16 / 10;
  margin-bottom: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--sunken);
  color: var(--dim);
  font: 600 26px var(--mono);
  transition: color 0.14s;
}
.card:hover .thumb { color: var(--accent); }
.card .name {
  padding: 0 3px;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card .meta { margin-top: 4px; padding: 0 3px; font-size: 11.5px; color: var(--dim); }
.card .foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding: 9px 3px 0;
  border-top: 1px solid var(--line);
}
.card .usage { font: 12px var(--mono); color: var(--dim); white-space: nowrap; }

/* The latest run's state: a dot and a word, coloured only by what it means. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 550;
  color: var(--muted);
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
}
.badge.ok { color: var(--accent); }
.badge.ok::before { background: var(--accent); box-shadow: var(--accent-glow); }
.badge.bad { color: var(--err); }
.badge.bad::before { background: var(--err); }
.badge.busy { color: #ffb84d; }
.badge.busy::before { background: #ffb84d; animation: pulse 1.1s ease-in-out infinite; }

.card .more {
  position: absolute;
  top: 16px;
  right: 16px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius-xs);
  background: var(--panel);
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  /* Out of the way until the card is hovered, like any card's actions. */
  opacity: 0;
  transition: opacity 0.14s, color 0.14s, border-color 0.14s;
}
.card:hover .more, .card .more:focus-visible { opacity: 1; }
/* No hover on touch screens, so there it simply shows. */
@media (hover: none) { .card .more { opacity: 1; } }
.card .more:hover { color: var(--accent); border-color: var(--accent); }

/* The popover's own defaults centre it on screen; this one sits by its button. */
.menu {
  position: fixed;
  inset: auto;
  margin: 0;
  min-width: 150px;
  padding: 5px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--fg);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}
.menu button {
  display: block;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--radius-xs);
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
}
.menu button:hover, .menu button:focus-visible { background: var(--panel); color: var(--fg); }
.menu button.danger:hover { background: var(--err-soft); color: var(--err); }

select {
  font: inherit;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
}
select:focus { outline: none; border-color: var(--accent); }

@media (max-width: 760px) {
  #shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  nav.nav {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0 8px 0 0; }
  #newApp { width: auto; margin: 0; }
  nav.nav .label, #recent { display: none; }
  nav.nav > .sp { display: none; }
  .main { padding: 24px 16px 48px; }
  .hero { margin-top: 2vh; font-size: 22px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .sectionHead input, .sectionHead select { flex: 1 1 140px; width: auto; }
}

/* ---------- usage ---------- */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.stat {
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.stat .label, .table th {
  font: 500 11.5px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--dim);
}
.stat .value { margin: 8px 0 4px; font-size: 26px; font-weight: 650; letter-spacing: -0.02em; }
.stat .sub { font-size: 13.5px; color: var(--muted); }

.chartCard {
  margin-top: 14px;
  padding: 16px 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.chartHead { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 12px; margin-bottom: 10px; }
.chartHead h3, .subhead { margin: 0; font-size: 15.5px; font-weight: 650; }
.subhead { margin: 32px 0 12px; }

.chart { position: relative; }
.chart svg { display: block; max-width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--line-strong); stroke-width: 1; }
.chart .tick { fill: var(--dim); font: 12px var(--mono); font-variant-numeric: tabular-nums; }
/* lime-600: the accent itself is too light for a filled mark on this surface
   (it fails the dark-mode lightness band); the hovered bar lifts to it. */
.chart .bar { fill: #65a30d; transition: fill 0.1s; }
.chart .bar.on { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .tip {
  position: absolute;
  pointer-events: none;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-xs);
  background: var(--panel-2);
  color: var(--fg);
  font: 13px var(--mono);
  white-space: nowrap;
}

.asTable { margin-top: 10px; }
.asTable summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.asTable .table { margin-top: 10px; }

.table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.table th, .table td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.table td { font-variant-numeric: tabular-nums; color: var(--muted); }
.table td:first-child { color: var(--fg); }
.table th:not(:first-child), .table td:not(:first-child) { text-align: right; }
.table a { color: var(--fg); text-decoration: none; }
.table a:hover { color: var(--accent); }
.table + .hint, #topTable .hint { margin: 0; }

/* ---------- sign in ---------- */

#login { display: grid; place-items: center; min-height: 100vh; padding: 24px 16px; overflow-y: auto; }
.loginCard {
  width: 100%;
  max-width: 380px;
  display: grid;
  gap: 14px;
  padding: 28px 26px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.loginCard .brand { padding: 0 0 6px; }
.loginCard h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -0.02em; }
.loginCard .why { margin: -6px 0 4px; }
.field { display: grid; gap: 7px; font-size: 11.5px; font-weight: 500; color: var(--dim); }
.loginCard .note:empty { display: none; }
.loginCard .note { margin: 0; font-size: 14px; color: var(--muted); }
a.go { display: block; text-align: center; text-decoration: none; }
.loginCard .server summary { cursor: pointer; font-size: 13.5px; color: var(--dim); }
.loginCard .server .field { margin-top: 10px; }

.account {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 4px 9px;
  padding: 12px 8px 2px;
  border-top: 1px solid var(--line);
}
.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  font-size: 14px;
}
.account .email { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account button { grid-column: 1 / -1; margin-top: 6px; }

@media (max-width: 760px) {
  .account { padding: 0; border: 0; grid-template-columns: auto auto; }
  .account .email { display: none; }
  .account button { grid-column: auto; margin: 0; }
}

/* ---------- security ---------- */

.notice {
  margin: 0 0 8px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--muted);
  font-size: 14.5px;
}
.notice:empty { display: none; }
.notice.small { margin: 8px 0 0; padding: 0; border: 0; background: none; color: var(--dim); font: 12px var(--mono); }
.subheadRow { display: flex; align-items: center; gap: 12px; margin: 32px 0 12px; }
.subheadRow .subhead { margin: 0; }
.subheadRow button { margin-left: auto; }
.subhead + .why { margin-top: -6px; }
.pill {
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font: 500 11.5px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#auditTable td:last-child { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#moreAudit { margin-top: 12px; }
/* Wide tables scroll sideways on a phone instead of widening the page. */
@media (max-width: 760px) {
  #securityView .table, #usageView .table { display: block; overflow-x: auto; white-space: nowrap; }
}

/* ---------- data ---------- */

#dataPanel[hidden] { display: none; }
#dataPanel { overflow-y: auto; }
.dataWrap { display: grid; gap: 12px; padding: 16px; align-content: start; }
.drop {
  display: grid;
  gap: 4px;
  justify-items: center;
  padding: 26px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color 0.14s, background 0.14s;
}
.drop strong { color: var(--fg); font-weight: 600; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop u { color: var(--accent); text-decoration: none; }
#dataStatus { margin: 0; }
#dataStatus:empty { display: none; }
.dataFile {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
}
.dataFile + .dataFile { margin-top: 6px; }
.dataFile .name {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--fg);
  font: inherit;
  font-size: 14.5px;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dataFile .name:hover { color: var(--accent); }
#dataPreview .subhead { margin: 8px 0 8px; }
.sheetTabs { margin-bottom: 8px; overflow-x: auto; width: fit-content; max-width: 100%; }
/* A sheet is as wide as its columns: it scrolls inside its own box. */
.sheetWrap { overflow: auto; max-height: 420px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.table.sheet { font-size: 13.5px; }
.table.sheet th, .table.sheet td { white-space: nowrap; text-align: left; }
.table.sheet th { position: sticky; top: 0; background: var(--panel); }

/* ---------- app container ---------- */

#sandboxState { font-size: 13px; white-space: nowrap; }
.menuNote { margin: 2px 10px 6px; font: 12px var(--mono); color: var(--dim); }
.menuNote:empty { display: none; }

/* ---------- settings ---------- */

#settingsPanel[hidden] { display: none; }
#settingsPanel { overflow-y: auto; }
.setting { padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.setting .subhead { margin: 0 0 6px; }
.setting .why { margin-bottom: 10px; }
.setting textarea { font-size: 15px; }
.settingBar { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.briefView { display: grid; gap: 12px; }
.briefView .label { font: 500 11.5px var(--mono); text-transform: uppercase; letter-spacing: 0.09em; color: var(--dim); margin-bottom: 3px; }
.briefView .text { white-space: pre-wrap; font-size: 14.5px; color: var(--muted); }

/* ---------- people ---------- */

/* What a role cannot use is not shown. The API refuses it regardless. */
#app[data-role="viewer"] .edit-only,
#app[data-role="viewer"] .dataFile .danger,
#app:not([data-role="owner"]) .owner-only { display: none !important; }

#people { display: grid; gap: 6px; margin-bottom: 12px; }
.person {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.person .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14.5px; }
.person.pending { border-style: dashed; }
.person.pending .who { color: var(--muted); }
.person select { padding: 5px 8px; }
.inviteForm { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
#inviteResult { margin-top: 12px; overflow-wrap: anywhere; }
#inviteResult code { font-size: 12.5px; }

.card .people { display: flex; align-items: center; gap: 4px; margin-top: 10px; padding: 0 3px; }
.card .people .avatar { width: 22px; height: 22px; font-size: 12px; }
.card .people .pill { margin-left: auto; }
@media (max-width: 760px) { .inviteForm { grid-template-columns: 1fr; } }
#shareResult { margin-top: 12px; overflow-wrap: anywhere; }
#shareResult code { font-size: 12.5px; }
#shareResult a { color: var(--accent); }

/* ---------- run report ---------- */

.report { align-self: flex-start; display: flex; flex-wrap: wrap; gap: 6px; max-width: 90%; margin-top: -4px; }
.report:empty { display: none; }
.check {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--muted);
  font: 12.5px var(--mono);
}
.check.passed { color: var(--accent); border-color: var(--accent-ring); }
.check.failed { color: var(--err); border-color: var(--err); background: var(--err-soft); }
.check.data { color: var(--fg); }
.report .warn { flex-basis: 100%; color: #ffb84d; font-size: 13.5px; }
.badge.warn { color: #ffb84d; }
.badge.warn::before { background: #ffb84d; }
.sheetForm { grid-template-columns: 1fr auto; }
#app[data-role="viewer"] .dataFile .edit-only { display: none; }
.notice.joins { margin: 8px 0 0; font-size: 13px; }
.table.profile td:nth-child(2) { color: var(--fg); }

/* ---------- dashboard plan ---------- */

.planStep h3 { margin-bottom: 6px; }
.planLabel { margin: 14px 0 6px; font: 500 11.5px var(--mono); text-transform: uppercase; letter-spacing: 0.09em; color: var(--dim); }
.planItem {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  cursor: pointer;
}
.planItem + .planItem { margin-top: 6px; }
.planItem input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.planItem strong { display: block; font-size: 14px; font-weight: 600; }
.planItem small { display: block; font-size: 13px; color: var(--muted); }
.planStep .cluster { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.planStep > button { margin-top: 14px; }
.why.dropped { margin-top: 12px; color: #ffb84d; }

.attached { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 720px; margin: 10px auto 0; }
.attached:empty { display: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 6px 4px 10px; border: 1px solid var(--accent-ring); border-radius: 999px; background: var(--accent-soft); color: var(--fg); font-size: 13px; }
.chipX { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 4px; }
.chipX:hover { color: var(--err); }

/* ---------- pipeline stages ---------- */

.work .stages { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0 13px 10px; list-style: none; }
.work .stages:empty { display: none; }
.work .stages li { padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px; font: 12px var(--mono); color: var(--dim); }
.work .stages li.done { color: var(--accent); border-color: var(--accent-ring); }
.work .stages li.active { color: #ffb84d; border-color: #ffb84d; }
.work .stages li.failed { color: var(--err); border-color: var(--err); }
.checkLine { font: 13px var(--mono); color: var(--muted); padding: 2px 0; }
.checkLine.passed { color: var(--accent); }
.checkLine.failed { color: var(--err); }
.refImage { max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.refText { max-height: 360px; overflow: auto; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--sunken); color: var(--muted); font: 13px/1.6 var(--mono); white-space: pre-wrap; }
#refNote.notice.small { color: #ffb84d; }
#refFiles { display: grid; gap: 6px; }
.brandForm { display: grid; gap: 12px; }
.brandRow { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brandLogo { height: 44px; max-width: 180px; object-fit: contain; padding: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }
.fileBtn { cursor: pointer; }
.colorPick { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.colorPick input { width: 44px; height: 32px; padding: 2px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.check input { width: auto; accent-color: var(--accent); }
#app[data-role="viewer"] #brandColor { pointer-events: none; opacity: 0.6; }
.dbBox > summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.dbBox[open] > summary { margin-bottom: 8px; }
.dbConn { margin-top: 10px; }
.dbPull { display: grid; grid-template-columns: 1fr; gap: 6px; margin-top: 6px; }
.dbPull textarea { min-height: 56px; font-family: var(--mono); font-size: 13px; }
#app:not([data-role="owner"]) .dbConn .owner-only { display: none; }

/* ---------- activity, templates, export ---------- */

#activityPanel[hidden] { display: none; }
#activityPanel { overflow-y: auto; }
.commentForm { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: end; }
.commentForm textarea { min-height: 52px; }
#feed { display: grid; gap: 10px; }
.feedItem { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.feedItem .avatar { width: 28px; height: 28px; font-size: 12px; }
.feedHead { font-size: 13px; color: var(--muted); }
.feedHead strong { color: var(--fg); font-weight: 600; }
.feedText { margin: 3px 0 0; padding: 8px 11px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--panel); white-space: pre-wrap; font-size: 14px; }
.feedItem.event .hint { margin: 3px 0 0; }
.templates { max-width: 720px; margin: 18px auto 0; }
.templates .planLabel { text-align: center; }
.chip.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
button.chip { font: inherit; font-size: 13px; cursor: pointer; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 0; }
#app[data-role="viewer"] #appMenu [data-sandbox] { display: none; }
