:root {
  --bg:          #0e1014;
  --panel:       #16181e;
  --panel-2:     #1c1f27;
  --line:        #24272f;
  --line-soft:   #1a1d24;
  --ink:         #d8dde6;
  --ink-dim:     #7b8596;
  --ink-faint:   #4e5663;
  --accent:      #f4c678;     /* warm amber */
  --accent-deep: #8c6728;
  --cool:        #7fb4d9;
  --warn:        #e08a5a;
  --ok:          #7aab6a;
  --hot:         #d95a5a;
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --sans:  "Geist", "Inter Tight", system-ui, sans-serif;
  --mono:  "JetBrains Mono", ui-monospace, Menlo, monospace;
}
* { margin:0; padding:0; box-sizing:border-box; }
html, body { height:100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Top bar ---------- */
.topbar {
  display:flex; align-items:center; justify-content:space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(244,198,120,0.04), transparent 60%),
    var(--panel);
}
.brand {
  display:flex; align-items:center; gap: 14px;
}
.brand .logo {
  height: 36px;
  width: auto;
  flex-shrink: 0;
  /* logo.svg is navy-on-white; flip for dark theme. */
  filter: invert(0.92) hue-rotate(180deg) saturate(0.9) brightness(1.05);
}
/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 300px 1fr 320px;
  height: calc(100vh - 60px);
}

/* ---------- Rail (chambers) ---------- */
.rail {
  border-right: 1px solid var(--line);
  background: var(--panel);
  display:flex; flex-direction:column;
  overflow: hidden;
}
.rail-head {
  padding: 16px 18px 8px;
  display:flex; align-items:baseline; justify-content:space-between;
}
.rail-head .title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.rail-head .count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
}
.rail-search {
  margin: 0 14px 8px;
  padding: 7px 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  outline: none;
}
.rail-search::placeholder { color: var(--ink-faint); }
.rail-list { flex:1; overflow-y:auto; padding: 4px 8px 24px; }
.rail-list::-webkit-scrollbar { width: 6px; }
.rail-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

.chamber {
  padding: 10px 12px;
  border-radius: 7px;
  margin-bottom: 2px;
  cursor: pointer;
  position: relative;
  border: 1px solid transparent;
}
.chamber:hover { background: var(--panel-2); }
.chamber.active {
  background: linear-gradient(180deg, rgba(244,198,120,0.06), rgba(244,198,120,0.02));
  border-color: rgba(244,198,120,0.18);
}
.chamber.active::before {
  content:""; position:absolute; left:-1px; top:10px; bottom:10px;
  width: 2px; background: var(--accent); border-radius: 2px;
}
.chamber-row1 {
  display:flex; align-items:center; gap: 8px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink:0;
}
.status-dot.running { background: var(--ok); box-shadow: 0 0 0 3px rgba(122,171,106,0.12); }
.status-dot.running-active {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(122,171,106,0.12);
  animation: cryo-pulse 1.2s ease-in-out infinite;
}
.status-dot.stopped { background: var(--ink-faint); }
.status-dot.complete { background: var(--cool); }
.status-dot.error { background: var(--hot); }
@keyframes cryo-pulse {
  0%, 100% {
    filter: brightness(1);
    box-shadow:
      0 0 0 3px rgba(122,171,106,0.18),
      0 0 3px 0 rgba(122,171,106,0.45);
  }
  50% {
    filter: brightness(1.35);
    box-shadow:
      0 0 0 3px rgba(122,171,106,0.32),
      0 0 14px 4px rgba(122,171,106,0.75);
  }
}
@media (prefers-reduced-motion: reduce) {
  .status-dot.running-active { animation: none; }
}
.chamber-name {
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chamber .unread {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 600;
  background: var(--accent);
  color: #2a1d07;
  padding: 1px 6px;
  border-radius: 8px;
  line-height: 14px;
}
.chamber-preview {
  font-family: var(--sans);
  font-size: 12px;
  color: var(--ink-dim);
  margin-top: 4px;
  margin-left: 15px;
  line-height: 1.45;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chamber-meta {
  display:flex; flex-direction: column; gap: 2px;
  margin-top: 5px; margin-left: 15px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}
.chamber-meta .task,
.chamber-meta .when {
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.chamber-meta .when.soon { color: var(--accent); }

.rail-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  display:flex; justify-content:space-between;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}
.rail-foot button {
  background: none; border: 1px solid var(--line);
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.rail-foot button:hover { color: var(--ink); border-color: var(--ink-faint); }

/* ---------- Center: thread ---------- */
.center {
  display:flex; flex-direction:column;
  min-width: 0; min-height: 0;
  background:
    radial-gradient(1200px 400px at 70% -10%, rgba(244,198,120,0.04), transparent 60%),
    var(--bg);
}
.thread-head {
  padding: 18px 28px 14px;
  border-bottom: 1px solid var(--line);
  display:flex; align-items: flex-start; justify-content: space-between;
  gap: 24px;
}
.thread-head .left { min-width: 0; }
.thread-head .title {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 26px;
  letter-spacing: -0.015em;
  color: var(--ink);
  display:flex; align-items:baseline; gap: 10px;
}
.thread-head .title .session {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}
.thread-head .task {
  font-family: var(--sans);
  font-size: 13px;
  color: var(--ink-dim);
  margin-top: 6px;
  max-width: 64ch;
}
.thread-head .task .label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-right: 6px;
}

.wake-chip {
  display:inline-flex; align-items: center; gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--accent);
  background: rgba(244,198,120,0.08);
  border: 1px solid rgba(244,198,120,0.18);
  padding: 4px 10px;
  border-radius: 999px;
}
.wake-chip .pulse {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(244,198,120,0.5);
  animation: pulse 1.8s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(244,198,120,0.4); }
  70%  { box-shadow: 0 0 0 7px rgba(244,198,120,0); }
  100% { box-shadow: 0 0 0 0 rgba(244,198,120,0); }
}

.lifecycle {
  display:flex; gap: 6px;
  margin-top: 8px;
}
.lifecycle button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 5px;
  cursor: pointer;
}
.lifecycle button:hover { background: var(--panel-2); border-color: var(--ink-faint); }
.lifecycle button.primary { background: var(--accent); color: #2a1d07; border-color: transparent; }
.lifecycle button.primary:hover { background: #ffd58a; }
.lifecycle button.danger { color: var(--hot); border-color: rgba(217,90,90,0.3); }
.lifecycle button.danger:hover { background: rgba(217,90,90,0.1); }
.lifecycle button:disabled {
  opacity: 0.55;
  cursor: wait;
  pointer-events: none;
}

/* Thread body */
.thread {
  flex: 1;
  /* min-height:0 lets `flex: 1` actually bound the thread height so
     overflow-y can scroll. Without it, flex's default `min-height: auto`
     keeps the thread as tall as its content and `scrollTop = scrollHeight`
     is a no-op (the page scrolls instead of the thread). */
  min-height: 0;
  overflow-y: auto;
  padding: 24px 28px 12px;
  display: flex; flex-direction: column; gap: 22px;
}
.day-marker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display:flex; align-items:center; gap: 12px;
  margin: 4px 0;
}
.day-marker::before, .day-marker::after {
  content:""; flex:1; height:1px; background: var(--line-soft);
}
/* Session boundary — emitted when the session number changes between two
   messages. Rendered as subtle gray to match the system-timestamp tone, not
   as a loud accent; the session number itself is what draws the eye. */
.session-marker {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display:flex; align-items:center; gap: 14px;
  margin: 10px 0 2px;
}
.session-marker::before, .session-marker::after {
  content:""; flex:1; height:1px; background: var(--line-soft);
}
.msg {
  max-width: 68ch;
  padding: 14px 18px;
  border-radius: 10px;
  position: relative;
}
.msg.agent {
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
}
.msg.human {
  align-self: flex-end;
  background: rgba(244,198,120,0.07);
  border: 1px solid rgba(244,198,120,0.18);
}
.msg-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  margin-bottom: 6px;
  letter-spacing: 0.04em;
  display:flex; gap: 10px;
}
.msg.agent .msg-meta .from { color: var(--cool); }
.msg.human .msg-meta .from { color: var(--accent); }
.msg-body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  white-space: pre-wrap;
}
.msg-body em { font-family: var(--serif); font-style: italic; color: var(--ink); }

/* System notice — centered gray text, no bubble. */
.sys-notice {
  align-self: center;
  max-width: min(80ch, 100%);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  line-height: 1.5;
  padding: 4px 10px;
  text-align: center;
  white-space: pre-wrap;
}

/* Older-messages fold at the top of the thread. Mirrors `.todo-history` and
   `.chamber-history` so every "history" collapser in the dashboard looks the
   same. */
.thread-history {
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 10px;
}
.thread-history > summary {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 6px 10px;
  list-style: none;
  text-align: center;
}
.thread-history > summary::-webkit-details-marker { display: none; }
.thread-history > summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
}
.thread-history[open] > summary::before { content: "▾ "; }
.thread-history > summary:hover { color: var(--ink-dim); }
.thread-history-body {
  display: flex; flex-direction: column; gap: 22px;
  padding-top: 16px;
}

/* Compose */
.compose {
  border-top: 1px solid var(--line);
  padding: 14px 28px 18px;
  background: var(--bg);
}
.compose-inner {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display:flex; gap: 10px; align-items: flex-end;
}
.compose textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  min-height: 24px;
  max-height: 140px;
}
.compose textarea::placeholder { color: var(--ink-faint); }
.compose .controls {
  display:flex; gap: 6px;
}
.compose .hint {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  padding: 6px 4px;
}
.compose .send {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.005em;
  background: var(--accent);
  color: #2a1d07;
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}
.compose .send:hover { background: #ffd58a; }

/* ---------- Right drawer ---------- */
.drawer {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display:flex; flex-direction:column;
  overflow: hidden;
}
.drawer-tabs {
  display:flex;
  border-bottom: 1px solid var(--line);
  padding: 0 8px;
}
.drawer-tab {
  flex:1;
  padding: 14px 6px;
  text-align: center;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  position: relative;
}
.drawer-tab:hover { color: var(--ink-dim); }
.drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}
.drawer-tab .dot {
  display:inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--warn);
  margin-left: 6px;
  vertical-align: 2px;
}
.drawer-tab .tab-count {
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-faint);
  background: var(--panel-2);
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 6px;
  vertical-align: 1px;
  text-transform: none;
}
.drawer-tab.active .tab-count {
  background: rgba(244,198,120,0.14);
  color: var(--accent);
}
.drawer-body {
  flex:1;
  overflow-y: auto;
  padding: 16px 18px 24px;
}
.drawer-body.hidden { display: none; }

/* Sync toggle switch */
.sync-toggle {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}
.sync-toggle input { opacity: 0; width: 0; height: 0; }
.sync-toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--panel-3, #2a2d37);
  border: 1px solid var(--line);
  border-radius: 10px;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.sync-toggle .slider::after {
  content:"";
  position: absolute;
  left: 2px; top: 1px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform 0.2s ease, background 0.2s ease;
}
.sync-toggle input:checked + .slider {
  background: rgba(122,171,106,0.22);
  border-color: var(--ok);
}
.sync-toggle input:checked + .slider::after {
  transform: translateX(14px);
  background: var(--ok);
}

.sync-help {
  margin-top: 14px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  color: var(--ink-faint);
  background: var(--panel-2);
  border: 1px solid var(--line-soft);
  border-radius: 6px;
}

.section-title {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 10px;
  display:flex; justify-content: space-between; align-items: baseline;
}
.section-title .count {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  letter-spacing: 0;
  text-transform: none;
}

/* Todos */
.todos { display:flex; flex-direction: column; gap: 4px; }
.todo {
  display:flex; align-items:baseline; gap: 10px;
  padding: 7px 8px;
  border-radius: 5px;
  font-size: 13px;
  line-height: 1.45;
}
.todo:hover { background: var(--panel-2); }
.todo .check {
  flex-shrink:0;
  width: 14px; height: 14px;
  border-radius: 3px;
  border: 1.5px solid var(--ink-faint);
  margin-top: 2px;
  position: relative;
}
.todo.done .check {
  background: var(--cool);
  border-color: var(--cool);
}
.todo.done .check::after {
  content:"✓";
  font-size: 10px; font-weight: 700;
  color: #0e1014;
  position: absolute;
  top: -2px; left: 2px;
}
.todo .text {
  flex:1; color: var(--ink);
}
.todo.done .text {
  color: var(--ink-faint);
  text-decoration: line-through;
}
.todo .when {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  flex-shrink: 0;
}
.todo .when.soon { color: var(--accent); }
.todo-more {
  padding: 6px 8px 2px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}
.todo-history {
  margin-top: 14px;
  border-top: 1px solid var(--line-soft);
  padding-top: 10px;
}
.todo-history > summary {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}
.todo-history > summary::-webkit-details-marker { display: none; }
.todo-history > summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s ease;
}
.todo-history[open] > summary::before {
  content: "▾ ";
}
.todo-history > summary:hover { color: var(--ink-dim); }
.todo-history > .todos { margin-top: 8px; }

/* Completed-chamber fold in the sidebar rail. Mirrors `.todo-history` so the
   two collapsible "History" sections feel like one pattern. */
.chamber-history {
  margin-top: 10px;
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
}
.chamber-history > summary {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 6px 10px;
  list-style: none;
}
.chamber-history > summary::-webkit-details-marker { display: none; }
.chamber-history > summary::before {
  content: "▸ ";
  display: inline-block;
  margin-right: 4px;
  transition: transform 0.15s ease;
}
.chamber-history[open] > summary::before { content: "▾ "; }
.chamber-history > summary:hover { color: var(--ink-dim); }

/* Sync */
.sync-list { display:flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.sync-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: var(--panel-2);
}
.sync-card-head {
  display:flex; align-items:center; justify-content: space-between;
  margin-bottom: 8px;
}
.sync-card-name {
  display:flex; align-items:center; gap: 8px;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}
.sync-card-name .badge {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 1.5px 5px;
  border-radius: 3px;
  background: rgba(122,171,106,0.14);
  color: var(--ok);
}
.sync-card-name .badge.stopped {
  background: rgba(78,86,99,0.18); color: var(--ink-dim);
}
.sync-target {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sync-meta {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}
.sync-foot {
  margin-top: 6px;
  display:flex; justify-content: space-between;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--ink-faint);
}

/* Log */
.log-wrap {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #0b0d12;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.log {
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  color: var(--ink-dim);
  padding: 12px;
  white-space: pre-wrap;
  max-height: 240px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.log::-webkit-scrollbar { width: 6px; }
.log::-webkit-scrollbar-track { background: transparent; }
.log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.log::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }
.log .ts { color: var(--ink-faint); }
.log .k { color: var(--cool); }
.log .v { color: var(--accent); }
/* NOTES.md — rendered as faithful plaintext (no markdown parsing), but
   styled for reading: sans-serif body, generous line-height, ink-on-panel
   contrast. The `<pre>` keeps whitespace/newlines from the source file. */
.notes-wrap {
  margin-top: 8px;
}
.notes {
  font-family: var(--sans);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 14px 18px;
  min-height: 180px;
  max-height: 520px;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
}
/* Utility */
.divider {
  height: 1px; background: var(--line-soft); margin: 18px 0;
}
