[hidden] { display: none !important; }  /* the hidden attribute always wins over display rules */
:root {
  --bg: #fff; --fg: #1d1d1f; --muted: #6b7280; --border: #e3e5e8; --soft: #f3f4f6;
  --accent: #2563eb; --done: #9ca3af; --hover: #f1f2f4;
  --green: #16a34a; --amber: #d97706; --red: #dc2626; --grey: #6b7280;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, Menlo, Monaco, "DejaVu Sans Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c; --fg: #e6e6e6; --muted: #9aa0a6; --border: #2c2f35; --soft: #20232a;
    --accent: #6ea8fe; --done: #6b7280; --hover: #23262c;
    --green: #34c759; --amber: #f5a623;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 var(--font); color: var(--fg); background: var(--bg);
  display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button, .btn {
  min-height: 28px; padding: 3px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--soft); color: var(--fg); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
button:hover, .btn:hover { background: var(--hover); }
button:disabled { opacity: .5; cursor: default; }

/* header */
#header {
  flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border-bottom: 1px solid var(--border); min-height: 40px;
}
#header .title { font-weight: 600; font-size: 15px; }
#header .spacer { flex: 1; }
.pill {
  font-size: 12px; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--grey);
  white-space: nowrap;
}
.pill.running { background: var(--green); }
.pill.needs_setup { background: var(--amber); }
.pill.error { background: var(--red); }

/* layout */
#layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr; }
.pane { min-height: 0; min-width: 0; display: flex; flex-direction: column; position: relative; }
#splitter { display: none; }
@media (min-width: 768px) {
  /* terminal | divider | outline; split.js sets --split/--rest when the divider is dragged */
  #layout { grid-template-columns: minmax(0, var(--split, 1fr)) 6px minmax(0, var(--rest, 1fr)); }
  #splitter {
    display: block; cursor: col-resize; touch-action: none; position: relative;
    background: var(--border); border-left: 2px solid var(--soft); border-right: 2px solid var(--soft);
  }
  #splitter:hover, #splitter:focus-visible, body.splitting #splitter { background: var(--accent); outline: none; }
  #splitter::before { content: ""; position: absolute; inset: 0 -5px; }   /* wider grab area than it looks */
}
body.splitting, body.splitting * { cursor: col-resize !important; user-select: none !important; }
@media (max-width: 767px) {               /* phone: one pane at a time, chosen by the tab strip */
  body:not(.phone-agent) #term-pane { display: none; }
  body.phone-agent #right-pane { order: -1; }      /* keep the tab strip above the terminal so you can leave */
  body.phone-agent #tab-body { display: none; }
  body.phone-agent #layout { grid-template-rows: auto 1fr; }
}
@media (min-width: 768px) {
  body.phone-agent #right-pane { display: flex; }
  #tabs [data-tab="agent"] { display: none; }
}
#term-pane { background: #111318; }

/* terminal */
#term-host { flex: 1 1 auto; min-height: 0; position: relative; overflow: hidden; padding: 4px; }
#term { position: absolute; inset: 4px; }
#term .xterm { height: 100%; }
/* xterm's viewport always reserves a scrollbar; keep it dark so its gutter isn't a white square */
#term .xterm-viewport { scrollbar-width: thin; scrollbar-color: #3a4049 transparent; background: #000 !important; }
#term .xterm-viewport::-webkit-scrollbar { width: 8px; background: transparent; }
#term .xterm-viewport::-webkit-scrollbar-thumb { background: #3a4049; border-radius: 4px; }
#term .xterm-viewport::-webkit-scrollbar-corner { background: transparent; }
#term-overlay {
  position: absolute; inset: 0; overflow: auto; padding: 24px; background: #111318f2; color: #f4f4f4;
  z-index: 5; display: flex; align-items: flex-start; justify-content: center;
}
#term-overlay pre {
  margin: 0; max-width: 62ch; padding: 16px 18px; border: 1px solid #3a4049; border-radius: 8px;
  background: #1b1e24; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.6 var(--mono);
}
#compose-input:disabled, #compose-send:disabled { opacity: .45; cursor: not-allowed; }

#term-pane #compose { background: #1b1e24; }
#term-pane #compose-input { background: #262a31; color: #e6e6e6; border-color: #343941; }
#term-pane #compose-send { background: #2b3038; color: #e6e6e6; border-color: #3a4049; }
#compose { flex: 0 0 auto; display: flex; gap: 6px; padding: 6px; background: var(--soft); align-items: flex-end; }
#compose-input {
  flex: 1; resize: none; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); max-height: calc(1.4em * 6 + 16px); line-height: 1.4; overflow-y: auto;
}
#compose-send { min-height: 36px; }
#keybar { flex: 0 0 auto; display: flex; gap: 4px; padding: 0 6px 6px; background: var(--soft); overflow-x: auto; }
#keybar button { min-width: 40px; min-height: 36px; flex: 0 0 auto; }

/* right pane */
#tabs {
  flex: 0 0 auto; display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--border);
  padding: 0 6px; background: var(--soft);
}
#tabs button {
  border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  min-height: 38px; padding: 6px 10px; color: var(--muted); white-space: nowrap;
}
#tabs button.active { color: var(--fg); border-bottom-color: var(--accent); font-weight: 600; }
#tab-body { flex: 1; min-height: 0; position: relative; }
.tab-panel { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }

/* doc tab */
#doc-bar { flex: 0 0 auto; display: flex; gap: 10px; align-items: center; padding: 4px 12px; font-size: 12px; color: var(--muted); min-height: 28px; }
#doc-save-status.error { color: var(--red); }
#doc-reload { border: none; background: none; color: var(--accent); padding: 0; min-height: 0; font-size: 12px; text-decoration: underline; }
#doc-editor {
  flex: 1; min-height: 0; width: 100%; border: none; outline: none; resize: none; padding: 6px 12px 40vh;
  font: 13px/1.5 var(--mono); background: var(--bg); color: var(--fg); tab-size: 2;
}

/* fatal */
#fatal { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; gap: 12px; align-items: center; justify-content: center; padding: 24px; text-align: center; }
#fatal p { max-width: 480px; font-size: 16px; }

/* encrypted-mode sign-in (built by e2e.js): a non-modal dialog covering the page, below #fatal and
   below password-manager menus (see e2e.js for why it isn't modal) */
.e2e-login[open] { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; width: auto; height: auto; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: var(--bg); }
.e2e-login form { display: flex; flex-direction: column; gap: 10px; box-sizing: border-box; border: 1px solid var(--border); border-radius: 8px; padding: 20px; width: min(320px, 90vw); background: var(--bg); color: var(--fg); }
.e2e-login h2 { margin: 0; font-size: 16px; }
.e2e-login label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; color: var(--muted); }
.e2e-login input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); font-size: 16px; }  /* 16px: no iOS zoom */
.e2e-login-note { margin: 0; min-height: 1.4em; color: var(--red); font-size: 13px; }

#header button, #header .btn { white-space: nowrap; }

/* narrow phones: keep the header on one line */
@media (max-width: 480px) {
  #header .wide { display: none; }          /* "Restart agent" -> "Restart", "New conversation" -> "New" */
  #header { gap: 5px; padding: 4px 6px; }
  #header button, #header .btn { padding: 3px 6px; font-size: 12px; }
  #header .title { font-size: 14px; }
  .pill { font-size: 11px; padding: 1px 6px; }
}

/* touch: bigger targets for shell controls (outline rows: see outline.css) */
@media (pointer: coarse) {
  button, .btn { min-height: 36px; padding: 4px 12px; }
}
