:root {
  color-scheme: light;
  --ink: #17201f;
  --ink-soft: #3c4946;
  --muted: #71807b;
  --canvas: #edf1ed;
  --surface: #ffffff;
  --surface-soft: #f7f9f6;
  --line: #dce4de;
  --line-strong: #cbd7cf;
  --accent: #0c756c;
  --accent-deep: #075b55;
  --accent-pale: #dcefeb;
  --coral: #d97959;
  --coral-pale: #f7e5dd;
  --warning: #b26d25;
  --danger: #a7433d;
  --shadow: 0 14px 34px rgba(29, 55, 48, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--canvas);
}

body {
  color: var(--ink);
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(12, 117, 108, 0.23);
  outline-offset: 2px;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  display: grid;
  width: 100%;
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  grid-template-rows: 72px minmax(0, 1fr);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 30px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--accent);
}

.brand-mark .icon {
  width: 22px;
  height: 22px;
}

.brand-copy {
  display: grid;
  gap: 1px;
}

.brand-copy strong {
  font-size: 17px;
  line-height: 1.1;
  letter-spacing: 0;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 12px;
  white-space: nowrap;
}

.status-dot,
.service-indicator {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
}

.status-badge[data-state="online"] .status-dot,
.service-indicator[data-state="online"] {
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-pale);
}

.status-badge[data-state="warning"] .status-dot,
.service-indicator[data-state="warning"] {
  background: var(--warning);
  box-shadow: 0 0 0 4px #f5e8d6;
}

.status-badge[data-state="offline"] .status-dot,
.service-indicator[data-state="offline"] {
  background: var(--danger);
  box-shadow: 0 0 0 4px #f4dddb;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
  background: var(--surface);
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}

.icon-button:hover {
  border-color: var(--line-strong);
  color: var(--accent-deep);
  background: var(--surface-soft);
}

.icon-button:active {
  transform: translateY(1px);
}

.accent-button {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.accent-button:hover {
  border-color: var(--accent-deep);
  color: #fff;
  background: var(--accent-deep);
}

.workspace {
  display: grid;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) 310px;
}

.chat-column {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  background: var(--canvas);
}

.conversation-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  width: min(930px, calc(100% - 64px));
  margin: 0 auto;
  padding: 42px 0 22px;
}

.section-kicker {
  display: block;
  color: var(--accent);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0;
  line-height: 1.3;
}

.title-block h1,
.inspector-heading h2,
.dialog-header h2,
.welcome-panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.title-block h1 {
  margin-top: 7px;
  font-size: clamp(24px, 3vw, 34px);
  font-weight: 720;
  line-height: 1.18;
}

.title-block p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.text-button,
.outline-button,
.primary-button,
.small-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 650;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}

.text-button {
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid transparent;
  color: var(--muted);
  background: transparent;
}

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

.welcome-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px 15px;
  width: min(930px, calc(100% - 64px));
  margin: 0 auto 5px;
  padding: 17px 19px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--coral);
  border-radius: 8px;
  background: var(--surface);
}

.welcome-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  color: var(--coral);
  background: var(--coral-pale);
}

.welcome-icon .icon {
  width: 20px;
  height: 20px;
}

.welcome-panel h2 {
  font-size: 15px;
  font-weight: 720;
}

.welcome-panel p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.suggestions {
  display: flex;
  grid-column: 2;
  flex-wrap: wrap;
  gap: 7px;
}

.suggestion {
  min-height: 31px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink-soft);
  background: var(--surface-soft);
  font-size: 12px;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.suggestion:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-pale);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  width: min(930px, calc(100% - 64px));
  min-height: 0;
  margin: 0 auto;
  padding: 22px 0 18px;
  overflow-y: auto;
  scrollbar-color: var(--line-strong) transparent;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 88%;
  animation: message-in 220ms ease both;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.assistant-avatar {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  place-items: center;
  border: 1px solid #c2ded9;
  border-radius: 9px;
  color: var(--accent-deep);
  background: var(--accent-pale);
}

.assistant-avatar .icon {
  width: 18px;
  height: 18px;
}

.user-avatar {
  display: grid;
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  place-items: center;
  border: 1px solid #e9c1b2;
  border-radius: 9px;
  color: #8a4935;
  background: var(--coral-pale);
  font-size: 12px;
  font-weight: 760;
}

.message-stack {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 11px;
}

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

.message-bubble {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-soft);
  background: var(--surface);
  font-size: 14px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .message-bubble {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.message-tools {
  display: flex;
  min-height: 20px;
  align-items: center;
  gap: 5px;
}

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

.copy-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

.copy-button:hover {
  color: var(--accent-deep);
}

.copy-button .icon {
  width: 14px;
  height: 14px;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 9px;
  width: min(930px, calc(100% - 64px));
  margin: 0 auto;
  padding: 0 0 14px;
  color: var(--muted);
  font-size: 12px;
}

.small-avatar {
  width: 27px;
  height: 27px;
  flex-basis: 27px;
  border-radius: 8px;
}

.small-avatar .icon {
  width: 15px;
  height: 15px;
}

.typing-dots {
  display: inline-flex;
  gap: 3px;
}

.typing-dots i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-pulse 1s infinite ease-in-out;
}

.typing-dots i:nth-child(2) {
  animation-delay: 120ms;
}

.typing-dots i:nth-child(3) {
  animation-delay: 240ms;
}

.error-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(930px, calc(100% - 64px));
  margin: 0 auto 12px;
  padding: 10px 12px;
  border: 1px solid #e4b9b4;
  border-radius: 7px;
  color: #7e3732;
  background: #fff4f2;
  font-size: 12px;
}

.error-actions {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: 0 0 auto;
}

.small-action {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid #d99d96;
  color: #7e3732;
  background: transparent;
}

.small-action:hover {
  background: #fbe5e1;
}

.tiny-button {
  width: 28px;
  height: 28px;
  border-color: transparent;
  color: #8d514c;
  background: transparent;
}

.tiny-button:hover {
  background: #fbe5e1;
}

.composer-wrap {
  padding: 0 0 calc(24px + env(safe-area-inset-bottom));
  background: var(--canvas);
}

.composer {
  width: min(930px, calc(100% - 64px));
  margin: 0 auto;
  padding: 10px 12px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer-main {
  display: flex;
  min-width: 0;
  align-items: flex-end;
  gap: 10px;
}

#messageInput {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  max-height: 150px;
  flex: 1 1 auto;
  padding: 9px 2px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 14px;
  line-height: 1.55;
}

#messageInput::placeholder {
  color: #9aa7a1;
}

.send-button {
  display: inline-flex;
  min-width: 79px;
  height: 42px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  color: #fff;
  background: var(--accent);
  font-size: 13px;
  font-weight: 700;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.send-button:hover {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
}

.send-button:active {
  transform: translateY(1px);
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.security-note {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.security-note .icon {
  width: 12px;
  height: 12px;
}

.inspector {
  display: flex;
  min-height: 0;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.inspector-heading {
  padding: 42px 26px 24px;
  border-bottom: 1px solid var(--line);
}

.inspector-heading h2 {
  margin-top: 7px;
  font-size: 20px;
  font-weight: 720;
}

.inspector-section {
  padding: 24px 26px;
  border-bottom: 1px solid var(--line);
}

.section-label {
  margin-bottom: 15px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0;
  text-transform: uppercase;
}

.service-status-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.service-status-row strong,
.service-status-row span {
  display: block;
}

.service-status-row strong {
  font-size: 14px;
}

.service-status-row span:not(.service-indicator) {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.detail-list {
  display: grid;
  gap: 10px;
  margin: 22px 0 18px;
}

.detail-list div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.detail-list dt {
  color: var(--muted);
}

.detail-list dd {
  max-width: 175px;
  margin: 0;
  overflow: hidden;
  color: var(--ink-soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.outline-button,
.primary-button {
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  background: var(--surface);
}

.outline-button:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-pale);
}

.inspector-section .outline-button {
  width: 100%;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.stat {
  display: grid;
  gap: 2px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
}

.stat strong {
  font-size: 21px;
  font-weight: 720;
}

.stat span {
  color: var(--muted);
  font-size: 11px;
}

.inspector-footer {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding: 22px 26px;
  color: var(--muted);
  font-size: 11px;
}

.footer-note {
  display: flex;
  align-items: center;
  gap: 8px;
}

.footer-mark {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--coral);
}

.version-label {
  color: #9aa7a1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
}

.settings-dialog {
  width: min(460px, calc(100% - 30px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(26, 49, 43, 0.2);
}

.settings-dialog::backdrop {
  background: rgba(24, 38, 34, 0.35);
}

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

.dialog-header h2 {
  margin-top: 6px;
  font-size: 21px;
  font-weight: 720;
}

.settings-form {
  display: grid;
  gap: 8px;
  padding: 22px 24px 24px;
}

.settings-form label {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}

.settings-form label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.settings-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: 0;
  color: var(--ink);
  background: var(--surface-soft);
  font-size: 13px;
}

.settings-form input:focus {
  border-color: var(--accent);
  background: var(--surface);
}

.field-hint {
  margin: -2px 0 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

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

.primary-button {
  border-color: var(--accent);
  color: #fff;
  background: var(--accent);
}

.primary-button:hover {
  border-color: var(--accent-deep);
  background: var(--accent-deep);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 5;
  max-width: min(360px, calc(100% - 44px));
  padding: 10px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--ink-soft);
  background: var(--surface);
  box-shadow: var(--shadow);
  font-size: 12px;
}

[hidden] {
  display: none !important;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .inspector {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-shell {
    grid-template-rows: 62px minmax(0, 1fr);
  }

  .topbar {
    padding: 0 15px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 9px;
  }

  .brand-copy small {
    display: none;
  }

  .status-badge {
    display: inline-flex;
    min-height: 30px;
    max-width: 96px;
    gap: 6px;
    padding: 0 8px;
    font-size: 11px;
  }

  #statusText {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    gap: 7px;
  }

  .icon-button {
    width: 37px;
    height: 37px;
  }

  .conversation-header,
  .welcome-panel,
  .messages,
  .typing-indicator,
  .error-banner,
  .composer {
    width: calc(100% - 30px);
  }

  .conversation-header {
    padding: 27px 0 16px;
  }

  .title-block h1 {
    font-size: 25px;
  }

  .text-button {
    min-width: 36px;
    padding: 0;
  }

  .text-button span {
    display: none;
  }

  .welcome-panel {
    grid-template-columns: auto minmax(0, 1fr);
    margin-bottom: 0;
  }

  .suggestions {
    grid-column: 1 / -1;
    margin-top: 2px;
  }

  .suggestion {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .messages {
    gap: 15px;
    padding-top: 17px;
  }

  .message {
    max-width: 94%;
  }

  .message-bubble {
    padding: 10px 12px;
    font-size: 13px;
  }

  .composer-wrap {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .composer {
    padding: 8px 9px 8px;
  }

  #messageInput,
  .settings-form input {
    font-size: 16px;
  }

  .send-button {
    min-width: 44px;
    width: 44px;
    padding: 0;
  }

  .send-label {
    display: none;
  }

  .composer-meta {
    font-size: 9px;
  }

  .security-note {
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .error-banner {
    align-items: flex-start;
  }
}

@media (max-width: 360px) {
  .topbar {
    gap: 8px;
    padding: 0 10px;
  }

  .brand {
    gap: 8px;
  }

  .status-badge {
    min-width: 56px;
    max-width: 56px;
    justify-content: center;
    padding: 0 6px;
  }

  .status-badge::after {
    content: attr(data-short-label);
  }

  #statusText {
    display: none;
  }
}

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