/* Theme and shared elements */
:root {
  --background: #101916;
  --surface: #17251f;
  --raised: #1e3227;
  --hover: #2a4935;
  --line: #365e44;
  --muted: #91ad9a;
  --text: #d2e4d8;
  --bright: #e9f4ed;
  --accent: #79c995;
  --human: #86b6a0;
  color-scheme: dark;
  font: 15px/1.6 system-ui, sans-serif;
  background: var(--background);
  color: var(--text);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  height: 100dvh;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}
button {
  font: inherit;
  background: var(--raised);
  color: var(--text);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 7px;
  cursor: pointer;
}
button:hover { background: var(--hover); }
button:disabled { opacity: .4; cursor: default; }
section { padding: 50px 6vw; max-width: 1100px; width: 100%; }
h1 { font-size: 34px; letter-spacing: -1.2px; line-height: 1.2; margin: 12px 0 20px; font-weight: 550; }
h2 { font-size: 16px; font-weight: 500; }
.eyebrow { font: 11px/1.6 monospace; letter-spacing: 2px; color: var(--accent); }
small { display: block; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.65 system-ui, sans-serif; }
textarea {
  display: block;
  width: 100%;
  resize: vertical;
  min-height: 130px;
  background: var(--surface);
  color: var(--bright);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  font: inherit;
  margin: 25px 0 14px;
}
textarea:focus { outline: 2px solid var(--accent); }
form button { float: right; }
select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  max-width: 100%;
}
.author { color: inherit; text-decoration: none; }
.author:hover { text-decoration: underline; }
.state-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: 0 0 10px; background: #356341; }
.state-dot.green { background: var(--accent); }
.state-dot.amber { background: #e5b454; }
.state-dot.red { background: #e97878; }
.state-dot.gray { background: #356341; }
#error {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #4c2525;
  border: 1px solid #a06464;
  border-radius: 8px;
  padding: 12px 24px;
  max-width: 90vw;
}

/* Header and authenticated connectivity */
header { display: block; height: auto; min-height: 76px; border-bottom: 1px solid var(--line); padding: 12px 32px; }
.primary-navbar { display: flex; align-items: center; flex-wrap: wrap; gap: 16px; width: 100%; }
.brand {
  flex: 1 1 230px;
  min-width: 0;
  font-weight: 750;
  color: var(--bright);
  text-decoration: none;
  font-size: 22px;
  letter-spacing: -1px;
}
.brand span { color: var(--accent); }
.brand .tagline {
  display: block;
  font: 12px/1.4 system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--muted);
  white-space: normal;
  overflow-wrap: anywhere;
}
.brand .tagline span { color: inherit; }
.brand .tagline-dot { padding: 0 3px; }
#navbar-connectivity { flex: 0 1 auto; max-width: calc(100% - 300px); margin-left: auto; order: 1; }
#navbar-connectivity:empty { display: none; }
#connectivity-navbar { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 4px 14px; }
.connection-status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 0;
  font-size: 11px;
  line-height: 1.4;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}
.connection-status.online { color: var(--accent); }
.connection-status.offline { color: #eeaaaa; }
a.connection-status:hover { filter: brightness(1.2); }
.connection-status .state-dot { width: 7px; height: 7px; flex-basis: 7px; }
#login { order: 2; margin-left: auto; flex-shrink: 0; width: 34px; height: 34px; padding: 0; font-size: 21px; }

/* Desktop task navigation and draggable divider */
main {
  display: grid;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr);
  grid-template-columns: var(--sidebar-width, minmax(30em, 32vw)) 6px minmax(0, 1fr);
}
#task-sidebar { grid-column: 1; padding: 24px 16px; overflow-y: auto; min-height: 0; }
#welcome, #detail { grid-column: 3; grid-row: 1; }
#sidebar-resize { grid-column: 2; grid-row: 1; background: var(--line); cursor: col-resize; touch-action: none; }
#sidebar-resize:hover, #sidebar-resize:focus-visible { background: var(--accent); outline: 0; }
.sidebar-resizing, .sidebar-resizing * { cursor: col-resize !important; user-select: none !important; }
#sidebar-toggle, #sidebar-close, #sidebar-backdrop { display: none; }
.aside-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.task {
  display: block;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  padding: 10px 12px;
  text-align: left;
  margin: 4px 0;
  color: var(--text);
  cursor: pointer;
}
.task:hover { background: var(--surface); }
.task.selected, .task.selected:hover { border-color: var(--line); background: var(--raised); }
.task strong { display: block; font-weight: 500; }
.task-select { display: block; width: 100%; border: 0; background: transparent; padding: 0; text-align: left; }
.task-select:hover { background: transparent; }
.task-heading { display: flex; align-items: center; gap: 10px; }
.task-heading strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.task-meta { padding-left: 20px; font-size: 12px; color: var(--muted); }
.task-meta span { display: inline; }
.sidebar-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 22px; padding-top: 16px; border-top: 1px solid var(--line); }
.sidebar-tools button { font-size: 11px; padding: 6px 9px; }
#instructions, #connections { margin-left: 0; }

/* New-task wizard, drafts and repository discovery */
#welcome { max-width: 1200px; padding: 28px 36px; width: 100%; overflow-y: auto; }
#welcome > h1 { margin: 8px 0 14px; font-size: 32px; }
#welcome > p { margin: 0 0 18px; }
#welcome > p:not(.eyebrow) { color: var(--muted); }
#signin-note { clear: both; padding-top: 15px; font-size: 12px; }
#task-composer { padding: 0; max-width: none; width: 100%; margin-top: 20px; }
#close-task-composer { float: none; margin: 0 0 16px; }
#task-composer h1 { font-size: 24px; margin: 0 70px 16px 0; }
#task-composer form { display: flow-root; }
#create { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; display: flow-root; }
#create textarea { margin: 0 0 12px; background: var(--background); min-height: 100px; }
#task-composer #objective { margin-top: 14px; min-height: 130px; }
#task-composer #start-task { margin-top: 16px; }
#reference-editor label { display: block; font-size: 12px; color: var(--muted); }
#reference-content { font: 13px/1.6 ui-monospace, monospace; min-height: 280px; height: 35dvh; margin: 8px 0 18px; resize: vertical; }
.drafts-section { max-width: none; padding: 0; margin: 24px 0; }
.drafts-section > p { font-size: 12px; color: var(--muted); }
#draft-gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.draft-choice { text-align: left; background: var(--surface); padding: 14px; }
#draft-gallery .scratch-choice { border-style: dashed; }
.scratch-choice small { margin-top: 4px; }
.repository-selection { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); gap: 10px; }
.repository-selection button { float: none; padding: 3px 8px; font-size: 11px; }
.model-choice { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; margin: 15px 0; }
.model-choice label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.model-choice label:last-of-type { flex: 1; min-width: 200px; }
#change-model button { float: none; }
.resource-heading { display: flex; align-items: center; justify-content: space-between; margin-top: 24px; }
.resource-heading h2 { font-size: 18px; margin: 0; }
.resource-heading button { font-size: 12px; padding: 4px 10px; }
#github-identity { font-size: 12px; color: var(--muted); margin: 4px 0 14px; }
#resource-warning { color: #d5b379; font-size: 12px; }
.resource-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; }
.resource-card { padding: 16px; width: 100%; max-width: none; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.resource-card h3 { font-size: 15px; margin: 0 0 4px; }
.resource-card > p { font-size: 12px; color: var(--muted); margin: 0 0 12px; }
.resource-card > small { margin-top: 12px; }
.resource-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.resource-row small { white-space: nowrap; }
.repository-choice { background: transparent; border-color: transparent; padding: 5px 0; min-width: 0; flex: 1; text-align: left; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.repository-choice.selected { color: var(--bright); background: var(--hover); padding-left: 8px; }
.external-link, .destination-row a { color: var(--text); text-decoration: none; }
.external-link:hover, .destination-row a:hover { text-decoration: underline; }
.destination-row { margin: 12px 0; }
.mcp-card { grid-column: 1 / -1; }
.empty-resource { font-size: 12px; color: var(--muted); }

/* Task heading, settings and composer */
#detail { display: flex; flex-direction: column; height: 100%; min-height: 0; max-width: none; padding: 22px 32px 16px; }
.detail-head { display: flex; gap: 20px; justify-content: space-between; flex-shrink: 0; align-items: flex-start; }
.detail-head > div:first-child { min-width: 0; }
.detail-head h1 { margin: 5px 0 8px; font-size: 25px; }
.detail-head .eyebrow { margin: 0; }
#task-id { letter-spacing: 0; }
#task-repository { font-size: 12px; color: var(--muted); margin: 4px 0; overflow-wrap: anywhere; }
#task-repository a { color: var(--text); text-decoration: none; }
#task-repository a:hover { text-decoration: underline; }
#phase { font-size: 13px; color: var(--muted); margin: 4px 0; overflow-wrap: anywhere; }
#controls { display: flex; gap: 6px; align-content: start; flex-wrap: nowrap; flex-shrink: 0; align-items: center; }
#controls button { width: 36px; height: 36px; padding: 0; font-size: 20px; line-height: 1; }
#delete-task { color: #efb8b8; border-color: #805454; background: #382424; }
#refine-task { flex-shrink: 0; font-size: 12px; padding: 6px 10px; margin-left: auto; white-space: nowrap; }
#worker-countdown { font-size: 12px; color: var(--text); margin: 6px 0; }
#reason { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
#reason:empty, #task-draft:empty, #turn-elapsed:empty { display: none; }
#task-settings { flex-shrink: 0; font-size: 13px; }
#task-settings summary { cursor: pointer; color: var(--muted); }
#task-settings[open] { max-height: 35vh; overflow-y: auto; }
#task-draft { font-size: 12px; color: var(--muted); margin: 4px 0; }
#rename { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0; }
#rename input { flex: 1; min-width: 160px; background: var(--surface); color: var(--bright); border: 1px solid var(--line); border-radius: 7px; padding: 8px; font: inherit; }
#rename button { float: none; font-size: 12px; }
#context-controls { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; flex-shrink: 0; }
.context-knob { font-size: 11px; padding: 4px 10px; background: var(--raised); color: var(--muted); border-color: var(--line); }
.context-knob.enabled { background: var(--hover); color: var(--text); border-color: var(--line); }
#processing-state { flex-shrink: 0; margin: 4px 0 8px; font-size: 12px; color: var(--text); }
#turn-elapsed { flex-shrink: 0; font-size: 12px; color: var(--muted); margin: 0 0 8px; }
#followup { display: flex; align-items: flex-end; gap: 12px; flex-shrink: 0; border-top: 1px solid var(--line); padding-top: 12px; }
#followup textarea { flex: 1; min-height: 72px; height: 72px; max-height: 180px; margin: 0; padding: 12px; resize: vertical; }
#followup button { float: none; flex-shrink: 0; }

/* Conversation, prompts and tool activity */
#timeline { display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; overflow-y: auto; padding: 12px 8px 12px 0; margin-top: 12px; }
.entry { width: 85%; padding: 16px 20px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.entry.user, .entry.external { align-self: flex-start; background: var(--raised); border-left: 3px solid var(--human); }
.entry.agent { align-self: flex-end; border-right: 3px solid var(--accent); }
.entry.controller { align-self: center; width: 92%; background: transparent; border-left: 2px solid #94794b; padding-left: 16px; }
.meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.avatar { border-radius: 50%; background: var(--line); flex: 0 0 28px; }
.prompt-status { display: inline-block; margin-left: 0; color: var(--text); font-size: 11px; }
.prompt-context { font-size: 12px; color: var(--muted); }
.prompt-context summary { cursor: pointer; }
.prompt-context pre { margin-top: 8px; }
.response-metrics { margin-top: 10px; color: var(--muted); line-height: 1.6; }
.entry.prompt-running { border-color: var(--accent); border-left: 3px solid var(--accent); background: var(--raised); box-shadow: 0 0 0 1px #79c99526; }
.running-badge, .queued-badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 12px; padding: 2px 9px; font-weight: 650; }
.running-badge { background: var(--hover); color: var(--bright); }
.queued-badge { background: #4b3e27; color: #efd297; }
.prompt-spinner { display: inline-block; width: 11px; height: 11px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: prompt-spin 1s linear infinite; }
.remove-prompt { margin-left: auto; width: 28px; height: 28px; padding: 0; font-size: 18px; background: transparent; color: #efb8b8; border-color: #805454; }
.entry.prompt-removed { opacity: .65; }
.prompt-removed .prompt-status { color: #b7a3a3; }
@keyframes prompt-spin { to { transform: rotate(360deg); } }
.timeline-activity { display: flex; align-items: center; justify-content: center; gap: 8px; align-self: center; font-size: 12px; color: var(--muted); padding: 6px 12px; max-width: 90%; overflow-wrap: anywhere; }
.activity-icon { color: var(--text); font-size: 11px; flex-shrink: 0; }
.tool-activity { margin-top: 10px; font-size: 12px; color: var(--muted); }
.tool-activity summary { cursor: pointer; }
.tool-call { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px; }
.tool-heading { font-size: 12px; }
.tool-call pre { font: 12px/1.6 ui-monospace, monospace; white-space: pre-wrap; background: var(--background); padding: 10px; border-radius: 5px; margin: 6px 0; }

/* Rendered Markdown */
.markdown { font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; min-width: 0; }
.markdown > :first-child { margin-top: 12px; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 12px 0; }
.markdown a { color: var(--text); }
.markdown ul, .markdown ol { padding-left: 24px; }
.markdown li + li { margin-top: 4px; }
.markdown pre { font: 13px/1.6 ui-monospace, monospace; white-space: pre; overflow-x: auto; overflow-wrap: normal; background: var(--background); border: 1px solid var(--line); border-radius: 6px; padding: 12px; max-width: 100%; }
.markdown code { font: 13px/1.6 ui-monospace, monospace; background: var(--background); border-radius: 3px; padding: 2px 4px; }
.markdown pre code { padding: 0; background: none; }
.markdown blockquote { border-left: 3px solid var(--accent); margin: 12px 0; padding-left: 12px; color: var(--muted); }
.markdown h1, .markdown h2, .markdown h3, .markdown h4, .markdown h5, .markdown h6 { font-weight: 650; letter-spacing: 0; line-height: 1.4; margin: 16px 0 8px; font-size: 16px; }
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 18px; }
.markdown table { display: block; overflow-x: auto; border-collapse: collapse; max-width: 100%; margin: 12px 0; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* Dialogs */
dialog { background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 12px; max-width: 850px; width: 90vw; max-height: 85vh; padding: 30px; }
dialog::backdrop { background: #0009; }
dialog h2 { font-size: 21px; margin-top: 28px; }
dialog pre { background: var(--background); padding: 15px; border-radius: 6px; font: 13px/1.6 monospace; }
#close-setup, #close-share, #close-instructions { float: right; }
#share-url { width: 100%; padding: 10px; background: var(--background); border: 1px solid var(--line); border-radius: 6px; color: var(--text); font: 13px/1.5 ui-monospace, monospace; }
.share-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
#share-banner { font-size: 12px; color: var(--text); margin: 4px 0; }
#instructions-dialog > p { font-size: 13px; color: var(--muted); }
#instructions-content { font: 13px/1.6 ui-monospace, monospace; }
#instructions-dialog .resource-heading { gap: 16px; margin-top: 16px; }

/* Read-only transcripts */
.read-only aside, .read-only header button, .read-only #controls,
.read-only #task-settings, .read-only #followup, .read-only #processing-state,
.read-only #task-id, .read-only #task-repository, .read-only #phase,
.read-only #share-banner, .read-only #task-draft, .read-only #context-controls,
.read-only #worker-countdown, .read-only #reason, .read-only #turn-elapsed { display: none !important; }
.read-only header #login { display: block !important; }
.read-only main { grid-template-columns: minmax(0, 1fr); }
.read-only #sidebar-resize { display: none; }
.read-only #welcome, .read-only #detail { grid-column: 1; }
.read-only .detail-head { align-items: center; gap: 12px; }
.read-only .detail-head h1 { font-size: 22px; margin: 0; }
.read-only #detail { padding-top: 16px; }
.read-only #timeline { margin-top: 6px; }
.read-only .context-knob:disabled { opacity: 1; cursor: default; }

/* Sidebar drawer and connectivity placement */
@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); }
  #welcome, #detail { grid-column: 1; }
  #sidebar-resize { display: none; }
  .primary-navbar { gap: 12px; flex-wrap: nowrap; }
  #navbar-connectivity { display: none; }
  #sidebar-connectivity #connectivity-navbar { justify-content: flex-start; gap: 6px 14px; margin-top: 22px; }
  #sidebar-toggle { display: block; flex: 0 0 34px; width: 34px; height: 34px; padding: 0; font-size: 22px; order: -1; border: 0; background: transparent; }
  #task-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 61;
    width: min(30em, calc(100vw - 40px));
    height: 100dvh;
    padding: 20px 16px;
    background: var(--background);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform .15s ease, visibility .15s;
  }
  .sidebar-open #task-sidebar { transform: translateX(0); visibility: visible; }
  #sidebar-close { display: block; margin: 0 0 8px auto; width: 34px; height: 34px; padding: 0; font-size: 25px; border: 0; background: transparent; }
  #sidebar-backdrop:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 60; background: #0009; border: 0; border-radius: 0; padding: 0; }
  .read-only #sidebar-toggle, .read-only #sidebar-backdrop { display: none !important; }
}

@media (max-width: 750px) {
  header { padding-left: 16px; padding-right: 16px; }
  header button { font-size: 11px; padding: 7px 8px; }
  .brand { font-size: 16px; }
  .brand .tagline { font-size: 10px; }
  section { padding: 28px 20px; }
  h1 { font-size: 29px; }
  .aside-head { margin-bottom: 5px; }
  #detail { padding: 14px 16px 12px; }
  .detail-head { gap: 10px; }
  .detail-head h1 { font-size: 21px; }
  #controls { gap: 4px; }
  #controls button { width: 30px; height: 30px; font-size: 18px; }
  #task-id { font-size: 9px; }
  #followup { gap: 8px; }
  #followup button { padding: 8px 10px; }
  .entry { width: 92%; }
  #welcome { padding: 20px 16px; }
  #welcome > h1 { font-size: 27px; }
  .resource-grid { grid-template-columns: 1fr; }
  .mcp-card { grid-column: auto; }
  #create { padding: 14px; }
  #create .model-choice { gap: 10px; }
}

@media (max-width: 650px) {
  .brand { flex: 1; }
  .connection-status { font-size: 10px; }
  .sidebar-tools { margin-top: 10px; padding-top: 8px; }
  #reference-content { min-height: 220px; }
}

@media (prefers-reduced-motion: reduce) {
  .prompt-spinner { animation: none; }
  #task-sidebar { transition: none; }
}
