:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #f9fbff;
  --text: #182230;
  --muted: #607086;
  --line: #dbe3ee;
  --brand: #0d7c8a;
  --brand-dark: #075963;
  --accent: #e0653b;
  --ok: #1d8f5a;
  --warn: #b77800;
  --danger: #c84545;
  --shadow: 0 18px 50px rgba(34, 51, 79, 0.12);
  --radius: 8px;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(13, 124, 138, 0.09), transparent 280px),
    var(--bg);
  color: var(--text);
}

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

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

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 26px 28px 18px;
}

.topbar h1,
.section-head h2 {
  margin: 0;
  line-height: 1.15;
}

.topbar h1 {
  font-size: clamp(25px, 4vw, 40px);
}

.section-head h2 {
  font-size: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 700;
}

.top-actions,
.section-head,
.row-actions,
.quick-strip,
.composer,
.inline-form,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.ghost-button,
.icon-button,
.primary-button,
.quick-strip button,
.row-actions button,
.command-help button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  padding: 9px 13px;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.ghost-button:hover,
.icon-button:hover,
.quick-strip button:hover,
.row-actions button:hover,
.command-help button:hover {
  border-color: rgba(13, 124, 138, 0.45);
  background: #eef8f9;
}

.primary-button {
  border-color: var(--brand);
  background: var(--brand);
  color: white;
  font-weight: 700;
}

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

.danger-lite {
  color: var(--danger);
}

.chat-layout,
.admin-layout {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 28px 36px;
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.admin-layout {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 18px;
}

.work-surface,
.stat-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.work-surface {
  padding: 18px;
}

.wide {
  grid-column: 1 / -1;
}

.chat-surface {
  min-height: calc(100vh - 130px);
  display: grid;
  grid-template-rows: auto minmax(360px, 1fr) auto auto;
  gap: 14px;
}

.live-panel {
  align-self: start;
  position: sticky;
  top: 16px;
}

.section-head {
  justify-content: space-between;
  align-items: flex-start;
}

.status-pill,
.tag,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill {
  color: var(--ok);
  background: rgba(29, 143, 90, 0.1);
}

.tag {
  color: var(--accent);
  background: rgba(224, 101, 59, 0.11);
}

.messages {
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  padding: 14px;
}

.message {
  max-width: 76%;
  margin: 0 0 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
}

.message p {
  margin: 8px 0 0;
  white-space: pre-wrap;
  line-height: 1.55;
  word-break: break-word;
}

.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 12px;
}

.user-message {
  margin-left: auto;
  border-color: rgba(13, 124, 138, 0.28);
  background: #eaf7f7;
}

.bot-message {
  margin-right: auto;
}

.quick-strip {
  flex-wrap: wrap;
}

.composer {
  align-items: flex-end;
  gap: 12px;
  padding-top: 2px;
}

.field {
  display: grid;
  gap: 7px;
  align-content: start;
}

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

.field input,
.field select,
.field textarea,
.inline-form input,
.inline-form select,
.stack-form input,
.stack-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 9px 11px;
  outline: none;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.inline-form input:focus,
.inline-form select:focus,
.stack-form input:focus,
.stack-form select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13, 124, 138, 0.12);
}

.field textarea {
  min-height: 150px;
  resize: vertical;
  line-height: 1.55;
}

.compact-field {
  width: 150px;
}

.room-field {
  width: 180px;
}

.message-field {
  flex: 1;
  min-width: 240px;
}

.check-field {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.queue-headline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
  color: var(--muted);
}

.queue-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.queue-list li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 8px;
}

.queue-rank {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--brand);
  color: white;
  font-weight: 800;
}

.queue-list small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.empty-row {
  color: var(--muted);
  text-align: center;
}

.divider {
  height: 1px;
  margin: 18px 0;
  background: var(--line);
}

.mini-stats {
  display: grid;
  gap: 10px;
  margin: 0;
}

.mini-stats div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid #eef2f7;
  padding-bottom: 9px;
}

.mini-stats dt,
.mini-stats dd {
  margin: 0;
}

.mini-stats dt {
  color: var(--muted);
}

.mini-stats dd {
  font-weight: 800;
}

.command-help {
  display: grid;
  gap: 9px;
}

.stats-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
}

.stat-card {
  padding: 18px;
}

.stat-card span,
.stat-card small {
  display: block;
  color: var(--muted);
}

.stat-card strong {
  display: block;
  margin: 8px 0 6px;
  font-size: 30px;
  line-height: 1;
}

.inline-form {
  flex-wrap: wrap;
  margin: 14px 0;
}

.inline-form input,
.inline-form select {
  max-width: 180px;
}

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

.room-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.room-grid .field:has([name="id"]) {
  grid-column: span 2;
}

.room-grid .field:has([name="name"]),
.room-grid .field:has([name="hostName"]) {
  grid-column: span 3;
}

.room-grid .field:has([name="wecomTargetType"]),
.room-grid .field:has([name="wecomTarget"]) {
  grid-column: span 2;
}

.room-grid .field:has(textarea) {
  grid-column: span 6;
}

.room-grid .field:has(textarea) textarea {
  min-height: 270px;
}

.room-grid .settings-save {
  grid-column: 1 / -1;
}

.span-2 {
  grid-column: span 2;
}

.toggle-row {
  grid-column: 1 / -1;
  flex-wrap: wrap;
  align-items: center;
  padding: 4px 0;
}

.toggle-row label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  color: var(--muted);
}

.settings-save {
  grid-column: 1 / span 2;
  justify-self: start;
}

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

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

.stack-form button {
  justify-self: start;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.compact-table table {
  min-width: 460px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #f7f9fc;
}

td {
  line-height: 1.45;
}

.row-actions {
  flex-wrap: wrap;
}

.row-actions button {
  min-height: 32px;
  padding: 6px 9px;
}

.status-queued {
  color: var(--ok);
  background: rgba(29, 143, 90, 0.11);
}

.status-cancelled {
  color: var(--warn);
  background: rgba(183, 120, 0, 0.12);
}

.status-deleted,
.status-void {
  color: var(--danger);
  background: rgba(200, 69, 69, 0.11);
}

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

.activity-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-strong);
  padding: 11px 12px;
}

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

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

.note {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 16px 0 10px;
}

.preview-toolbar strong {
  display: block;
  margin-top: 4px;
}

.preview-box {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #071826;
  color: #d8eff0;
  padding: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 320px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(420px, calc(100vw - 44px));
  border-radius: var(--radius);
  background: #10202f;
  color: white;
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

@media (max-width: 1120px) {
  .chat-layout,
  .admin-columns {
    grid-template-columns: 1fr;
  }

  .live-panel {
    position: static;
  }

  .stats-grid,
  .settings-grid,
  .room-grid,
  .integration-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .room-grid .field:has([name="id"]),
  .room-grid .field:has([name="name"]),
  .room-grid .field:has([name="hostName"]),
  .room-grid .field:has([name="wecomTargetType"]),
  .room-grid .field:has([name="wecomTarget"]) {
    grid-column: span 1;
  }

  .room-grid .field:has(textarea),
  .room-grid .settings-save {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .topbar,
  .chat-layout,
  .admin-layout {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar,
  .composer,
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .message {
    max-width: 100%;
  }

  .compact-field,
  .room-field,
  .message-field,
  .inline-form input,
  .inline-form select {
    width: 100%;
    max-width: none;
  }

  .stats-grid,
  .settings-grid,
  .room-grid,
  .integration-grid,
  .stack-form {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .room-grid .field:has([name="id"]),
  .room-grid .field:has([name="name"]),
  .room-grid .field:has([name="hostName"]),
  .room-grid .field:has([name="wecomTargetType"]),
  .room-grid .field:has([name="wecomTarget"]),
  .room-grid .field:has(textarea),
  .room-grid .settings-save {
    grid-column: auto;
  }

  .settings-save {
    grid-column: auto;
    width: 100%;
  }
}
