:root {
  color-scheme: dark;
  --bg: #111019;
  --panel: #1b1926;
  --line: #333041;
  --muted: #aaa5ba;
  --ink: #eeebf6;
  --accent: #b69aff;
  font-family: Inter, ui-sans-serif, system-ui, sans-serif;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
button,
input,
textarea,
select {
  font: inherit;
}
button,
.button,
.filebutton {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #242130;
  color: var(--ink);
  padding: 10px 15px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
button:hover,
.button:hover,
.filebutton:hover {
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.45;
  cursor: wait;
}
.primary {
  background: var(--accent);
  color: #21152f;
  border-color: transparent;
  font-weight: 650;
}
.subtle {
  background: transparent;
  color: var(--muted);
  padding: 7px 10px;
}
input,
textarea,
select {
  width: 100%;
  background: #12111b;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 8px;
  outline: none;
}
input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
}
textarea {
  resize: vertical;
  line-height: 1.55;
}
label {
  display: block;
  color: #c8c2d7;
  font-size: 13px;
  margin: 13px 0;
}
label input,
label textarea,
label select {
  margin-top: 7px;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
}
.check input {
  width: auto;
  margin: 0;
  accent-color: var(--accent);
}
input[type="color"] {
  height: 42px;
}
h1,
h2,
h3,
p {
  margin-top: 0;
}
h1 {
  font-weight: 550;
  font-size: 27px;
  letter-spacing: -0.6px;
  margin-bottom: 0;
}
h2 {
  font-size: 19px;
  font-weight: 550;
}
h3 {
  font-size: 15px;
}
.muted,
small {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.65;
}
.eyebrow {
  font-size: 10px;
  letter-spacing: 1.8px;
  color: var(--muted);
  margin-bottom: 10px;
}
.pill {
  font-size: 12px;
  background: #252333;
  color: #c3b3e8;
  border: 1px solid #453952;
  border-radius: 30px;
  padding: 7px 12px;
  white-space: nowrap;
}
#app {
  display: grid;
  grid-template-columns: 248px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}
aside {
  background: #17151f;
  border-right: 1px solid var(--line);
  height: 100%;
  min-height: 0;
  padding: 30px 20px;
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 29px;
  color: var(--accent);
  text-decoration: none;
  margin-bottom: 34px;
}
.brand span {
  font-size: 23px;
  color: var(--ink);
}
.brand small {
  display: block;
  font-size: 8px;
  letter-spacing: 2.5px;
  color: var(--muted);
  margin-top: 3px;
}
nav {
  display: grid;
  gap: 5px;
  margin: 28px 0;
}
nav button {
  text-align: left;
  background: none;
  border-color: transparent;
  color: var(--muted);
}
nav button.active {
  background: #2a223b;
  color: #d5c3ff;
}
#chatlist {
  overflow-y: auto;
  flex: 1;
}
#chatlist button {
  display: block;
  text-align: left;
  width: 100%;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#chatlist button.selected {
  background: #25212f;
  color: var(--ink);
}
footer {
  border-top: 1px solid var(--line);
  padding-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
header {
  flex: none;
  padding: 32px 44px 25px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.view {
  padding: 24px 44px;
  max-width: 1450px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  flex: 1;
  overflow-y: auto;
}
#view-chat {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.chatbar {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
}
.chatbar label {
  margin: 0;
  flex: 1;
  min-width: 150px;
}
.chatbar .check {
  flex: 1.5;
}
.chatbar select {
  font-size: 12px;
}
#messages {
  min-height: 0;
  padding: 28px 12px;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
.welcome {
  padding: 70px 10px;
  text-align: center;
}
.welcome .orb {
  margin: 0 auto 24px;
}
.welcome h2 {
  font-size: 28px;
}
.message {
  margin: 0 0 24px;
}
.message .speaker {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 9px;
  display: flex;
  gap: 12px;
  align-items: center;
}
.message.user {
  background: #242030;
  padding: 19px 22px;
  border-radius: 14px;
  margin-left: 10%;
}
.message.user .speaker {
  color: var(--muted);
}
.message .content {
  white-space: pre-wrap;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.message.assistant {
  padding: 8px 4px;
}
.message details {
  margin-top: 14px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 12px;
}
.message details p {
  white-space: pre-wrap;
  margin: 10px 0;
  line-height: 1.6;
}
.message .speak {
  padding: 3px 7px;
  font-size: 11px;
}
.composer {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  background: var(--bg);
  padding: 5px 0 16px;
}
.composer form {
  background: var(--panel);
  border: 1px solid #474052;
  border-radius: 16px;
  padding: 12px;
}
.composer textarea {
  border: 0;
  background: none;
  padding: 7px;
  min-height: 70px;
  max-height: min(160px, 22dvh);
}
#routehint {
  max-height: 3.3em;
  overflow-y: auto;
  overflow-wrap: anywhere;
}
.composeactions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.composeactions > div {
  display: flex;
  gap: 8px;
}
.composeactions button,
.filebutton {
  font-size: 12px;
  padding: 8px 12px;
}
.filebutton {
  margin: 0;
}
.composer small {
  display: block;
  text-align: center;
  margin-top: 10px;
}
.sectionhead,
.filters,
.actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.sectionhead p {
  margin: 0;
  color: var(--muted);
}
.filters input {
  flex: 2;
}
.filters select {
  flex: 1;
}
.cards {
  display: grid;
  gap: 14px;
}
.memorycard,
article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
}
.memorycard p {
  white-space: pre-wrap;
  line-height: 1.6;
  overflow-wrap: anywhere;
}
.memorycard .actions {
  margin: 16px 0 0;
  justify-content: flex-end;
}
.memorycard small {
  display: block;
}
.memorycard .status {
  color: var(--accent);
  font-size: 12px;
}
.settinggrid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.settinggrid h2:not(:first-child) {
  margin-top: 28px;
}
.sticky {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 20px 0;
  display: flex;
  align-items: center;
  gap: 20px;
}
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: radial-gradient(ellipse at 50% 25%, #302140, transparent 60%);
}
.authcard {
  width: min(440px, 92vw);
  padding: 32px;
}
.authcard h1 {
  font-size: 42px;
  margin-bottom: 20px;
}
.authcard button {
  width: 100%;
  margin: 14px 0;
}
.orb {
  width: 65px;
  height: 65px;
  display: grid;
  place-items: center;
  font-size: 30px;
  border-radius: 22px;
  background: linear-gradient(135deg, #c3a4f2, #705592);
  color: #23142f;
  box-shadow: 0 0 65px #9873cb30;
  margin-bottom: 24px;
}
.error {
  color: #ffaeb2;
}
#notice {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: #423450;
  border: 1px solid #82718f;
  border-radius: 10px;
  z-index: 100;
  max-width: 90vw;
  box-shadow: 0 10px 40px #0008;
}
dialog {
  width: min(570px, 92vw);
  max-height: 90vh;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  color: var(--ink);
  padding: 28px;
}
dialog::backdrop {
  background: #0009;
}
#userlist {
  margin-bottom: 25px;
}
[hidden] {
  display: none !important;
}
@media (max-width: 1000px) {
  #app {
    grid-template-columns: 205px 1fr;
  }
  aside {
    padding: 25px 14px;
  }
  .view,
  header {
    padding: 22px;
  }
  .settinggrid {
    grid-template-columns: 1fr;
  }
  .chatbar {
    gap: 12px;
  }
  .composeactions {
    flex-wrap: wrap;
  }
}
@media (max-width: 650px) {
  #app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  aside {
    height: auto;
    position: static;
    border-right: 0;
    padding: 10px 16px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
  }
  .brand {
    margin: 0;
    font-size: 22px;
    gap: 6px;
  }
  .brand span {
    font-size: 20px;
  }
  .brand small {
    display: none;
  }
  #newchat {
    font-size: 12px;
    padding: 8px 10px;
  }
  nav {
    grid-column: 1 / -1;
    display: flex;
    overflow: auto;
    margin: 0;
    gap: 2px;
  }
  nav button {
    white-space: nowrap;
    padding: 7px 8px;
    font-size: 12px;
  }
  aside > .eyebrow,
  #chatlist {
    display: none;
  }
  footer {
    grid-column: 1 / -1;
    padding-top: 6px;
    font-size: 12px;
  }
  footer button {
    padding: 4px 8px !important;
    font-size: 12px;
  }
  header {
    padding: 10px 16px;
  }
  header .eyebrow {
    display: none;
  }
  header h1 {
    font-size: 23px;
  }
  .view {
    padding: 12px 16px;
  }
  .chatbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    gap: 8px;
  }
  .chatbar label {
    min-width: 0;
    font-size: 11px;
  }
  .chatbar select {
    padding: 7px 4px;
    margin-top: 4px;
  }
  .chatbar .check {
    grid-column: 1 / -1;
    min-width: 0;
  }
  #deletechat {
    grid-column: 3;
    grid-row: 1;
    align-self: end;
    font-size: 11px;
    padding: 7px 4px;
  }
  .composer {
    padding-bottom: 0;
  }
  .composer form {
    padding: 8px;
  }
  .composer textarea {
    height: 62px;
    min-height: 44px;
    max-height: 100px;
    padding: 4px;
  }
  .composeactions button,
  .filebutton {
    padding: 7px 8px;
    font-size: 11px;
  }
  .composer small {
    font-size: 10px;
    line-height: 1.3;
    margin-top: 6px;
  }
  #routehint {
    max-height: 1.65em;
    margin-bottom: 6px;
  }
  .welcome {
    padding: 12px 0;
  }
  .sectionhead {
    align-items: flex-start;
  }
  .message.user {
    margin-left: 0;
  }
  #messages {
    min-height: 0;
    padding: 12px 6px;
  }
}

.grouprule {
  border-top: 1px solid var(--line);
  padding: 15px 0;
}
.grouprule summary {
  cursor: pointer;
  color: var(--accent);
}

.profilepreview {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 16px;
  margin: 8px 0;
}

.messageavatar {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 50%;
}

.knowledge-sources { margin-top: 12px; font-size: .85rem; overflow-wrap: anywhere; }
.knowledge-sources summary { cursor: pointer; }
.knowledge-sources a { color: inherit; text-decoration: underline; }

.message .content.markdown { white-space: normal; min-width: 0; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: .65em 0; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 1em 0 .45em; line-height: 1.35; }
.markdown h1 { font-size: 1.45em; }
.markdown h2 { font-size: 1.3em; }
.markdown h3, .markdown h4 { font-size: 1.15em; }
.markdown ul, .markdown ol { padding-left: 1.6em; margin: .6em 0; }
.markdown li { margin: .25em 0; }
.markdown pre { white-space: pre; overflow-x: auto; padding: 12px; background: #17131f; border-radius: 8px; }
.markdown code { font-family: ui-monospace, monospace; font-size: .9em; }
.markdown :not(pre) > code { background: #242030; padding: .1em .3em; border-radius: 4px; }
.markdown blockquote { margin: .8em 0; padding-left: 1em; border-left: 3px solid var(--muted); }
.markdown table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; }
.markdown th, .markdown td { border: 1px solid var(--line); padding: .4em .7em; }
.markdown a { color: inherit; text-decoration: underline; }

.generated-picture {display:block;max-width:100%;width:768px;height:auto;border-radius:12px;margin:12px 0;}

#projectpanel { padding: .5rem 1rem; max-height: 32vh; overflow: auto; border-bottom: 1px solid #ffffff20; }
#projectpanel textarea { width:100%; }
#projectdocs pre { white-space: pre-wrap; max-height: 12rem; overflow:auto; }

/* Quiet conversation layout: controls live in menus, the chat owns the space. */
header { padding: 12px 28px; min-height: 60px; gap: 12px; }
header h1 { font-size: 18px; letter-spacing: -.2px; }
header > div:first-of-type { flex: 1; min-width: 0; }
.headeractions { display: flex; align-items: center; gap: 12px; }
#chatoptions { font-size: 25px; line-height: 1; padding: 6px 12px; }
#menutoggle { display: none; }
aside { padding: 22px 16px; }
.brand { margin-bottom: 22px; }
nav { margin: 20px 0; }
#view-chat { grid-template-rows: minmax(0, 1fr) auto; padding: 0 28px 14px; }
#messages { padding-top: 24px; }
.welcome { padding: clamp(24px, 10vh, 100px) 10px 24px; }
.welcome h2 { font-size: clamp(22px, 3vw, 28px); }
.composer { padding: 8px 0 0; }
.composer textarea { min-height: 64px; }
.composeactions { align-items: center; flex-wrap: wrap; }
#send { margin-left: auto; }
#imagename { max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#routehint { margin: 0 0 8px; font-size: 12px; }
.composer small { font-size: 11px; margin-top: 7px; }
.dialoghead { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.dialoghead h2 { margin: 0; }
#chatoptionsdialog .chatbar { display: grid; grid-template-columns: 1fr; gap: 16px; }
#chatoptionsdialog .chatbar label { min-width: 0; font-size: 13px; }
#chatoptionsdialog select { font-size: 14px; }
#chatoptionsdialog #deletechat { grid-column: auto; grid-row: auto; justify-self: start; }
#projectpanel { max-height: none; padding: 18px 0 0; margin-top: 18px; border-top: 1px solid var(--line); border-bottom: 0; }
#projectpanel summary { cursor: pointer; }
.attachmentactions, .attachmentactions > div { display: flex; flex-wrap: wrap; gap: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
@media (max-width: 650px) {
  #app { display: flex; }
  main { width: 100%; height: 100%; }
  #sidebar { display: none; }
  #app.menu-open #sidebar { display: flex; position: fixed; inset: 58px 0 0 0; z-index: 20; height: auto; padding: 20px; }
  #app.menu-open #chatlist { display: block; }
  #app.menu-open aside > .eyebrow { display: block; }
  #sidebar nav { display: grid; margin: 16px 0; }
  #sidebar footer { margin-top: 12px; }
  #menutoggle { display: inline-block; }
  header { padding: 10px 12px; min-height: 58px; }
  header h1 { font-size: 17px; }
  .headeractions { gap: 4px; }
  .pill { font-size: 11px; padding: 5px 8px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
  #view-chat { padding: 0 12px 10px; }
  #messages { padding: 16px 2px; }
  .composer textarea { min-height: 56px; }
  #chatoptionsdialog { padding: 20px; }
}

#headernewchat { white-space: nowrap; font-size: 12px; }
@media (max-width: 650px) {
  header { gap: 6px; }
  #headernewchat { padding: 7px 5px; font-size: 11px; }
  .headeractions .pill { display: none; }
}

.chatrow { display: flex; align-items: center; min-width: 0; }
#chatlist .chatrow > button:first-child { flex: 1; min-width: 0; }
#chatlist .deleteconversation { width: 32px; flex: none; text-align: center; font-size: 19px; padding: 6px; }
.editmessage { margin-left: auto; font-size: 11px; }

#routehint:not([hidden]) { color: var(--ink); display: flex; align-items: center; gap: 8px; }
#routehint:not([hidden])::before { content: ""; flex: 0 0 12px; width: 12px; height: 12px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: thinking-spin .9s linear infinite; }
@keyframes thinking-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #routehint:not([hidden])::before { animation: none; } }

#view-chat { grid-template-rows: auto minmax(0, 1fr) auto; }
.chatpersonalitybar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin: 6px 0 0; font-size: 12px; }
.chatpersonalitybar select { width: auto; max-width: 70%; margin: 0; padding: 5px 8px; font-size: 12px; background: transparent; }

#advancedsettings { margin-top: 24px; border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
#advancedsettings > summary { cursor: pointer; color: var(--muted); }
#advancedsettings > .settinggrid { margin-top: 20px; }
