:root {
  --bg: #0b0d10;
  --surface: #14181d;
  --surface-2: #1c2229;
  --text: #e6e9ee;
  --muted: #8b95a3;
  --accent: #4cc2ff;
  --live: #37d67a;
  --warn: #ffb020;
  --error: #ff5a5a;
  --border: #232a32;
  --vvh: 100dvh;
}
* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}
#app {
  height: 100dvh;
  height: var(--vvh, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.screen {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}
.screen[hidden] {
  display: none;
}
.app-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.app-header .title {
  font-weight: 600;
  flex: 1;
}
.session-search {
  width: 100%;
  padding: 8px 12px;
  margin: 0 16px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
.session-search::placeholder {
  color: var(--muted);
}
.scroll-area {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}
.pill {
  font-size: 13px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
}
.pill.live {
  color: var(--live);
}
.pill.connecting {
  color: var(--warn);
  animation: pulse 1.4s ease-in-out infinite;
}
.section-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
  padding: 12px 16px 4px;
  text-transform: uppercase;
}
.machine-label {
  font-size: 14px;
  font-weight: 600;
  padding: 16px 16px 2px;
  border-bottom: 1px solid var(--border);
}
.badge.offline {
  color: var(--warn);
}
.row {
  min-height: 44px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  touch-action: manipulation;
  cursor: pointer;
}
.row-main {
  display: flex;
  align-items: center;
  gap: 8px;
}
.row .label {
  font-weight: 500;
  flex: 1;
}
.row .dir {
  color: var(--muted);
  font-size: 13px;
}
.row-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
  padding-left: 16px;
}
.recent-row .label {
  color: var(--muted);
  font-weight: 400;
}
.recent-toggle {
  color: var(--accent);
  text-align: center;
  font-size: 14px;
}
.list-empty {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  padding: 20px 16px;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: 0 0 auto;
}
.dot.live {
  background: var(--live);
}
.badge {
  display: inline-block;
  font-size: 12px;
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 6px;
}
.pulse {
  color: var(--live);
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}
.icon-button {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 6px 10px;
  touch-action: manipulation;
}
.session-header {
  flex: 1;
  min-width: 0;
}
.session-label {
  font-weight: 600;
}
.session-sub {
  color: var(--muted);
  font-size: 13px;
}
.badge.readonly {
  color: var(--warn);
}
.badge.live {
  color: var(--live);
}
.ctx-chip {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
#transcript {
  padding: 12px 16px;
}
.msg {
  margin-bottom: 14px;
  max-width: 100%;
}
.msg.user {
  display: flex;
  justify-content: flex-end;
}
.msg.user .bubble {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 14px;
  padding: 8px 12px;
  max-width: 85%;
  white-space: pre-wrap;
}
.msg.assistant {
  color: var(--text);
  line-height: 1.5;
}
.msg.assistant pre {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px;
  overflow-x: auto;
  max-width: 100%;
}
.msg.assistant code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 1px 4px;
}
/* The copy control is a right-aligned header above the code (in-flow, never over the code —
   important since the code scrolls horizontally under any absolute overlay). */
.code-block {
  display: flex;
  flex-direction: column;
}
.code-block .copy-btn {
  align-self: flex-end;
  margin-bottom: 6px;
  padding: 3px 8px;
  font-size: 12px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 28px;
  touch-action: manipulation;
}
.code-block .copy-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
/* Copy control sits in-flow below the message (never overlapping text): left-aligned under
   assistant prose. Hidden by default and revealed via the composer's "Copy" toggle. */
.msg .copy-btn {
  padding: 3px 8px;
  font-size: 12px;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  min-height: 28px;
  touch-action: manipulation;
}
.msg .copy-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}
.msg.assistant .copy-btn {
  display: block;
  width: fit-content;
  margin-top: 8px;
}
/* Copy buttons (message + code block) are hidden by default via opacity — their reserved space
   stays, so revealing them never shifts the layout. The composer's "Copy" chip sets
   .copy-visible on <body> to reveal them. */
.copy-btn {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s ease;
}
.copy-visible .copy-btn {
  opacity: 1;
  pointer-events: auto;
}
.msg.assistant a {
  color: var(--accent);
}
.msg.other {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}
.tool-chip {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 14px;
  color: var(--muted);
  touch-action: manipulation;
}
/* Stack the command/path over its output in a column. A horizontal row collapses on a narrow
   phone: a long command consumes the width and the output is squeezed into a sliver that wraps
   one character per line. */
.msg.tool-result {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 6px 0;
  font-size: 14px;
  min-width: 0;
  touch-action: manipulation;
}
.msg.tool-result .tool-name {
  color: var(--muted);
  font-weight: 600;
  overflow-wrap: anywhere;
}
.msg.tool-result .tool-line {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  min-width: 0;
}
.msg.tool-result .tool-expand {
  align-self: flex-start;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.msg.tool-result.error {
  border-color: var(--error);
  color: var(--error);
}
/* Edit diff shown beneath an edit's tool-result row: removed lines in red, added in green. Scrolls
   horizontally on its own so long lines never widen the page. */
.tool-diff {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin: -2px 0 6px;
  overflow-x: auto;
  max-width: 100%;
  font-size: 12.5px;
  line-height: 1.45;
  white-space: pre;
}
.tool-diff .diff-add {
  display: block;
  color: var(--live);
}
.tool-diff .diff-del {
  display: block;
  color: var(--error);
}
.tool-diff .diff-more {
  display: block;
  color: var(--muted);
  font-style: italic;
}
/* Thinking traces: collapsed to a header by default. Tapping the header opens one block (.open);
   the composer's "Think" chip reveals them all (body.thinking-visible). */
.thinking {
  margin: 6px 0;
  border-left: 2px solid var(--border);
  padding-left: 8px;
}
.thinking-head {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
}
.thinking-caret {
  display: inline-block;
  font-style: normal;
  transition: transform 0.12s ease;
}
.thinking.open .thinking-caret,
.thinking-visible .thinking-caret {
  transform: rotate(90deg);
}
.thinking-body {
  display: none;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-top: 4px;
}
.thinking.open .thinking-body,
.thinking-visible .thinking-body {
  display: block;
}
.cursor {
  display: inline-block;
  animation: blink 1s step-start infinite;
  color: var(--accent);
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}
.spinner {
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
#screen-token {
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.token-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.token-card h1 {
  margin-bottom: 4px;
}
.token-card .muted {
  color: var(--muted);
  font-size: 14px;
}
#token-input {
  width: 100%;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  margin: 12px 0;
}
button {
  font-size: 16px;
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: var(--accent);
  color: #04141c;
  font-weight: 600;
  touch-action: manipulation;
}
.error-text {
  color: var(--error);
  font-size: 13px;
  margin-top: 8px;
}
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  left: 16px;
  right: 16px;
  background: var(--surface-2);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: center;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}
.toast.error {
  border: 1px solid var(--error);
  color: var(--error);
}
#composer-mount {
  flex: 0 0 auto;
  position: relative;
  border-top: 1px solid var(--border);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
#composer-mount[hidden] {
  display: none;
}
.cmd-overlay {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 100%;
  max-height: 40dvh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 6px;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
}
.cmd-row {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  touch-action: manipulation;
}
.cmd-row + .cmd-row {
  border-top: 1px solid var(--border);
}
.cmd-name {
  font-weight: 600;
  color: var(--text);
  flex: 0 0 auto;
}
.cmd-desc {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
}
.chip {
  flex: 0 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  touch-action: manipulation;
}
.chip-slash {
  color: var(--accent);
  font-weight: 700;
}
/* The Think + Copy toggles group at the far right of the chip row; the first one carries the auto
   margin that pushes the pair over. Their active state mirrors whether each is currently on. */
.chip-think {
  margin-left: auto;
}
.chip-think.active,
.chip-copy.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-2);
}
.abort-row {
  display: flex;
  justify-content: flex-end;
  padding-bottom: 6px;
}
.abort-btn {
  background: var(--surface-2);
  color: var(--error);
  border: 1px solid var(--error);
}
.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.composer-input {
  flex: 1 1 auto;
  font-size: 16px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  resize: none;
  max-height: 40dvh;
}
.composer-input:disabled,
button:disabled {
  opacity: 0.5;
}
.queue-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.mic-btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  min-width: 40px;
  min-height: 40px;
  padding: 8px 12px;
  font-size: 20px;
}
.mic-btn.listening {
  background: var(--live);
  color: #04141c;
  border-color: var(--live);
  animation: pulse 1.4s ease-in-out infinite;
}
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}
.sheet-backdrop[hidden],
.sheet[hidden] {
  display: none;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 16px);
}
.sheet-grabber {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 6px auto 14px;
}
.sheet-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  touch-action: manipulation;
}
.sheet-label {
  color: var(--muted);
  flex: 0 0 auto;
}
.sheet-value {
  flex: 1 1 auto;
  font-weight: 500;
}
.sheet-section {
  margin-top: 16px;
}
.sheet-heading {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}
.model-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  touch-action: manipulation;
}
.check {
  width: 18px;
  color: var(--accent);
}
.model-name {
  flex: 1 1 auto;
}
.model-provider {
  color: var(--muted);
  font-size: 13px;
}
.model-toggle {
  color: var(--accent);
  justify-content: center;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.sheet-loading {
  color: var(--muted);
  padding: 10px 0;
}
.thinking-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.thinking-seg {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  touch-action: manipulation;
}
.thinking-seg.active {
  background: var(--accent);
  color: #04141c;
  font-weight: 600;
}
.sheet-spawn {
  width: 100%;
  margin-top: 18px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.sheet-end {
  width: 100%;
  margin-top: 10px;
  background: transparent;
  color: var(--error);
  border: 1px solid var(--error);
}
.sheet-changes {
  width: 100%;
  margin-top: 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.changes-files {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}
.change-row {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 13px;
  padding: 2px 0;
}
.change-status {
  flex: 0 0 auto;
  width: 2ch;
  white-space: pre;
  color: var(--accent, #4a9eff);
}
.change-path {
  flex: 1 1 auto;
  word-break: break-all;
}
.changes-stat {
  margin: 0;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  font-family: var(--mono, ui-monospace, monospace);
  font-size: 12px;
  white-space: pre;
}
.changes-empty {
  color: var(--text-dim, #888);
  padding: 8px 0;
}
.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  touch-action: manipulation;
}
.settings-label {
  flex: 1 1 auto;
}
.toggle {
  flex: 0 0 auto;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  position: relative;
  transition: background 0.15s ease;
}
.toggle.on {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle .knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  transition: left 0.15s ease;
}
.toggle.on .knob {
  left: 20px;
}
.settings-note {
  margin: 4px 0 8px;
  font-size: 13px;
}
.lan-url {
  color: var(--accent);
  word-break: break-all;
}
.muted-note {
  color: var(--muted);
}
.session-hint {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

/* Trust modal overlay */
#trust-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
#trust-modal[hidden] {
  display: none;
}
.trust-modal-content {
  background: var(--surface);
  border-radius: 16px;
  padding: 24px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.trust-modal-content h2 {
  margin: 0 0 16px;
  font-size: 20px;
}
.trust-cwd {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace;
  font-size: 13px;
  word-break: break-all;
  margin-bottom: 16px;
}
.trust-modal-content p {
  margin: 0 0 16px;
  color: var(--muted);
}
.trust-options {
  margin-bottom: 16px;
}
.trust-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}
.trust-remember input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.trust-buttons {
  display: flex;
  gap: 12px;
}
.trust-approve {
  flex: 1;
  background: var(--live);
  color: #04141c;
  border: none;
}
.trust-deny {
  flex: 1;
  background: var(--surface-2);
  color: var(--error);
  border: 1px solid var(--error);
}
.resume-bar {
  flex: 0 0 auto;
  padding: 10px 16px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--border);
  text-align: center;
}
.resume-bar[hidden] {
  display: none;
}
#resume-button {
  width: 100%;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.resume-hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

/* Tool output modal */
#tool-output-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1001;
}
#tool-output-backdrop[hidden] {
  display: none;
}
#tool-output-modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1002;
  padding: 20px;
}
#tool-output-modal[hidden] {
  display: none;
}
.tool-output-content {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.tool-output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.tool-output-header h3 {
  margin: 0;
  font-size: 16px;
}
.tool-output-close {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
  padding: 0 4px;
}
.tool-output-body {
  flex: 1;
  overflow-y: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
  font-family: "SF Mono", "Menlo", "Monaco", "Courier New", monospace;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
}
.tool-output-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.tool-output-actions button {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
