/* ============================================================
   MICRO — modern chat UI theme
   ============================================================ */
:root{
  --bg: #0a0a0b;
  --bg-sidebar: #131316;
  --surface: #1c1c20;
  --surface-2: #26262b;
  --border: rgba(255,255,255,.08);
  --border-strong: rgba(255,255,255,.14);

  --accent-rgb: 255, 51, 68;
  --accent: #ff3344;
  --accent-hover: #ff5563;
  --accent-soft: #ff8f98;

  --danger: #ff4d6d;
  --amber: #f5a623;
  --green: #3ddc84;

  --text: #ececf0;
  --text-dim: #a2a2ab;
  --text-faint: #6c6c76;

  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* Swapped in while the Learning Protocol is active - everything deriving
   from --accent/--accent-rgb (send button, links, active states, the
   assistant's avatar mark) recolors automatically. Reverts the instant
   learning ends. */
body.theme-learning{
  --accent-rgb: 34, 197, 94;
  --accent: #22c55e;
  --accent-hover: #34d768;
  --accent-soft: #86efac;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea{ font-family: var(--font-body); }

::selection{ background: rgba(var(--accent-rgb), .35); color: var(--text); }

::-webkit-scrollbar{ width: 9px; height: 9px; }
::-webkit-scrollbar-track{ background: transparent; }
::-webkit-scrollbar-thumb{ background: var(--surface-2); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover{ background: #38383f; background-clip: content-box; }

.empty-hint{ font-size: 12.5px; color: var(--text-faint); line-height: 1.5; padding: 6px 2px; }

/* ------------------------------------------------------------- app shell */
.app-shell{
  position: relative;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: flex;
  overflow: hidden;
}

.sidebar-overlay{
  display: none;
  position: fixed; inset: 0; z-index: 39;
  background: rgba(0,0,0,.55);
}
.sidebar-overlay.open{ display: block; }
@media (min-width: 881px){ .sidebar-overlay{ display: none !important; } }

/* ---------------------------------------------------------------- sidebar */
.sidebar{
  flex: 0 0 264px;
  width: 264px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  transition: flex-basis .18s ease, width .18s ease, opacity .18s ease, transform .18s ease;
}
@media (min-width: 881px){
  .sidebar.collapsed{ flex-basis: 0; width: 0; border-right: none; opacity: 0; pointer-events: none; }
}
@media (max-width: 880px){
  .sidebar{
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: 280px; flex-basis: 280px;
    transform: translateX(-100%);
    box-shadow: 0 0 50px rgba(0,0,0,.6);
  }
  .sidebar.mobile-open{ transform: translateX(0); }
}

.sidebar-head{ display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; flex: 0 0 auto; }
.sidebar-logo{ display: flex; align-items: center; gap: 9px; min-width: 0; }
.logo-mark{
  width: 27px; height: 27px; border-radius: 8px; flex: 0 0 auto;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
}
.logo-text{ font-weight: 700; font-size: 15px; letter-spacing: -.1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.new-chat-btn{
  margin: 6px 12px 8px;
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text);
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background .15s;
}
.new-chat-btn:hover{ background: var(--surface); }
.new-chat-btn svg{ flex: 0 0 auto; color: var(--text-dim); }

.sidebar-tools{ display: flex; flex-direction: column; padding: 2px 8px; gap: 1px; flex: 0 0 auto; }
.sidebar-item{
  display: flex; align-items: center; gap: 10px;
  padding: 8px 9px;
  border-radius: 8px;
  background: none; border: none;
  color: var(--text-dim);
  font-size: 13.5px;
  text-align: left;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.sidebar-item svg{ flex: 0 0 auto; opacity: .8; }
.sidebar-item:hover{ background: var(--surface); color: var(--text); }
.sidebar-item span{ overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-section-label{
  margin: 14px 16px 2px; font-size: 11px; letter-spacing: .5px;
  color: var(--text-faint); text-transform: uppercase; font-weight: 700;
  flex: 0 0 auto;
}
.chats-list{
  flex: 1; min-height: 0; overflow-y: auto;
  padding: 4px 8px 8px;
  display: flex; flex-direction: column; gap: 1px;
}
.sidebar-foot{
  border-top: 1px solid var(--border);
  padding: 8px 8px 10px;
  display: flex; flex-direction: column; gap: 2px;
  flex: 0 0 auto;
}

/* chat session rows (built by app.js, live in the sidebar) */
.chat-session-item{
  display: flex; align-items: center; gap: 8px;
  padding: 8px 9px;
  border-radius: 8px;
  cursor: pointer;
  animation: fade-in .2s ease;
  transition: background .15s;
}
.chat-session-item:hover{ background: var(--surface); }
.chat-session-item.active{ background: var(--surface-2); }
.chat-session-item .cs-info{ flex: 1; min-width: 0; }
.chat-session-item .cs-title{
  font-size: 13.3px; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-session-item .cs-meta{ font-size: 10.5px; color: var(--text-faint); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-session-item .cs-delete{
  opacity: 0; flex: 0 0 auto;
  background: none; border: none; color: var(--text-faint);
  font-size: 17px; line-height: 1; cursor: pointer; padding: 3px 6px; border-radius: 6px;
  transition: opacity .12s, background .12s, color .12s;
}
.chat-session-item:hover .cs-delete, .chat-session-item .cs-delete:focus{ opacity: 1; }
.chat-session-item .cs-delete:hover{ color: var(--danger); background: var(--surface-2); }

.status-pill{
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; letter-spacing: .1px;
  padding: 7px 9px;
  color: var(--text-faint);
}
.status-pill .dot{ width: 7px; height: 7px; border-radius: 50%; background: var(--text-faint); flex: 0 0 auto; }
.status-pill[data-ok="true"] .dot{ background: var(--green); box-shadow: 0 0 7px var(--green); animation: pulse-dot 2s ease-in-out infinite; }
.status-pill[data-ok="false"] .dot{ background: var(--danger); }
.status-pill[data-ok="true"]{ color: var(--text-dim); }
@keyframes pulse-dot{ 0%,100%{ opacity: 1; } 50%{ opacity: .35; } }

/* generic small icon button (topbar) */
.icon-btn{
  width: 34px; height: 34px; border-radius: 8px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text-dim); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover{ background: var(--surface); color: var(--text); }

/* ------------------------------------------------------------- chat main */
.chat-main{
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-topbar{
  display: flex; align-items: center; gap: 4px;
  padding: 8px 10px;
  flex: 0 0 auto;
  min-height: 54px;
}
.model-picker{ position: relative; min-width: 0; }
.model-select{
  appearance: none; -webkit-appearance: none;
  background-color: transparent;
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="%239a9aa3" d="M7 10l5 5 5-5z"/></svg>');
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 14px;
  border: none; color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 7px 26px 7px 10px;
  border-radius: 8px;
  max-width: 220px;
  text-overflow: ellipsis;
}
.model-select:hover{ background-color: var(--surface); }
.topbar-spacer{ flex: 1; }
.state-badge[hidden]{ display: none; }
.state-badge{
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--text-dim);
  padding: 6px 13px; border-radius: 999px;
  background: var(--surface);
  flex: 0 0 auto;
  white-space: nowrap;
}
.state-badge .state-dot{ width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse-dot 1.1s ease-in-out infinite; flex: 0 0 auto; }

/* --------------------------------------------------------------- stage */
.chat-stage{
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
}

.empty-state{
  flex: 1;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 20px;
}
.empty-logo{
  width: 54px; height: 54px; border-radius: 16px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 25px; font-weight: 800;
  box-shadow: 0 0 44px rgba(var(--accent-rgb), .28);
}
.empty-state h1{ font-size: 25px; font-weight: 600; color: var(--text); margin: 0; letter-spacing: -.2px; }
.chat-stage.has-messages .empty-state{ display: none; }
.chat-stage:not(.has-messages) .transcript{ display: none; }

.transcript{
  width: 100%;
  max-width: 800px;
  min-width: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 26px;
}

@keyframes fade-in{ from{ opacity: 0; transform: translateY(6px); } to{ opacity: 1; transform: translateY(0); } }

/* -------------------------------------------------------------- messages */
.msg{
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  animation: fade-in .25s ease;
}
.msg.user{ justify-content: flex-end; }
.msg.system{ justify-content: center; }

.msg-avatar{
  width: 28px; height: 28px; border-radius: 8px; flex: 0 0 auto;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 800;
  margin-top: 2px;
}

.msg-col{ display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg.assistant .msg-col{ flex: 1; min-width: 0; }
.msg.user .msg-col{ align-items: flex-end; max-width: 74%; }
.msg.system .msg-col{ max-width: 70%; align-items: center; }

.msg-body{ min-width: 0; }
.msg.assistant .msg-body{ padding-top: 3px; }
.msg-body.pending .msg-text{ color: var(--text-faint); font-style: italic; }
.msg.user .msg-body{
  background: var(--surface);
  border-radius: 20px;
  padding: 10px 16px;
}
.msg.system .msg-body{ color: var(--text-faint); font-size: 12.5px; text-align: center; }

.msg-text{ font-size: 15.5px; line-height: 1.65; color: var(--text); word-wrap: break-word; }
.msg.user .msg-text{ white-space: pre-wrap; }
.msg-text > *:first-child{ margin-top: 0 !important; }
.msg-text > *:last-child{ margin-bottom: 0 !important; }
.msg-text p{ margin: 0 0 12px; }
.msg-text ul, .msg-text ol{ margin: 0 0 12px; padding-left: 22px; }
.msg-text li{ margin-bottom: 4px; }
.msg-text pre{
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 14px; overflow-x: auto; margin: 4px 0 14px;
}
.msg-text pre code{ background: none; padding: 0; font-size: 13px; color: var(--text); }
.msg-text code{
  background: var(--surface-2); padding: 2px 6px; border-radius: 5px;
  font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace; font-size: .88em;
}
.msg-text blockquote{
  margin: 4px 0 12px; padding-left: 14px;
  border-left: 3px solid var(--border-strong); color: var(--text-dim);
}
.msg-text h3, .msg-text h4, .msg-text h5, .msg-text h6{ margin: 18px 0 8px; font-weight: 700; line-height: 1.3; color: var(--text); }
.msg-text h3{ font-size: 1.25em; } .msg-text h4{ font-size: 1.12em; } .msg-text h5, .msg-text h6{ font-size: 1em; }
.msg-text a{ color: var(--accent-soft); text-decoration: underline; text-underline-offset: 2px; }
.msg-text a:hover{ color: var(--accent); }
.msg-text hr{ border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.msg-text strong{ font-weight: 700; color: var(--text); }
.msg-text em{ font-style: italic; }

.msg-image{
  display: block; max-width: 320px; max-height: 320px; width: auto; height: auto;
  border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 10px;
}

.cursor{
  display: inline-block; width: 8px; height: 1em; background: var(--accent);
  vertical-align: -2px; margin-left: 2px; border-radius: 1px;
  animation: blink 1s step-start infinite;
}
@keyframes blink{ 50%{ opacity: 0; } }

/* collapsible "thinking" trace */
.msg-think-toggle{
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); font-size: 13px; font-family: inherit;
  padding: 3px 2px;
}
.msg-think-toggle:hover{ color: var(--text-dim); }
.msg-think .chev{ display: inline-block; font-size: 9px; transition: transform .15s ease; }
.msg-think.expanded .chev{ transform: rotate(90deg); }
.msg-think-body{
  display: none;
  margin: 4px 0 2px 2px;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border);
  color: var(--text-faint);
  font-size: 13px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word;
  max-height: 260px; overflow-y: auto;
}
.msg-think.expanded .msg-think-body{ display: block; }

.msg-sources{
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 2px;
}
.msg-sources a{
  font-size: 11.5px; color: var(--text-dim); text-decoration: none;
  background: var(--surface); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
  transition: color .15s, border-color .15s;
}
.msg-sources a:hover{ color: var(--accent-soft); border-color: var(--border-strong); }

.msg-actions{
  display: flex; gap: 1px; margin-top: 1px;
  opacity: 0; transition: opacity .12s ease;
}
.msg:hover .msg-actions{ opacity: 1; }
.msg.streaming .msg-actions{ display: none; }
.msg-action-btn{
  width: 28px; height: 28px; border-radius: 7px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text-faint);
  cursor: pointer; transition: background .12s, color .12s;
}
.msg-action-btn:hover{ background: var(--surface); color: var(--text); }
.msg-action-btn.flash{ color: var(--green); }
@media (hover: none){ .msg-actions{ opacity: 1; } }

/* ------------------------------------------------------------ tool cards */
.tool-card{
  border: 1px solid var(--border);
  background: var(--surface);
  border-left: 3px solid var(--text-faint);
  border-radius: 12px;
  padding: 14px 16px;
  animation: fade-in .25s ease;
  max-width: 800px;
  width: 100%;
}
.tool-card-head{
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 700;
  color: var(--text);
  margin-bottom: 9px;
}
.tool-card-icon{ font-size: 14px; }
.tool-card-detail{
  font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace; font-size: 12px; line-height: 1.55;
  color: var(--text-dim); background: rgba(0,0,0,.28);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; margin: 0 0 12px;
  max-height: 220px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
}
.tool-card-actions{ display: flex; gap: 8px; }
.tool-card-result{
  margin-top: 10px; font-size: 12.5px; color: var(--text-dim);
  border-top: 1px solid var(--border); padding-top: 9px;
  white-space: pre-wrap; word-break: break-word;
}
.tool-card.danger-high{ border-left-color: var(--danger); }
.tool-card.danger-self{
  border-left-color: var(--danger);
  animation: fade-in .25s ease, self-edit-pulse 1.6s ease-in-out infinite;
}
.tool-card.danger-normal{ border-left-color: var(--accent-soft); }
@keyframes self-edit-pulse{
  0%,100%{ border-left-color: var(--danger); }
  50%{ border-left-color: var(--accent); }
}
.tool-card.resolved-approved{ opacity: .8; animation: none; }
.tool-card.resolved-denied{ opacity: .55; border-left-color: var(--text-faint); animation: none; }
.tool-card.resolved-approved .tool-card-actions,
.tool-card.resolved-denied .tool-card-actions{ display: none; }

/* --------------------------------------------------------------- composer */
.composer-area{
  width: 100%;
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 20px 18px;
  flex: 0 0 auto;
}

.image-preview-wrap[hidden]{ display: none; }
.image-preview-wrap{
  width: 100%; max-width: 768px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  margin-bottom: 8px;
  animation: fade-in .2s ease;
}
.image-preview-wrap img{ width: 38px; height: 38px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.image-preview-label{ font-size: 12.5px; color: var(--text-dim); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-preview-remove{ background: none; border: none; color: var(--text-faint); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.image-preview-remove:hover{ color: var(--danger); }

.composer{
  width: 100%; max-width: 768px;
  display: flex; align-items: center; gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 28px;
  padding: 7px 7px 7px 8px;
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within{ border-color: rgba(var(--accent-rgb), .5); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .1); }
.composer input[type="text"]{
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: var(--text); font-size: 15.5px; padding: 9px 6px;
}
.composer input[type="text"]::placeholder{ color: var(--text-faint); }
.composer input[type="text"]:disabled{ opacity: .5; }

.composer-icon-btn{
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: transparent; border: none; color: var(--text-dim); cursor: pointer;
  transition: background .15s, color .15s;
}
.composer-icon-btn:hover{ background: var(--surface-2); color: var(--text); }
.composer-icon-btn:disabled{ opacity: .35; cursor: not-allowed; }

.attach-btn.needs-setup{ position: relative; color: var(--amber); }
.attach-btn.needs-setup::after{
  content: ""; position: absolute; top: 4px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 5px var(--amber);
}
.attach-btn.pulling{ color: var(--amber); animation: attach-pulling 1s ease-in-out infinite; cursor: wait; }
@keyframes attach-pulling{ 0%,100%{ opacity: 1; } 50%{ opacity: .4; } }

.mic-btn.listening{
  color: #fff; background: var(--accent);
  animation: mic-pulse 1.4s ease-out infinite;
}
.mic-btn.unsupported{ opacity: .3; cursor: not-allowed; }
.mic-btn.blocked{ color: var(--danger); background: rgba(255,77,109,.1); }
@keyframes mic-pulse{
  0%{ box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .5); }
  100%{ box-shadow: 0 0 0 12px rgba(var(--accent-rgb), 0); }
}

.wake-btn{
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2); border: none; color: var(--text-faint); cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.wake-btn:hover{ color: var(--text-dim); }
.wake-btn.active{
  color: #fff; background: var(--accent);
  animation: wake-breathe 2.6s ease-in-out infinite;
}
@keyframes wake-breathe{
  0%,100%{ box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .35); }
  50%{ box-shadow: 0 0 0 7px rgba(var(--accent-rgb), 0); }
}
.wake-btn.triggered{ animation: wake-flash .6s ease; }
@keyframes wake-flash{
  0%{ box-shadow: 0 0 0 0 rgba(var(--accent-rgb), .8); }
  100%{ box-shadow: 0 0 0 18px rgba(var(--accent-rgb), 0); }
}
.wake-btn.unsupported{ opacity: .3; cursor: not-allowed; }
.wake-btn.blocked{ color: #fff; background: var(--danger); }

.send-btn{
  width: 36px; height: 36px; border-radius: 50%; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border: none; cursor: pointer;
  transition: background .15s, transform .1s;
}
.send-btn:hover{ background: var(--accent-hover); }
.send-btn:active{ transform: scale(.94); }
.send-btn:disabled{ background: var(--surface-2); color: var(--text-faint); cursor: not-allowed; }

.composer-hint{ font-size: 11.5px; color: var(--text-faint); margin-top: 11px; text-align: center; padding: 0 12px; }

/* ---------------------------------------------------------------- buttons */
.hud-btn{
  font-family: inherit;
  font-size: 13px; font-weight: 600;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  padding: 9px 16px;
  border-radius: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.hud-btn:hover{ background: var(--surface-2); }
.hud-btn:active{ transform: scale(.98); }
.hud-btn:disabled{ opacity: .45; cursor: not-allowed; }
.hud-btn.primary{ background: var(--accent); border-color: var(--accent); color: #fff; }
.hud-btn.primary:hover{ background: var(--accent-hover); border-color: var(--accent-hover); }
.hud-btn.danger{ color: var(--danger); border-color: rgba(255,77,109,.35); background: transparent; }
.hud-btn.danger:hover{ background: rgba(255,77,109,.1); }
.hud-btn.small{ padding: 6px 11px; font-size: 11.5px; border-radius: 8px; }

.hud-select{
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 9px;
  max-width: 180px;
}
.hud-select.full{ width: 100%; max-width: none; }
.settings-grid{
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 12px;
}

/* ---------------------------------------------------------------- modals */
.modal-backdrop{
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-backdrop.open{ display: flex; }

.modal{
  position: relative;
  width: min(480px, 100%);
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 24px 70px rgba(0,0,0,.55);
  padding: 26px 26px 24px;
  animation: modal-in .16s ease;
}
.modal.modal-wide{ width: min(920px, 100%); }
@keyframes modal-in{ from{ opacity: 0; transform: scale(.97) translateY(4px); } to{ opacity: 1; transform: scale(1) translateY(0); } }

.modal h2{ font-size: 17px; font-weight: 700; margin: 0 0 6px; color: var(--text); letter-spacing: -.1px; }
.modal-desc{ font-size: 13px; color: var(--text-dim); margin: 0 0 18px; line-height: 1.55; }
.modal-desc.small{ font-size: 12px; margin: 0 0 10px; }
.modal label{ display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin: 14px 0 6px; }
.modal input[type="text"], .modal input[type="number"], .modal input[type="password"]{
  width: 100%; background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); padding: 9px 12px; border-radius: 9px; font-size: 14px; outline: none;
}
.modal input[type="text"]:focus, .modal input[type="number"]:focus, .modal input[type="password"]:focus{
  border-color: rgba(var(--accent-rgb), .5);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .1);
}
.row-check{ display: flex !important; align-items: center; gap: 9px; cursor: pointer; font-weight: 500 !important; color: var(--text-dim) !important; margin: 12px 0 !important; }
.row-check input{ accent-color: var(--accent); width: 15px; height: 15px; }
.row-check.danger-check{ color: var(--danger) !important; }
.row-check.danger-check input{ accent-color: var(--danger); }

.settings-subhead{
  font-size: 11.5px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--text-faint); margin: 24px 0 4px; padding-top: 18px;
  border-top: 1px solid var(--border);
}
.settings-subhead.danger-head{ color: var(--danger); }
.input-row{ display: flex; gap: 8px; align-items: center; }
.input-row input{ flex: 1; }
.input-row .hud-btn{ flex: 0 0 auto; white-space: nowrap; }
.hint-text{ font-size: 11px; color: var(--text-faint); margin: 6px 0 0; line-height: 1.45; }
.hint-text code{ background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

.code-hint{
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px;
  padding: 11px 13px; font-family: 'SFMono-Regular', Consolas, 'Courier New', monospace; font-size: 10.8px;
  color: var(--text-dim); line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  margin: 6px 0 0;
}
.setup-steps{
  margin: 0 0 14px; padding-left: 18px; color: var(--text-dim);
  font-size: 12.5px; line-height: 1.55;
}
.setup-steps li{ margin: 8px 0; }
.setup-steps a{ color: var(--accent); }
.setup-steps code, .modal-desc code{
  background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 11.5px;
}

.modal-close{
  position: absolute; top: 14px; right: 14px;
  width: 30px; height: 30px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text-faint);
  font-size: 20px; cursor: pointer; line-height: 1;
}
.modal-close:hover{ background: var(--surface); color: var(--text); }

.modal-actions{ display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

.duration-boxes{ display: flex; gap: 10px; flex-wrap: wrap; }
.duration-box{
  flex: 1 1 0; min-width: 64px; margin: 0 !important;
  display: flex; flex-direction: column; gap: 5px;
  font-size: 10.5px !important; letter-spacing: .3px; color: var(--text-faint);
}
.duration-box span{ text-align: center; }
.duration-box input[type="number"]{
  width: 100%; text-align: center;
  font-size: 16px; font-weight: 700; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong);
  padding: 10px 8px; border-radius: 9px; outline: none;
  -moz-appearance: textfield;
}
.duration-box input[type="number"]::-webkit-outer-spin-button,
.duration-box input[type="number"]::-webkit-inner-spin-button{ -webkit-appearance: none; margin: 0; }
.duration-box input[type="number"]:focus{ border-color: rgba(var(--accent-rgb), .5); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .1); }
.duration-hint{ font-size: 12px; font-weight: 600; color: var(--accent-soft); margin-top: 8px; }

.learn-progress-wrap{ margin-top: 6px; text-align: center; }
.progress-ring-wrap{ position: relative; width: 108px; height: 108px; margin: 0 auto 12px; }
.progress-ring{ width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg{ fill: none; stroke: var(--surface-2); stroke-width: 6; }
.ring-fg{
  fill: none; stroke: var(--accent); stroke-width: 6; stroke-linecap: round;
  stroke-dasharray: 276.5; stroke-dashoffset: 276.5;
  transition: stroke-dashoffset .5s linear;
}
.progress-pct{ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 700; color: var(--text); }
.learn-topic-label{ font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.learn-status-text{ font-size: 12.5px; color: var(--text-dim); margin-bottom: 12px; min-height: 16px; }
.learn-feed{
  text-align: left; max-height: 180px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px; font-size: 12px; line-height: 1.6; color: var(--text-dim);
  display: flex; flex-direction: column; gap: 4px;
}
.learn-feed .fline{ animation: fade-in .25s ease; }
.learn-feed .fline .tag{ color: var(--accent-soft); margin-right: 4px; font-weight: 600; }
.learn-feed .fline.learned .tag{ color: var(--green); }
.learn-feed .fline.warn .tag{ color: var(--amber); }

/* ------------------------------------------------------------- update log */
.updates-list{ display: flex; flex-direction: column; gap: 18px; max-height: 54vh; overflow-y: auto; padding-right: 4px; }
.update-entry{ border-left: 2px solid var(--accent-soft); padding-left: 13px; animation: fade-in .3s ease; }
.update-entry-head{ display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }
.update-date{ font-size: 11px; font-weight: 600; color: var(--text-faint); white-space: nowrap; }
.update-title{ font-size: 14px; font-weight: 700; color: var(--text); }
.update-items{ margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--text-dim); line-height: 1.6; }
.update-items li{ margin-bottom: 4px; }

/* ---------------------------------------------------------- activity log */
.activity-log{ display: flex; flex-direction: column-reverse; gap: 7px; max-height: 54vh; overflow-y: auto; }
.activity-item{
  font-size: 12px; color: var(--text-dim); line-height: 1.45;
  padding-left: 10px; border-left: 2px solid var(--border);
  animation: fade-in .3s ease;
}
.activity-item .t{ color: var(--text-faint); font-size: 10px; letter-spacing: .3px; display: block; }
.activity-item.warn{ border-left-color: var(--amber); color: var(--amber); }
.activity-item.err{ border-left-color: var(--danger); color: var(--danger); }
.activity-item.ok{ border-left-color: var(--green); }

/* ----------------------------------------------------------- topics */
.topics-list{ display: flex; flex-direction: column; gap: 8px; }
.topic-item{
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-soft);
  background: var(--surface);
  border-radius: 10px;
  cursor: default;
  animation: fade-in .3s ease;
}
.topic-item .topic-name{ font-size: 13.5px; font-weight: 700; color: var(--text); display: block; }
.topic-item .topic-meta{ font-size: 10.5px; color: var(--text-faint); letter-spacing: .2px; margin-top: 2px; display: block; }
.topic-item .topic-summary{ font-size: 12.5px; color: var(--text-dim); margin-top: 6px; line-height: 1.5; display: none; }
.topic-item.expanded .topic-summary{ display: block; }

/* ------------------------------------------------------------ discord dashboard */
.discord-guilds-list{ display: flex; flex-direction: column; gap: 12px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.discord-guild{
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent-soft);
  background: var(--surface);
  border-radius: 10px;
  padding: 11px 13px;
  animation: fade-in .3s ease;
}
.discord-guild-head{ display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.discord-guild-icon{ width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; object-fit: cover; }
.discord-guild-name{
  font-size: 13.5px; font-weight: 700; color: var(--text); flex: 1 1 auto;
  min-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.discord-guild-meta{ font-size: 10.5px; color: var(--text-faint); white-space: nowrap; }
.discord-channel-list{ margin-top: 10px; display: flex; flex-direction: column; }
.discord-channel-row{
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 0; border-top: 1px solid var(--border);
}
.discord-channel-row:first-child{ border-top: none; padding-top: 0; }
.discord-channel-name{ font-size: 12.5px; color: var(--text-dim); flex: 0 0 auto; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.discord-channel-row input[type="text"]{
  flex: 1 1 140px; min-width: 100px;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  color: var(--text); padding: 7px 10px; border-radius: 8px; font-size: 12.5px; outline: none;
}
.discord-channel-row input[type="text"]:focus{ border-color: rgba(var(--accent-rgb), .5); }
.discord-assign-toggle.assigned{ color: var(--green); border-color: rgba(61,220,132,.4); }
.discord-assign-toggle.assigned:hover{ background: rgba(61,220,132,.12); }
.discord-empty{ font-size: 12px; color: var(--text-faint); padding: 4px 0; }

/* -------------------------------------------------------------- 3D synthesis */
.gen3d-row{ display: flex; gap: 10px; margin-bottom: 12px; }
.gen3d-row input[type="text"]{
  flex: 1; background: var(--surface); border: 1px solid var(--border-strong);
  color: var(--text); padding: 9px 12px; border-radius: 9px; font-size: 14px; outline: none;
}
.gen3d-row input[type="text"]:focus{ border-color: rgba(var(--accent-rgb), .5); }
.gen3d-row .hud-btn{ flex: 0 0 auto; }
.gen3d-chips{ display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip{
  font-size: 11.5px; color: var(--text-dim); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 13px; cursor: pointer; transition: background .15s, color .15s;
}
.chip:hover{ background: var(--surface-2); color: var(--text); }
.gen3d-status-row{ display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.gen3d-status{ font-size: 12.5px; color: var(--text-dim); min-height: 16px; flex: 1; }
.gen3d-status.err{ color: var(--danger); }
.gen3d-status.ok{ color: var(--green); }
#gen3dExportBtn{ flex: 0 0 auto; font-size: 11.5px; padding: 7px 12px; }
.gen3d-viewport{
  width: 100%; height: min(52vh, 480px);
  border: 1px solid var(--border);
  border-radius: 14px;
  background: radial-gradient(ellipse 90% 90% at 50% 40%, rgba(255,255,255,.03), transparent 70%);
  overflow: hidden;
  position: relative;
}
.gen3d-viewport canvas{ display: block; width: 100%; height: 100%; }
.gen3d-viewport .empty-hint{ position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; }

/* ---------------------------------------------------------------- toasts */
.toast-stack{
  position: fixed; bottom: 20px; right: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast{
  background: var(--bg-sidebar); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 11px 16px; font-size: 13px; color: var(--text);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.45);
  animation: toast-in .25s ease, toast-out .4s ease 4.6s forwards;
  max-width: 320px;
}
.toast.err{ border-left-color: var(--danger); }
.toast.warn{ border-left-color: var(--amber); }
@keyframes toast-in{ from{ opacity: 0; transform: translateX(30px); } to{ opacity: 1; transform: translateX(0); } }
@keyframes toast-out{ to{ opacity: 0; transform: translateX(30px); } }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 880px){
  .chat-topbar{ padding: 8px 12px; }
}

@media (max-width: 640px){
  .sidebar{ width: 84vw; flex-basis: 84vw; }
  .chat-topbar{ min-height: 50px; }
  .model-select{ font-size: 14px; max-width: 150px; }
  .state-badge span:not(.state-dot){ display: none; }
  .state-badge{ padding: 6px 9px; }

  .empty-state h1{ font-size: 21px; }
  .empty-logo{ width: 46px; height: 46px; font-size: 21px; }

  .transcript{ padding: 16px 14px 10px; gap: 20px; }
  .msg.user .msg-col{ max-width: 86%; }
  .msg-text{ font-size: 15px; }
  .msg-image{ max-width: 220px; max-height: 220px; }
  .tool-card{ padding: 12px 13px; }

  .composer-area{ padding: 6px 12px 14px; }
  .composer{ padding: 6px 6px 6px 6px; }
  .composer input[type="text"]{ font-size: 15px; }
  .composer-icon-btn, .wake-btn, .send-btn{ width: 33px; height: 33px; }

  .modal{ padding: 20px 16px 16px; border-radius: 16px; }
  .modal h2{ font-size: 15px; }
  .modal-actions{ gap: 8px; }
  .modal-actions .hud-btn{ flex: 1 1 auto; }
  .input-row{ flex-wrap: wrap; }
  .input-row .hud-btn{ flex: 1 1 100%; }
  .settings-grid{ grid-template-columns: 1fr; }

  .gen3d-row{ flex-direction: column; align-items: stretch; }
  .gen3d-viewport{ height: min(40vh, 340px); }

  .discord-guild-meta{ flex: 1 1 100%; order: 3; }
  .discord-channel-row{ align-items: stretch; }
  .discord-channel-name{ max-width: none; flex: 1 1 100%; }
  .discord-channel-row input[type="text"]{ flex: 1 1 100%; order: 3; }
  .discord-channel-row .discord-assign-toggle{ flex: 1 1 auto; }
  .discord-channel-row .discord-send-btn{ flex: 0 0 auto; order: 4; }

  .toast-stack{ left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .toast{ max-width: none; }
}
