:root { --bg: #17171a; --bg2: #1f1f23; --bg3: #2a2a30; --line: #34343b; --text: #e6e6ea; --dim: #a3a3ad; --accent: #d97757; --ok: #7bc991; --warn: #edc478; }
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { height: 100dvh; display: flex; flex-direction: column; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; min-width: 0; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:focus-visible, summary:focus-visible, #conversation:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); flex: none; }
.topbar strong { font-size: 17px; }
.subtitle { margin-left: 10px; color: var(--dim); }
.read-only { color: var(--dim); font-size: 12px; text-align: right; }
.connection { min-height: 37px; padding: 8px 20px; background: var(--bg2); color: var(--dim); font-size: 12px; display: flex; gap: 16px; justify-content: space-between; flex: none; border-bottom: 1px solid var(--line); }
.connection.stale { background: #382d1d; color: var(--warn); }
.connection.expired { background: #3d2525; color: #ffb2a8; }
#last-checked { flex: none; }
main { display: grid; grid-template-columns: 300px minmax(0, 1fr); flex: 1; min-height: 0; }
#session-pane { overflow-y: auto; padding: 20px 12px; border-right: 1px solid var(--line); min-width: 0; }
.section-heading { display: flex; justify-content: space-between; align-items: baseline; padding: 0 8px; }
h1, h2, p { margin: 0; }
h1 { font-size: 19px; line-height: 1.3; }
h2 { font-size: 14px; }
#session-count, .muted { color: var(--dim); }
.pane-note { padding: 8px 8px 16px; font-size: 12px; }
.empty { color: var(--dim); padding: 28px 16px; text-align: center; }
#sessions { display: flex; flex-direction: column; gap: 6px; }
.session { width: 100%; text-align: left; padding: 12px; border: 1px solid transparent; border-radius: 8px; background: transparent; min-width: 0; }
.session:hover { background: var(--bg2); }
.session[aria-current="true"] { background: var(--bg3); border-color: var(--accent); }
.session-name { display: block; font-weight: 600; overflow-wrap: anywhere; }
.session-meta { display: block; color: var(--dim); font-size: 12px; margin: 4px 0 7px; overflow-wrap: anywhere; }
.status { font-size: 11px; color: var(--dim); border: 1px solid var(--line); padding: 3px 7px; border-radius: 20px; display: inline-block; white-space: nowrap; }
.status-working, .status-compacting { color: var(--ok); border-color: #3a5543; }
.status-waiting { color: var(--warn); border-color: #6b5532; }
#detail-pane { min-width: 0; min-height: 0; padding: 24px; display: flex; flex-direction: column; }
#choose-session { margin: auto; }
#session-detail { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.chat-heading { display: flex; align-items: flex-start; gap: 12px; flex: none; }
.chat-heading-text { min-width: 0; flex: 1; }
#chat-title { overflow-wrap: anywhere; }
#chat-meta { font-size: 12px; margin-top: 6px; overflow-wrap: anywhere; }
#back { display: none; border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); padding: 8px 10px; }
#panels { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; max-height: 30%; overflow-y: auto; flex: 0 1 auto; min-height: 0; }
#session-details { display: none; }
#session-details > summary { display: none; }
.panel { background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; min-width: 0; max-width: 100%; flex: 1 1 220px; }
.panel summary { cursor: pointer; font-size: 12px; font-weight: 600; }
.panel ul, .panel ol { margin: 10px 0 0; padding-inline-start: 20px; }
.panel li { font-size: 12px; padding: 3px 0; overflow-wrap: anywhere; }
.panel .completed { color: var(--dim); text-decoration: line-through; }
.panel .in_progress { color: var(--accent); }
.context { color: var(--dim); font-size: 12px; flex: 0 1 auto; }
.conversation-heading { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; padding-top: 24px; flex: none; }
.conversation-heading .muted { font-size: 11px; }
.history-note { margin: 5px 0 12px; font-size: 11px; flex: none; }
#conversation-state { padding: 14px 8px; flex: none; }
#conversation-state:empty { display: none; }
#conversation { min-height: min(250px, 30vh); overflow-y: auto; overflow-x: hidden; flex: 1; padding: 2px 5px 16px; scrollbar-gutter: stable; }
.message { border: 0; border-radius: 14px; background: transparent; margin: 0 auto 24px; padding: 8px 4px; max-width: 820px; overflow-wrap: anywhere; font-size: 15px; line-height: 1.65; }
.message-user { background: var(--bg3); padding: 12px 16px; max-width: min(85%, 720px); margin-inline-end: max(0px, calc((100% - 820px) / 2)); }
.message-label { color: var(--dim); font-size: 11px; margin-bottom: 7px; display: flex; justify-content: space-between; gap: 12px; }
.message-text, .message-code, .message-output { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; margin: 0; font: inherit; }
.message-code, .message-output { font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; margin-top: 8px; color: var(--dim); }
.message-title { font-weight: 600; }
.shortened { margin-top: 8px; color: var(--dim); font-size: 11px; }
#remote-access { background: var(--bg2); border-bottom: 1px solid var(--line); padding: 12px 20px; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; flex: none; }
#remote-access p { font-size: 12px; }
#device-fingerprint { margin-top: 6px; font: 11px/1.5 ui-monospace, monospace; overflow-wrap: anywhere; max-width: 100%; user-select: text; }
#remote-access button, #remote-control button, #remote-panels button { padding: 8px 12px; border: 1px solid var(--line); background: var(--bg3); border-radius: 6px; min-height: 38px; }
#pair-form { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; width: 100%; }
#pair-form label { font-size: 12px; }
#device-name { flex: 1; min-width: 100px; max-width: 300px; }
#remote-panels { display: flex; gap: 8px; overflow-y: auto; max-height: 25%; flex: none; margin-top: 8px; flex-wrap: wrap; }
#remote-panels details { background: var(--bg2); border: 1px solid var(--line); padding: 8px 10px; border-radius: 6px; flex: 1 1 180px; min-width: 0; font-size: 12px; }
#remote-panels summary { cursor: pointer; }
.inspection-content { margin-top: 8px; overflow-wrap: anywhere; }
.inspection-content:empty { display: none; }
.inspection-content p { margin-bottom: 6px; }
.inspection-content a { color: var(--accent); overflow-wrap: anywhere; }
#remote-panels button { font-size: 11px; padding: 5px 8px; margin-top: 6px; min-height: 30px; }
#remote-control { flex: none; border-top: 1px solid var(--line); padding: 10px 3px 12px; font-size: 12px; }
#remote-control.can-write #control-message { display: none; }
#message-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; padding: 8px; border: 1px solid var(--line); border-radius: 18px; background: var(--bg2); }
#message-form label { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
#message { grid-area: 1 / 1; min-height: 44px; max-height: 112px; resize: none; background: transparent; border: 0; border-radius: 10px; padding: 10px 8px; font-size: 16px; line-height: 24px; }
.command-buttons { display: contents; }
#send-message { grid-area: 1 / 2; align-self: end; border-radius: 14px !important; min-width: 52px; min-height: 44px !important; }
#queue-message { grid-area: 2 / 1; justify-self: start; }
#stop-session { grid-area: 2 / 2; justify-self: end; }
#queue-message, #stop-session { border: 0 !important; background: transparent !important; padding: 4px 8px !important; min-height: 30px !important; font-size: 11px; color: var(--dim); }
#send-message { background: var(--accent) !important; border-color: var(--accent) !important; color: #fff; }
#stop-session { margin-left: auto; }
#control-message { margin-bottom: 6px; }
#receipt { margin-top: 6px; color: var(--warn); overflow-wrap: anywhere; font-size: 11px; line-height: 1.4; max-height: 65px; overflow-y: auto; }
#receipt:empty { display: none; }
#recover-message, #check-receipt { font-size: 11px; padding: 4px 8px !important; min-height: 28px !important; }
#check-receipt { margin-top: 6px; }
@media (max-width: 700px) {
  #conversation { min-height: 0; }
  body.view-chat .topbar { display: none; }
  .topbar { padding: 12px 16px; }
  .topbar strong { font-size: 15px; }
  .subtitle { display: block; margin-left: 0; font-size: 12px; }
  .read-only { max-width: 130px; font-size: 11px; }
  .connection { padding: 5px 16px; gap: 8px; min-height: 27px; font-size: 11px; }
  #last-checked { display: none; }
  main { display: flex; }
  #session-pane { flex: 1; border: 0; padding: 20px 12px; }
  #detail-pane { display: none; flex: 1; padding: 0 12px; }
  body.view-chat #session-pane { display: none; }
  body.view-chat #detail-pane { display: flex; }
  .chat-heading { align-items: center; gap: 8px; min-height: 64px; }
  #back { display: block; flex: 0 0 36px; min-height: 44px; border: 0; padding: 0; background: transparent; font-size: 32px; }
  #back span { display: none; }
  .chat-heading-text { flex: 1; }
  #chat-title { font-size: 16px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #chat-meta { font-size: 11px; margin-top: 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
  #chat-status { margin-left: auto; font-size: 10px; border: 0; padding: 3px; }
  #panels { margin-top: 12px; max-height: 27%; }
  #session-details { display: block; flex: none; max-height: 30%; overflow-y: auto; margin-top: 0; margin-bottom: 8px; }
  #session-details > summary { display: block; position: sticky; top: 0; z-index: 1; cursor: pointer; padding: 5px 8px; background: var(--bg); border: 0; border-radius: 6px; font-size: 11px; font-weight: 500; color: var(--dim); }
  #session-details > summary::before { content: '▸ '; }
  #session-details[open] > summary::before { content: '▾ '; }
  #session-details #panels, #session-details #remote-panels { max-height: none; overflow: visible; }
  .panel { padding: 8px 10px; }
  .conversation-heading, .history-note { display: none; }
  #session-details .history-note { display: block; margin: 6px 8px; font-size: 11px; }
  #conversation { padding: 8px 4px 12px; scrollbar-gutter: auto; }
  .message { padding: 6px 2px; font-size: 16px; margin-bottom: 24px; }
  .message-user { padding: 10px 14px; max-width: 90%; margin-inline-end: 0; }
  #remote-control { border: 0; padding: 6px 0 8px; }
}
#view-switch { display: flex; gap: 4px; flex: none; margin: 4px 0; }
#view-switch button { border: 0; border-radius: 6px; background: transparent; color: var(--dim); padding: 4px 9px; font-size: 11px; }
#view-switch button[aria-pressed="true"] { color: var(--text); background: var(--bg3); }
#terminal-pane { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#terminal-status { font-size: 11px; padding: 4px 0; flex: none; }
#terminal-screen { min-height: 0; flex: 1; overflow: auto; background: var(--bg); }
#terminal-screen .xterm { padding: 4px; }
#terminal-keys { display: flex; gap: 4px; overflow-x: auto; flex: none; padding: 6px 0; }
#terminal-keys button { border: 1px solid var(--line); border-radius: 6px; background: var(--bg2); font-size: 11px; min-width: 36px; padding: 7px; flex: none; }
body.terminal-view #conversation, body.terminal-view .conversation-heading, body.terminal-view #conversation-state, body.terminal-view #session-details, body.terminal-view #panels, body.terminal-view #remote-panels, body.terminal-view .history-note { display: none !important; }
#attachments { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px; }
.attachment { border-radius: 8px; background: var(--bg3); max-width: 100%; padding: 3px 7px; display: inline-flex; align-items: center; gap: 5px; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#remote-control .attachment button { border: 0; padding: 0 3px; min-height: 24px; }
#attach-files { grid-area: 2 / 1; justify-self: start; min-width: 32px; min-height: 30px !important; padding: 0 6px !important; border: 0 !important; background: transparent !important; font-size: 20px; }
#queue-message { margin-left: 32px; }
#attachments:not([hidden]) ~ #message { grid-row: 2; }
#attachments:not([hidden]) ~ .command-buttons #send-message { grid-row: 2; }
#attachments:not([hidden]) ~ #attach-files, #attachments:not([hidden]) ~ .command-buttons #queue-message, #attachments:not([hidden]) ~ .command-buttons #stop-session { grid-row: 3; }

/* Polish pass: pills, dots, 44px targets and softer surfaces. Appended last so it wins over the base rules above; no markup, IDs or behavior changed. */
:root { --pill: 999px; }
button { -webkit-tap-highlight-color: transparent; transition: background-color .15s, border-color .15s, transform .1s; }
button:not(:disabled):active { transform: scale(.97); }
input, textarea, select { border-radius: 10px; }
.topbar { background: var(--bg2); }
.topbar strong { letter-spacing: .01em; }
.subtitle { background: var(--bg3); border-radius: var(--pill); padding: 2px 9px; font-size: 11px; }
/* Connection strip: a status dot in front of the message instead of bare text. */
.connection { align-items: center; }
#connection-message::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-inline-end: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px rgb(123 201 145 / .18); vertical-align: 0; }
.connection.stale #connection-message::before { background: var(--warn); box-shadow: 0 0 0 3px rgb(237 196 120 / .18); }
.connection.expired #connection-message::before { background: #ff8a7a; box-shadow: 0 0 0 3px rgb(255 138 122 / .18); }
/* Status pills get the same dot. */
.status { display: inline-flex; align-items: center; gap: 6px; background: var(--bg2); }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.session { background: var(--bg2); border-color: var(--line); }
.session:hover { background: var(--bg3); }
.message-user { border-radius: 18px 18px 4px 18px; }
#message-form { border-radius: 22px; box-shadow: 0 2px 12px rgb(0 0 0 / .25); }
#message-form:focus-within { border-color: var(--accent); }
#message:focus-visible { outline: 0; }
#send-message { border-radius: 18px !important; min-width: 64px; font-weight: 600; }
/* Composer action row: real tap targets (44px) with a subtle chip look. */
#queue-message, #stop-session { min-height: 36px !important; padding: 0 14px !important; font-size: 13px; border-radius: var(--pill) !important; background: var(--bg3) !important; color: var(--text); }
#stop-session { color: #ff8a7a; }
#attach-files { min-width: 36px; min-height: 36px !important; font-size: 24px; line-height: 1; border-radius: 50% !important; background: var(--bg3) !important; color: var(--text); padding: 0 !important; }
#queue-message { margin-left: 44px; }
#receipt { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }
#receipt:empty { padding: 0; border: 0; }
#recover-message, #check-receipt { min-height: 36px !important; padding: 0 14px !important; border-radius: var(--pill) !important; }
/* Chat/Terminal switch: a segmented control. */
#view-switch { display: inline-flex; align-self: flex-start; gap: 2px; padding: 3px; margin: 6px 0 8px; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--pill); }
#view-switch button { min-height: 30px; min-width: 88px; padding: 0 16px; border-radius: var(--pill); font-size: 13px; font-weight: 500; }
#view-switch button[aria-pressed="true"] { background: var(--accent); color: #fff; }
#terminal-keys { gap: 6px; padding: 8px 0; }
#terminal-keys button { min-height: 36px; min-width: 44px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
#remote-access { padding: 16px 20px; gap: 12px; }
#remote-access button, #remote-control button, #remote-panels button { border-radius: 10px; }
#remote-access button[type="submit"], #remote-login { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.panel, #remote-panels details { border-radius: 12px; }
@media (max-width: 700px) {
  #remote-access button, #remote-panels button, #remote-control button, #view-switch button, #terminal-keys button { min-height: 44px; }
  #view-switch button { min-height: 38px; }
  .topbar { padding: 12px 16px; }
  /* "Details" toggle: a tappable chip instead of tiny dim text. */
  #queue-message, #stop-session, #recover-message, #check-receipt { min-height: 44px !important; }
  #attach-files { min-width: 44px; min-height: 44px !important; }
  #queue-message { margin-left: 52px; }
  #session-details > summary { display: flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; }
  #session-details[open] > summary { margin-bottom: 8px; }
  #back { flex-basis: 44px; border-radius: 50%; color: var(--accent); }
  #chat-status { border: 1px solid var(--line); padding: 3px 9px; font-size: 11px; }
  .connection { padding: 6px 16px; }
  .message-user { max-width: 88%; }
  .message { margin-bottom: 18px; }
  #remote-control { padding: 6px 0 10px; }
  .session { min-height: 64px; }
}
@media (prefers-reduced-motion: reduce) { button { transition: none; } button:not(:disabled):active { transform: none; } }
/* Keyboard open: the 44px targets would eat the chat, so tighten the chrome around them instead. */
.keyboard-open .chat-heading { min-height: 48px; }
.keyboard-open #view-switch { margin: 2px 0 4px; }
.keyboard-open #view-switch button { min-height: 32px; }
.keyboard-open #session-details > summary { min-height: 36px; }
.keyboard-open #message-form { padding: 4px 8px; gap: 0 8px; }
.keyboard-open #message { min-height: 40px; }
.keyboard-open #remote-control { padding: 4px 0 6px; }
/* Follow-up polish. Status dots: Ready is healthy (green), busy states amber, stopped/unknown grey, expired red. */
.status-idle { color: var(--text); }
.status-idle::before { background: var(--ok); opacity: 1; }
.status-working::before, .status-compacting::before, .status-waiting::before { background: var(--warn); opacity: 1; }
.status-working, .status-compacting { color: var(--text); border-color: var(--line); }
.status-waiting { color: var(--warn); }
/* Key row: side inset and scroll-padding so the first key (and the one scrolled into view) never touches the edge. */
#terminal-keys { padding-inline: 12px; scroll-padding-inline: 12px; margin-inline: -12px; }
@media (max-width: 700px) {
  .subtitle { display: inline-block; margin-top: 2px; }
  #terminal-keys { gap: 4px; }
  #terminal-keys button { min-width: 40px; padding: 0 7px; font-size: 12px; }
  /* Sign-in and pairing: a card with a stacked form and full-width 48px buttons. */
  #remote-access { margin: 12px; border: 1px solid var(--line); border-radius: 16px; padding: 18px; flex-direction: column; align-items: stretch; gap: 14px; }
  #remote-access h2 { font-size: 17px; margin-bottom: 4px; }
  #remote-access p { font-size: 13px; line-height: 1.45; }
  #remote-access button { min-height: 48px; width: 100%; font-size: 15px; border-radius: 12px; }
  #pair-form { flex-direction: column; align-items: stretch; gap: 10px; }
  #pair-form label { font-size: 13px; color: var(--dim); }
  #device-name { max-width: none; min-height: 48px; font-size: 16px; padding: 0 14px; border-radius: 12px; }
  #computer-label select { width: 100%; min-height: 48px; margin-top: 6px; }
}
