:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f7f7f8;
  --panel: #ffffff;
  --panel-soft: #f3f3f3;
  --line: #e6e6e6;
  --line-strong: #d3d3d3;
  --text: #0d0d0d;
  --muted: #6f6f6f;
  --subtle: #8a8a8a;
  --brand-bg: #111111;
  --brand-text: #ffffff;
  --button-hover: #ececec;
  --item-active: #e9e9e9;
  --bubble-user: #f3f3f3;
  --bubble-user-text: #111111;
  --composer-bg: #ffffff;
  --composer-shadow: 0 6px 24px rgba(0, 0, 0, 0.07);
  --code-bg: #eeeeee;
  --code-text: #1f1f1f;
  --link: #0f62a8;
  --source-bg: #fafafa;
  --source-border: #dddddd;
  --source-text: #333333;
  --danger: #c94735;
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171717;
  --sidebar: #202020;
  --panel: #171717;
  --panel-soft: #262626;
  --line: #303030;
  --line-strong: #3c3c3c;
  --text: #ececec;
  --muted: #a5a5a5;
  --subtle: #8d8d8d;
  --brand-bg: #eeeeee;
  --brand-text: #111111;
  --button-hover: #2c2c2c;
  --item-active: #2d2d2d;
  --bubble-user: #2a2a2a;
  --bubble-user-text: #f2f2f2;
  --composer-bg: #202020;
  --composer-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --code-bg: #2b2b2b;
  --code-text: #f0f0f0;
  --link: #7db8ff;
  --source-bg: #202020;
  --source-border: #3a3a3a;
  --source-text: #dddddd;
  --danger: #ee7b67;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

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

.sidebar {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
}

.mobile-shade {
  display: none;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 8px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.brand-mark {
  display: grid;
  width: 26px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-bg);
  color: var(--brand-text);
  font-size: 13px;
  font-weight: 800;
}

.new-chat-button,
.ghost-button,
.send-button,
.stop-button {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 13px;
  font-weight: 650;
}

.new-chat-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
}

.new-chat-button:hover {
  background: var(--button-hover);
}

.ghost-button {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
}

.ghost-button:hover {
  color: var(--danger);
  background: var(--panel-soft);
}

.top-new-chat-button:hover {
  color: var(--text);
}

.send-button {
  min-width: 72px;
  background: var(--brand-bg);
  color: var(--brand-text);
}

.send-button:hover {
  filter: brightness(0.9);
}

.stop-button {
  background: var(--danger);
  color: #ffffff;
}

.search-wrap {
  display: grid;
  gap: 5px;
  padding: 6px 12px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.search-wrap input {
  width: 100%;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  outline: 0;
  background: var(--panel);
  color: var(--text);
  padding: 0 11px;
}

.search-wrap input:focus {
  border-color: var(--line-strong);
}

.sidebar-section-title {
  padding: 6px 14px 4px;
  color: var(--subtle);
  font-size: 12px;
  font-weight: 650;
}

.conversation-list {
  display: flex;
  min-height: 0;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.conversation-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  padding: 8px 9px;
  text-align: left;
}

.conversation-item:hover {
  background: var(--button-hover);
}

.conversation-item.active {
  background: var(--item-active);
}

.conversation-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 500;
}

.conversation-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.chat-panel {
  position: relative;
  grid-column: 2;
  grid-row: 1;
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  background: var(--panel);
}

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto auto;
  gap: 12px;
  align-items: center;
  min-height: 58px;
  padding: 9px 18px;
  background: var(--panel);
}

.title-group {
  min-width: 0;
}

.title-group h1 {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 16px;
  font-weight: 650;
  line-height: 1.25;
}

.title-group p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.theme-toggle {
  position: relative;
  width: 34px;
  height: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel-soft);
  padding: 0;
}

.theme-toggle span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text);
  transition:
    transform 140ms ease,
    background 140ms ease;
}

.theme-toggle.active span {
  transform: translateX(14px);
}

.icon-button {
  display: none;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 3px auto;
  border-radius: 999px;
  background: var(--text);
}

.messages {
  min-height: 0;
  flex: 1;
  overflow-y: auto;
  padding: 20px clamp(16px, 4vw, 46px) 22px;
}

.scroll-bottom-button {
  position: absolute;
  z-index: 4;
  bottom: 118px;
  left: 50%;
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  transform: translateX(-50%);
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--composer-bg);
  color: var(--text);
  box-shadow: var(--composer-shadow);
  font-size: 17px;
  line-height: 1;
}

.scroll-bottom-button:hover {
  background: var(--button-hover);
}

.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  padding: 0;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.confirm-dialog::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.confirm-dialog-panel {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.confirm-dialog h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
}

.confirm-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.confirm-dialog-error {
  color: var(--danger) !important;
  font-size: 13px !important;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.dialog-cancel-button,
.dialog-danger-button {
  min-height: 36px;
  border-radius: 999px;
  padding: 0 14px;
  font-weight: 650;
}

.dialog-cancel-button {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  color: var(--text);
}

.dialog-cancel-button:hover {
  background: var(--button-hover);
}

.dialog-danger-button {
  background: var(--danger);
  color: #ffffff;
}

.dialog-danger-button:hover {
  filter: brightness(0.95);
}

.chat-panel.empty-chat .messages {
  flex: 0 0 min(38vh, 320px);
  min-height: 220px;
  overflow: visible;
  padding-bottom: 18px;
}

.chat-panel.empty-chat .composer-shell {
  padding-bottom: max(18px, 20vh);
}

.empty-state {
  display: flex;
  height: 100%;
  align-items: center;
  justify-content: center;
  color: var(--text);
  text-align: center;
  font-size: clamp(26px, 4vw, 34px);
  font-weight: 600;
}

.chat-panel.empty-chat .empty-state {
  align-items: flex-end;
}

.message-row {
  display: flex;
  width: 100%;
  max-width: 760px;
  margin: 0 auto 22px;
}

.message-row.user {
  justify-content: flex-end;
}

.message {
  max-width: min(680px, 100%);
  border-radius: 18px;
  line-height: 1.58;
  word-wrap: break-word;
}

.message.user {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  padding: 10px 14px;
}

.message.assistant {
  width: 100%;
  background: transparent;
  color: var(--text);
  padding: 2px 0;
}

.message.error {
  color: #9d2d20;
}

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

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

.message pre {
  overflow-x: auto;
  margin: 12px 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #171717;
  padding: 12px;
}

.message code {
  border-radius: 5px;
  background: var(--code-bg);
  padding: 2px 5px;
  color: var(--code-text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message pre code {
  background: transparent;
  padding: 0;
  color: #f7f7f7;
}

.message a {
  color: var(--link);
}

.thinking {
  width: fit-content;
  max-width: 100%;
  margin-bottom: 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
}

.thinking summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  list-style: none;
  padding: 5px 0;
  color: var(--subtle);
  font-size: 13px;
  font-weight: 500;
}

.thinking summary::-webkit-details-marker {
  display: none;
}

.thinking summary::before {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 120ms ease;
}

.thinking[open] summary::before {
  transform: rotate(45deg);
}

.thinking-body {
  max-width: 760px;
  border-left: 2px solid var(--line-strong);
  padding: 8px 0 8px 12px;
  color: var(--muted);
  font-size: 13px;
  white-space: pre-wrap;
}

.research-status {
  display: grid;
  gap: 4px;
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.research-status div::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--subtle);
  vertical-align: 1px;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 0 0 12px;
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: min(100%, 260px);
  border: 1px solid var(--source-border);
  border-radius: 999px;
  color: var(--source-text);
  background: var(--source-bg);
  padding: 6px 9px;
  font-size: 12px;
  font-style: normal;
  line-height: 1.2;
  text-decoration: none;
}

.source-chip b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--source-text);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.source-chip:hover {
  background: var(--button-hover);
  color: var(--text);
}

.source-chip span {
  display: grid;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--brand-bg);
  color: var(--brand-text);
  font-size: 11px;
  font-style: normal;
  font-weight: 700;
}

.message a.citation-ref,
.message sup.citation-ref {
  display: inline-block;
  margin: 0 1px;
  color: #929292;
  font-size: 0.68em;
  font-style: italic;
  font-weight: 500;
  line-height: 0;
  text-decoration: none;
  vertical-align: super;
}

.message a.citation-ref:hover {
  color: #666666;
  text-decoration: underline;
}

.final-sources {
  margin-top: 16px;
  border-top: 1px solid #eeeeee;
  padding-top: 8px;
  color: #8f8f8f;
  font-size: 10px;
  font-style: italic;
  line-height: 1.35;
}

.final-sources div {
  margin-bottom: 5px;
  color: #9a9a9a;
  font-size: 9px;
  font-style: italic;
  font-weight: 600;
  text-transform: uppercase;
}

.final-sources ul {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.final-sources li {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1px;
  color: #8f8f8f;
  font-size: 10px;
  font-style: italic;
}

.final-sources span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.final-sources a {
  overflow: hidden;
  color: #a0a0a0;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.final-sources a:hover {
  color: #707070;
  text-decoration: underline;
}

.cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 2px;
  background: var(--text);
  vertical-align: -2px;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%,
  45% {
    opacity: 1;
  }
  46%,
  100% {
    opacity: 0;
  }
}

.composer-shell {
  padding: 10px clamp(14px, 4vw, 40px) 16px;
  background: var(--panel);
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: end;
  width: min(760px, 100%);
  min-height: 58px;
  margin: 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 28px;
  background: var(--composer-bg);
  padding: 7px 7px 7px 15px;
  box-shadow: var(--composer-shadow);
}

.composer textarea {
  grid-column: 1 / -1;
  min-height: 42px;
  max-height: 190px;
  resize: none;
  border: 0;
  border-radius: 20px;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 10px 4px;
  line-height: 1.45;
}

.tool-row {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  border: 1px solid var(--source-border);
  border-radius: 999px;
  background: var(--composer-bg);
  color: var(--muted);
  padding: 0 11px;
  font-size: 13px;
  font-weight: 650;
}

.tool-button:hover {
  background: var(--button-hover);
  color: var(--text);
}

.tool-button.active {
  border-color: var(--brand-bg);
  background: var(--brand-bg);
  color: var(--brand-text);
}

.tool-icon {
  font-size: 15px;
  line-height: 1;
}

.provider-switch {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  min-height: 26px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  padding: 1px;
  transition:
    border-color 120ms ease,
    opacity 120ms ease;
}

.provider-switch.disabled {
  opacity: 0.45;
}

.provider-switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.provider-switch label {
  display: grid;
  min-width: 48px;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  padding: 0 7px;
  font-size: 10px;
  font-weight: 600;
  line-height: 22px;
  cursor: pointer;
}

.provider-switch input:checked + label {
  background: var(--brand-bg);
  color: var(--brand-text);
}

.provider-switch.disabled input:checked + label {
  background: transparent;
  color: var(--muted);
}

.provider-switch input:disabled + label {
  cursor: not-allowed;
}

.composer-note {
  width: min(760px, 100%);
  margin: 7px auto 0;
  color: var(--subtle);
  font-size: 12px;
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(86vw, 330px);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-shade {
    position: fixed;
    z-index: 10;
    inset: 0;
    display: none;
    background: rgba(0, 0, 0, 0.55);
  }

  .mobile-shade.open {
    display: block;
  }

  .chat-panel {
    height: 100vh;
    height: 100dvh;
  }

  .icon-button {
    display: grid;
  }

  .topbar {
    grid-template-columns: auto minmax(0, 1fr) auto auto auto;
    min-height: 58px;
    gap: 8px;
    padding: 8px 10px;
  }

  .title-group h1 {
    font-size: 15px;
  }

  .ghost-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 13px;
  }

  .top-new-chat-button {
    max-width: 86px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theme-toggle {
    width: 32px;
    height: 19px;
  }

  .messages {
    padding: 18px 14px;
  }

  .scroll-bottom-button {
    bottom: 128px;
    width: 32px;
    height: 32px;
  }

  .confirm-dialog-panel {
    padding: 18px;
  }

  .confirm-dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chat-panel.empty-chat .messages {
    flex-basis: min(34vh, 260px);
    min-height: 180px;
  }

  .chat-panel.empty-chat .composer-shell {
    padding-bottom: 12vh;
  }

  .empty-state {
    font-size: 28px;
  }

  .message-row {
    margin-bottom: 18px;
  }

  .message.user {
    max-width: 92%;
  }

  .composer-shell {
    padding: 8px 10px 10px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) auto;
    border-radius: 22px;
    padding: 6px 6px 6px 12px;
  }

  .tool-row {
    grid-column: 1 / -1;
    order: 2;
  }

  .send-button,
  .stop-button {
    min-width: 64px;
    padding: 0 11px;
  }

  .stop-button {
    grid-column: 2;
  }
}
