#console-page, .thread-dropdown {
  --paper: #fcfbfa;
  --rail: #f2efed;
  --surface: #fff;
  --text: #24212c;
  --quiet: #625d6b;
  --line: #e5e0e5;
  --tint: #eee8f8;
  --accent: #68449a;
  --accent-hover: #573680;
  --positive: #247253;
  --negative: #a54e2e;
  --danger: #bb304a;
  --focus: #8961c2;
  --shadow: 0 8px 28px rgb(57 36 72 / 7%);
  color: var(--text);
}
:root:not([data-console="admin"]) {
  color-scheme: light;
  background: #fcfbfa;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-console="admin"]) {
    color-scheme: dark;
    background: #191720;
  }
  #console-page, .thread-dropdown {
    --paper: #191720;
    --rail: #201d28;
    --surface: #24212c;
    --text: #f0ecf5;
    --quiet: #b2aabb;
    --line: #3d3647;
    --tint: #352846;
    --accent: #ba9ee8;
    --accent-hover: #ccaef8;
    --positive: #83c9a4;
    --negative: #e3a58d;
    --danger: #ff8e9b;
    --focus: #bb9ee8;
    --shadow: 0 8px 28px rgb(0 0 0 / 13%);
  }
}
#console-page :focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
#console-page input:not([type="checkbox"]),
#console-page select,
#console-page textarea {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
#console-page .muted { color: var(--quiet); }
#console-page .primary {
  background: var(--accent);
  color: var(--surface);
}
#console-page .primary:hover { background: var(--accent-hover); filter: none; }
#console-page .secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}
#console-page button:disabled { cursor: default; opacity: .5; }
#entry {
  width: min(100%, 416px);
  margin: clamp(24px, 8vh, 80px) auto 40px;
}
#entry > .brand { justify-content: center; gap: 8px; margin: 0 0 24px; }
#entry > .brand img { width: 40px; height: 40px; }
#entry > .brand .brand-name { font-size: 20px; }
#entry > .brand #subtitle { border-left: 1px solid var(--line); padding-left: 12px; margin-left: 4px; }
.entry-card {
  padding: clamp(22px, 5vw, 36px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.entry-card h1 { margin: 0 0 22px; font-size: 26px; }
#login-methods {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 4px;
  border-radius: 10px;
  background: var(--rail);
  margin-bottom: 20px;
}
#login-methods button {
  min-height: 38px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--quiet);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
#login-methods button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / 12%);
  font-weight: 650;
}
#notice, #scan-message, #message {
  margin: 9px 0 0;
  color: var(--quiet);
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}
#notice { margin-bottom: 20px; }
.remember-login:not([hidden]) {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-height: 32px;
  margin: .75rem 0;
  cursor: pointer;
}
.remember-login input {
  flex: none;
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}
#scan-start { display: block; margin: 12px auto; }
#scan-image {
  display: block;
  width: 216px;
  height: auto;
  max-width: 100%;
  margin: 14px auto 0;
  border-radius: 8px;
}
#scan-message { text-align: center; }
#message:empty, #scan-message:empty, #node-message:empty, #resource-message:empty { display: none; }
#submit, #registration .button { width: 100%; }
#setup-toggle { margin-top: 10px; }
#login-form input, #registration input { margin-bottom: 16px; min-height: 44px; }
#login-form input:last-child { margin-bottom: 0; }
#remember-control { font-weight: 400; color: var(--quiet); }
.auth-switch {
  text-align: center;
  padding-top: 18px;
  margin: 22px 0 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
  color: var(--quiet);
}
.auth-switch button {
  font: inherit;
  font-weight: 600;
  padding: 5px 2px;
  color: var(--accent);
  background: transparent;
  border: 0;
  cursor: pointer;
}
#signup-message { color: var(--quiet); font-size: 14px; overflow-wrap: anywhere; }
#signup-message:empty { display: none; }
#signup-verify { margin-top: 18px; }
.entry-links { display: flex; flex-wrap: wrap; justify-content: center; align-items: baseline; gap: 20px; margin-top: 18px; font-size: 13px; }
.entry-links a, #device-options summary { color: var(--quiet); font-size: inherit; }
.entry-links a { text-decoration: none; }
.entry-links a:hover, .auth-switch button:hover { text-decoration: underline; }
#device-options { position: relative; margin: 0; }
#device-options button {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: 8px;
  white-space: nowrap;
}
#scan-approval a { margin-top: 8px; }

:root[data-console="admin"] #console-page {
  --surface: #101828;
  --text: #f2f5ff;
  --quiet: #a0aec5;
  --line: #394760;
  --accent: #aca5ff;
  --accent-hover: #c6bfff;
  --focus: #c6c0ff;
}
:root[data-console="admin"] #entry {
  max-width: 1020px;
  width: 100%;
  margin-top: 0;
}
:root[data-console="admin"] .entry-card { max-width: 510px; }
:root[data-console="admin"] .entry-links { justify-content: flex-start; }
:root[data-console="admin"] #entry > .brand { justify-content: flex-start; }
#admin-nodes { display: grid; gap: 12px; margin-top: 20px; }
#admin-nodes .node {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow-wrap: anywhere;
}
#admin-nodes .node p { margin: 6px 0; }

#console-page.workbench-open { width: 100%; margin: 0; }
#workspace {
  display: grid;
  grid-template-columns: 242px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  background: var(--paper);
  overflow: hidden;
}
#workbench-sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  gap: 26px;
  padding: 22px 14px 14px;
  border-right: 1px solid var(--line);
  background: var(--rail);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}
.sidebar-brand img { object-fit: contain; }
.sidebar-brand strong, .sidebar-brand span { display: block; }
.sidebar-brand strong { font-size: 16px; font-weight: 650; }
.sidebar-brand span { margin-top: 3px; font-size: 12px; color: var(--quiet); }
.agent-nav, .sidebar-footer { display: grid; gap: 5px; }
.sidebar-footer { margin-top: auto; }
.nav-item, .quiet-button, .model-button {
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.nav-item {
  position: relative;
  min-height: 43px;
  padding: 9px 12px;
  border-radius: 9px;
  text-align: left;
  font-size: 14px;
}
.nav-item:hover, .quiet-button:hover, .model-button:hover { background: var(--tint); }
.nav-item.current {
  background: var(--tint);
  color: var(--accent);
  font-weight: 650;
}
.nav-item.current::before {
  content: "";
  position: absolute;
  inset: 10px auto 10px 0;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}
.node-link span { display: block; }
.node-caption, .account-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--quiet);
}
.node-caption { margin-top: 4px; }
.account-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 8px 2px 0 12px;
}
.quiet-button {
  min-height: 40px;
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 13px;
  white-space: nowrap;
}
.mobile-only { display: none; }
#agent-view {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}
.agent-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: max(9px, env(safe-area-inset-top)) clamp(14px, 3vw, 32px) 9px;
  min-height: 60px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.agent-header h1 {
  margin: 0 auto 0 0;
  font-size: 17px;
  font-weight: 650;
  white-space: nowrap;
}
.model-button {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  min-height: 36px;
  max-width: min(56vw, 330px);
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  color: var(--quiet);
}
.model-button span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.model-button::before {
  content: "";
  flex: 0 0 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.model-button[data-route="local"] { color: var(--positive); }
.model-button[data-route="unavailable"] { color: var(--negative); }

.assistant {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
}
.conversation-scroll {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scrollbar-gutter: stable;
}
.assistant-empty {
  display: grid;
  place-content: center;
  justify-items: center;
  align-content: center;
  min-height: 100%;
  padding: 18px;
  text-align: center;
}
.assistant-empty img { object-fit: contain; }
.assistant-empty h2 {
  margin: 12px 0 6px;
  font-size: clamp(23px, 3vw, 33px);
  font-weight: 650;
  line-height: 1.3;
}
.assistant-empty p { max-width: 26em; margin: 0; color: var(--quiet); font-size: 14px; }
.assistant-log {
  display: grid;
  align-content: start;
  gap: 24px;
  width: min(780px, calc(100% - 38px));
  margin: 0 auto;
  padding: 30px 0;
}
.assistant-log:empty { display: none; }
.chat-turn { min-width: 0; overflow-wrap: anywhere; }
.chat-turn p { margin: 0; font-size: 15px; line-height: 1.75; white-space: pre-wrap; }
.chat-turn .user-text {
  width: fit-content;
  max-width: min(88%, 630px);
  margin-left: auto;
  padding: 10px 15px;
  border-radius: 15px 15px 4px 15px;
  background: var(--tint);
}
.agent-response { margin-top: 18px; }
.agent-response strong { font-size: 13px; color: var(--quiet); }
.agent-response p { margin-top: 5px; }
.chat-status { display: block; margin-top: 8px; font-size: 12px; color: var(--quiet); }
.resource-turn {
  width: fit-content;
  max-width: 100%;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
}
.resource-turn strong { font-size: 14px; font-weight: 600; }
.compose-area {
  width: min(780px, calc(100% - 38px));
  margin: 0 auto;
  padding: 8px 0 max(10px, env(safe-area-inset-bottom));
}
.composer {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 8px 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
#console-page .composer textarea {
  min-height: 48px;
  max-height: min(24dvh, 160px);
  padding: 8px 6px;
  border: 0;
  background: transparent;
  field-sizing: content;
  resize: none;
  overflow-y: auto;
}
#console-page .composer textarea:focus-visible { outline: none; }
.composer:focus-within { border-color: var(--focus); }
.composer textarea::placeholder { color: var(--quiet); opacity: 1; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.composer .chat-send {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: var(--surface);
  cursor: pointer;
}
.composer .chat-send:hover:not(:disabled) { background: var(--accent-hover); }
.composer .chat-send svg { transform: rotate(-90deg); }
.attach-button { color: var(--quiet); }
.attach-button span { font-size: 16px; }
#assistant-message {
  min-height: 18px;
  margin: 4px 0 0;
  color: var(--quiet);
  font-size: 12px;
  line-height: 1.5;
}

.agent-panel {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(100%, 440px);
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.agent-panel::backdrop, #drawer-backdrop { background: rgb(22 14 28 / 38%); }
.agent-panel > header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.agent-panel h2 { font-size: 17px; margin: 0; }
.panel-close { font-size: 23px; min-width: 40px; }
.panel-content { margin: 0; padding: 18px 20px max(20px, env(safe-area-inset-bottom)); }
.panel-content input, .panel-content textarea { margin-bottom: 16px; }
.panel-content textarea { resize: vertical; }
.panel-content p { font-size: 14px; }
#nodes { margin: 16px 0; display: grid; }
.node-line { padding: 11px 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.node-line strong, .node-line span { display: block; }
.node-line strong { font-size: 14px; }
.node-line span { color: var(--quiet); font-size: 13px; margin-top: 4px; }
.node-line details { margin-top: 4px; }
.node-line summary { font-size: 12px; color: var(--quiet); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (min-width: 741px) and (min-height: 560px) {
  .assistant:has(.assistant-empty:not([hidden])) {
    grid-template-rows: auto auto;
    align-content: center;
  }
  .assistant-empty { padding-bottom: 22px; }
}
@media (max-width: 740px) {
  #workspace { grid-template-columns: minmax(0, 1fr); }
  .mobile-only { display: inline-block; min-width: 40px; font-size: 20px; }
  #workbench-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 2;
    width: min(80vw, 286px);
    visibility: hidden;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  #workbench-sidebar.drawer-open { visibility: visible; }
  .sidebar-brand #close-navigation { margin-left: auto; }
  #drawer-backdrop { position: fixed; z-index: 1; inset: 0; border: 0; }
  .agent-header { min-height: 55px; gap: 6px; padding-right: 12px; padding-left: 8px; }
  .agent-header h1 { font-size: 16px; }
  .assistant-log, .compose-area { width: min(100% - 24px, 780px); }
  .assistant-log { gap: 20px; padding: 19px 0; }
  .agent-panel {
    inset: auto 0 0;
    width: 100%;
    height: auto;
    max-height: 86dvh;
    border-radius: 16px 16px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}
@media (max-height: 450px) {
  .assistant-empty h2 { font-size: 20px; margin-top: 4px; }
  .assistant-empty img { width: 48px; height: 32px; }
  .assistant-empty p { display: none; }
}

#thread-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
#thread-list section + section { margin-top: 14px; }
#thread-list h2, #thread-list small, #history-status { color: var(--quiet); font-size: 12px; margin: 0; padding: 4px 12px; }
#history-status:empty { display: none; }
#thread-list button { display: block; width: 100%; min-height: 34px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-header h1 { overflow: hidden; text-overflow: ellipsis; }

#thread-list .thread-row{display:flex;align-items:center}#thread-list .thread-row .nav-item{min-width:0;flex:1}#thread-list [data-thread-id]{width:34px;flex:none;background:transparent;color:inherit;border:0;cursor:pointer}
.thread-dropdown {
  position: fixed;
  inset: auto;
  margin: 0;
  width: min(11rem, calc(100vw - 16px));
  max-height: calc(100vh - 16px);
  padding: .35rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.thread-dropdown::backdrop { background: transparent; }
.thread-dropdown h3, .thread-dropdown [role="status"]:empty { display: none; }
.thread-dropdown form { display: grid; gap: .125rem; }
.thread-dropdown button {
  appearance: none;
  padding: .5rem .75rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.thread-dropdown button:hover:not(:disabled) { background: var(--tint); }
.thread-dropdown button:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.thread-dropdown button[data-op="delete"] { color: var(--danger); }
.thread-dropdown button[data-confirm="true"] { border-color: currentColor; }
.thread-dropdown:has([data-confirm="true"]) { width: min(17rem, calc(100vw - 16px)); }
.thread-dropdown [role="status"] { margin: .5rem .75rem; color: var(--quiet); }
.composer-actions .model-button{max-width:75%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}

@media(max-width:760px){.compose-area{padding-bottom:env(safe-area-inset-bottom,0px)}#assistant-message:empty{display:none}}
