:root {
  --bg: #1a1a17;
  --surface: #1f1f1c;
  --surface-2: #26261f;
  --border: #2a2a26;
  --border-strong: #3a3a35;
  --text: #ededeb;
  --text-muted: #969690;
  --text-dim: #6c6c66;
  --accent: #c69b6a;
  --accent-strong: #d8a979;
  --accent-dim: rgba(198, 155, 106, 0.14);
  --primary-bg: #efeeec;
  --primary-bg-hover: #ffffff;
  --primary-text: #1a1a17;
  --added: #8aaf72;
  --added-bg: rgba(138, 175, 114, 0.10);
  --removed: #c97064;
  --removed-bg: rgba(201, 112, 100, 0.10);
  --running: #d4a851;
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  height: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre { font-family: var(--mono); font-size: 0.9em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 3px; color: var(--text); }

/* ----- Index page ----- */
body.page-index {
  padding: 56px 40px;
  max-width: 720px;
  margin: 0 auto;
  height: auto;
}

body.page-index h1 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--text);
}

body.page-index .subtitle {
  color: var(--text-muted);
  margin: 0 0 32px;
  font-size: 14px;
}

body.page-index .screens {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

body.page-index .screens li {
  background: var(--bg);
  padding: 14px 18px;
}

body.page-index .screens a {
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
}

body.page-index .screens a:hover { color: var(--accent-strong); }

body.page-index .meta {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 400;
}

/* ----- App layout ----- */
body.page-app {
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100%;
}

/* ----- Sidebar ----- */
.sidebar {
  background: #161613;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar .tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 6px;
}

.sidebar .tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font: inherit;
  padding: 12px 10px 11px;
  cursor: pointer;
  border-bottom: 1px solid transparent;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: -1px;
}

.sidebar .tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.sidebar .tab.disabled { color: var(--text-dim); cursor: not-allowed; }

.session-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  flex: 1;
  overflow-y: auto;
}

.session-list li {
  padding: 12px 16px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  position: relative;
}

.session-list li:hover { background: var(--surface); }
.session-list li.active { background: var(--surface); }

.session-list li.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--text);
}

.session-list li.in-rollup::before { background: var(--accent); }

.status {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 8px;
}

.status.idle { background: var(--text-dim); }
.status.running { background: var(--running); box-shadow: 0 0 0 3px rgba(212, 168, 81, 0.16); }
.status.rollup { background: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.session-list .title {
  color: var(--text);
  font-weight: 500;
  font-size: 13.5px;
}

.session-list .meta {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 32px;
  color: var(--text);
}

.empty-state p { margin: 4px 0; }
.empty-state .muted { color: var(--text-muted); font-size: 13px; max-width: 220px; line-height: 1.5; margin-top: 8px; }

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid var(--border);
}

/* ----- Buttons ----- */
.btn-primary, .btn-secondary, .btn-ghost {
  font: inherit;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 500;
  white-space: nowrap;
  font-size: 13px;
  border: 1px solid transparent;
  transition: background 80ms ease;
}

.btn-primary {
  background: var(--primary-bg);
  color: var(--primary-text);
  border-color: var(--primary-bg);
}
.btn-primary:hover { background: var(--primary-bg-hover); border-color: var(--primary-bg-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--surface); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ----- Main ----- */
.main {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

.main-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.main-header {
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  font-size: 13px;
}

.main-header .breadcrumb { color: var(--text-muted); }
.main-header .separator { color: var(--text-dim); }
.main-header .session-title { color: var(--text); font-weight: 500; }

.main-header h2 { margin: 0; font-size: 15px; font-weight: 500; }

.spacer { flex: 1; }

/* ----- Conversation (no role labels, color-only role distinction) ----- */
.conversation {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.conversation-inner {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 32px 24px;
  position: relative;
}

/* ----- Pending edits bar (sticky, lives inside .conversation) ----- */
.pending-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 32px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  flex-shrink: 0;
  backdrop-filter: blur(6px);
}

.pending-bar .pending-count {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.pending-bar .pending-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
}

.pending-bar .pending-nav button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 24px;
  height: 24px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.pending-bar .pending-nav button:hover { background: var(--surface-2); }

/* ----- Tool calls inline in assistant messages ----- */
.msg .content > p { margin: 0 0 12px; }
.msg .content > p:last-child { margin-bottom: 0; }
.msg .content > p:first-child { margin-top: 0; }

.tool-call {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin: 10px 0;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.4;
}

.tool-call .tool-name {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  flex-shrink: 0;
  min-width: 36px;
}

.tool-call .tool-input { color: var(--text-muted); }

.msg {
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.msg:last-child { border-bottom: none; }

/* role labels are visually hidden but kept for accessibility */
.msg .role {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.msg .content {
  line-height: 1.7;
  font-size: 14.5px;
  word-wrap: break-word;
}

.msg.user .content { color: var(--text-muted); }
.msg.assistant .content { color: var(--text); }

/* ----- Composer ----- */
.composer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.composer textarea {
  resize: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font: inherit;
  min-height: 80px;
  line-height: 1.55;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.composer textarea:disabled { opacity: 0.45; cursor: not-allowed; }

.composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.composer-actions .hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-right: auto;
}

/* ----- Modal ----- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  width: 440px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
}

.modal header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal h2 { margin: 0; font-size: 15px; font-weight: 500; }

.modal-body { padding: 22px 20px; }

.modal-body label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}

.modal-body input, .modal-body select {
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  letter-spacing: normal;
  text-transform: none;
}

.modal-body input:focus { outline: none; border-color: var(--accent); }

.modal-body .muted { color: var(--text-muted); font-size: 12px; margin-top: 14px; text-transform: none; letter-spacing: normal; font-weight: 400; }

/* ----- New session page ----- */
.new-session {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 56px 32px;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

.new-session .form-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.new-session label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--text-muted);
}

.new-session select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
}

.new-session .composer {
  border-top: none;
  padding: 0;
  max-width: none;
  margin: 0;
}

/* ----- Rollup banner ----- */
.rollup-banner {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  border-top: 2px solid var(--accent);
  font-size: 13px;
  flex-shrink: 0;
}

.rollup-label {
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.1em;
  font-size: 11px;
  text-transform: uppercase;
}

.rollup-instruction {
  color: var(--text-muted);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rollup-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.rollup-nav button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  font: inherit;
  line-height: 1;
}

.rollup-nav button:hover { background: var(--surface-2); }

.rollup-actions { display: flex; gap: 6px; }

/* ----- Edit zones (gutter stripe, no boxes) ----- */
.edit-block {
  position: relative;
  padding: 4px 0;
  margin: 8px 0;
}

.edit-block::before {
  content: '';
  position: absolute;
  left: -16px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--accent);
  opacity: 0.55;
  border-radius: 1px;
}

.edit-block.current::before {
  width: 3px;
  opacity: 1;
}

.edit-header {
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  padding: 6px 0 2px;
}

.edit-block .msg {
  border-bottom: none;
  padding: 6px 0;
}

/* removed messages: keep strikethrough visible regardless of role color */
.edit-block .msg.removed .content {
  text-decoration: line-through;
  text-decoration-color: var(--text-dim);
  opacity: 0.55;
  color: var(--text);
}

/* new messages: plain — they appear after the arrow, no extra chrome */

.edit-arrow {
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  padding: 6px 0;
}

.msg.modified .content .text-removed {
  text-decoration: line-through;
  background: var(--removed-bg);
  color: var(--removed);
  padding: 1px 4px;
  border-radius: 2px;
}

.msg.modified .content .text-added {
  background: var(--added-bg);
  color: var(--added);
  padding: 1px 4px;
  border-radius: 2px;
}

/* ----- Rollup chat (quiet, same width, no header) ----- */
.rollup-chat {
  background: var(--bg);
  border-top: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 38vh;
  min-height: 240px;
  max-height: 380px;
}

.rollup-chat-thread {
  flex: 1;
  overflow-y: auto;
}

.rollup-chat-thread .conversation-inner {
  padding: 8px 32px;
}

.rollup-chat .composer {
  border-top: 1px solid var(--border);
  flex-direction: row;
  align-items: stretch;
  gap: 8px;
  padding: 12px 24px;
  max-width: 720px;
}

.rollup-chat .composer textarea {
  flex: 1;
  min-height: 56px;
}

.rollup-chat .composer .btn-primary { align-self: stretch; padding: 0 18px; }
