:root {
  color-scheme: light;
  --ink: #14232d;
  --muted: #5e6d75;
  --deep: #143642;
  --teal: #0f766e;
  --teal-dark: #0b5d57;
  --fog: #eef3f4;
  --paper: #ffffff;
  --line: #d6e0e2;
  --danger: #a33232;
  --danger-bg: #fff1f1;
  --focus: #b45309;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--fog);
  color: var(--ink);
}

body {
  min-width: 280px;
  overflow: hidden;
}

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

button,
summary,
select,
input[type="checkbox"] {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 860px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--paper);
  border-inline: 1px solid var(--line);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: max(14px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) 14px max(18px, env(safe-area-inset-left));
  background: var(--deep);
  color: #f8fcfc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  fill: none;
  stroke: #79d6c9;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand h1 {
  margin: 0;
  font-size: 1.12rem;
  letter-spacing: 0.01em;
}

.brand p {
  margin: 3px 0 0;
  color: #c7dadd;
  font-size: 0.78rem;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid #56717a;
  border-radius: 12px;
  background: transparent;
  color: #f8fcfc;
}

.icon-button:hover {
  background: #214b58;
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings {
  border-bottom: 1px solid var(--line);
  background: #f8fbfb;
}

.settings summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  font-weight: 650;
  list-style-position: inside;
}

.settings-summary {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-align: right;
}

.settings-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px 18px;
  padding: 0 18px 18px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
  font-size: 0.88rem;
  font-weight: 650;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid #afc0c4;
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  font-weight: 400;
}

.field-help {
  grid-column: 1 / -1;
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.55;
}

.toggle-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 44px;
}

.toggle-row span {
  display: grid;
  gap: 3px;
}

.toggle-row small {
  color: var(--muted);
  font-weight: 400;
}

.toggle-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--teal);
}

.chat-main {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.message-list {
  width: 100%;
  min-height: 100%;
  padding: 22px 18px 28px;
}

.empty-state {
  max-width: 390px;
  margin: 9vh auto 0;
  text-align: center;
  color: var(--muted);
}

.empty-state svg {
  width: 68px;
  height: 68px;
  fill: none;
  stroke: #6a9298;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h2 {
  margin: 18px 0 8px;
  color: var(--deep);
  font-size: 1.18rem;
}

.empty-state p {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.65;
}

.message {
  display: grid;
  gap: 6px;
  margin-bottom: 20px;
}

.message-meta {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
}

.message-content {
  max-width: 88%;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 5px var(--radius) var(--radius) var(--radius);
  background: #f6f9f9;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

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

.message.user .message-content {
  border-color: var(--teal);
  border-radius: var(--radius) 5px var(--radius) var(--radius);
  background: var(--teal);
  color: #ffffff;
}

.message.assistant.pending .message-content::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-left: 4px;
  vertical-align: -0.15em;
  background: var(--teal);
  animation: blink 0.9s steps(2, start) infinite;
}

.composer-area {
  padding: 10px max(16px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: #f8fbfb;
}

#chat-form {
  display: grid;
  gap: 10px;
}

#message-input {
  width: 100%;
  min-height: 52px;
  max-height: 150px;
  resize: none;
  overflow-y: auto;
  padding: 13px 14px;
  border: 1px solid #afc0c4;
  border-radius: 13px;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.5;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.status-text {
  min-width: 0;
  margin-right: auto;
  color: var(--muted);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 9px 18px;
  border-radius: 11px;
  font-weight: 650;
}

.primary-button {
  border: 1px solid var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  border-color: var(--teal-dark);
  background: var(--teal-dark);
}

.secondary-button {
  border: 1px solid #9fb2b7;
  background: transparent;
  color: var(--deep);
}

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

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.privacy-note {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.45;
  text-align: center;
}

.error-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
  padding: 10px 12px;
  border: 1px solid #dfa8a8;
  border-radius: 10px;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 0.82rem;
  line-height: 1.5;
}

.error-banner span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.error-banner button {
  flex: 0 0 auto;
  margin-left: auto;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-decoration: underline;
}

.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;
}

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

@media (max-width: 600px) {
  .app-shell {
    border-inline: 0;
  }

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

  .field-help,
  .toggle-row {
    grid-column: auto;
  }

  .settings-body .secondary-button {
    width: 100%;
  }

  .message-list {
    padding-inline: 14px;
  }

  .message-content {
    max-width: 94%;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
