:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f9f9f8;
  --hover: #efefef;
  --line: #e6e6e4;
  --text: #111111;
  --muted: #6f6f6b;
  --soft: #9b9b96;
  --bubble: #f4f4f4;
  --black: #111111;
  --danger: #b42318;
  --shadow: 0 16px 48px rgba(20, 20, 20, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
}

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

body.is-login { background: #f7f7f5; }

.startup-view {
  display: grid;
  min-height: 100vh;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: #f7f7f5;
  color: var(--muted);
  font-size: 14px;
}

.startup-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #dededb;
  border-top-color: var(--black);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.login-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: var(--black);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
}

.login-copy {
  margin: 34px 0 24px;
}

.login-copy h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: 0;
}

.login-copy p,
.login-hint {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.login-form,
.field {
  display: grid;
  gap: 14px;
}

.field {
  gap: 8px;
}

.field span {
  color: #353535;
  font-size: 14px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid #d9d9d7;
  border-radius: 8px;
  outline: 0;
}

.field input:focus {
  border-color: #111;
}

.primary-button {
  min-height: 46px;
  border-radius: 8px;
  background: var(--black);
  color: #fff;
  font-weight: 750;
}

.primary-button:hover {
  background: #30302e;
}

.primary-button:disabled,
.secondary-button:disabled,
.table-actions button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.login-hint {
  text-align: center;
  font-size: 13px;
}

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

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 8px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  transition: margin-left 180ms ease;
}

.sidebar-header,
.brand,
.nav-button,
.search-box,
.history-item,
.profile,
.topbar,
.chat-switch {
  display: flex;
  align-items: center;
}

.sidebar-header {
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 12px;
}

.brand {
  min-width: 0;
  gap: 10px;
  padding: 4px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.brand-copy {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}

.brand-copy strong {
  font-size: 15px;
}

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

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  color: #454542;
}

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

.nav-button {
  width: 100%;
  gap: 10px;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.nav-button.active,
.nav-button:hover {
  background: var(--hover);
}

.search-box {
  gap: 10px;
  min-height: 38px;
  margin-top: 4px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--text);
}

.search-box:hover {
  background: var(--hover);
}

.search-box svg {
  width: 19px;
  height: 19px;
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.sidebar-section {
  display: grid;
  gap: 6px;
  min-height: 0;
  margin-top: 22px;
  padding: 0 8px;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 28px;
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
}

.text-button {
  padding: 4px 7px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

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

.history-list {
  display: grid;
  gap: 2px;
  overflow: auto;
  max-height: calc(100vh - 330px);
}

.history-empty {
  padding: 8px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 4px 0 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: left;
}

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

.history-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.history-open {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
  flex: 1;
  min-height: 34px;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.history-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 2px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.history-item:hover .history-actions,
.history-item:focus-within .history-actions {
  opacity: 1;
}

.history-time {
  flex: 0 0 auto;
  color: var(--soft);
  font-size: 12px;
}

.profile {
  gap: 10px;
  margin-top: auto;
  padding: 12px 8px 0;
}

.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: #c2185b;
  color: #fff;
  font-weight: 800;
}

.profile-text {
  display: grid;
  flex: 1;
  min-width: 0;
  line-height: 1.2;
}

.profile-text strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.logout-button {
  flex: 0 0 auto;
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr) auto;
  min-width: 0;
  height: 100vh;
  height: 100dvh;
  background: #fff;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  max-width: 180px;
  padding: 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #f1f1ef;
  color: #62605d;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill.configured {
  background: #e7f3ef;
  color: #0f766e;
}

.chat-switch {
  gap: 4px;
  min-height: 38px;
  padding: 0 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
}

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

.chat-switch svg {
  width: 16px;
  height: 16px;
}

.floating-menu {
  display: none;
}

.chat-stage {
  overflow: auto;
  display: flex;
  flex-direction: column;
  width: min(820px, calc(100vw - 48px));
  margin: 0 auto;
  padding: 40px 0 168px;
}

.empty-state {
  display: grid;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  gap: 24px;
  text-align: center;
}

.empty-state h1 {
  margin: 0;
  font-size: 28px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: 0;
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(560px, 100%);
}

.starter-grid button {
  display: grid;
  gap: 5px;
  min-height: 82px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.starter-grid button:hover {
  background: var(--hover);
}

.starter-grid strong {
  font-size: 14px;
}

.starter-grid span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.message-list {
  display: grid;
  width: min(760px, 100%);
  gap: 22px;
  margin: 0 auto;
}

.message {
  display: grid;
  gap: 8px;
}

.message.user {
  justify-items: end;
}

.bubble {
  max-width: min(620px, 82%);
  padding: 12px 16px;
  border-radius: 8px;
  line-height: 1.68;
  word-break: break-word;
  white-space: pre-wrap;
}

.bot .bubble {
  max-width: 100%;
  padding-left: 0;
  background: transparent;
}

.user .bubble {
  background: var(--bubble);
}

.message-tools {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 160ms ease;
}

.message:hover .message-tools,
.message:focus-within .message-tools {
  opacity: 1;
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}

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

.mini-icon-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.mini-icon-button:hover,
.mini-icon-button.active {
  background: var(--hover);
  color: var(--text);
}

.mini-icon-button svg {
  width: 17px;
  height: 17px;
}

.bubble.loading::after {
  display: inline-block;
  width: 18px;
  content: " ";
  animation: pulseDots 900ms infinite;
}

@keyframes pulseDots {
  0% { content: " "; }
  35% { content: "."; }
  65% { content: ".."; }
  100% { content: "..."; }
}

.composer-wrap {
  position: sticky;
  bottom: 0;
  display: grid;
  justify-items: center;
  gap: 14px;
  padding: 18px 24px 30px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 30%);
}

.attachment-tray {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: min(780px, 100%);
}

.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  max-width: min(360px, 100%);
  padding: 6px 6px 6px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.file-icon {
  flex: 0 0 auto;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--hover);
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.file-name {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.file-size {
  flex: 0 0 auto;
  color: var(--soft);
  font-size: 12px;
}

.composer {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 38px 44px;
  align-items: end;
  gap: 6px;
  width: min(780px, 100%);
  min-height: 58px;
  padding: 8px 9px;
  border: 1px solid #d9d9d7;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.08);
}

.composer textarea {
  display: block;
  min-height: 40px;
  max-height: 150px;
  padding: 9px 4px;
  border: 0;
  outline: 0;
  resize: none;
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
}

textarea::placeholder,
input::placeholder {
  color: var(--soft);
}

.send-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--black);
  color: #fff;
}

.send-button:hover {
  background: #30302e;
}

.send-button:disabled {
  cursor: not-allowed;
  background: #d4d4d2;
}

.stop-icon,
.is-generating .send-icon {
  display: none;
}

.is-generating .stop-icon {
  display: block;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.quick-actions button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: #4d4d49;
  font-size: 14px;
}

.quick-actions button:hover {
  background: var(--hover);
}

.quick-actions svg {
  width: 18px;
  height: 18px;
}

.scroll-bottom {
  position: absolute;
  right: 28px;
  bottom: 132px;
  z-index: 3;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--black);
  color: #fff;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(20, 20, 20, 0.28);
}

.modal-backdrop.open {
  display: flex;
}

.settings-dialog {
  width: min(720px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 30px 90px rgba(20, 20, 20, 0.18);
}

.settings-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 22px 16px;
  border-bottom: 1px solid var(--line);
}

.settings-header h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0;
}

.settings-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.settings-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px 22px 22px;
}

.settings-form .field {
  gap: 8px;
}

.settings-form .field input,
.settings-form .field select,
.settings-form .field textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid #d9d9d7;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  outline: 0;
}

.settings-form .field textarea {
  resize: vertical;
  line-height: 1.5;
}

.wide {
  grid-column: 1 / -1;
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--black);
}

.settings-actions {
  display: flex;
  grid-column: 1 / -1;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

.secondary-button {
  min-height: 46px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #373632;
  font-weight: 650;
}

.secondary-button:hover {
  background: #f5f5f3;
}

body.sidebar-collapsed .sidebar { margin-left: -270px; }
body.sidebar-collapsed .app-shell { grid-template-columns: 0 minmax(0, 1fr); }
body.sidebar-collapsed .floating-menu { display: inline-grid; }

:focus-visible {
  outline: 2px solid #111;
  outline-offset: 2px;
}

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

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 4;
    width: 270px;
    box-shadow: 18px 0 40px rgba(0, 0, 0, 0.12);
  }

  body.sidebar-open::after {
    position: fixed;
    inset: 0;
    z-index: 3;
    background: rgba(17, 17, 17, 0.28);
    content: "";
  }

  body:not(.sidebar-open) .sidebar { margin-left: -270px; }
  body:not(.sidebar-open) .floating-menu { display: inline-grid; }

  .topbar {
    padding: 0 14px;
  }

  .top-actions {
    gap: 4px;
  }

  .status-pill {
    display: none;
  }

  .top-actions .icon-button {
    width: 36px;
    height: 36px;
  }

  .chat-switch {
    font-size: 16px;
    max-width: calc(100vw - 182px);
  }

  .chat-switch span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-stage {
    width: min(100% - 28px, 820px);
    padding: 28px 0 190px;
  }

  .empty-state {
    align-content: center;
  }

  .empty-state h1 {
    font-size: 24px;
  }

  .starter-grid {
    grid-template-columns: 1fr;
  }

  .composer-wrap {
    padding: 16px 14px max(18px, env(safe-area-inset-bottom));
  }

  .attachment-tray {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .attachment-chip {
    flex: 0 0 auto;
    max-width: 300px;
  }

  .composer {
    grid-template-columns: 40px minmax(0, 1fr) 42px;
  }

  #voiceBtn {
    display: none;
  }

  .quick-actions {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    justify-content: flex-start;
    padding-bottom: 2px;
  }

  .quick-actions button {
    flex: 0 0 auto;
  }

  .history-actions {
    opacity: 1;
  }

  .scroll-bottom {
    right: 16px;
    bottom: 132px;
  }

  .login-panel {
    padding: 24px;
  }

  .settings-form {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    flex-wrap: wrap;
  }

  .settings-actions button {
    flex: 1 1 140px;
  }
}
