:root {
  color-scheme: light;
  font-family: Inter, "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  background: #f3f5f7;
  color: #172033;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  display: grid;
  place-items: center;
  padding: 24px;
}

.chat-shell {
  width: min(760px, 100%);
  min-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  overflow: hidden;
  background: #ffffff;
  border: 1px solid #dfe4ea;
  border-radius: 20px;
  box-shadow: 0 18px 55px rgb(32 45 64 / 10%);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 28px;
  border-bottom: 1px solid #e9edf1;
}

.eyebrow {
  margin: 0 0 4px;
  color: #6a7483;
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
}

.current-thread-title {
  max-width: 280px;
  margin: 6px 0 0;
  overflow: hidden;
  color: #7a8492;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #6a7483;
  font-size: 13px;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.usage-control {
  position: relative;
}

.usage-button {
  font-variant-numeric: tabular-nums;
}

.usage-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 10px);
  right: 0;
  width: min(320px, calc(100vw - 32px));
  padding: 16px;
  color: #172033;
  background: #ffffff;
  border: 1px solid #dfe4ea;
  border-radius: 14px;
  box-shadow: 0 16px 42px rgb(32 45 64 / 18%);
}

.usage-panel-heading {
  margin-bottom: 12px;
  font-size: 14px;
  font-weight: 800;
}

.usage-bucket + .usage-bucket {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid #e9edf1;
}

.usage-bucket > strong {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
}

.usage-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 10px;
  padding: 7px 0;
  font-size: 13px;
}

.usage-row b {
  color: #18784d;
  font-variant-numeric: tabular-nums;
}

.usage-row small {
  grid-column: 1 / -1;
  color: #7a8492;
}

.usage-empty {
  margin: 0;
  color: #6a7483;
  font-size: 13px;
  line-height: 1.55;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #d49b27;
  box-shadow: 0 0 0 4px rgb(212 155 39 / 12%);
}

.status-dot.online {
  background: #20a66a;
  box-shadow: 0 0 0 4px rgb(32 166 106 / 12%);
}

.status-dot.offline {
  background: #d14e4e;
  box-shadow: 0 0 0 4px rgb(209 78 78 / 12%);
}

.messages {
  min-height: 320px;
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  padding: 28px;
}

.message {
  width: fit-content;
  max-width: 86%;
  margin-bottom: 18px;
  padding: 14px 16px;
  border-radius: 14px;
}

.message p {
  margin: 4px 0 0;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message p:empty {
  display: none;
}

.message-attachments {
  margin-top: 8px;
}

.message-attachments img {
  display: block;
  width: auto;
  max-width: min(360px, 70vw);
  max-height: 360px;
  object-fit: contain;
  border-radius: 10px;
}

.message-label {
  color: #6a7483;
  font-size: 12px;
  font-weight: 700;
}

.assistant-message {
  background: #f1f4f7;
}

.user-message {
  margin-left: auto;
  color: #ffffff;
  background: #172033;
}

.user-message .message-label {
  color: #c7cfda;
}

.error-message {
  color: #852929;
  background: #fff0f0;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 20px 24px 10px;
  border-top: 1px solid #e9edf1;
}

.composer-input {
  min-width: 0;
  display: grid;
  gap: 8px;
}

.pending-image {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 9px;
  background: #f5f7f9;
  border: 1px solid #dfe4ea;
  border-radius: 12px;
}

.pending-image img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 8px;
}

.pending-image div {
  min-width: 0;
  display: grid;
  gap: 4px;
}

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

.pending-image strong {
  font-size: 13px;
}

.pending-image span {
  color: #7a8492;
  font-size: 12px;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
}

textarea {
  width: 100%;
  min-height: 76px;
  resize: vertical;
  padding: 14px 15px;
  color: inherit;
  background: #fafbfc;
  border: 1px solid #d8dee6;
  border-radius: 12px;
  font: inherit;
  line-height: 1.5;
  outline: none;
}

textarea:focus {
  border-color: #73839a;
  box-shadow: 0 0 0 3px rgb(115 131 154 / 13%);
}

.effort-selector {
  width: fit-content;
  height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0 10px;
  color: #596579;
  background: #eef1f4;
  border: 1px solid transparent;
  border-radius: 999px;
  cursor: pointer;
}

.effort-selector:focus-within {
  border-color: #aab5c4;
  box-shadow: 0 0 0 3px rgb(115 131 154 / 10%);
}

.effort-selector select {
  appearance: none;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 0;
  outline: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.effort-arrow {
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
}

.attachment-button,
.remove-image-button {
  min-width: auto;
  width: auto;
  color: #445064;
  background: #eef1f4;
}

.attachment-button {
  height: 30px;
  padding: 0 11px;
  font-size: 12px;
}

.remove-image-button {
  align-self: center;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.attachment-button:hover:not(:disabled),
.remove-image-button:hover:not(:disabled) {
  background: #e2e7ec;
}

button {
  align-self: end;
  min-width: 92px;
  height: 46px;
  color: #ffffff;
  background: #172033;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #2a3850;
}

.secondary-button {
  min-width: auto;
  height: 34px;
  padding: 0 12px;
  color: #445064;
  background: #eef1f4;
  font-size: 13px;
}

.secondary-button:hover:not(:disabled) {
  background: #e2e7ec;
}

button:disabled,
textarea:disabled,
.effort-selector:has(select:disabled) {
  cursor: not-allowed;
  opacity: 0.6;
}

.effort-selector select:disabled {
  cursor: not-allowed;
}

.hint {
  margin: 0;
  padding: 0 24px 18px;
  color: #7a8492;
  font-size: 12px;
}

[hidden] {
  display: none !important;
}

.drawer-backdrop {
  position: fixed;
  z-index: 40;
  inset: 0;
  background: rgb(23 32 51 / 34%);
  backdrop-filter: blur(2px);
}

.history-drawer {
  position: fixed;
  z-index: 50;
  top: 0;
  right: 0;
  width: min(390px, 92vw);
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  color: #172033;
  background: #ffffff;
  border-left: 1px solid #dfe4ea;
  box-shadow: -18px 0 55px rgb(32 45 64 / 18%);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px;
  border-bottom: 1px solid #e9edf1;
}

.history-header h2 {
  margin: 0;
  font-size: 20px;
}

.icon-button {
  min-width: 38px;
  width: 38px;
  height: 38px;
  padding: 0;
  color: #445064;
  background: #eef1f4;
  font-size: 24px;
  line-height: 1;
}

.history-list {
  overflow-y: auto;
  padding: 12px;
}

.history-item {
  width: 100%;
  min-width: 0;
  height: auto;
  display: grid;
  gap: 6px;
  margin: 0 0 8px;
  padding: 13px 14px;
  text-align: left;
  color: #334055;
  background: #f5f7f9;
  border: 1px solid transparent;
  border-radius: 12px;
}

.history-item:hover:not(:disabled) {
  background: #edf1f5;
}

.history-item.current {
  color: #172033;
  background: #eef4ff;
  border-color: #cbd9f0;
}

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

.history-item span {
  color: #7a8492;
  font-size: 12px;
  font-weight: 500;
}

.history-item.loading {
  opacity: 0.65;
}

.history-empty {
  margin: 18px 10px;
  color: #7a8492;
  font-size: 13px;
  line-height: 1.6;
}

.error-copy {
  color: #a33333;
}

body.drawer-open {
  overflow: hidden;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.login-shell {
  width: min(420px, 100%);
  padding: 36px;
  background: #ffffff;
  border: 1px solid #dfe4ea;
  border-radius: 20px;
  box-shadow: 0 18px 55px rgb(32 45 64 / 10%);
}

.login-copy {
  margin: 10px 0 28px;
  color: #6a7483;
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label {
  font-size: 13px;
  font-weight: 700;
}

.login-form input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  color: inherit;
  background: #fafbfc;
  border: 1px solid #d8dee6;
  border-radius: 12px;
  font: inherit;
  outline: none;
}

.login-form input:focus {
  border-color: #73839a;
  box-shadow: 0 0 0 3px rgb(115 131 154 / 13%);
}

.login-form button {
  width: 100%;
  margin-top: 8px;
}

.login-error {
  min-height: 1.5em;
  margin: 16px 0 0;
  color: #a33333;
  font-size: 13px;
  line-height: 1.5;
}

@media (max-width: 560px) {
  body {
    padding: 0;
  }

  .chat-shell {
    min-height: 100vh;
    border: 0;
    border-radius: 0;
  }

  .chat-header,
  .messages {
    padding: 20px;
  }

  .chat-header {
    align-items: flex-start;
    gap: 12px;
  }

  .header-actions {
    max-width: 160px;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 8px;
  }

  .status {
    width: 100%;
    justify-content: flex-end;
  }

  .usage-panel {
    position: fixed;
    top: 86px;
    right: 12px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 16px 20px 10px;
  }

  button {
    width: 100%;
  }

  .secondary-button {
    width: auto;
  }

  .attachment-button,
  .remove-image-button {
    width: auto;
  }

  .login-shell {
    min-height: 100vh;
    display: grid;
    align-content: center;
    border: 0;
    border-radius: 0;
  }
}
