/* tether web client — dark theme, mobile-first.
 *
 * Layout notes:
 *  - The app root height is driven by --app-height, which app.js keeps in sync
 *    with window.visualViewport so the soft keyboard never covers the terminal
 *    or the extra-keys row.
 *  - Buttons are sized >= 40px tall for touch targets.
 *  - CJK glyph rendering relies on xterm.js's default font fallback chain
 *    (monospace + system CJK fonts); no custom web font is bundled.
 */

:root {
  --bg: #101418;
  --bg-raised: #1a2027;
  --bg-input: #232b34;
  --fg: #e6e9ec;
  --fg-dim: #8b97a3;
  --accent: #4ea1ff;
  --accent-press: #2f81e0;
  --danger: #ff6b6b;
  --border: #2c353f;
  --app-height: 100vh; /* overwritten by app.js from visualViewport */
  /* Markdown / syntax-highlight token palette (timeline rich text). */
  --code-bg: #0b0e12;
  --tok-kw: #c586c0;
  --tok-str: #98c379;
  --tok-com: #6b7680;
  --tok-num: #d19a66;
  --diff-add: #62d789;
  --diff-del: #ff6b6b;
  --diff-hunk: #37c8c3;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none; /* no pull-to-refresh while scrolling the term */
}

.view {
  display: flex;
  flex-direction: column;
  height: var(--app-height);
  width: 100%;
  overflow: hidden;
  /* Positioned ancestor for the screencast overlay (.screen-panel, docs/19 §9). */
  position: relative;
}

.view[hidden] { display: none; }

/* ---------- connect view ---------- */

#view-connect {
  align-items: center;
  justify-content: center;
  overflow-y: auto;
}

.connect-card {
  width: min(28rem, 92vw);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}

.connect-card h1 {
  margin: 0 0 1rem;
  font-size: 1.4rem;
  font-weight: 600;
}

.connect-card label {
  display: block;
  margin: 0.8rem 0 0.25rem;
  font-size: 0.85rem;
  color: var(--fg-dim);
}

.connect-card input[type="url"],
.connect-card input[type="text"],
.connect-card input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.connect-card input:focus { border-color: var(--accent); }

.auth-mode {
  display: flex;
  gap: 1.25rem;
  margin-top: 1rem;
  font-size: 0.95rem;
}

.auth-mode label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  color: var(--fg);
}

button.primary {
  display: block;
  width: 100%;
  margin-top: 1.25rem;
  padding: 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}

button.primary:active { background: var(--accent-press); }
button.primary:disabled { opacity: 0.5; cursor: default; }

.status {
  min-height: 1.2em;
  margin: 0.75rem 0 0;
  font-size: 0.9rem;
  color: var(--danger);
  word-break: break-word;
}

.hint {
  margin: 0.75rem 0 0;
  font-size: 0.78rem;
  color: var(--fg-dim);
}

/* ---------- shared top bar ---------- */

.bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.bar-btn {
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
  color: var(--accent);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
}

.bar-btn:active { background: var(--bg-input); }
.bar-btn.danger { color: var(--danger); }
.bar-btn:disabled { opacity: 0.4; cursor: default; }
.bar-btn.active { background: var(--bg-input); }

/* Read-only screencast overlay (docs/19 §9): covers the terminal while active. */
.screen-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
  z-index: 20;
}
.screen-panel[hidden] { display: none; }
.screen-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0.5rem;
  background: var(--bg-bar, #101418);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.screen-info { font-size: 0.85rem; color: var(--fg-dim, #9aa); }
.screen-video {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #000;
}
/* While remote-input control is active (docs/19 §6): show a crosshair and stop
   the browser's own text/gesture handling so events forward cleanly to the PC. */
.screen-video.controlling {
  cursor: crosshair;
  outline: 2px solid var(--accent, #4ea1ff);
  outline-offset: -2px;
  touch-action: none;
}

/* Compact select in a top bar (terminal colour-theme picker). */
.bar-select {
  flex: 0 0 auto;
  max-width: 8.5rem;
  min-height: 36px;
  padding: 0.25rem 0.4rem;
  font-size: 0.8rem;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  outline: none;
  cursor: pointer;
}

.bar-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conn-state {
  font-size: 0.8rem;
  color: var(--fg-dim);
  white-space: nowrap;
}

/* Connected over the relay: amber — working, but going through the server. */
.conn-state.online { color: #e0b341; }
/* Connected over a direct P2P DataChannel: green — end-to-end, lowest latency. */
.conn-state.online.direct { color: #62d789; font-weight: 600; }

/* Manual reconnect (↻): shown in every bar only while disconnected. */
.reconnect-btn {
  flex: 0 0 auto;
  min-width: 40px;
  min-height: 40px;
  padding: 0.4rem 0.6rem;
  font-size: 1rem;
  color: var(--accent);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

.reconnect-btn:active { background: var(--bg-input); }
.reconnect-btn[hidden] { display: none; }

/* ---------- session tree view ---------- */

.session-tree {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem;
}

.session-tree .empty {
  color: var(--fg-dim);
  text-align: center;
  margin-top: 2rem;
}

.agent-group {
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.agent-header {
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  font-size: 0.9rem;
  background: var(--bg-raised);
  color: var(--fg);
}

.agent-header .agent-note {
  font-weight: 400;
  color: var(--fg-dim);
  font-size: 0.8rem;
}

.session-row {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 0.6rem;
  padding: 0.7rem 0.75rem;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  color: var(--fg);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  min-height: 48px;
}

.session-row:active { background: var(--bg-input); }

.session-row .session-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-row .session-meta {
  color: var(--fg-dim);
  font-size: 0.8rem;
  white-space: nowrap;
}

.session-row .session-close {
  color: var(--danger);
  background: transparent;
  border: none;
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
}

.sessions-footer {
  flex: 0 0 auto;
  padding: 0.5rem 0.75rem calc(0.5rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-raised);
}

.sessions-footer .primary { margin-top: 0; }
.sessions-footer .status { margin-top: 0.4rem; }

/* Terminal + AI session buttons side by side. */
.new-session-row {
  display: flex;
  gap: 0.5rem;
}

.new-session-row .primary { flex: 1; min-width: 0; }

/* Secondary flavour of .primary: outlined accent (the AI session button). */
button.primary.secondary {
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
}

button.primary.secondary:active { background: var(--border); }

/* New-session forms (terminal shell / M12 semantic runtime + cwd) plus their
 * launch parameters, revealed under the buttons. */
.launch-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.launch-form[hidden] { display: none; }

.launch-form select,
.launch-form input {
  min-height: 44px;
  padding: 0.45rem 0.6rem;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.launch-form select { flex: 0 0 auto; }

.launch-form input {
  flex: 1 1 10rem;
  min-width: 0;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.launch-form input:focus { border-color: var(--accent); }

.launch-form .primary {
  flex: 0 0 auto;
  display: inline-block;
  width: auto;
  margin-top: 0;
  padding: 0 1.1rem;
}

/* Launch-parameter preset checkboxes: a full-width wrapping row that changes
 * with the selected runtime (docs/06 open.args). */
.launch-presets {
  flex: 1 1 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.9rem;
}

.launch-presets:empty { display: none; }

.launch-preset {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--fg);
  cursor: pointer;
}

.launch-preset input {
  flex: 0 0 auto;
  min-height: 0;
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

/* ---------- files view (M11) ---------- */

/* Breadcrumb path bar: horizontally scrollable, current segment highlighted. */

.breadcrumbs {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 0.15rem 0.4rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
  scrollbar-width: none;
}

.breadcrumbs::-webkit-scrollbar { display: none; }

.breadcrumbs button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0.3rem 0.45rem;
  font-size: 0.9rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--accent);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation;
}

.breadcrumbs button:active { background: var(--bg-input); }

.breadcrumbs button.current {
  color: var(--fg);
  font-weight: 600;
  cursor: default;
}

.breadcrumbs .crumb-sep { color: var(--fg-dim); }

/* Directory write-action toolbar (new folder / upload / refresh). */
.files-toolbar {
  flex: 0 0 auto;
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem 0.5rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.files-tool {
  min-height: 40px;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.files-tool:active { background: var(--border); }
.files-tool:disabled { opacity: 0.45; cursor: default; }

/* Status line reuses .status (danger red) but stays compact in the column. */
.files-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 0.75rem;
}

.files-status:empty { display: none; }

.file-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.25rem 0;
}

.file-list .empty {
  color: var(--fg-dim);
  text-align: center;
  margin-top: 2rem;
}

/* A row is a flex container: a main (navigate/preview) button + action buttons. */
.file-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  border-bottom: 1px solid var(--border);
}

.file-main {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  background: transparent;
  border: none;
  color: var(--fg);
  font-size: 0.95rem;
  text-align: left;
  cursor: pointer;
  min-height: 48px;
}

.file-main:active { background: var(--bg-input); }

.file-main .file-icon { flex: 0 0 auto; }

.file-main .file-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-main .file-meta {
  flex: 0 0 auto;
  color: var(--fg-dim);
  font-size: 0.78rem;
  white-space: nowrap;
}

/* Per-entry action buttons (download / rename / delete), right-aligned. */
.file-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.file-action {
  min-width: 40px;
  min-height: 44px;
  padding: 0 0.5rem;
  font-size: 0.95rem;
  color: var(--fg-dim);
  background: transparent;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
}

.file-action:active { background: var(--bg-input); color: var(--fg); }

/* Read-only text preview: replaces the list until closed. */

.file-preview {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.file-preview[hidden] { display: none; }

.preview-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.15rem 0.25rem 0.15rem 0.75rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.preview-title {
  flex: 1;
  font-size: 0.85rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;         /* long paths: keep the filename end visible */
  text-align: left;
}

.preview-truncated {
  flex: 0 0 auto;
  margin: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  color: #ffd94a;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.preview-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Inline image preview: scrollable, image fits the width, checkerboard so
 * transparent PNGs are legible on the dark background. */
.preview-image-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.6rem;
}

.preview-image-wrap[hidden] { display: none; }

.preview-image {
  max-width: 100%;
  height: auto;
  border: 1px solid var(--border);
  background:
    repeating-conic-gradient(#2c353f 0% 25%, transparent 0% 50%) 50% / 20px 20px;
}

/* One-shot command runner pinned to the bottom (docs/06 exec frame). */

.exec-bar {
  flex: 0 0 auto;
  padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
}

.exec-row {
  display: flex;
  gap: 0.4rem;
}

.exec-row input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.exec-row input:focus { border-color: var(--accent); }

.exec-run {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 64px;
  padding: 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.exec-run:active { background: var(--accent-press); }
.exec-run:disabled { opacity: 0.5; cursor: default; }

.exec-output {
  margin: 0.4rem 0 0;
  max-height: 35vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0.6rem;
  background: #000;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

.exec-output[hidden] { display: none; }

/* ---------- timeline view (M12 semantic sessions) ---------- */

/* Message list: bubbles flow oldest-first, pinned to the bottom while the
 * user has not scrolled up; streamed items update in place. */

.tl-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.6rem 0.6rem 0.3rem;
}

.tl-bubble-row { display: flex; }
.tl-bubble-row.role-user { justify-content: flex-end; }

.tl-bubble {
  max-width: 85%;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

.role-user .tl-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.role-assistant .tl-bubble {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* System (and unknown-role) items: quiet, un-bubbled notices. */
.role-system .tl-bubble,
.role-other .tl-bubble {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--fg-dim);
  font-size: 0.85rem;
}

/* kind:"status" items: centered one-liners (turn started, adapter exited…). */
.tl-status-line {
  align-self: center;
  max-width: 92%;
  padding: 0.1rem 0.5rem;
  color: var(--fg-dim);
  font-size: 0.8rem;
  text-align: center;
  word-break: break-word;
}

/* Streaming (final=false): blinking caret at the end of the growing text. */
.tl-bubble-row.streaming .tl-bubble::after,
.tl-status-line.streaming::after,
.tl-tool.streaming .tl-tool-text::after {
  content: '\258D'; /* ▍ */
  margin-left: 1px;
  animation: tl-caret 1s steps(2, start) infinite;
}

@keyframes tl-caret {
  50% { opacity: 0; }
}

/* Collapsible tool block (kind tool-use / tool-result). */

.tl-tool {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.tl-tool summary {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.45rem 0.7rem;
  font-size: 0.85rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.tl-tool summary::before {
  content: '\1F527'; /* wrench */
  font-size: 0.8rem;
}

.tl-tool summary:active { background: var(--bg-input); }

.tl-tool .tl-tool-name {
  font-weight: 600;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tl-tool .tl-tool-kind { color: var(--fg-dim); }

.tl-tool .tl-tool-text {
  margin: 0;
  max-height: 40vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 0.7rem;
  background: #000;
  border-top: 1px solid var(--border);
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Approval cards (tl-approval): pinned between the list and the composer. */

.tl-approvals {
  flex: 0 0 auto;
  max-height: 40vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.tl-approvals:empty { display: none; }

.tl-approval-card {
  margin: 0.35rem 0.6rem;
  padding: 0.6rem 0.7rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
}

.tl-approval-text {
  font-size: 0.9rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg);
  white-space: pre-wrap;
  word-break: break-word;
}

.tl-approval-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.tl-approval-options button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.tl-approval-options button:active {
  background: var(--accent-press);
  color: #fff;
}

/* Session-scoped error line (reuses .status red) above the composer. */
.tl-status {
  flex: 0 0 auto;
  margin: 0;
  padding: 0 0.75rem;
}

.tl-status:empty { display: none; }

/* Composer: textarea grows via rows=1 + max-height, send stays aligned. */

.tl-composer {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.4rem;
  padding: 0.4rem 0.5rem calc(0.4rem + env(safe-area-inset-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
}

.tl-composer textarea {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  max-height: 7rem;
  resize: none;
  padding: 0.6rem 0.7rem;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.tl-composer textarea:focus { border-color: var(--accent); }

.tl-send {
  flex: 0 0 auto;
  min-height: 44px;
  min-width: 64px;
  padding: 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.tl-send:active { background: var(--accent-press); }

/* ---------- terminal view ---------- */

/* Observe takeover: the button highlights (yellow, like the armed Ctrl key)
 * while active; the notice warns that input is a low-fidelity screen mirror. */
#takeover-button.active { color: #ffd94a; font-weight: 700; }

.observe-notice {
  flex: 0 0 auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: #ffd94a;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid #ffd94a;
  word-break: break-word;
}

.observe-notice[hidden] { display: none; }

/* M9 approval prompt banner: sits between the top bar and the terminal.
 * Option buttons are >= 40px tall for touch targets (like the extra keys). */

.prompt-banner {
  flex: 0 0 auto;
  padding: 0.5rem 0.6rem;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}

.prompt-banner[hidden] { display: none; }

.prompt-banner-head {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.prompt-text {
  flex: 1;
  align-self: center;
  font-size: 0.9rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg);
  word-break: break-word;
}

.prompt-dismiss {
  flex: 0 0 auto;
  min-width: 40px;
  min-height: 40px;
  color: var(--fg-dim);
  background: transparent;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.prompt-dismiss:active { background: var(--bg-input); }

.prompt-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.prompt-options button {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0.4rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom on quick taps */
}

.prompt-options button:active {
  background: var(--accent-press);
  color: #fff;
}

#terminal-container {
  flex: 1;
  min-height: 0; /* let the terminal shrink when the keyboard opens */
  background: #000;
  padding: 2px;
}

#terminal-container .xterm { height: 100%; }

.extra-keys {
  flex: 0 0 auto;
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  gap: 2px;
  padding: 2px 2px calc(2px + env(safe-area-inset-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  scrollbar-width: none;
}

.extra-keys::-webkit-scrollbar { display: none; }

.extra-keys button {
  flex: 0 0 auto;
  min-width: 44px;
  min-height: 40px;
  padding: 0.4rem 0.7rem;
  font-size: 0.85rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  color: var(--fg);
  background: transparent;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  touch-action: manipulation; /* no double-tap zoom on rapid key taps */
}

.extra-keys button:active { background: var(--bg-input); }

/* One-shot modifier armed (Ctrl): highlighted like android's yellow state. */
.extra-keys button.armed { color: #ffd94a; font-weight: 700; }

/* ---------- timeline rich text (Markdown / highlight / diff) ---------- */

/* Markdown-rendered bubbles switch off pre-wrap (block elements handle their
 * own wrapping); a plain (user) bubble keeps its pre-wrap literal layout. */
.tl-bubble.md { white-space: normal; }

.tl-bubble.md > :first-child { margin-top: 0; }
.tl-bubble.md > :last-child { margin-bottom: 0; }

.tl-bubble.md .md-p { margin: 0.4rem 0; }

.tl-bubble.md .md-h {
  margin: 0.5rem 0 0.3rem;
  line-height: 1.25;
}
.tl-bubble.md h1.md-h { font-size: 1.2rem; }
.tl-bubble.md h2.md-h { font-size: 1.1rem; }
.tl-bubble.md h3.md-h,
.tl-bubble.md h4.md-h,
.tl-bubble.md h5.md-h,
.tl-bubble.md h6.md-h { font-size: 1rem; }

.tl-bubble.md .md-list { margin: 0.3rem 0; padding-left: 1.3rem; }
.tl-bubble.md .md-list li { margin: 0.15rem 0; }

.tl-bubble.md a { color: var(--accent); word-break: break-all; }

.role-user .tl-bubble.md a { color: #fff; text-decoration: underline; }

.tl-bubble.md .md-quote {
  margin: 0.4rem 0;
  padding: 0.1rem 0.7rem;
  border-left: 3px solid var(--border);
  color: var(--fg-dim);
}

.tl-bubble.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0.5rem 0;
}

/* Inline + fenced code inside a Markdown bubble. */
.md-code-inline {
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
  background: var(--code-bg);
  border: 1px solid var(--border);
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.85em;
}

.role-user .tl-bubble.md .md-code-inline {
  background: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.3);
}

.md-pre {
  margin: 0.45rem 0;
  padding: 0.5rem 0.65rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.md-pre .md-code {
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  white-space: pre;
  color: var(--fg);
}

/* Syntax-highlight token colours (shared by bubbles + code blocks). */
.md-tok-kw { color: var(--tok-kw); }
.md-tok-str { color: var(--tok-str); }
.md-tok-com { color: var(--tok-com); font-style: italic; }
.md-tok-num { color: var(--tok-num); }

/* Diff view (fenced ```diff``` blocks + diff-shaped tool results). */
.md-diff {
  margin: 0.45rem 0;
  padding: 0.4rem 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: ui-monospace, Menlo, Consolas, "Noto Sans Mono CJK SC", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre;
  color: var(--fg);
}

.md-diff-line { display: block; padding: 0 0.6rem; }
.md-diff-add { background: rgba(98, 215, 137, 0.14); color: var(--diff-add); }
.md-diff-del { background: rgba(255, 107, 107, 0.14); color: var(--diff-del); }
.md-diff-hunk { color: var(--diff-hunk); }
.md-diff-meta { color: var(--fg-dim); }

/* A tool-result rendered as a diff: drop the plain-pre padding, the diff
 * block brings its own frame. */
.tl-tool .tl-tool-text.has-diff {
  padding: 0;
  background: transparent;
  border-top: 1px solid var(--border);
}
.tl-tool .tl-tool-text.has-diff .md-diff {
  margin: 0;
  border: none;
  border-radius: 0;
}

/* ---------- session sharing (docs/23) ---------- */

/* Guest banner: 只读围观 / 可交互. Sits directly under the top bar. */
.guest-banner {
  flex: 0 0 auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  color: var(--accent);
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  text-align: center;
  word-break: break-word;
}
.guest-banner[hidden] { display: none; }
.guest-banner.ended {
  color: var(--danger);
  border-left-color: var(--danger);
}

/* Owner-only affordances are hidden while viewing as a share guest. */
body.guest #disconnect-button,
body.guest .sessions-footer { display: none; }

/* Share modal (owner side): pick perm, mint a link, manage/revoke. */
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
}
.share-modal[hidden] { display: none; }

.share-dialog {
  width: 100%;
  max-width: 420px;
  max-height: 90%;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.share-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}
.share-title { font-size: 1.05rem; font-weight: 600; }

.share-body { display: flex; flex-direction: column; }

.share-perm {
  display: flex;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.share-perm label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
}

#share-label,
#share-url {
  width: 100%;
  padding: 0.6rem;
  font-size: 0.95rem;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.share-result {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.75rem;
}
.share-result[hidden] { display: none; }
.share-result #share-url { flex: 1; min-width: 0; }

.share-manage { margin-top: 1rem; }
.share-manage-head {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--fg-dim);
  margin-bottom: 0.4rem;
}
.share-list-rows { display: flex; flex-direction: column; gap: 0.35rem; }

.share-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--bg-input);
  border-radius: 8px;
}
.share-row-info {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  word-break: break-word;
}
