:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f6f8f8;
  --surface-active: #e9f7f2;
  --text: #15191d;
  --muted: #687078;
  --border: #dce2e5;
  --border-strong: #cbd3d7;
  --accent: #008c61;
  --accent-dark: #00754f;
  --danger: #d64545;
  --warning: #a26908;
  --radius-sm: 8px;
  --radius: 12px;
  --sidebar-chat: 280px;
  --sidebar-admin: 240px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.brand {
  display: inline-block;
  color: #101316;
  font-size: 31px;
  font-weight: 760;
  letter-spacing: -1.2px;
  line-height: 1;
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 640;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease;
}

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

.button.primary:hover {
  background: var(--accent-dark);
}

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

.button.secondary:hover {
  background: var(--surface-soft);
}

.button.full {
  width: 100%;
}

.button:disabled,
.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button:focus-visible,
.icon-button:focus-visible,
.text-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgb(0 140 97 / 18%);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: var(--sidebar-chat) minmax(0, 1fr);
}

.admin-shell {
  grid-template-columns: var(--sidebar-admin) minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  height: 100vh;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--border);
  background: #fff;
}

.sidebar-top {
  min-height: 0;
  padding: 31px 22px 20px;
}

.chat-sidebar .sidebar-top {
  display: flex;
  flex: 1;
  flex-direction: column;
}

.new-chat {
  width: 100%;
  margin-top: 34px;
  min-height: 49px;
  font-size: 16px;
}

.sidebar-label {
  margin: 31px 7px 11px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.conversation-list {
  min-height: 0;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  width: 100%;
  min-height: 45px;
  align-items: center;
  gap: 11px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: #353b40;
  cursor: pointer;
  text-align: left;
}

.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.conversation-item.active {
  background: var(--surface-active);
  color: var(--accent-dark);
  font-weight: 620;
}

.sidebar-empty {
  margin: 18px 11px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-account {
  padding: 19px 22px 24px;
  border-top: 1px solid var(--border);
}

.account-line,
.account-link,
.logout-button {
  display: flex;
  min-height: 43px;
  align-items: center;
  gap: 11px;
}

.account-link {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 14px;
}

.account-link:hover {
  color: var(--accent-dark);
}

.avatar {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--text);
  border-radius: 50%;
  font-size: 13px;
}

.logout-button {
  width: 100%;
  margin-top: 5px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #373d42;
  cursor: pointer;
  text-align: left;
}

.logout-button:hover {
  color: var(--danger);
}

.chat-main {
  display: grid;
  height: 100vh;
  min-width: 0;
  grid-template-rows: 70px minmax(0, 1fr) auto;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 31px;
  border-bottom: 1px solid var(--border);
}

.chat-header h1 {
  overflow: hidden;
  margin: 0;
  font-size: 20px;
  font-weight: 680;
  letter-spacing: -0.2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-button,
.mobile-menu {
  display: inline-flex;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.icon-button:hover,
.mobile-menu:hover {
  border-color: var(--border);
  background: var(--surface-soft);
  color: var(--text);
}

.mobile-menu {
  display: none;
}

.sidebar-close {
  display: none;
}

.message-stage {
  min-height: 0;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.messages {
  width: min(940px, calc(100% - 72px));
  margin: 0 auto;
  padding: 40px 0 32px;
}

.message-row {
  display: flex;
  width: 100%;
  margin-bottom: 29px;
}

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

.message-row.assistant {
  align-items: flex-start;
  gap: 14px;
}

.message-bubble {
  max-width: 82%;
  padding: 17px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: #252a2f;
  line-height: 1.78;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message-row.user .message-bubble {
  border-color: #8ed5bb;
  background: #f0faf6;
}

.message-row.assistant .message-bubble {
  flex: 1;
  max-width: calc(100% - 52px);
}

.bot-mark,
.empty-mark {
  display: inline-flex;
  width: 37px;
  height: 37px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--accent);
  border-radius: 50%;
  background: #edf9f4;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 720;
}

.empty-chat {
  display: grid;
  min-height: 48vh;
  place-items: center;
  align-content: center;
  text-align: center;
}

.empty-chat h2 {
  margin: 18px 0 6px;
  font-size: 21px;
  letter-spacing: -0.2px;
}

.empty-chat p {
  margin: 0;
  color: var(--muted);
}

.composer-wrap {
  padding: 0 34px 20px;
  background: #fff;
}

.composer {
  width: min(990px, 100%);
  margin: 0 auto;
  padding: 18px 18px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}

.composer:focus-within {
  border-color: #7fcab0;
  box-shadow: 0 0 0 3px rgb(0 140 97 / 8%);
}

.composer textarea {
  width: 100%;
  min-height: 68px;
  resize: none;
  border: 0;
  outline: 0;
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}

.composer textarea::placeholder {
  color: #949ba1;
}

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

#character-count {
  color: var(--muted);
  font-size: 12px;
}

.send-button {
  min-width: 86px;
}

.grounding-note {
  width: min(990px, 100%);
  margin: 8px auto 0;
  color: #7a8288;
  font-size: 12px;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
  background: #fff;
}

.auth-panel {
  width: min(400px, 100%);
  padding: 8px 8px 18px;
}

.auth-brand {
  margin-bottom: 62px;
}

.auth-panel h1 {
  margin: 0 0 8px;
  font-size: 25px;
  letter-spacing: -0.4px;
}

.auth-copy {
  margin: 0 0 31px;
  color: var(--muted);
}

.form-stack,
.modal-form {
  display: grid;
  gap: 18px;
}

.form-stack label,
.modal-form label {
  display: grid;
  gap: 7px;
  color: #454b50;
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font-size: 14px;
  outline: 0;
}

.form-error {
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--danger);
  font-size: 13px;
}

.admin-nav {
  display: grid;
  gap: 5px;
  margin-top: 50px;
}

.admin-nav a {
  display: flex;
  min-height: 49px;
  align-items: center;
  gap: 12px;
  margin: 0 -22px;
  padding: 0 24px 0 31px;
  border-left: 3px solid transparent;
  color: #353b40;
  font-size: 15px;
}

.admin-nav a:hover {
  background: var(--surface-soft);
}

.admin-nav a.active {
  border-left-color: var(--accent);
  background: var(--surface-active);
  color: var(--accent-dark);
  font-weight: 650;
}

.admin-main {
  min-width: 0;
  padding: 34px 42px 56px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 43px;
}

.admin-header h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.6px;
}

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

.version-section > h2,
.table-section > h2,
.sync-notes > h2 {
  margin: 0 0 13px;
  font-size: 18px;
  font-weight: 680;
}

.version-grid {
  display: grid;
  margin: 0;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.version-grid > div {
  min-width: 0;
  padding: 0 28px;
  border-right: 1px solid var(--border);
}

.version-grid > div:first-child {
  padding-left: 22px;
}

.version-grid > div:last-child {
  border-right: 0;
}

.version-grid dt {
  margin-bottom: 13px;
  color: var(--muted);
  font-size: 12px;
}

.version-grid dd {
  overflow: hidden;
  margin: 0;
  font-size: 17px;
  font-weight: 610;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-text,
.result {
  color: var(--muted);
}

.status-text i,
.result i {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: #9aa2a8;
}

.status-text.ready,
.result.success {
  color: var(--accent-dark);
}

.status-text.ready i,
.result.success i {
  background: var(--accent);
}

.result.failed {
  color: #6c4444;
}

.result.failed i {
  background: #ec5656;
}

.result.running i,
.result.pending i {
  background: #d49a24;
}

.sync-progress {
  margin: 28px 0 33px;
  padding: 20px 25px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.sync-progress.hidden {
  display: none;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.progress-track {
  height: 4px;
  margin-top: 14px;
  overflow: hidden;
  background: #e7ebed;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent);
  transition: width 220ms ease;
}

.admin-columns {
  display: grid;
  gap: 31px;
  grid-template-columns: minmax(0, 1fr) 290px;
}

.table-section {
  min-width: 0;
}

.table-section.wide {
  width: 100%;
}

.table-scroll {
  overflow-x: auto;
  border-top: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 15px 13px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: #4d545a;
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

td {
  color: #292e33;
}

.mono {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 12px;
}

.empty-cell {
  padding: 48px 14px;
  color: var(--muted);
  text-align: center;
}

.sync-notes {
  padding-left: 25px;
  border-left: 1px solid var(--border);
}

.sync-notes ol {
  display: grid;
  gap: 21px;
  margin: 0;
  padding: 17px 0 0 23px;
  border-top: 1px solid var(--border);
  color: #40464b;
  font-size: 13px;
  line-height: 1.65;
}

.text-button {
  padding: 2px;
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 620;
  cursor: pointer;
}

.text-button:hover {
  text-decoration: underline;
}

.table-actions {
  display: flex;
  gap: 14px;
  white-space: nowrap;
}

.audit-question {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal {
  width: min(480px, calc(100% - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 22px 60px rgb(20 27 32 / 16%);
}

.modal::backdrop {
  background: rgb(12 18 22 / 28%);
}

.modal-form {
  padding: 24px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.modal-head h2 {
  margin: 0;
  font-size: 19px;
}

.modal-head .icon-button {
  font-size: 25px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.audit-modal {
  width: min(720px, calc(100% - 32px));
}

.audit-detail-list {
  display: grid;
  gap: 20px;
  margin: 0;
}

.audit-detail-list div {
  display: grid;
  gap: 6px;
}

.audit-detail-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.audit-detail-list dd {
  max-height: 240px;
  margin: 0;
  overflow-y: auto;
  color: #2b3035;
  white-space: pre-wrap;
}

.toast {
  position: fixed;
  right: 28px;
  bottom: 26px;
  z-index: 50;
  max-width: 420px;
  margin: 0;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: 0 12px 35px rgb(20 27 32 / 12%);
  color: var(--text);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

.admin-mobile-menu {
  position: absolute;
  top: 24px;
  left: 20px;
}

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

  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-102%);
    width: min(300px, 86vw);
    box-shadow: 18px 0 45px rgb(18 26 31 / 14%);
    transition: transform 180ms ease;
  }

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

  .mobile-menu {
    display: inline-flex;
  }

  .sidebar-close {
    position: absolute;
    top: 20px;
    right: 14px;
    display: inline-flex;
  }

  .chat-header {
    padding: 0 18px;
  }

  .chat-header h1 {
    flex: 1;
    margin: 0 12px;
    font-size: 17px;
  }

  .messages {
    width: calc(100% - 32px);
    padding-top: 26px;
  }

  .message-bubble {
    max-width: 90%;
  }

  .composer-wrap {
    padding: 0 16px 14px;
  }

  .admin-main {
    padding: 80px 20px 40px;
  }

  .admin-mobile-menu {
    display: inline-flex;
  }

  .version-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .version-grid > div {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
  }

  .version-grid > div:nth-child(2) {
    border-right: 0;
  }

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

  .sync-notes {
    padding-left: 0;
    border-left: 0;
  }
}

@media (max-width: 560px) {
  .chat-main {
    grid-template-rows: 60px minmax(0, 1fr) auto;
  }

  .messages {
    width: calc(100% - 22px);
  }

  .message-row.assistant {
    gap: 8px;
  }

  .bot-mark {
    width: 30px;
    height: 30px;
  }

  .message-row.assistant .message-bubble {
    max-width: calc(100% - 38px);
  }

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

  .composer textarea {
    min-height: 54px;
  }

  .grounding-note {
    display: none;
  }

  .admin-header {
    display: grid;
  }

  .admin-header .button {
    width: 100%;
  }

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

  .version-grid > div {
    border-right: 0;
  }
}

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