/*
 * Genie's palette is the family's.
 *
 * `unity-theme.css` — linked from index.html, and a byte-identical copy of the
 * canonical theme — owns the colours; Genie is a CodeOps console, so it wears the
 * **operations** scheme. The names below are the ones this stylesheet's rules have
 * always used, aliased onto the theme's tokens, which is what let the console gain
 * light mode without every rule in this file being rewritten.
 *
 * `--ok` is deliberately *not* listed here. The theme already defines it, and
 * `--ok: var(--ok)` is a cycle: the custom property would be invalid at
 * computed-value time and take the colour down with it.
 */
:root {
  --bg: var(--canvas);
  --bg-panel: var(--surface);
  --bg-raised: var(--surface-muted);
  /* Hover has to read as "a little further from the page" in both modes, so it is
     mixed from the ink rather than taken from a second, dark-only palette. */
  --bg-hover: color-mix(in oklab, var(--ink) 9%, var(--surface-muted));
  --border: var(--line);
  --text: var(--ink);
  --text-dim: var(--ink-soft);
  --accent: var(--brand);
  --accent-dim: var(--brand-ring);
  --warn: var(--attention);
  --err: var(--bad);
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: var(--font-sans);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
}

.mono { font-family: var(--mono); }
.muted { color: var(--text-dim); }
.hidden { display: none !important; }

/* Visible only to screen readers, for status announcements. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 8px;
  z-index: 100;
  background: var(--bg-raised);
  border: 1px solid var(--accent-dim);
  border-radius: 6px;
  padding: 8px 12px;
  color: var(--text);
  text-decoration: none;
}
.skip-link:focus { left: 12px; }

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

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  height: 100vh;
}

/* --- sidebar --- */

.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  min-height: 0;
}

.sidebar-head, .files-head, .viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 600; letter-spacing: 0.01em; }

.sessions { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }

.session {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  margin-bottom: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  cursor: pointer;
  overflow: hidden;
}

.session:hover { background: var(--bg-hover); color: var(--text); }
.session.active { background: var(--bg-raised); border-color: var(--border); color: var(--text); }
.session-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.session-meta { display: block; font-size: 11px; color: var(--text-dim); margin-top: 3px; }

/* A chat and what may be done to it: the row opacifies its controls on hover or
   keyboard focus, so the list reads as titles until you reach for one. */
.session-row { display: flex; align-items: stretch; gap: 2px; border-radius: 8px; margin-bottom: 4px; }
.session-row .session { margin-bottom: 0; }
.session-row.archived { opacity: 0.72; }
.session-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  padding-right: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.session-row:hover .session-actions,
.session-row:focus-within .session-actions { opacity: 1; }
.session-action {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 10px;
  line-height: 1;
  padding: 3px 5px;
  cursor: pointer;
}
.session-action:hover { background: var(--bg-hover); color: var(--text); }
.session-action.danger:hover,
.session-action.armed { color: var(--bad); border-color: currentColor; }
.session-archived-toggle {
  display: block;
  width: 100%;
  text-align: left;
  padding: 6px 10px;
  margin-top: 6px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
}
.session-archived-toggle:hover { color: var(--text); background: var(--bg-hover); }

.sidebar-foot { padding: 12px 14px; border-top: 1px solid var(--border); font-size: 12px; }
/* The family's switch (`.ot-theme`, styled by unity-theme.css) sits under the status
   rows in the sidebar foot. */
.theme-row { margin-top: 10px; }
.row { display: flex; align-items: center; gap: 7px; }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim); flex: none;
}
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.bad { background: var(--err); }
#workspace-label { margin-top: 6px; font-size: 11px; word-break: break-all; }

/* --- main --- */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-title {
  font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  max-width: 220px;
}

.btn-ghost, .btn-primary, .btn-danger {
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text);
  font: inherit;
  padding: 6px 11px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--bg-hover); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 500; }
.topbar-right .field { display: flex; align-items: center; gap: 6px; }

.badge {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--warn);
  border: 1px solid color-mix(in oklab, var(--attention) 45%, transparent);
  background: color-mix(in oklab, var(--attention) 12%, transparent);
  border-radius: 999px;
  padding: 2px 9px;
  white-space: nowrap;
}

/* The offline badge is a live state, not a configuration hint, so it reads as
   an alert rather than as the amber "approval: risky" chip. */
.badge.offline {
  color: var(--err);
  border-color: color-mix(in oklab, var(--bad) 50%, transparent);
  background: color-mix(in oklab, var(--bad) 12%, transparent);
}

.btn-ghost.mini { padding: 1px 7px; font-size: 11px; margin-left: auto; }

/* Deleting a file is armed on the first click, not done by it. The button says
   so, in the colour reserved for things that cannot be undone. */
.btn-ghost.armed {
  color: var(--err);
  border-color: color-mix(in oklab, var(--bad) 50%, transparent);
  background: color-mix(in oklab, var(--bad) 12%, transparent);
}

.sweep-report { padding: 4px 0 20px; }
.sweep-section { margin-bottom: 18px; }
.sweep-heading { font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.sweep-body {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-all;
}

.topbar-right .field.check { gap: 4px; }
.field.check input { accent-color: var(--accent-dim); cursor: pointer; }
.field.check input:disabled { cursor: not-allowed; opacity: 0.5; }

.input-text {
  width: 190px;
  min-width: 0;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
}
.input-text::placeholder { color: var(--text-dim); }

.input-num {
  width: 62px;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
}

.btn-primary:hover { filter: brightness(1.06); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-danger { background: var(--bad-soft); border-color: var(--bad); }
.btn-danger:hover { filter: brightness(1.08); }

/* --- messages --- */

.messages { flex: 1; overflow-y: auto; padding: 22px 20px 8px; min-height: 0; }

.empty { max-width: 460px; margin: 8vh auto 0; text-align: center; }
.empty h2 { margin: 0 0 8px; font-weight: 600; }

.msg { max-width: 860px; margin: 0 auto 18px; }

.msg-user {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-assistant { padding: 0 2px; line-height: 1.62; }
.msg-assistant p { margin: 0 0 10px; }
.msg-assistant > :last-child { margin-bottom: 0; }
.msg-assistant h1, .msg-assistant h2, .msg-assistant h3 { margin: 16px 0 8px; font-size: 15px; }
.msg-assistant .li { padding-left: 4px; margin: 3px 0; }
.msg-assistant strong { font-weight: 600; }
.msg-assistant a { color: var(--accent); }

.msg-notice,
.notice {
  max-width: 860px;
  margin: 0 auto 14px;
  padding: 7px 11px;
  border-left: 2px solid var(--warn);
  background: color-mix(in oklab, var(--attention) 10%, transparent);
  color: var(--text-dim);
  font-size: 12.5px;
  border-radius: 0 6px 6px 0;
}

.msg-error {
  border: 1px solid var(--bad);
  background: var(--bad-soft);
  color: var(--bad);
  border-radius: 8px;
  padding: 10px 13px;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12.5px;
}

code.inline {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

pre.code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
  line-height: 1.5;
}

.cursor::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* --- tool cards --- */

.tool {
  max-width: 860px;
  margin: 0 auto 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  overflow: hidden;
}
.tool summary {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 12.5px;
  list-style: none;
}
.tool summary::-webkit-details-marker { display: none; }
.tool-name { color: var(--accent); }
.tool-arg { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-stat { margin-left: auto; font-size: 11.5px; color: var(--text-dim); }

.tool-content { border-top: 1px solid var(--border); }
.tool > .tool-content > .tool-body { border-top: none; }

.tool-raw > summary {
  padding: 7px 12px;
  cursor: pointer;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11.5px;
  list-style: none;
}
.tool-raw > summary::-webkit-details-marker { display: none; }
.tool-raw > summary::before { content: "▸ "; }
.tool-raw[open] > summary::before { content: "▾ "; }

.tool-body {
  margin: 0;
  padding: 11px 13px;
  border-top: 1px solid var(--border);
  background: var(--surface-sunken);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  max-height: 340px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-dim);
}

/* --- diffs --- */

.diff {
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
}

.diff-head {
  padding: 6px 12px;
  color: var(--text-dim);
  font-size: 11.5px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  left: 0;
}

.diff-hunk-head {
  padding: 5px 12px;
  color: var(--text-dim);
  background: color-mix(in oklab, var(--brand) 8%, transparent);
  font-size: 11.5px;
}

.diff-line { display: flex; min-width: max-content; padding: 0 12px; }
.diff-num {
  flex: none;
  width: 4ch;
  text-align: right;
  color: var(--text-dim);
  opacity: 0.6;
  user-select: none;
}
.diff-sign { flex: none; width: 2ch; text-align: center; user-select: none; }
.diff-text { white-space: pre; padding-left: 4px; }

.diff-line.add { background: color-mix(in oklab, var(--ok) 14%, transparent); }
.diff-line.add .diff-sign, .diff-line.add .diff-text { color: var(--ok); }
.diff-line.del { background: color-mix(in oklab, var(--bad) 14%, transparent); }
.diff-line.del .diff-sign, .diff-line.del .diff-text { color: var(--bad); }
.diff-line.ctx .diff-text { color: var(--text-dim); }

/* --- approval prompts --- */

.approval {
  max-width: 860px;
  margin: 0 auto 14px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  background: color-mix(in oklab, var(--attention) 9%, transparent);
  overflow: hidden;
}
.approval.approved { border-color: var(--ok); background: color-mix(in oklab, var(--ok) 9%, transparent); }
.approval.denied { border-color: var(--err); background: color-mix(in oklab, var(--bad) 9%, transparent); }

.approval-head { padding: 10px 13px; display: flex; flex-direction: column; gap: 4px; }
.approval-title { font-weight: 600; }
.approval-summary { font-size: 12px; color: var(--text-dim); word-break: break-word; }
.approval-body:empty { display: none; }

.approval-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 13px;
  border-top: 1px solid var(--border);
}
.approval-note { font-size: 12.5px; color: var(--text-dim); }

/* --- viewer diff --- */

.viewer-actions { display: flex; align-items: center; gap: 8px; }
.viewer-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewer-diff { overflow: auto; min-height: 0; flex: 1; }
.viewer-diff.hidden { display: none; }
.viewer-note { padding: 14px 16px; margin: 0; }
.diff-inline { border-bottom: none; }

/* --- composer --- */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  max-width: 860px;
  margin: 0 auto;
  padding: 12px 20px 20px;
  width: 100%;
}

#input {
  flex: 1;
  resize: none;
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  line-height: 1.5;
  max-height: 220px;
  min-height: 42px;
}
#input:focus { outline: none; border-color: var(--accent-dim); }

/* --- files --- */

/*
 * An overlay, not a docked third column. Docked, it took 280px from the pane the
 * code is written in, and a long line in the preview was what paid for it.
 * Closed is the default; the toggle in the top bar is the only way in and out.
 */
.files {
  display: none;
  flex-direction: column;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  min-height: 0;
}
.files.open {
  display: flex;
  position: fixed;
  inset: 0 0 0 auto;
  width: 340px;
  z-index: 30;
}

.files-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.files-workspace {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.files-workspace .field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.files-workspace .select { width: 100%; }
.files-note { margin: 0; font-size: 11px; line-height: 1.45; word-break: break-all; }
.files-note:empty { display: none; }

.files-path { padding: 8px 14px; font-size: 11px; color: var(--text-dim); border-bottom: 1px solid var(--border); word-break: break-all; }
.files-list { flex: 1; overflow-y: auto; padding: 6px; min-height: 0; }

.file-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  padding: 6px 9px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-family: var(--mono);
  font-size: 12px;
  cursor: pointer;
}
.file-entry:hover { background: var(--bg-hover); color: var(--text); }
.file-entry.changed { color: var(--text); }
.file-entry .changed-mark {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--warn);
}
.file-entry .size { margin-left: auto; font-size: 10.5px; opacity: 0.65; }
.file-entry .glyph { opacity: 0.7; flex: none; }

/* --- preview pane --- */

/*
 * Docked under the conversation rather than beside it: the files panel is
 * already the right-hand third, and this one has to stay usable on the narrow
 * screens where that panel is hidden.
 */
.preview {
  display: none;
  flex-direction: column;
  flex: none;
  height: min(52vh, 520px);
  min-height: 140px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
}
.preview.open { display: flex; }

.preview-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.preview-head .brand { font-size: 12px; }
#preview-title { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; }

.preview-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.preview-diff { overflow: auto; max-height: 55%; border-bottom: 1px solid var(--border); }
.preview-diff.hidden { display: none; }

/*
 * The app view: the project running, filling the pane.
 *
 * The frame is given every pixel below the bar. A preview that is a window into
 * a small box is not a preview — the layout the user is judging is the layout that
 * has to fit, and the pane's own chrome is the only thing allowed to take space.
 */
.preview-app { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.preview-app-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
}
.preview-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
  background: var(--text-dim);
}
.preview-dot.up { background: var(--ok); }
.preview-dot.down { background: var(--warn); }
#preview-app-url { flex: none; }
.preview-app-note {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-app-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; flex: none; }
/*
 * White, not the panel colour: whatever shows through before the app paints is
 * the page's background, and the app's own idea of it is the one to trust.
 */
.preview-frame {
  flex: 1;
  min-height: 0;
  width: 100%;
  border: 0;
  background: #fff;
}
.preview-app-log {
  margin: 0;
  padding: 8px 12px;
  max-height: 40%;
  overflow: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.preview-app-empty { margin: 0; padding: 14px; font-size: 12.5px; }

/*
 * While a file is still arriving the change and the file are shown side by side:
 * the point of the pane during a write is watching it take shape, and the diff
 * against what was there before is the other half of that. The pane grows to give
 * both columns room, then goes back to one column when the write lands.
 */
.preview.live { height: min(60vh, 520px); }
.preview.live .preview-content { flex-direction: row; }
.preview.live #preview-diff {
  flex: 1;
  min-width: 0;
  max-height: none;
  border-bottom: none;
  border-right: 1px solid var(--border);
}  .preview.live #preview-body { flex: 1; min-width: 0; }

/*
 * Wrapped, not scrolled sideways. This pane is narrow and the point of it is that
 * you can read the file as it lands; a line that runs off the right edge asks you
 * to scroll to see the half of it that matters.
 */
.preview-body {
  margin: 0;
  padding: 11px 14px;
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--surface-sunken);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.settings-form { gap: 14px; padding: 16px; overflow-y: auto; }
.settings-form .field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; }
.settings-form .field.check { flex-direction: row; align-items: center; gap: 8px; }
.settings-form .input-text { width: 100%; }
.settings-note { margin: 4px 0 0; font-size: 12px; line-height: 1.5; }
.settings-note:empty { display: none; }
/* The caret marks a file that is still arriving, not one that is finished. */
.preview-body.generating::after {
  content: "▍";
  color: var(--accent);
  animation: blink 1s steps(2) infinite;
}

/* Token colours: the four kinds the highlighter emits, plus JSON keys. */
.tok-comment { color: var(--ink-faint); font-style: italic; }
.tok-string { color: var(--ok); }
.tok-number { color: var(--tone-sentinel); }
.tok-keyword { color: var(--accent); }
.tok-key { color: var(--attention); }

.badge.ok {
  color: var(--ok);
  border-color: color-mix(in oklab, var(--ok) 45%, transparent);
  background: color-mix(in oklab, var(--ok) 12%, transparent);
}
.badge.bad {
  color: var(--err);
  border-color: color-mix(in oklab, var(--bad) 50%, transparent);
  background: color-mix(in oklab, var(--bad) 12%, transparent);
}

/* --- sweep rows --- */

.sweep-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
}
.sweep-row .btn-ghost { flex: none; padding: 1px 7px; font-size: 11px; }
.sweep-row .sweep-model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#sweep-status.stale { color: var(--warn); }

/* --- viewer overlay --- */

.viewer {
  position: fixed;
  inset: 6vh 6vw;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-pop);
  z-index: 40;
}
#viewer-title { font-size: 12.5px; color: var(--text-dim); }
.viewer-body {
  margin: 0;
  padding: 14px 16px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  white-space: pre;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1080px) {
  .app { grid-template-columns: 200px minmax(0, 1fr); }
  .files.open { width: min(340px, 90vw); }
}
