/* Praxis — the QQ signature chassis (Doctrine interface grammar, re-plugged for Praxis).
   Source of truth: the QQ Gold Standard design system.
   Same chassis at every size: topbar + views + bottom tab nav. No sidebars, no SaaS chrome.
   Provider-neutral: no provider/model names anywhere user-facing.
   Documented deviations from Doctrine: --text-3 lightened #6B7280 -> #7D8694 (WCAG AA 4.5:1
   for sub-16px mono labels); Deep depth state uses green (the reference badge-slot accent),
   keeping gold scarce next to SEND. */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; }

:root {
  --bg: #0A0A0A;
  --bg-card: #111318;
  --bg-surface: #151922;
  --bg-hover: #1E2438;
  --gold: #C9A227;
  --gold-light: #E5C158;
  --gold-dim: rgba(201, 162, 39, .10);
  --gold-glow: rgba(201, 162, 39, .18);
  --cyan: #00D9FF;
  --text: #FFFFFF;
  --text-2: #B0B0B0;
  --text-3: #7D8694; /* AA-adjusted from Doctrine #6B7280 — see header note */
  --border: #1F2937;
  --border-2: rgba(255, 255, 255, .06);
  --red: #E74C3C;
  --green: #27AE60;
  --amber: #F39C12;
  --mono: 'IBM Plex Mono', 'Courier New', monospace;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --body: 'Source Serif 4', Georgia, serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --col: 720px; /* content column on wide screens; chassis itself is full-bleed */
}

html { overscroll-behavior: none; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none;
}
body.app-mode { overflow: hidden; }

/* Grain overlay — all pages */
body::after {
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 9999; opacity: .025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-repeat: repeat; background-size: 256px 256px;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold-light); }
:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }
::selection { background: var(--gold-dim); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 1000;
  background: var(--bg-card); border: 1px solid var(--gold); color: var(--gold);
  font-family: var(--mono); font-size: .65rem; letter-spacing: .1em; text-transform: uppercase; padding: 12px 16px;
}
.skip-link:focus { left: 16px; top: calc(8px + var(--safe-top)); }

/* ================= GATE (landing / auth / onboarding — the Doctrine auth-gate grammar) ================= */
.gate { position: fixed; inset: 0; z-index: 500; display: flex; align-items: flex-start; justify-content: center; background: var(--bg); padding: 24px; padding-top: calc(24px + var(--safe-top)); overflow-y: auto; }
.gate::before { content: ''; position: fixed; top: 40%; left: 50%; transform: translate(-50%, -50%); width: 400px; height: 400px; background: radial-gradient(circle, rgba(201,162,39,.08) 0%, transparent 70%); pointer-events: none; }
.gate-box { width: 100%; max-width: 320px; text-align: center; position: relative; z-index: 2; margin: auto; }
.gate-logo { font-family: var(--serif); font-size: 42px; font-weight: 300; color: var(--gold); letter-spacing: .02em; margin-bottom: 2px; }
.gate-sub { font-size: .6rem; color: var(--text-3); letter-spacing: .25em; text-transform: uppercase; margin-bottom: 10px; }
#gate-auth .gate-sub, #gate-onboarding .gate-sub { margin-bottom: 32px; }
.gate-lede { font-family: var(--body); font-weight: 300; font-size: 15px; line-height: 1.65; color: var(--text-2); margin: 14px 0 30px; }
.gate-stack { display: flex; flex-direction: column; gap: 10px; }
.gate-links { margin-top: 34px; font-size: .58rem; letter-spacing: .18em; text-transform: uppercase; color: var(--text-3); }
.gate-links a, .gate-note a { color: var(--text-3); display: inline-block; padding: 14px 8px; margin: -14px -2px; }
.gate-links a:hover, .gate-note a:hover { color: var(--gold); }
.gate-err { color: var(--red); font-size: 11px; margin-top: 10px; min-height: 16px; }
.gate-note { font-size: .58rem; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); margin-top: 16px; }
.gate-back { background: none; border: none; color: var(--text-3); font-family: var(--mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; cursor: pointer; margin-top: 14px; padding: 14px 12px; }
.gate-back:hover { color: var(--gold); }

/* fields (exact auth-field grammar) */
.field-row { text-align: left; margin-bottom: 12px; }
.field-label { display: block; font-size: .6rem; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 4px; }
.afield {
  width: 100%; background: transparent; border: 1px solid var(--border); padding: 14px 16px;
  color: var(--text); font-size: 14px; font-family: var(--mono); outline: none;
  transition: border-color .3s; border-radius: 0; -webkit-appearance: none; min-height: 48px;
}
.afield:focus { border-color: var(--gold); }
.afield::placeholder { color: #8A93A1; }
.afield[aria-invalid="true"] { border-color: var(--red); }
.checkrow { display: flex; align-items: flex-start; gap: 10px; text-align: left; margin: 4px 0 16px; }
.checkrow input {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px;
  border: 1px solid var(--border); background: transparent; border-radius: 0;
  flex: none; margin-top: 2px; cursor: pointer; display: grid; place-content: center;
}
.checkrow input:checked { border-color: var(--gold); }
.checkrow input:checked::before { content: ''; width: 10px; height: 10px; background: var(--gold); }
.checkrow input:focus-visible { outline: 1px solid var(--gold); outline-offset: 2px; }
.checkrow label { font-family: var(--body); font-weight: 300; font-size: 13px; line-height: 1.5; color: var(--text-2); }

/* buttons (exact d-submit / sheet-btn grammar) */
.gbtn {
  width: 100%; background: linear-gradient(135deg, var(--gold), var(--gold-light)); border: none;
  padding: 16px; color: #0A0A0A; font-size: .7rem; font-weight: 600; cursor: pointer;
  letter-spacing: .15em; text-transform: uppercase; font-family: var(--mono);
  min-height: 48px; border-radius: 0; -webkit-appearance: none;
}
.gbtn:disabled { opacity: .4; pointer-events: none; }
.gbtn-ghost { background: none; border: 1px solid var(--border); color: var(--text-2); }
.gbtn-ghost:hover, .gbtn-ghost:active { border-color: var(--gold); color: var(--gold); }
.gbtn-danger { background: none; border: 1px solid rgba(231,76,60,.5); color: var(--red); }
.gbtn-danger:hover, .gbtn-danger:active { border-color: var(--red); background: rgba(231,76,60,.08); }

/* onboarding rows */
.ob-list { text-align: left; margin: 6px 0 26px; }
.ob-item { padding: 13px 0; border-bottom: 1px solid var(--border-2); }
.ob-item:last-child { border-bottom: none; }
.ob-k { font-size: .58rem; color: var(--gold); letter-spacing: .14em; text-transform: uppercase; margin-bottom: 3px; }
.ob-v { font-family: var(--body); font-weight: 300; font-size: 14px; color: var(--text-2); line-height: 1.55; }

/* ================= APP SHELL ================= */
#app { display: none; height: 100%; flex-direction: column; }
#app.on { display: flex; }

/* Topbar (exact) */
.topbar {
  padding: 8px 16px; padding-top: calc(8px + var(--safe-top));
  background: var(--bg); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex-shrink: 0;
  min-height: calc(48px + var(--safe-top));
}
.topbar-inner { display: flex; align-items: center; gap: 10px; width: 100%; max-width: var(--col); margin: 0 auto; }
.topbar-brand { font-family: var(--serif); font-size: 22px; font-weight: 300; color: var(--gold); letter-spacing: .02em; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--green); box-shadow: 0 0 6px rgba(39,174,96,.5); }
.live-dot.err { background: transparent; border: 2px solid var(--red); box-shadow: 0 0 6px rgba(231,76,60,.4); }
.topbar-time { font-size: .6rem; color: var(--text-3); }

/* Content + views (exact) */
.content { flex: 1; overflow: hidden; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; display: none; padding: 16px; padding-bottom: calc(16px + 56px + var(--safe-bottom)); }
.view.active { display: block; }
.view-inner { max-width: var(--col); margin: 0 auto; }
.view::-webkit-scrollbar { width: 2px; }
.view::-webkit-scrollbar-thumb { background: var(--border); }
.view { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* Bottom nav (exact) */
.bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; background: var(--bg-card); border-top: 1px solid var(--border); display: flex; padding-bottom: var(--safe-bottom); z-index: 100; }
.bottom-nav-inner { display: flex; width: 100%; max-width: var(--col); margin: 0 auto; }
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px 8px; background: none; border: none; color: var(--text-3);
  font-family: var(--mono); font-size: .55rem; letter-spacing: .06em; text-transform: uppercase;
  cursor: pointer; transition: color .2s; min-height: 48px;
}
.nav-btn.active { color: var(--gold); }
.nav-btn:hover { color: var(--text-2); }
.nav-btn.active:hover { color: var(--gold); }
.nav-icon { font-size: 18px; line-height: 1; }
#nav-new .nav-icon { font-weight: 600; font-size: 20px; }

/* Section heads (exact) */
.section-head { font-size: .65rem; color: var(--gold); letter-spacing: .12em; text-transform: uppercase; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.section-count { color: var(--text-3); font-weight: 400; }

/* ================= THREADS (board grammar) ================= */
.ptr-indicator { text-align: center; padding: 8px; font-size: .6rem; color: var(--text-3); display: none; }
.board-group { margin-bottom: 20px; }
.board-group-label { font-size: .6rem; color: var(--text-3); letter-spacing: .08em; text-transform: uppercase; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.group-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.dot-today { background: var(--gold); box-shadow: 0 0 6px rgba(201,162,39,.5); }
.dot-week { background: var(--cyan); box-shadow: 0 0 6px rgba(0,217,255,.35); }
.dot-old { background: #6B7280; }

.thread-card {
  display: block; width: 100%; text-align: left; font: inherit; color: inherit;
  background: var(--bg-surface); border: 1px solid var(--border-2);
  padding: 12px 14px; margin-bottom: 8px; min-height: 48px; cursor: pointer;
  transition: border-color .15s; border-radius: 0; -webkit-appearance: none;
}
.thread-card:hover { border-color: var(--border); background: var(--bg-hover); }
.thread-card:active { border-color: var(--gold); background: var(--bg-hover); }
.thread-card.current { border-color: rgba(201,162,39,.35); }
.th-time { font-size: .6rem; color: var(--text-3); letter-spacing: .04em; display: block; }
.th-title { font-family: var(--body); font-weight: 300; font-size: 14px; color: var(--text); margin-top: 3px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ================= CHAT (exact grammar; bars full-bleed, content column-constrained) ================= */
#view-chat { display: none; padding: 0; flex-direction: column; }
#view-chat.active { display: flex; }

.chat-bar { padding: 10px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-bar-inner { display: flex; align-items: center; gap: 8px; width: 100%; max-width: var(--col); margin: 0 auto; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chat-bar-inner::-webkit-scrollbar { display: none; }
.c-new, .c-depth, .c-research { position: relative; }
.c-new::after, .c-depth::after, .c-research::after { content: ''; position: absolute; inset: -7px 0; }
.c-new { background: none; border: 1px solid var(--border); color: var(--text-2); padding: 6px 12px; font-family: var(--mono); font-size: .6rem; cursor: pointer; white-space: nowrap; min-height: 32px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; }
.c-new:hover, .c-new:active { border-color: var(--gold); color: var(--gold); }
.c-title { flex: 1; min-width: 60px; background: var(--bg-surface); border: 1px solid var(--border); padding: 6px 10px; min-height: 32px; display: flex; align-items: center; justify-content: center; font-size: .6rem; color: var(--text-2); letter-spacing: .04em; text-transform: uppercase; overflow: hidden; }
.c-title span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-depth { background: none; border: 1px solid var(--border); color: var(--text-3); padding: 6px 10px; font-family: var(--mono); font-size: .55rem; cursor: pointer; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; min-height: 32px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; }
.c-depth.deep { border-color: var(--green); color: var(--green); }
.c-research { background: none; border: 1px solid var(--border); color: var(--text-3); padding: 6px 10px; font-family: var(--mono); font-size: .55rem; cursor: pointer; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; min-height: 32px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; }
.c-research.on { border-color: var(--cyan); color: var(--cyan); }

/* Research Mode — searched badge + sources rendered after an assistant bubble */
.msg-research { align-self: flex-start; max-width: 88%; margin: -4px 0 2px; }
.searched-badge { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: .55rem; letter-spacing: .1em; text-transform: uppercase; color: var(--cyan); }
.searched-badge.none { color: var(--text-3); }
.searched-badge .sb-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 6px rgba(0,217,255,.4); flex: none; }
.searched-badge .sb-fresh { color: var(--text-3); letter-spacing: .04em; }
.sources { margin-top: 6px; border-left: 1px solid var(--border); padding-left: 10px; display: flex; flex-direction: column; gap: 5px; }
.source-item { display: flex; gap: 7px; align-items: baseline; font-size: 12px; line-height: 1.4; }
.source-item .si-num { font-family: var(--mono); font-size: .55rem; color: var(--text-3); flex: none; min-width: 16px; }
.source-item a { font-family: var(--body); font-weight: 300; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.source-item a:hover { color: var(--cyan); }

/* Access intake — request form fields (select + textarea) + paused/invite-disabled message */
select.afield { cursor: pointer; -webkit-appearance: none; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237D8694' fill='none'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; padding-right: 36px; }
select.afield option { background: var(--bg-card); color: var(--text); }
textarea.afield { min-height: 84px; resize: vertical; line-height: 1.5; font-family: var(--body); font-weight: 300; font-size: 14px; }
.access-msg { font-family: var(--body); font-weight: 300; font-size: 15px; line-height: 1.65; color: var(--text-2); margin: 14px 0 26px; }
.gate-ok { font-family: var(--body); font-weight: 300; font-size: 15px; line-height: 1.65; color: var(--text-2); margin: 14px 0 26px; }
.gate-ok .ok-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 7px rgba(39,174,96,.5); margin-right: 8px; }

.chat-msgs { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 16px; }
.chat-msgs-inner { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: var(--col); margin: 0 auto; }
.chat-msgs::-webkit-scrollbar { width: 2px; }
.chat-msgs::-webkit-scrollbar-thumb { background: var(--border); }
.chat-msgs { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

.chat-bubble { max-width: 88%; padding: 10px 14px; font-size: 13px; line-height: 1.6; word-break: break-word; -webkit-touch-callout: default; }
.chat-bubble.user { align-self: flex-end; background: var(--gold-dim); border: 1px solid rgba(201,162,39,.2); color: var(--text); white-space: pre-wrap; }
.chat-bubble.assistant { align-self: flex-start; background: var(--bg-surface); border: 1px solid var(--border-2); color: var(--text-2); font-family: var(--body); font-weight: 300; font-size: 14px; }
.chat-bubble.assistant p { margin: 0 0 .7em; } .chat-bubble.assistant p:last-child { margin-bottom: 0; }
.chat-bubble.assistant pre { background: var(--bg); border: 1px solid var(--border); padding: 10px; overflow-x: auto; margin: .5em 0; font-family: var(--mono); font-size: 12px; }
.chat-bubble.assistant code { font-family: var(--mono); font-size: .9em; background: var(--bg); padding: 1px 5px; }
.chat-bubble.assistant pre code { background: none; padding: 0; }
.chat-bubble.error { align-self: center; background: rgba(231,76,60,.1); border: 1px solid rgba(231,76,60,.3); color: var(--red); font-size: 12px; white-space: pre-wrap; }
.streaming-cursor::after { content: '|'; animation: blink .8s infinite; color: var(--gold); }
@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: 0; } }

.chat-empty { margin-top: 60px; text-align: center; color: var(--text-3); font-size: 12px; line-height: 1.8; }
.chat-empty .ce-serif { font-family: var(--serif); font-size: 26px; font-weight: 300; color: var(--text-2); display: block; margin-bottom: 4px; }

.chat-compose { padding: 10px 16px; padding-bottom: calc(10px + 56px + var(--safe-bottom)); border-top: 1px solid var(--border); flex-shrink: 0; }
.chat-compose-inner { display: flex; gap: 8px; align-items: flex-end; width: 100%; max-width: var(--col); margin: 0 auto; }
.chat-input { flex: 1; background: var(--bg-surface); border: 1px solid var(--border); padding: 12px 14px; color: var(--text); font-size: 14px; font-family: var(--mono); outline: none; resize: none; min-height: 48px; max-height: 120px; line-height: 1.5; border-radius: 0; -webkit-appearance: none; }
.chat-input:focus { border-color: var(--gold); }
.chat-input::placeholder { color: #8A93A1; }
.chat-send { background: linear-gradient(135deg, var(--gold), var(--gold-light)); border: none; padding: 12px 18px; color: #0A0A0A; font-size: .7rem; font-weight: 600; cursor: pointer; letter-spacing: .08em; text-transform: uppercase; font-family: var(--mono); min-height: 48px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; }
.chat-send:disabled { opacity: .4; pointer-events: none; }
.chat-stop { background: var(--red); border: none; padding: 12px 18px; color: #fff; font-size: .7rem; font-weight: 600; cursor: pointer; letter-spacing: .08em; text-transform: uppercase; font-family: var(--mono); min-height: 48px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; }

/* ================= ACCOUNT (status grammar) ================= */
.status-section { margin-bottom: 22px; }
.metric-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border-2); }
.metric-row:last-child { border-bottom: none; }
.metric-label { color: var(--text-3); font-size: .65rem; }
.metric-val { color: var(--text); font-weight: 600; font-size: .65rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 60%; }
.acct-actions { display: flex; flex-direction: column; gap: 8px; }
.acct-actions .gbtn-ghost, .acct-actions .gbtn-danger { width: 100%; padding: 14px 16px; font-size: .65rem; letter-spacing: .08em; min-height: 48px; font-family: var(--mono); text-transform: uppercase; cursor: pointer; border-radius: 0; -webkit-appearance: none; }
.legal-links { display: flex; gap: 10px; padding-top: 4px; }
.legal-links a { font-size: .6rem; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); display: inline-block; padding: 14px 8px; margin: -10px -2px; }
.legal-links a:hover { color: var(--gold); }

/* ================= BOTTOM SHEET (exact) ================= */
.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.sheet-overlay.on { display: flex; }
.sheet { background: var(--bg-card); border-top: 2px solid var(--gold-dim); width: 100%; max-width: var(--col); max-height: 85vh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 20px 16px; padding-bottom: calc(20px + var(--safe-bottom)); }
.sheet::-webkit-scrollbar { width: 2px; }
.sheet::-webkit-scrollbar-thumb { background: var(--border); }
.sheet { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.sheet-handle { width: 36px; height: 4px; background: var(--border); margin: 0 auto 16px; border-radius: 2px; }
.sheet-title { font-family: var(--serif); font-size: 20px; font-weight: 400; color: var(--text); margin-bottom: 2px; }
.sheet-id { font-size: .6rem; color: var(--text-3); margin-bottom: 14px; letter-spacing: .04em; }
.sheet-section { margin-bottom: 12px; }
.sheet-label { font-size: .55rem; color: var(--gold); letter-spacing: .1em; text-transform: uppercase; margin-bottom: 3px; }
.sheet-body { color: var(--text-2); line-height: 1.5; white-space: pre-wrap; font-family: var(--body); font-weight: 300; font-size: 13px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.sheet-btn { flex: 1; min-width: 100px; background: none; border: 1px solid var(--border); color: var(--text-2); padding: 12px 16px; font-family: var(--mono); font-size: .65rem; cursor: pointer; letter-spacing: .06em; text-transform: uppercase; min-height: 48px; border-radius: 0; -webkit-appearance: none; }
.sheet-btn:hover, .sheet-btn:active { border-color: var(--gold); color: var(--gold); }
.sheet-btn.primary { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: #0A0A0A; border: none; font-weight: 600; }
.sheet-btn.danger { border-color: rgba(231,76,60,.5); color: var(--red); }
.sheet-btn.danger:hover, .sheet-btn.danger:active { border-color: var(--red); color: var(--red); background: rgba(231,76,60,.08); }

/* Empty + spinner (exact) */
.empty { text-align: center; padding: 40px 20px; color: var(--text-3); font-size: 12px; }
.spinner { width: 24px; height: 24px; border: 2px solid var(--border); border-top-color: var(--gold); border-radius: 50%; animation: spin .7s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast (chassis-toned; stays in a11y tree — visibility, not [hidden]) */
.toast { position: fixed; bottom: calc(64px + var(--safe-bottom)); left: 50%; transform: translateX(-50%); background: var(--bg-card); border: 1px solid var(--gold-dim); color: var(--text); padding: 12px 18px; z-index: 300; font-family: var(--mono); font-size: .68rem; letter-spacing: .04em; visibility: hidden; opacity: 0; transition: opacity .15s; }
.toast.show { visibility: visible; opacity: 1; }

/* ================= LEGAL PAGES (document mode — same tokens) ================= */
.doc-topbar { padding: 10px 16px; padding-top: calc(10px + var(--safe-top)); background: var(--bg); border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.doc-topbar-inner { display: flex; align-items: center; justify-content: space-between; width: 100%; max-width: 760px; margin: 0 auto; }
.doc-topbar .topbar-brand { font-size: 20px; }
.doc-links a { font-size: .6rem; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3); margin-left: 10px; display: inline-block; padding: 14px 8px; }
.doc-links a:hover { color: var(--gold); }
.legal { max-width: 760px; margin: 0 auto; padding: 48px 20px 80px; font-family: var(--body); font-weight: 300; font-size: 16px; line-height: 1.65; -webkit-touch-callout: default; }
.legal h1 { font-family: var(--serif); font-weight: 300; font-size: 2.6rem; line-height: 1.15; margin-bottom: 8px; }
.legal .kicker { font-family: var(--mono); font-size: .65rem; font-weight: 500; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); display: block; margin-bottom: 14px; }
.legal h2 { font-family: var(--mono); font-size: .75rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); margin-top: 2.6em; margin-bottom: .9em; }
.legal p, .legal li { color: var(--text-2); margin-bottom: 1em; }
.legal strong { color: var(--text); font-weight: 600; }
.legal ul { padding-left: 1.2em; margin-bottom: 1em; }
.legal li { margin-bottom: .4em; }
.legal .status-line { font-family: var(--mono); font-size: .68rem; letter-spacing: .04em; color: var(--text-3); border-left: 2px solid var(--gold); padding-left: 14px; margin-bottom: 8px; }
.legal .pending { font-family: var(--mono); font-size: .72rem; color: var(--amber); border: 1px solid rgba(243,156,18,.4); padding: 1px 8px; letter-spacing: .06em; text-transform: uppercase; }
.legal .draft-banner { background: var(--bg-card); border: 1px solid var(--border); border-left: 2px solid var(--amber); padding: 16px 18px; color: var(--text-2); font-size: .94rem; margin: 24px 0 8px; }
.doc-footer { border-top: 1px solid var(--border); padding: 26px 20px calc(26px + var(--safe-bottom)); }
.doc-footer-inner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; max-width: 760px; margin: 0 auto; font-family: var(--mono); font-size: .6rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); }
.doc-footer a { color: var(--text-3); margin-left: 8px; display: inline-block; padding: 14px 8px; }
.doc-footer a:hover { color: var(--gold); }

@media (max-width: 360px) {
  .legal h1 { font-size: 2rem; }
}

/* ===== User MCP connector management (additive; reuses :root tokens; radius 0; no new palette) ===== */
.conn-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.back-link { background: none; border: none; color: var(--text-3); font-family: var(--mono); font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; cursor: pointer; padding: 8px 0; min-height: 32px; -webkit-appearance: none; }
.back-link:hover, .back-link:active { color: var(--gold); }
.conn-sub { font-family: var(--body); font-weight: 300; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.acct-sub { font-family: var(--body); font-weight: 300; font-size: 13px; color: var(--text-2); margin: -4px 0 10px; }
.safety-note { border-left: 2px solid var(--gold); background: var(--gold-dim); padding: 10px 12px; font-family: var(--body); font-weight: 300; font-size: 12.5px; color: var(--text-2); margin-bottom: 22px; }
.fl-hint { color: var(--text-3); text-transform: none; letter-spacing: 0; font-weight: 400; }
.adv { margin-bottom: 14px; }
.adv summary { font-family: var(--mono); font-size: .55rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.adv summary:hover { color: var(--gold); }
.adv-note { color: var(--text-3); font-family: var(--body); font-weight: 300; font-size: 12.5px; margin-top: 8px; }
.conn-status { font-family: var(--mono); font-size: .55rem; letter-spacing: .08em; text-transform: uppercase; display: inline-flex; align-items: center; gap: 5px; }
.conn-status .cs-dot { width: 6px; height: 6px; border-radius: 50%; flex: none; }
.conn-status.active { color: var(--green); } .conn-status.active .cs-dot { background: var(--green); }
.conn-status.revoked { color: var(--text-3); } .conn-status.revoked .cs-dot { background: var(--text-3); }
.cc-sub { display: block; font-family: var(--mono); font-size: .58rem; color: var(--text-3); margin-top: 4px; letter-spacing: .02em; word-break: break-all; }
.tool-row { border-bottom: 1px solid var(--border-2); padding: 12px 0; }
.tool-row:last-child { border-bottom: none; }
.tool-name { font-family: var(--mono); font-size: .72rem; color: var(--text); letter-spacing: .02em; word-break: break-word; }
.tool-desc { font-family: var(--body); font-weight: 300; font-size: 12.5px; color: var(--text-2); margin: 4px 0 8px; white-space: pre-wrap; word-break: break-word; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.seg-opt { position: relative; background: none; border: 1px solid var(--border); color: var(--text-3); padding: 6px 10px; font-family: var(--mono); font-size: .55rem; letter-spacing: .04em; text-transform: uppercase; cursor: pointer; min-height: 32px; border-radius: 0; -webkit-appearance: none; white-space: nowrap; }
.seg-opt::after { content: ''; position: absolute; inset: -7px 0; }
.seg-opt:hover { color: var(--gold); border-color: var(--gold); }
.seg-opt[aria-pressed="true"] { color: var(--gold); border-color: var(--gold); }
.seg-opt.allow[aria-pressed="true"] { color: var(--green); border-color: var(--green); }
.seg-opt.deny[aria-pressed="true"] { color: var(--text-2); border-color: var(--text-2); }
.tool-ctl { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 8px; }
.tool-ctl .afield { min-height: 36px; padding: 6px 28px 6px 10px; font-size: .6rem; width: auto; background-position: right 8px center; }
.tool-run { background: none; border: 1px solid var(--border); color: var(--text-2); padding: 6px 12px; font-family: var(--mono); font-size: .55rem; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; min-height: 32px; border-radius: 0; -webkit-appearance: none; }
.tool-run:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.tool-run:disabled { opacity: .35; pointer-events: none; }
.untrusted { background: var(--bg-surface); border: 1px solid var(--border); padding: 10px 12px; margin-top: 8px; font-family: var(--mono); font-size: .62rem; color: var(--text-2); white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
.untrusted-label { display: block; font-family: var(--mono); font-size: .5rem; letter-spacing: .12em; text-transform: uppercase; color: var(--text-3); margin-bottom: 6px; }
.audit-row { display: flex; flex-wrap: wrap; gap: 6px 12px; padding: 8px 0; border-bottom: 1px solid var(--border-2); font-family: var(--mono); font-size: .6rem; color: var(--text-2); }
.audit-row:last-child { border-bottom: none; }
.audit-row .ar-time { color: var(--text-3); }
.audit-row .ar-state.ok { color: var(--green); }
.audit-row .ar-state.err { color: var(--red); }
.audit-row .ar-model { color: var(--text-3); }

/* ===== built-in first-party QualeQuest connector (owner-only; reuses tokens; radius 0) ===== */
.builtin-card { border: 1px solid var(--gold-dim); background: var(--bg-card); padding: 14px 14px 16px; }
.bi-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.bi-name { font-family: var(--serif); font-size: 20px; font-weight: 400; color: var(--gold); letter-spacing: .01em; }
.bi-desc { font-family: var(--body); font-weight: 300; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.bi-scopes { margin: 10px 0 4px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bi-scopes .field-label { width: 100%; margin-bottom: 2px; }
.scope-chip { font-family: var(--mono); font-size: .55rem; letter-spacing: .06em; text-transform: uppercase; color: var(--text-2); border: 1px solid var(--border); padding: 4px 8px; }
.bi-actions { margin-top: 12px; }

/* ---- chat tool execution ---- */
.chat-tools{appearance:none;background:transparent;border:1px solid var(--border);color:var(--gold);font-family:var(--mono);font-size:11px;letter-spacing:.08em;text-transform:uppercase;padding:0 12px;min-height:48px;display:inline-flex;align-items:center;cursor:pointer}
.chat-tools:hover{border-color:var(--gold)}
.chat-toolchip{display:flex;align-items:center;gap:8px;margin:0 0 8px;font-family:var(--mono);font-size:11px;color:var(--text-2)}
.chat-toolchip .tc-label{color:var(--gold);letter-spacing:.1em;text-transform:uppercase}
.chat-toolchip .tc-name{color:var(--text)}
.chat-toolchip .tc-src{color:var(--text-3)}
.chat-toolchip .tc-x{margin-left:auto;background:none;border:none;color:var(--text-2);font-size:16px;cursor:pointer;line-height:1;min-height:44px;min-width:44px}
.picker-tool{display:block;width:100%;text-align:left;background:var(--bg-surface);border:1px solid var(--border);color:var(--text);padding:12px 14px;margin:0 0 8px;cursor:pointer;font-family:inherit}
.picker-tool:hover{border-color:var(--gold)}
.picker-tool .pt-name{display:block;font-weight:500}
.picker-tool .pt-src{display:block;font-family:var(--mono);font-size:11px;color:var(--gold);margin-top:2px}
.picker-tool .pt-desc{display:block;font-size:13px;color:var(--text-2);margin-top:4px}
.gov-verdict{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:6px 0 2px;padding:8px 12px;border:1px solid var(--border);font-family:var(--mono);font-size:11px}
.gov-verdict .gv-badge{letter-spacing:.08em;text-transform:uppercase}
.gov-verdict.pass{border-color:var(--green)}.gov-verdict.pass .gv-badge{color:var(--green)}
.gov-verdict.proposal{border-color:var(--gold)}.gov-verdict.proposal .gv-badge{color:var(--gold)}
.gov-verdict.recorded .gv-badge{color:var(--text-2)}
.gov-verdict.reject{border-color:var(--red);background:rgba(231,76,60,.12)}.gov-verdict.reject .gv-badge{color:var(--red)}
.gov-verdict .gv-viol{flex-basis:100%;color:var(--text-2)}
.cap-chip{display:inline-flex;align-items:center;gap:8px;margin:6px 0 2px;font-family:var(--mono);font-size:11px;color:var(--text-2)}
.cap-chip .cc-dot{width:6px;height:6px;background:var(--gold);border-radius:50%}
.cap-chip.failed .cc-dot{background:var(--red)}
.cap-chip .cc-src{color:var(--text-3)}
.chat-audit{margin:2px 0 8px}
.chat-audit .ar-ev,.chat-audit .ar-user{font-family:var(--mono);font-size:10px;color:var(--text-3)}

.picker-search{width:100%;margin:0 0 10px;background:var(--bg-surface);border:1px solid var(--border);color:var(--text);font-family:inherit;font-size:14px;padding:10px 12px}
.picker-search:focus{outline:none;border-color:var(--gold)}
.picker-list{max-height:52vh;overflow-y:auto;-webkit-overflow-scrolling:touch}

/* Mobile compose: full-width message input so Tools/Send don't squeeze it (additive; phones <=560px; desktop unchanged) */
@media (max-width: 560px) {
  .chat-compose-inner { flex-wrap: wrap; justify-content: flex-end; }
  .chat-input { flex: 1 1 100%; }
  .chat-tools, .chat-send, .chat-stop { flex: 0 0 auto; }
}

/* TASK-34-MARKER: write-confirm card (propose->confirm) — chassis tokens, sharp corners */
.write-confirm{background:var(--bg-card,#151922);border:1px solid var(--border,#1F2937);border-left:3px solid var(--gold,#C9A227);padding:14px 16px;margin:10px 0;max-width:86%;border-radius:0}
.wc-label{font-family:'IBM Plex Mono',monospace;font-size:.68rem;font-weight:600;letter-spacing:.18em;text-transform:uppercase;color:var(--gold,#C9A227);margin-bottom:8px}
.wc-endpoint{font-family:'IBM Plex Mono',monospace;font-size:.72rem;color:var(--text-2,#B0B0B0);margin-bottom:8px;word-break:break-all}
.wc-payload{font-family:'IBM Plex Mono',monospace;font-size:.7rem;color:var(--text-2,#B0B0B0);background:var(--bg-input,#0D1117);border:1px solid var(--border,#1F2937);padding:10px;margin:0 0 12px;white-space:pre-wrap;word-break:break-all;max-height:180px;overflow:auto;border-radius:0}
.wc-actions{display:flex;gap:10px}
.wc-btn{font-family:'IBM Plex Mono',monospace;font-size:.7rem;font-weight:600;letter-spacing:.12em;text-transform:uppercase;padding:10px 16px;cursor:pointer;border-radius:0}
.wc-confirm{background:linear-gradient(135deg,var(--gold,#C9A227),var(--gold-light,#E5C158));color:#0A0A0A;border:none}
.wc-cancel{background:transparent;border:1px solid var(--border,#1F2937);color:var(--text-2,#B0B0B0)}
.wc-cancel:hover{border-color:var(--gold,#C9A227);color:var(--gold,#C9A227)}
.wc-status{font-family:'IBM Plex Mono',monospace;font-size:.7rem;margin-top:10px;color:var(--text-2,#B0B0B0)}
.wc-done .wc-actions .wc-btn{opacity:.35;pointer-events:none}

/* TASK-37-MARKER: session chip + Session-sheet toggle rows (chat-bar decongestion) */
.c-session { background: none; border: 1px solid var(--border); color: var(--text-3); padding: 6px 10px; font-family: var(--mono); font-size: .55rem; cursor: pointer; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; min-height: 32px; flex-shrink: 0; border-radius: 0; -webkit-appearance: none; position: relative; }
.c-session::after { content: ''; position: absolute; inset: -7px 0; }
.c-session.live { border-color: var(--gold); color: var(--gold); }
.session-toggle { flex: none; width: 100%; text-align: left; margin-bottom: 6px; }
.session-toggle.deep { border-color: var(--green); color: var(--green); }
.session-toggle.on { border-color: var(--cyan); color: var(--cyan); }
.session-desc { font-family: var(--body); font-weight: 300; font-size: 12px; color: var(--text-3); line-height: 1.45; margin: 0 0 14px; }
