:root {
  color-scheme: dark;
  font-family: system-ui, sans-serif;
  color: #f7f5ef;
  background: #141419;
  --line: #37363e;
  --muted: #c3c1ca;
  --accent: #f1e4bd;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 300px; }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; }
button, input, textarea { border-radius: .65rem; }
input, textarea {
  min-width: 0; padding: .7rem .85rem; outline-offset: 2px;
  border: 1px solid var(--line); color: inherit; background: #1d1d24;
}
button {
  min-height: 44px; padding: .55rem .85rem; cursor: pointer;
  border: 1px solid transparent; color: inherit; background: transparent;
  touch-action: manipulation;
}
button:disabled { cursor: default; opacity: .56; }
button:hover:not(:disabled) { filter: brightness(1.15); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.primary { color: #151419; background: var(--accent); font-weight: 650; }
.secondary { border-color: var(--line); background: #25252d; }
.quiet { color: var(--muted); text-align: left; }
.brand { color: var(--accent); font-size: .875rem; font-weight: 700; letter-spacing: .17em; }
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 26rem); padding: 2rem; border: 1px solid var(--line); border-radius: 1.25rem; background: #1b1b22; }
.login-card img { margin-bottom: 1rem; border-radius: .9rem; }
.login-card h1 { font-size: 2.4rem; margin: .3rem 0; }
.login-card p { color: var(--muted); }
.login-card form { display: grid; gap: .7rem; margin-top: 1.6rem; }
.workspace { width: 100%; height: 100dvh; display: grid; grid-template-columns: 18rem minmax(0, 1fr); }
#sidebar { display: flex; flex-direction: column; min-height: 0; gap: .65rem; padding: 1rem; border-right: 1px solid var(--line); background: #18181f; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; gap: .45rem; }
.sidebar-head strong { font-size: 1.3rem; }
#sidebar input { width: 100%; }
#threads { min-height: 0; overflow-y: auto; flex: 1; }
.thread { display: block; text-align: left; width: 100%; margin-block: .15rem; color: #eeedf1; }
.thread.selected { background: #2f2e37; border-color: #5c5967; }
.thread span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread small { color: var(--muted); margin-top: .25rem; display: block; }
#chat { min-width: 0; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.chat-head { display: flex; align-items: center; gap: .6rem; min-height: 4.65rem; padding: .75rem max(1rem, env(safe-area-inset-right)) .7rem max(1rem, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); }
.thread-heading { flex: 1; min-width: 0; }
.thread-heading h1 { font-size: 1.02rem; line-height: 1.35; margin: 0; overflow-wrap: anywhere; }
.thread-heading p { color: var(--muted); margin: .15rem 0 0; font-size: .875rem; }
.mobile-toggle { display: none; }
#scroll-region { overflow: auto; overscroll-behavior: contain; }
#content, #composer { width: min(100%, 53rem); margin-inline: auto; padding: 1rem; }
#empty { color: var(--muted); }
#messages { display: flex; flex-direction: column; gap: 1.2rem; }
.bubble { max-width: 100%; line-height: 1.64; overflow-wrap: anywhere; }
.bubble header { margin-bottom: .25rem; font-weight: 650; color: var(--accent); font-size: .875rem; }
.bubble p { margin: 0; white-space: pre-wrap; }
.bubble.user { margin-left: auto; width: fit-content; max-width: 93%; padding: .7rem .9rem; background: #292730; border-radius: .8rem .8rem .2rem .8rem; }
.bubble.agent { padding: .2rem 0 .35rem; }
.approval { margin-top: 1rem; padding: .9rem; border: 1px solid #786c4a; border-radius: .75rem; background: #252219; }
.approval h2 { font-size: 1rem; margin: 0 0 .55rem; }
.approval p { overflow-wrap: anywhere; }
.approval pre { font: .87rem/1.55 ui-monospace, monospace; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 16rem; overflow: auto; }
.approval .actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.approval label { display: grid; gap: .4rem; margin: .7rem 0; }
#composer { padding: .65rem 1rem max(.8rem, env(safe-area-inset-bottom)); }
#send-form { display: flex; align-items: end; gap: .55rem; }
#message { flex: 1; width: 100%; resize: vertical; min-height: 44px; max-height: 10rem; border-radius: .8rem; }
#login-error, #chat-error { color: #ffb5a8; margin: .55rem 0; white-space: pre-line; overflow-wrap: anywhere; }
@media (max-width: 680px) {
  .workspace { display: block; }
  #sidebar, #chat { height: 100%; }
  #sidebar { border: none; }
  .workspace:not(.chat-open) #chat, .workspace.chat-open #sidebar { display: none; }
  .mobile-toggle { display: block; border-color: var(--line); }
  #content, #composer { padding-inline: .8rem; }
}

.login-card details { margin-top: 1rem; }
#pair-code strong { display: block; color: white; font-size: 1.7rem; letter-spacing: .12em; margin: .4rem 0; }
#install { margin-top: 1rem; }
