:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #eef2f7;
  --line: #dce3ed;
  --text: #18202f;
  --muted: #6f7b8d;
  --accent: #1769e0;
  --accent-strong: #0f55bd;
  --success: #16835f;
  --warning: #a46608;
  --danger: #c23b36;
  --shadow: 0 12px 32px rgba(20, 32, 52, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family:
    "Microsoft YaHei UI",
    "Microsoft YaHei",
    "Segoe UI",
    Arial,
    sans-serif;
}

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

button {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
}

button:hover {
  border-color: #b7c4d7;
}

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

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

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

button.secondary,
button.subtle {
  color: #dbeafe;
  border-color: rgba(219, 234, 254, 0.18);
  background: rgba(219, 234, 254, 0.08);
}

button.compact {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

button.danger {
  color: #fecaca;
  border-color: rgba(194, 59, 54, 0.35);
  background: rgba(194, 59, 54, 0.16);
}

button.danger:hover {
  border-color: rgba(248, 113, 113, 0.7);
  background: rgba(194, 59, 54, 0.24);
}

button.full-width {
  width: 100%;
  margin-top: 12px;
}

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

.account-pane {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 20px;
  background: #111827;
  color: #f9fafb;
}

.brand {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.brand p {
  margin: 6px 0 0;
  color: #aab4c5;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-width: 64px;
  justify-content: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  white-space: nowrap;
}

.badge-idle {
  background: #374151;
  color: #e5e7eb;
}

.badge-online {
  background: rgba(22, 131, 95, 0.18);
  color: #67e8b9;
}

.badge-error {
  background: rgba(194, 59, 54, 0.2);
  color: #ffb4af;
}

.panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.05);
}

.section-title {
  margin-bottom: 12px;
  color: #cbd5e1;
  font-size: 13px;
}

.account-list {
  display: grid;
  gap: 12px;
}

.account-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.account-body {
  min-width: 0;
}

.account-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-name-wrap {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  color: #fff;
  background: #263246;
  font-weight: 700;
}

.account-name,
.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title {
  flex: 1;
  min-width: 0;
}

.account-meta {
  margin-top: 4px;
  color: #aab4c5;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.account-meta-error {
  color: #fecaca;
}

.unread-badge {
  display: inline-flex;
  flex: none;
  min-width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border-radius: 999px;
  color: #fff;
  background: #e11d48;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
}

.account-unread {
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.94);
}

.conversation-unread {
  min-width: 20px;
}

.conversation-douyin-id {
  margin-top: 3px;
  color: #64748b;
  font-size: 12px;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 86px;
  gap: 8px;
  margin-top: 14px;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.log-item {
  border-left: 3px solid #64748b;
  padding-left: 8px;
  color: #d5dce8;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.log-success {
  border-color: var(--success);
}

.log-error {
  border-color: var(--danger);
}

.log-warn {
  border-color: var(--warning);
}

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

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

.toolbar strong {
  margin-right: 10px;
  font-size: 18px;
}

.toolbar span {
  color: var(--muted);
  font-size: 13px;
}

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

.account-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.filter-chip {
  height: 32px;
  padding: 0 11px;
  color: var(--muted);
  background: var(--surface);
}

.filter-chip.active {
  color: #fff;
  border-color: var(--accent);
  background: var(--accent);
}

.inbox-layout {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  height: calc(100vh - 64px);
  min-height: 0;
}

.conversation-pane {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--line);
  background: #f9fbfe;
}

.conversation-list {
  height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
}

.conversation-item {
  display: grid;
  gap: 7px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}

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

.conversation-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}

.conversation-main {
  min-width: 0;
}

.conversation-avatar,
.chat-avatar {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
  background: #dbe5f2;
}

.avatar-fallback {
  display: grid;
  place-items: center;
  color: #30415c;
  font-weight: 700;
}

.conversation-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.conversation-actions {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
}

.conversation-time {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.icon-action {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border-color: transparent;
  font-size: 12px;
}

.icon-action:hover {
  color: var(--danger);
  border-color: rgba(194, 59, 54, 0.24);
  background: rgba(194, 59, 54, 0.08);
}

.conversation-preview {
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-tag {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  margin: 4px 0 2px;
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--accent-strong);
  background: #e8f1ff;
  font-size: 11px;
}

.source-tag.warning {
  color: #9a5b00;
  background: #fff4d6;
}

.source-tag.danger {
  color: var(--danger);
  background: rgba(194, 59, 54, 0.1);
}

.chat-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  background: var(--bg);
  overflow: hidden;
}

.empty-state {
  place-self: center;
  width: min(420px, 88%);
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 22px;
}

.chat-view {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: 74px minmax(0, 1fr) 110px;
}

.hidden {
  display: none;
}

.login-view {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(135deg, #0f172a, #1e293b);
}

.login-view.hidden {
  display: none;
}

.login-card {
  width: min(380px, 100%);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #e5eefc;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.32);
}

.login-card h1 {
  margin: 0 0 8px;
}

.login-card p {
  margin: 0 0 20px;
  color: #b7c4d7;
}

.login-card label {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.login-card input,
.admin-card input,
.admin-card select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
}

.login-error {
  min-height: 20px;
  margin-top: 12px;
  color: #fecaca;
  font-size: 13px;
}

.staff-name {
  margin-top: 8px;
  font-size: 20px;
  font-weight: 700;
}

.admin-link {
  display: inline-block;
  margin-top: 12px;
  color: #bfdbfe;
  text-decoration: none;
}

.admin-link:hover {
  text-decoration: underline;
}

.admin-shell {
  min-height: 100vh;
  overflow: auto;
  background: var(--bg);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.admin-header h1 {
  margin: 0;
  font-size: 24px;
}

.admin-header p {
  margin: 5px 0 0;
  color: var(--muted);
}

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

.admin-actions a {
  color: var(--accent-strong);
  text-decoration: none;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(320px, 0.8fr);
  gap: 18px;
  padding: 22px 28px 34px;
}

.admin-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.admin-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.admin-list {
  display: grid;
  gap: 10px;
}

.admin-account-row,
.admin-staff-row,
.admin-stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px auto auto auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.admin-staff-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.admin-stat-row {
  grid-template-columns: minmax(0, 1fr) auto auto auto;
}

.admin-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.admin-empty {
  color: var(--muted);
  font-size: 14px;
}

.admin-log-list {
  max-height: 430px;
  overflow: auto;
}

.chat-header {
  display: flex;
  align-items: center;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.chat-header h2 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 18px;
}

.chat-avatar {
  width: 44px;
  height: 44px;
}

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

.message-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 22px;
}

.message {
  align-self: flex-start;
  max-width: min(720px, 82%);
  border-radius: 8px;
  padding: 10px 12px 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.message.agent {
  align-self: flex-end;
  background: #dbeafe;
}

.message.system {
  align-self: center;
  max-width: 76%;
  color: var(--muted);
  background: var(--surface-soft);
  box-shadow: none;
  font-size: 13px;
}

.message-content {
  line-height: 1.55;
  word-break: break-word;
}

.message-time {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

.message.system .message-time {
  text-align: center;
}

.message-note {
  color: var(--text);
}

.message-inline-link,
.message-card-link {
  color: var(--accent-strong);
  text-decoration: none;
}

.message-inline-link:hover,
.message-card-link:hover {
  text-decoration: underline;
}

.message-media-block {
  display: grid;
  gap: 8px;
}

.message-image-link {
  display: inline-flex;
  width: fit-content;
}

.message-inline-image {
  display: block;
  max-width: min(280px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.message-card {
  display: grid;
  grid-template-columns: 116px minmax(0, 1fr);
  gap: 12px;
  min-width: 260px;
}

.message-card-cover {
  display: block;
}

.message-card-cover img {
  display: block;
  width: 116px;
  height: 116px;
  border-radius: 8px;
  object-fit: cover;
  background: #eef2f7;
}

.message-card-body {
  display: grid;
  align-content: start;
  gap: 8px;
}

.message-card-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.35;
}

.message-card-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 12px;
  align-items: stretch;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.composer textarea {
  width: 100%;
  min-height: 80px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  background: #f8fafc;
  outline: none;
}

.composer textarea:focus {
  border-color: #b7c4d7;
}

.composer textarea:disabled {
  color: var(--muted);
  background: #f1f5f9;
}

.composer-side {
  display: grid;
  grid-template-rows: 40px minmax(0, 1fr);
  gap: 8px;
}

.composer-actions {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
}

.composer-actions button {
  width: 100%;
}

.composer-actions .secondary {
  color: var(--text);
  border-color: var(--line);
  background: #f8fafc;
}

.composer-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.composer-hint.is-error {
  color: var(--danger);
}

.composer-hint.is-success {
  color: var(--success);
}

.composer-hint.is-info {
  color: var(--muted);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.46);
}

.modal-backdrop.hidden {
  display: none;
}

.modal {
  display: grid;
  gap: 16px;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border-radius: 8px;
  padding: 20px;
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.25);
}

.auth-modal {
  width: min(430px, 100%);
}

#adminAuthModal .auth-modal {
  width: min(880px, 100%);
}

.modal-header,
.modal-footer,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.modal-header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.modal-grid {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

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

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  color: var(--text);
  background: #f8fafc;
  outline: none;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #b7c4d7;
}

.modal-status {
  flex: 1;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.modal-status.is-error {
  color: var(--danger);
}

.modal-status.is-success {
  color: var(--success);
}

.auth-qr-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.auth-modal-grid {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(280px, 1fr);
  gap: 14px;
}

.auth-page-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 280px;
  max-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
}

.auth-page-box img {
  max-width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.auth-qr-box img {
  width: min(260px, 82vw);
  height: min(260px, 82vw);
  border-radius: 8px;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 14px 38px rgba(15, 23, 42, 0.12);
}

.auth-qr-placeholder {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.local-auth-box {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.local-auth-box p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.local-auth-box textarea {
  width: 100%;
  min-height: 92px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  background: #fff;
  font-family: Consolas, Monaco, "Courier New", monospace;
  font-size: 12px;
}

.auth-status {
  text-align: left;
  line-height: 1.5;
}

.user-results {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.user-result {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
  cursor: pointer;
}

.user-result:hover,
.user-result.active {
  border-color: #b7c4d7;
  background: #eef6ff;
}

.user-result-title {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-fields {
  display: grid;
  gap: 4px;
  margin-top: 8px;
}

.user-field {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.user-field span {
  color: #64748b;
}

.user-field strong {
  min-width: 0;
  color: var(--text);
  font-weight: 500;
  overflow-wrap: anywhere;
}

.user-field a {
  color: #2563eb;
  text-decoration: none;
}

.user-result-meta,
.user-result-signature {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

@media (max-width: 960px) {
  html,
  body {
    overflow: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(220px, 42vh) minmax(0, 1fr);
    height: 100vh;
    min-height: 0;
  }

  .account-pane {
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .workspace {
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }

  .inbox-layout {
    grid-template-columns: 1fr;
    grid-template-rows: 240px minmax(0, 1fr);
    height: 100%;
    min-height: 0;
  }

  .conversation-list {
    height: 100%;
  }

  .chat-pane {
    min-height: 0;
  }

  .chat-view {
    min-height: 0;
    grid-template-rows: 74px minmax(0, 1fr) 140px;
  }

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

  .composer-side {
    grid-template-rows: 40px auto;
  }

  .message-card {
    grid-template-columns: 1fr;
  }

  .message-card-cover img {
    width: 100%;
    max-width: 280px;
    height: auto;
    aspect-ratio: 1 / 1;
  }

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

  .auth-modal-grid {
    grid-template-columns: 1fr;
  }
}
