/* Webadmin — the builder. Warm paper, one accent, nothing decorative that a
   non-technical reader has to decode. Shared by /settings and /activity. */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --surface-3: #e6e1d8;
  --border: #ded8ce;
  --border-strong: #c9c1b4;
  --text: #1e1b16;
  --muted: #6e675d;
  --accent: #c2410c;
  --accent-hover: #a3360a;
  --accent-soft: #fbe9df;
  --accent-text: #ffffff;
  --ok: #167a4a;
  --ok-soft: #dff2e6;
  --warn: #9a6410;
  --warn-soft: #fbf0d9;
  --danger: #b6303c;
  --danger-soft: #fbe3e5;
  --shadow: 0 14px 36px rgba(48, 33, 18, 0.11);
  --shadow-soft: 0 1px 3px rgba(48, 33, 18, 0.07), 0 6px 18px rgba(48, 33, 18, 0.05);
  --radius: 14px;
  --radius-sm: 10px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent);
  --sidebar-w: 268px;
  --preview-w: 480px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1d1a16;
    --surface-2: #262119;
    --surface-3: #302a22;
    --border: #38312a;
    --border-strong: #4b433a;
    --text: #f2ece4;
    --muted: #a49b8e;
    --accent: #f0865a;
    --accent-hover: #f59a74;
    --accent-soft: #3a2519;
    --accent-text: #1a0f08;
    --ok: #5ed08a;
    --ok-soft: #1a3324;
    --warn: #f0b95d;
    --warn-soft: #362a14;
    --danger: #ff7b86;
    --danger-soft: #3a2024;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
    --shadow-soft: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.015em; }
h1 { font-size: 17px; }
h2 { font-size: 21px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
ol, ul { margin: 0; padding: 0; }
code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 0.9em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
pre { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; line-height: 1.5; margin: 0; white-space: pre-wrap; word-break: break-word; }
button, textarea, input, select { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lead { max-width: 58ch; }
.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; }

/* -------------------------------------------------------------- Controls */

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 15px;
  font-weight: 600;
  cursor: pointer;
  background: var(--surface-2);
  transition: background 0.15s, border-color 0.15s, transform 0.08s;
}
.btn:hover { filter: brightness(0.975); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); filter: none; }
.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--border-strong); filter: none; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-small { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; }

.icon-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  border-radius: 9px;
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  cursor: pointer;
  font-size: 15px;
  text-decoration: none;
  flex: none;
}
.icon-button:hover { background: var(--surface-2); color: var(--text); }

textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 11px 13px;
  resize: none;
  line-height: 1.55;
}
textarea:focus { border-color: var(--accent); }

/* ---------------------------------------------------------------- Layout */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}
.app.with-preview { grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--preview-w); }
.scrim { position: fixed; inset: 0; background: rgba(20, 14, 6, 0.4); z-index: 30; border: 0; }

/* --------------------------------------------------------------- Sidebar */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  min-height: 0;
}
.sidebar-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 0; }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; flex: 1; }
.brand-mark {
  width: 26px; height: 26px; flex: none;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--accent); color: var(--accent-text);
  font-size: 12px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 14.5px; letter-spacing: -0.01em; }
.brand-text .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.task-list { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; flex: 1; min-height: 0; margin: 0 -4px; padding: 0 4px; }
.task-item {
  display: flex; align-items: flex-start; gap: 9px;
  width: 100%; text-align: left;
  padding: 9px 10px;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; cursor: pointer;
}
.task-item:hover { background: var(--surface-3); }
.task-item.active { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-soft); }
.task-icon { font-size: 15px; line-height: 1.35; flex: none; }
.task-item-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; }
.task-item-text strong { font-weight: 570; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-item-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); flex: none; margin-top: 7px; }
.status-dot.working { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.status-dot.queued { background: var(--warn); }
.status-dot.done { background: var(--ok); }
.status-dot.failed { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.sidebar-links { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }
.side-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  border: 0; background: transparent; color: var(--text);
  text-decoration: none; font-size: 14px; font-weight: 550; cursor: pointer; width: 100%; text-align: left;
}
.side-link:hover { background: var(--surface-3); }
.side-link.active { background: var(--surface); box-shadow: var(--shadow-soft); }
.side-icon { color: var(--muted); width: 16px; text-align: center; }
.side-count { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 500; }

.sidebar-foot { padding: 0 4px; }
.conn { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.conn .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.conn-ok { color: var(--ok); }
.conn-bad { color: var(--danger); }
.empty { color: var(--muted); padding: 10px 8px; }

/* ------------------------------------------------------------------ Main */

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h1 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.site-status {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 6px 4px 11px;
  border: 1px solid var(--border); border-radius: 999px;
  font-size: 12.5px; font-weight: 550; color: var(--muted);
}
.site-status .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); flex: none; }
.site-status[data-state="running"] { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, var(--border)); }
.site-status[data-state="running"] .dot { background: var(--ok); }
.site-status[data-state="starting"] .dot,
.site-status[data-state="restarting"] .dot,
.site-status[data-state="unreachable"] .dot { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.site-status[data-state="starting"],
.site-status[data-state="restarting"],
.site-status[data-state="unreachable"] { color: var(--warn); }
.site-status[data-state="crashed"] { color: var(--danger); }
.site-status[data-state="crashed"] .dot { background: var(--danger); }

.banner {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px;
  background: var(--warn-soft);
  border-bottom: 1px solid color-mix(in srgb, var(--warn) 25%, transparent);
  font-size: 13.5px;
}
.banner.working { background: var(--accent-soft); border-bottom-color: color-mix(in srgb, var(--accent) 25%, transparent); }
.banner-text { flex: 1; }

.stage { flex: 1; min-height: 0; display: flex; }
.view { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ New change */

.view-new { overflow-y: auto; }
.new-inner { width: min(680px, 100%); margin: 0 auto; padding: 46px 24px 60px; display: flex; flex-direction: column; gap: 14px; }
.new-inner h2 { font-size: 26px; }

.composer { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-soft); overflow: hidden; }
.composer textarea { border: 0; border-radius: 0; background: transparent; padding: 15px 16px 6px; font-size: 15.5px; }
.composer textarea:focus { box-shadow: none; }
.composer:focus-within { border-color: var(--accent); }
.composer-foot { display: flex; align-items: center; gap: 12px; padding: 8px 12px 11px 16px; }
.composer-foot .muted { flex: 1; }
.composer-buttons { display: flex; align-items: center; gap: 10px; flex: none; }

.examples { display: flex; flex-wrap: wrap; gap: 7px; }
.example {
  border: 1px dashed var(--border-strong); background: transparent;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--muted); cursor: pointer;
}
.example:hover { border-style: solid; color: var(--text); background: var(--surface); }
.empty-state { text-align: center; padding: 40px 0; }

/* --------------------------------------------------------- Conversation */

.messages { flex: 1; overflow-y: auto; padding: 22px 24px 8px; display: flex; flex-direction: column; gap: 11px; }
.messages > * { width: min(720px, 100%); margin-inline: auto; }

.bubble-row { display: flex; flex-direction: column; gap: 3px; }
.bubble-row.user { align-items: flex-end; }
.bubble { max-width: 88%; padding: 11px 14px; border-radius: var(--radius); }
.bubble.user { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 5px; white-space: pre-wrap; }
.bubble.agent { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; box-shadow: var(--shadow-soft); }
.bubble.agent > :first-child { margin-top: 0; }
.bubble.agent p + p { margin-top: 9px; }
.bubble.agent ul, .bubble.agent ol { margin: 8px 0 8px 20px; }
.bubble.agent li { margin: 3px 0; }
.bubble.agent h3 { margin: 12px 0 5px; font-size: 14.5px; }
.bubble.agent pre { background: var(--surface-2); padding: 10px 12px; border-radius: 9px; overflow-x: auto; margin: 8px 0; }
.bubble.agent blockquote { margin: 8px 0; padding-left: 11px; border-left: 2px solid var(--border-strong); color: var(--muted); }
.stamp { font-size: 11.5px; color: var(--muted); }

.note { font-size: 13px; color: var(--muted); text-align: center; padding: 3px 0; }
.note.error { color: var(--danger); background: var(--danger-soft); border-radius: 9px; padding: 9px 12px; text-align: left; }

.step-chip, .tool-row {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: 13px; overflow: hidden;
}
.step-chip > summary, .step-chip > *:only-child, .tool-row > summary, .tool-row > * {
  display: flex; align-items: center; gap: 8px; padding: 8px 11px; cursor: default; list-style: none;
}
.step-chip > summary, .tool-row > summary { cursor: pointer; }
.step-chip > summary::-webkit-details-marker, .tool-row > summary::-webkit-details-marker { display: none; }
.step-label, .tool-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step-mark { width: 15px; text-align: center; color: var(--muted); font-size: 12px; }
.step-chip.done .step-mark { color: var(--ok); }
.step-chip.failed { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.step-chip.failed .step-mark { color: var(--danger); }
.chev { color: var(--muted); font-size: 11px; }
.chev::before { content: "▾"; }
details[open] > summary .chev::before { content: "▴"; }
.step-body { padding: 0 11px 11px; display: flex; flex-direction: column; gap: 7px; }
.step-body pre, .tool-row pre { background: var(--surface-2); padding: 9px 11px; border-radius: 8px; max-height: 260px; overflow: auto; }
.tool-row pre { margin: 0 11px 11px; }
.step-error { color: var(--danger); }
.tool-row.failed { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.tool-icon { width: 16px; text-align: center; }
.thinking { font-size: 13px; color: var(--muted); }
.thinking > summary { cursor: pointer; }
.thinking > div { padding: 8px 0 0 14px; border-left: 2px solid var(--border); margin-top: 6px; white-space: pre-wrap; }
.plan-card { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 11px 13px; font-size: 13.5px; }
.plan-card ul { margin: 7px 0 0 18px; }
.plan-card li.completed { color: var(--muted); text-decoration: line-through; }

.spinner {
  width: 13px; height: 13px; flex: none;
  border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.working-row { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); padding: 4px 2px; }

/* A saved version, inline in the conversation. */
.save-card {
  display: flex; align-items: center; gap: 11px;
  border: 1px solid color-mix(in srgb, var(--ok) 35%, var(--border));
  background: var(--ok-soft);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13.5px;
}
.save-card .save-mark { color: var(--ok); font-weight: 700; }
.save-card .save-text { flex: 1; min-width: 0; }
.save-card strong { font-weight: 600; }

.task-foot { border-top: 1px solid var(--border); background: var(--surface); padding: 11px 24px 14px; }
.task-foot > * { width: min(720px, 100%); margin-inline: auto; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 9px; }
.quick-actions:empty { display: none; }
.reply { display: flex; gap: 9px; align-items: flex-end; }
.reply textarea { max-height: 180px; }
.send-button { flex: none; }

/* -------------------------------------------------------------- Versions */

.view-versions { overflow-y: auto; }
.versions-inner { width: min(760px, 100%); margin: 0 auto; padding: 34px 24px 60px; display: flex; flex-direction: column; gap: 18px; }
.notice { border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius-sm); padding: 11px 13px; font-size: 13.5px; box-shadow: var(--shadow-soft); }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }

.rail { list-style: none; display: flex; flex-direction: column; }
.rail-item { position: relative; padding: 0 0 12px 34px; }
/* The line down the rail, drawn between the dots rather than through them. */
.rail-item::before {
  content: ""; position: absolute; left: 10px; top: 20px; bottom: 0;
  width: 2px; background: var(--border);
}
.rail-item:last-child::before { display: none; }
.rail-dot {
  position: absolute; left: 4px; top: 12px;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.rail-item.current .rail-dot { border-color: var(--accent); background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.rail-item.newer .rail-dot { border-style: dashed; }

.version-card {
  display: flex; align-items: center; gap: 14px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: 12px 14px;
  box-shadow: var(--shadow-soft);
}
.rail-item.current .version-card { border-color: var(--accent); }
.rail-item.newer .version-card { background: transparent; box-shadow: none; }
.version-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.version-title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.version-meta { font-size: 12.5px; color: var(--muted); }
.tag {
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
  padding: 2px 7px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.tag.now { background: var(--accent-soft); color: var(--accent); }
.tag.latest { background: var(--ok-soft); color: var(--ok); }

/* --------------------------------------------------------------- Preview */

.preview { display: flex; flex-direction: column; border-left: 1px solid var(--border); background: var(--surface-2); min-width: 0; }
.preview-bar { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid var(--border); background: var(--surface); }
.widths { display: flex; gap: 2px; background: var(--surface-2); padding: 2px; border-radius: 8px; flex: 1; }
.width-button { flex: 1; border: 0; background: transparent; border-radius: 6px; padding: 5px 8px; font-size: 12.5px; font-weight: 550; color: var(--muted); cursor: pointer; }
.width-button.is-on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-soft); }
.preview-tools { display: flex; gap: 2px; flex: none; }
.preview-stage { flex: 1; position: relative; overflow: auto; display: grid; place-items: start center; padding: 14px; }
#preview-frame {
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  box-shadow: var(--shadow); width: 100%; height: 100%;
  transform-origin: top center;
}
.preview-cover { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; background: color-mix(in srgb, var(--surface-2) 92%, transparent); }
.preview-cover-inner { text-align: center; display: flex; flex-direction: column; gap: 9px; align-items: center; max-width: 340px; }
.preview-cover details { width: 100%; text-align: left; font-size: 12px; color: var(--muted); }
.preview-cover pre { margin-top: 6px; max-height: 190px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px; }

/* --------------------------------------------------------------- Dialogs */

.dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 0; box-shadow: var(--shadow); max-width: 440px; width: calc(100% - 32px);
}
.dialog::backdrop { background: rgba(20, 14, 6, 0.45); }
.dialog form { padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 11px 17px; border-radius: 11px; box-shadow: var(--shadow);
  max-width: min(560px, calc(100% - 32px)); z-index: 60; font-size: 14px;
}
.toast.error { background: var(--danger); color: #fff; }

/* ------------------------------------------------------------ Responsive */

.only-narrow { display: none; }
@media (max-width: 1180px) {
  .app.with-preview { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .app.with-preview .main { display: none; }
  .app.with-preview .preview { border-left: 0; }
}
@media (max-width: 860px) {
  .only-narrow { display: inline-grid; }
  .hide-narrow { display: none; }
  .app, .app.with-preview { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(310px, 86vw); z-index: 40;
    transform: translateX(-102%); transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }
  .app.show-list .sidebar { transform: none; }
  .new-inner, .versions-inner { padding-top: 26px; }
  .messages, .task-foot { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* Close / stop a request straight from the list, without opening it first. */
.task-row { position: relative; display: flex; }
.task-row > .task-item { flex: 1; padding-right: 30px; }
.task-close {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent;
  color: var(--muted); font-size: 11px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity .12s, background .12s;
}
.task-row:hover .task-close, .task-close:focus-visible, .task-close.always { opacity: 1; }
.task-close.always { color: var(--danger); }
.task-close:hover { background: var(--surface-3); color: var(--ink); }
.task-close:disabled { opacity: .4; cursor: default; }

/* The count or file list that keeps a run of identical steps informative. */
.tool-detail::before { content: "·"; margin-right: 6px; opacity: .55; }
.tool-detail { color: var(--muted); font-size: 12.5px; flex: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.tool-row.failed .step-mark { color: var(--danger); }
