/* Dark palette borrowed from command-and-control's console so the two feel
   like one family. Committed to dark: this is read on a phone, often at night. */
:root {
  --bg: #0c0f14; --surface: #151a22; --surface-alt: #1c232e; --border: #2a3441;
  --text: #e6edf5; --dim: #8b98a9; --faint: #5c6875;
  --accent: #4d9fff; --accent-dim: #1e3a5f;
  --red: #ff5c5c; --red-dim: #3d1a1a; --amber: #ffb340; --green: #3ddc84;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* The frame is pinned: the page itself never scrolls or rubber-bands; only the
   thread inside it does. touch-action pan-x pan-y removes pinch zoom; the JS
   in app.js swallows what Safari still lets through. */
html, body {
  margin: 0; padding: 0; height: 100%; width: 100%;
  position: fixed; inset: 0; overflow: hidden;
  background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none; touch-action: pan-x pan-y;
  -webkit-text-size-adjust: 100%; -webkit-user-select: text;
}
#app { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 12px; }
button:disabled { opacity: 0.5; cursor: default; }
a { color: var(--accent); }

/* ---- login ---- */
.login { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; padding-top: max(24px, env(safe-area-inset-top)); gap: 14px; overflow-y: auto; }
.login .logo { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 20px; margin: 4px 0 0; font-weight: 700; }
.login p { color: var(--dim); margin: 0 0 8px; text-align: center; }
.login form { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 10px; }
.login input { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 13px 14px; font-size: 16px; outline: none; }
.login input:focus { border-color: var(--accent); }
.login button.primary { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; padding: 13px; border-radius: 12px; font-size: 16px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; text-align: center; }

/* ---- chat head ---- */
.head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--border); position: relative; z-index: 10; flex-shrink: 0; }
.head .title { flex: 1; min-width: 0; }
.head .name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.head .meta { color: var(--faint); font-size: 11.5px; font-family: var(--mono); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 4px; background: var(--green); flex-shrink: 0; }
.dot.busy { background: var(--amber); animation: pulse 1s infinite alternate; }
.dot.closed { background: var(--red); }
@keyframes pulse { from { opacity: 0.4; } to { opacity: 1; } }
.menubtn { border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; background: var(--surface); color: var(--text); white-space: nowrap; }
.menubtn.small { font-size: 12px; font-family: var(--mono); color: var(--dim); padding: 4px 9px; border-radius: 7px; }
.menubtn.small b { color: var(--text); font-weight: 500; }
.tunebar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 12px; border-bottom: 1px solid var(--border); position: relative; z-index: 9; flex-shrink: 0; }
.tunebar .spacer { flex: 1; }
.note { color: var(--faint); font-size: 11.5px; flex-basis: 100%; }

/* dropdown menus */
.menu { position: absolute; top: calc(100% + 4px); right: 0; min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px 0; z-index: 30; box-shadow: 0 6px 18px rgba(0,0,0,0.45); }
.menu.left { right: auto; left: 0; }
.menu .item { padding: 9px 12px; cursor: pointer; }
.menu .item.on { background: var(--surface-alt); }
.menu .item .lbl { color: var(--dim); font-size: 14px; }
.menu .item.on .lbl { color: var(--text); }
.menu .item .hint { color: var(--faint); font-size: 11px; margin-top: 1px; }
.menu .item.danger .lbl { color: var(--red); }
.anchor { position: relative; }

/* usage strip */
.usage { padding: 6px 12px 7px; border-bottom: 1px solid var(--border); flex-shrink: 0; font-size: 11.5px; color: var(--dim); font-family: var(--mono); }
.usage .row { display: flex; justify-content: space-between; gap: 8px; }
.usage .bar { height: 4px; border-radius: 2px; background: var(--surface-alt); margin-top: 5px; overflow: hidden; }
.usage .fill { height: 100%; background: var(--green); width: 0; transition: width 0.4s; }
.usage.warn .fill { background: var(--amber); }
.usage.hot .fill { background: var(--red); }

/* thread */
.thread { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--faint); text-align: center; padding: 40px 20px; font-size: 14px; }
.wrap { display: flex; flex-direction: column; align-items: flex-start; max-width: 92%; min-width: 0; }
.wrap.mine { align-self: flex-end; align-items: flex-end; max-width: 85%; }
.bubble { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; border-top-left-radius: 4px; padding: 9px 13px; max-width: 100%; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.mine .bubble { background: var(--accent-dim); border-color: var(--accent); border-top-left-radius: 14px; border-top-right-radius: 4px; }
.bubble p { margin: 0 0 8px; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child, .bubble pre:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble pre { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px; margin: 0 0 8px; }
.bubble code { font-family: var(--mono); font-size: 13px; background: rgba(255,255,255,0.06); padding: 1px 4px; border-radius: 4px; }
.bubble pre code { background: none; padding: 0; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 15px; margin: 4px 0 6px; }
.bubble img { display: block; max-width: 240px; width: 100%; border-radius: 10px; background: var(--surface-alt); margin-bottom: 6px; }
.bubble.partial { opacity: 0.85; }
.bubble.partial::after { content: '▍'; color: var(--accent); animation: pulse 0.8s infinite alternate; }
.stamp { color: var(--faint); font-size: 10.5px; margin-top: 3px; padding: 0 4px; }
.errrow { color: var(--amber); font-size: 12.5px; padding: 6px 10px; border: 1px dashed var(--border); border-radius: 10px; align-self: center; max-width: 92%; text-align: center; }
.toolrow { padding-left: 6px; color: var(--faint); font-size: 11.5px; font-family: var(--mono); line-height: 15px; overflow-wrap: anywhere; }
.toolrow + .toolrow { margin-top: -6px; }
.detail { margin-left: 8px; padding: 4px 0 4px 10px; border-left: 2px solid var(--border); min-width: 0; max-width: 100%; }
.detail.thinking { border-left-color: var(--accent); }
.detail .lbl { color: var(--faint); font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; }
.detail pre { margin: 0; color: var(--dim); font-size: 11px; line-height: 15px; font-family: var(--mono); white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }

/* closed / read-only banner */
.banner { padding: 12px 14px; background: var(--red-dim); border-top: 1px solid var(--red); color: var(--text); font-size: 14px; flex-shrink: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.banner.soft { background: var(--surface); border-top-color: var(--border); color: var(--dim); }
.banner b { color: var(--red); }
.banner.soft b { color: var(--amber); }

/* attachments tray + composer */
.tray { display: flex; gap: 8px; padding: 8px; border-top: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.thumb { position: relative; flex-shrink: 0; }
.thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.thumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 11px; background: var(--red); color: var(--bg); border: none; padding: 0; font-weight: 800; line-height: 22px; }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; position: relative; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; padding: 0; color: var(--accent); font-size: 20px; flex-shrink: 0; }
.iconbtn.rec { border-color: var(--red); background: var(--red-dim); color: var(--red); }
.iconbtn.busy { color: var(--dim); }
.composer textarea { flex: 1; min-height: 40px; max-height: 160px; resize: none; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; font-size: 16px; line-height: 20px; outline: none; }
.composer textarea:focus { border-color: var(--accent); }
.sendbtn { background: var(--accent); color: var(--bg); border-color: var(--accent); font-weight: 700; padding: 10px 16px; border-radius: 12px; height: 40px; flex-shrink: 0; }
.sendbtn:disabled { background: var(--surface-alt); color: var(--faint); border-color: var(--border); opacity: 1; }
.micnote { position: absolute; bottom: 100%; left: 10px; margin-bottom: 6px; background: var(--surface); border: 1px solid var(--red); color: var(--red); border-radius: 6px; padding: 4px 8px; font-size: 11px; }
.toast { position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; font-size: 13px; color: var(--dim); z-index: 40; max-width: 90%; }
