:root {
  color-scheme: dark;
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-2: #19243d;
  --border: #33415f;
  --text: #f7f9ff;
  --muted: #b8c1d8;
  --accent: #8ba7ff;
  --accent-strong: #b7c6ff;
  --danger: #ff8e9b;
  --warning-bg: #3a2c0d;
  --warning-border: #e5b842;
  --focus: #ffd166;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; padding-top: 55px; background: var(--bg); color: var(--text); min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, input, select { min-height: 44px; }
button { border: 1px solid transparent; border-radius: .65rem; padding: .65rem 1rem; background: var(--accent); color: #081126; font-weight: 750; cursor: pointer; }
button:hover { background: var(--accent-strong); }
button:disabled { cursor: not-allowed; opacity: .5; }
button.secondary { background: transparent; color: var(--text); border-color: var(--border); }
button.danger { color: #27060b; background: var(--danger); }
button.danger.secondary { color: var(--danger); background: transparent; border-color: var(--danger); }
input, select, textarea { width: 100%; background: #0a1122; color: var(--text); border: 1px solid #54627e; border-radius: .55rem; padding: .7rem .8rem; }
textarea { resize: vertical; min-height: 5.5rem; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.skip-link { position: fixed; z-index: 100; top: .5rem; left: .5rem; transform: translateY(-200%); background: #fff; color: #000; padding: .75rem; }
.skip-link:focus { transform: none; }
.environment-banner { position: fixed; z-index: 20; inset: 0 0 auto; min-height: 55px; display: flex; align-items: center; justify-content: center; gap: .8rem; padding: .7rem 1rem; color: #211500; background: #ffd166; border-bottom: 3px solid #ffb703; text-align: center; }
.environment-banner strong { font-size: 1.05rem; }
.auth-shell { min-height: calc(100vh - 55px); display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(circle at 70% 10%, #223259 0, transparent 38%); }
.card { border: 1px solid var(--border); background: var(--surface); border-radius: 1rem; padding: 1.25rem; }
.auth-card { width: min(100%, 430px); display: grid; gap: .75rem; box-shadow: 0 22px 70px #0008; }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.55rem, 3vw, 2.3rem); margin-bottom: .35rem; }
h2 { font-size: 1.05rem; }
.eyebrow { color: var(--accent-strong); letter-spacing: .14em; font-size: .75rem; font-weight: 800; margin-bottom: .3rem; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: #ffb1ba; }
.app-shell { min-height: calc(100vh - 55px); grid-template-columns: 240px 1fr; }
.app-shell:not([hidden]) { display: grid; }
.sidebar { display: flex; flex-direction: column; gap: 2rem; border-right: 1px solid var(--border); background: #0d1427; padding: 1.25rem; }
.brand { display: flex; align-items: center; gap: .75rem; }
.brand > span { width: 40px; height: 40px; display: grid; place-items: center; background: var(--accent); color: #081126; border-radius: .8rem; font-weight: 900; }
nav { display: grid; gap: .5rem; }
.nav-button { text-align: left; background: transparent; color: var(--muted); }
.nav-button.active { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.sidebar-footer { margin-top: auto; display: grid; gap: 1rem; }
.status-dot::before { content: ""; display: inline-block; width: .65rem; height: .65rem; margin-right: .5rem; border-radius: 50%; background: #7f8aa2; }
.status-dot.online::before { background: #62d59b; }
.status-dot.connecting::before { background: #ffd166; }
.workspace { min-width: 0; padding: clamp(1rem, 3vw, 2.25rem); }
.panel { max-width: 1300px; margin: 0 auto; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.2rem; }
.notice { border: 1px solid var(--border); background: var(--surface-2); border-radius: .7rem; padding: .8rem 1rem; margin-bottom: 1rem; }
.notice.warning { border-color: var(--warning-border); background: var(--warning-bg); color: #ffe8a3; display: flex; flex-wrap: wrap; gap: .4rem .8rem; }
.chat-layout { display: grid; grid-template-columns: minmax(190px, 250px) minmax(0, 1fr); min-height: calc(100vh - 190px); border: 1px solid var(--border); border-radius: 1rem; overflow: hidden; background: var(--surface); }
.conversation-rail { border-right: 1px solid var(--border); padding: 1rem; background: #0f172b; }
.conversation-list { display: grid; gap: .45rem; }
.conversation-button { width: 100%; background: transparent; color: var(--text); border-color: transparent; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-button.active { background: var(--surface-2); border-color: var(--accent); }
.chat-stage { min-width: 0; display: grid; grid-template-rows: auto 1fr auto; }
.chat-toolbar { min-height: 75px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem; border-bottom: 1px solid var(--border); }
.chat-toolbar h2 { margin-bottom: .2rem; }
.messages { overflow-y: auto; max-height: calc(100vh - 390px); min-height: 260px; padding: 1rem; display: flex; flex-direction: column; gap: 1rem; }
.message { max-width: min(78%, 720px); border-radius: .85rem; padding: .8rem 1rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { align-self: flex-end; background: #31498d; }
.message.assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); }
.message.streaming::after { content: "▋"; color: var(--accent); animation: blink .8s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.composer { padding: 1rem; border-top: 1px solid var(--border); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-top: .7rem; }
.empty { color: var(--muted); padding: 1rem 0; }
.hero-empty { margin: auto; display: grid; gap: .4rem; text-align: center; }
.form-grid { display: grid; grid-template-columns: minmax(150px, .4fr) 1fr; gap: 1rem; align-items: center; max-width: 780px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }
.toggle { display: inline-flex; align-items: center; gap: .7rem; min-height: 44px; }
.toggle input { width: 24px; min-height: 24px; accent-color: var(--accent); }
.persona-card { max-width: 780px; margin-top: 1rem; display: grid; grid-template-columns: 1fr auto; gap: 1rem; align-items: end; }
.persona-card > div { grid-column: 1 / -1; }
.inline-form { display: grid; grid-template-columns: 150px 1fr; gap: .7rem 1rem; align-items: center; margin-bottom: 1rem; }
.inline-form button { grid-column: 2; justify-self: end; }
.memory-list { display: grid; gap: .75rem; }
.memory-item { display: grid; grid-template-columns: 1fr auto; gap: .7rem; align-items: start; }
.memory-item dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem .8rem; margin: 0; }
.memory-item dt { color: var(--muted); }
.memory-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.toast { position: fixed; z-index: 50; right: 1rem; bottom: 1rem; max-width: min(420px, calc(100vw - 2rem)); border: 1px solid var(--accent); background: #18264a; border-radius: .8rem; padding: 1rem; box-shadow: 0 10px 40px #0009; }
dialog { color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 1rem; width: min(440px, calc(100vw - 2rem)); }
dialog::backdrop { background: #000b; }
.dialog-body { padding: .5rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .7rem; }
.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; }
@media (max-width: 760px) {
  body { padding-top: 77px; }
  .environment-banner { min-height: 77px; flex-direction: column; gap: .15rem; font-size: .85rem; }
  .app-shell:not([hidden]) { display: block; }
  .sidebar { position: sticky; z-index: 10; top: 77px; padding: .6rem; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand strong, .sidebar-footer .status-dot { display: none; }
  .brand > span { width: 44px; height: 44px; }
  nav { display: flex; overflow-x: auto; }
  .nav-button { flex: 0 0 auto; text-align: center; padding: .6rem .8rem; }
  .sidebar-footer { margin: 0; display: block; }
  #logout-button { padding-inline: .7rem; }
  .workspace { padding: 1rem; }
  .panel-header { align-items: flex-start; }
  .chat-layout { display: block; min-height: auto; overflow: visible; }
  .conversation-rail { border-right: 0; border-bottom: 1px solid var(--border); }
  .conversation-list { display: flex; overflow-x: auto; }
  .conversation-button { width: auto; max-width: 180px; flex: 0 0 auto; }
  .messages { max-height: 48vh; }
  .message { max-width: 92%; }
  .composer-actions { align-items: flex-end; }
  .form-grid, .inline-form, .persona-card { grid-template-columns: 1fr; }
  .form-grid .full, .inline-form button, .persona-card > div { grid-column: 1; }
  .form-grid label { margin-bottom: -.65rem; }
  .inline-form label { margin-bottom: -.5rem; }
  .memory-item { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; } }
