:root {
  color-scheme: dark;
  --bg: #000000;
  --sidebar: #080808;
  --sidebar-hover: #1f1f1f;
  --sidebar-active: #2a2a2a;
  --surface: #000000;
  --composer: #212121;
  --composer-border: #2f2f2f;
  --text: #f4f4f4;
  --muted: #a6a6a6;
  --muted-strong: #d6d6d6;
  --border: #222222;
  --accent: #ec671a;
  --accent-dark: #ff8a3d;
  --danger: #ff6b65;
  --user-bubble: #2f2f2f;
  --focus: rgba(255, 255, 255, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
textarea,
select,
input {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 100vh;
  background: var(--bg);
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 10px;
  border-right: 1px solid var(--border);
  background: var(--sidebar);
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  padding: 0 4px 8px;
}

.sidebar-header strong {
  color: #ffffff;
  font-size: 18px;
  font-weight: 750;
}

.sidebar-icon-button,
.attach-button,
.mic-button {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.sidebar-icon-button {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  font-size: 15px;
}

.sidebar-icon-button:hover,
.attach-button:hover,
.mic-button:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.app-nav,
.sidebar-section {
  display: grid;
  gap: 2px;
}

.nav-item,
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  padding: 0 10px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 620;
  text-align: left;
}

.nav-item:hover,
.history-item:hover {
  background: var(--sidebar-hover);
}

.nav-item.active,
.history-item.active {
  background: var(--sidebar-active);
  color: #ffffff;
}

.nav-item span {
  display: inline-grid;
  place-items: center;
  width: 16px;
  color: var(--muted);
  font-size: 14px;
}

.sidebar-section {
  margin-top: 22px;
}

.sidebar-section h2 {
  margin: 0;
  padding: 0 10px 8px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 750;
}

.history-item {
  display: block;
  min-height: 31px;
  color: #d0d0d0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 2px;
}

.history-empty {
  padding: 4px 10px;
  color: #8f8f8f;
  font-size: 13px;
  line-height: 1.35;
}

.recents {
  min-height: 0;
  overflow: hidden;
}

.sidebar-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: auto;
  padding: 10px 8px 4px;
  border-top: 1px solid var(--border);
}

.sidebar-account img {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--accent);
  padding: 5px;
}

.sidebar-account strong,
.sidebar-account span {
  display: block;
}

.sidebar-account strong {
  color: #ffffff;
  font-size: 13px;
  line-height: 1.2;
}

.sidebar-account span {
  color: var(--muted);
  font-size: 12px;
}

.sidebar-account > div {
  min-width: 0;
  flex: 1 1 auto;
}

.sidebar-account strong,
.sidebar-account span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-button,
.logout-button {
  flex: 0 0 auto;
  min-height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.admin-button:hover,
.logout-button:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.admin-button[hidden],
.logout-button[hidden] {
  display: none;
}

.chat-area {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  background: var(--surface);
  overflow: hidden;
}

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.76);
  backdrop-filter: blur(18px);
  padding: 24px;
}

.auth-overlay[hidden] {
  display: none;
}

.auth-card {
  display: grid;
  gap: 14px;
  width: min(100%, 360px);
  border: 1px solid #2d2d2d;
  border-radius: 8px;
  background: #111111;
  padding: 28px;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.54);
}

.auth-card img {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: var(--accent);
  padding: 7px;
}

.auth-card h1 {
  margin: 0 0 4px;
  color: #ffffff;
  font-size: 24px;
  line-height: 1.15;
}

.auth-card label {
  display: grid;
  gap: 7px;
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 700;
}

.auth-card input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #333333;
  border-radius: 8px;
  outline: 0;
  background: #1b1b1b;
  color: var(--text);
  padding: 0 12px;
}

.auth-card input:focus {
  border-color: #5a5a5a;
}

.auth-error {
  min-height: 18px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.auth-card button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #f4f4f4;
  color: #111111;
  cursor: pointer;
  font-size: 14px;
  font-weight: 800;
}

.auth-card button:disabled {
  cursor: progress;
  opacity: 0.55;
}

.topbar,
.badge {
  display: none;
}

.messages {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 26px 0 126px;
}

body:not(.has-messages) .messages {
  display: grid;
  place-items: center;
  overflow: hidden;
  padding: 0;
}

.empty-state {
  display: grid;
  place-items: center;
  transform: translateY(-50px);
  padding: 0 24px;
}

.empty-state[hidden] {
  display: none;
}

.empty-state h2 {
  margin: 0;
  color: #e8e8e8;
  font-size: 23px;
  line-height: 1.2;
  text-align: center;
  font-weight: 700;
}

.message {
  display: grid;
  grid-template-columns: 34px minmax(0, 740px);
  gap: 14px;
  width: min(100%, 840px);
  margin: 0 auto;
  padding: 20px 24px;
}

.message.user {
  grid-template-columns: minmax(0, 740px);
  justify-items: end;
}

.message.user .avatar {
  display: none;
}

.avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  margin-top: 2px;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

.avatar img {
  width: 18px;
  height: 18px;
  object-fit: contain;
}

.message.user .bubble {
  max-width: min(76%, 680px);
  border-radius: 18px;
  background: var(--user-bubble);
  padding: 10px 15px;
}

.message.assistant .bubble {
  width: 100%;
  padding-top: 1px;
}

.bubble {
  min-width: 0;
  color: var(--text);
  line-height: 1.58;
  font-size: 15px;
}

.bubble p {
  margin: 0 0 12px;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding-left: 22px;
}

.answer-heading {
  margin-top: 18px;
  color: var(--text);
  font-weight: 700;
}

.bubble a {
  color: var(--accent-dark);
  font-weight: 650;
  text-decoration: none;
}

.bubble a:hover {
  text-decoration: underline;
}

.citation-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 21px;
  height: 21px;
  margin-left: 4px;
  border-radius: 999px;
  background: rgba(236, 103, 26, 0.18);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  vertical-align: 1px;
}

.sources {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.sources h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.sources ol {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 20px;
}

.sources li {
  color: var(--muted);
  font-size: 14px;
}

.sources li a,
.source-meta {
  display: block;
}

.source-meta {
  margin-top: 2px;
  color: #8d8d8d;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.artifacts {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.artifact-card {
  display: inline-grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  width: min(100%, 420px);
  border: 1px solid #343434;
  border-radius: 8px;
  background: #171717;
  padding: 10px;
  color: var(--text);
  text-decoration: none;
}

.artifact-card:hover {
  border-color: #4a4a4a;
  background: #1f1f1f;
  text-decoration: none;
}

.artifact-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #244a84;
  color: #ffffff;
  font-size: 14px;
  font-weight: 850;
}

.artifact-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.artifact-text strong,
.artifact-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-text strong {
  color: #ffffff;
  font-size: 14px;
}

.artifact-text small {
  color: var(--muted);
  font-size: 12px;
}

.incomplete-notice {
  display: grid;
  gap: 4px;
  margin-top: 16px;
  border: 1px solid rgba(255, 138, 61, 0.35);
  border-radius: 10px;
  background: rgba(236, 103, 26, 0.12);
  padding: 10px 12px;
  color: #ffd3b7;
}

.incomplete-notice strong,
.incomplete-notice span {
  display: block;
}

.incomplete-notice strong {
  color: #ffb176;
  font-size: 13px;
}

.incomplete-notice span {
  font-size: 13px;
  line-height: 1.45;
}

.composer-wrap {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 0 20px 24px;
  background: linear-gradient(to top, #000 72%, rgba(0, 0, 0, 0));
}

body:not(.has-messages) .composer-wrap {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  width: min(770px, calc(100% - 64px));
  margin: 0;
  padding: 0;
  transform: translate(-50%, 0);
  background: transparent;
}

.composer-wrap p {
  height: 0;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.attachment-tray[hidden] {
  display: none;
}

.attachment-chip {
  display: inline-grid;
  grid-template-columns: minmax(0, 1fr) 24px;
  align-items: center;
  gap: 8px;
  max-width: min(100%, 330px);
  border: 1px solid #343434;
  border-radius: 8px;
  background: #151515;
  padding: 7px 7px 7px 10px;
}

.attachment-chip div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.attachment-chip span,
.attachment-chip small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip span {
  color: #eeeeee;
  font-size: 13px;
  font-weight: 700;
}

.attachment-chip small {
  color: var(--muted);
  font-size: 11px;
}

.attachment-chip button {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.attachment-chip button:hover {
  background: #2a2a2a;
  color: #ffffff;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  border: 1px solid var(--composer-border);
  border-radius: 999px;
  background: var(--composer);
  padding: 4px 6px;
  box-shadow: none;
}

.composer.has-input {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  grid-template-areas:
    "input input input"
    "attach spacer actions";
  align-items: end;
  gap: 10px 8px;
  min-height: 126px;
  border-radius: 28px;
  padding: 14px 12px 10px;
}

.composer:focus-within {
  border-color: #3a3a3a;
  box-shadow: none;
}

.attach-button,
.mic-button,
.send-button {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 999px;
}

.attach-button {
  color: #cfcfcf;
  font-size: 23px;
  line-height: 1;
}

.composer.has-input .attach-button {
  grid-area: attach;
}

textarea {
  flex: 1 1 auto;
  width: 100%;
  min-width: 120px;
  min-height: 34px;
  max-height: 140px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 7px 0;
  line-height: 1.45;
  overflow-y: auto;
}

.composer.has-input textarea {
  grid-area: input;
  min-height: 58px;
  max-height: 120px;
  padding: 0 8px;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.45;
}

textarea::placeholder {
  color: #a9a9a9;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
  min-width: 0;
}

.composer.has-input .composer-actions {
  grid-area: actions;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.technical-controls {
  display: none;
}

.auto-mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border-radius: 999px;
  background: #2b2b2b;
  color: var(--muted-strong);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.tool-select {
  position: relative;
  display: inline-flex;
  align-items: center;
  max-width: 128px;
  min-width: 0;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0;
}

.source-select {
  max-width: 170px;
}

.engagement-select {
  max-width: 190px;
}

.tool-select.open,
.tool-select:hover {
  background: #2b2b2b;
}

.select-label,
.native-select {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.native-select {
  pointer-events: none;
}

.select-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  width: 100%;
  max-width: 128px;
  min-height: 34px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 9px 0 11px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}

.source-select .select-trigger {
  max-width: 170px;
}

.engagement-select .select-trigger {
  max-width: 190px;
}

.select-trigger:hover {
  color: var(--muted-strong);
}

.select-trigger:focus-visible {
  outline: 1px solid #5a5a5a;
  outline-offset: 1px;
}

.select-trigger:disabled {
  cursor: progress;
  opacity: 0.5;
}

.select-trigger [data-selected-label] {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.select-chevron {
  flex: 0 0 auto;
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  border-top: 5px solid #9c9c9c;
}

.select-menu {
  position: absolute;
  bottom: calc(100% + 7px);
  left: 0;
  z-index: 30;
  display: none;
  width: max(100%, 156px);
  max-width: 240px;
  padding: 6px;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  background: #202020;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.48);
}

.source-select .select-menu {
  right: 0;
  left: auto;
  width: 190px;
}

.engagement-select .select-menu {
  right: 0;
  left: auto;
  width: 210px;
}

.tool-select.open .select-menu {
  display: grid;
  gap: 2px;
}

.select-option {
  display: block;
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d8d8d8;
  padding: 0 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.select-option:hover,
.select-option:focus-visible {
  outline: 0;
  background: #303030;
  color: #ffffff;
}

.select-option[aria-selected="true"] {
  background: #3a3a3a;
  color: #ffffff;
}

.mic-button {
  color: #d7d7d7;
}

.mic-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.send-button {
  display: grid;
  place-items: center;
  border: 0;
  background: #f4f4f4;
  color: #111111;
  cursor: pointer;
  font-size: 17px;
  font-weight: 850;
  line-height: 1;
}

.send-button:hover {
  background: #ffffff;
}

.send-button:disabled {
  cursor: progress;
  opacity: 0.45;
}

.error {
  color: var(--danger);
  white-space: pre-wrap;
}

.partial-error {
  color: var(--text);
}

.stream-error-notice {
  display: grid;
  gap: 4px;
  margin-top: 16px;
  border: 1px solid rgba(255, 107, 101, 0.38);
  border-radius: 10px;
  background: rgba(255, 107, 101, 0.1);
  padding: 10px 12px;
  color: #ffc2bf;
}

.stream-error-notice strong,
.stream-error-notice span {
  display: block;
}

.stream-error-notice strong {
  color: #ff8f89;
  font-size: 13px;
}

.stream-error-notice span {
  font-size: 13px;
  line-height: 1.45;
}

.bubble.streaming {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: auto;
  max-width: min(100%, 620px);
  min-height: 38px;
  border: 1px solid #2c2c2c;
  border-radius: 14px;
  background: #161616;
  padding: 8px 12px;
  color: var(--muted-strong);
}

.message.assistant .bubble.streaming {
  width: fit-content;
  padding: 8px 12px;
}

.stream-content {
  display: inline-block;
  min-height: 24px;
  color: var(--muted-strong);
  line-height: 1.45;
}

.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 18px;
  margin-left: 2px;
  border-radius: 999px;
  background: var(--accent-dark);
  vertical-align: -3px;
  animation: blink 1s steps(2, start) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .chat-area {
    height: 100dvh;
  }

  body:not(.has-messages) .composer-wrap {
    width: min(720px, calc(100% - 24px));
  }

  .messages {
    padding-bottom: 142px;
  }

  .message {
    grid-template-columns: 30px minmax(0, 1fr);
    padding-left: 16px;
    padding-right: 16px;
  }

  .message.user {
    grid-template-columns: minmax(0, 1fr);
  }

  .message.user .bubble {
    max-width: 88%;
  }

  .composer-wrap {
    padding-right: 12px;
    padding-left: 12px;
  }

  .composer:not(.has-input) {
    flex-wrap: wrap;
    border-radius: 24px;
    padding: 5px 7px;
  }

  .composer.has-input {
    min-height: 126px;
    border-radius: 28px;
    padding: 14px 12px 10px;
  }

  .composer:not(.has-input) textarea {
    flex-basis: calc(100% - 86px);
  }

  .composer:not(.has-input) .composer-actions {
    width: 100%;
    justify-content: space-between;
  }

  .composer.has-input .composer-actions {
    width: auto;
    justify-content: flex-end;
  }

  .composer-tools {
    flex: 1 1 auto;
    overflow: hidden;
  }

  .tool-select {
    flex: 1 1 auto;
    max-width: none;
  }

  .select-trigger {
    max-width: none;
    min-width: 0;
  }
}

@media (max-width: 520px) {
  .empty-state {
    transform: translateY(-62px);
  }

  .empty-state h2 {
    font-size: 21px;
  }

  .select-trigger {
    font-size: 12px;
    padding-left: 8px;
  }

  .source-select {
    display: none;
  }
}
