:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --line: #d9e1ec;
  --brand: #229ed9;
  --brand-dark: #1474a4;
  --success: #157347;
  --warn: #b76e00;
  --danger: #b42318;
  --shadow: 0 18px 50px rgba(20, 32, 54, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: linear-gradient(180deg, #152033 0%, #101827 100%);
  color: #e8eef8;
  padding: 24px 18px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--brand);
  font-weight: 800;
}

.brand-title {
  font-weight: 750;
}

.brand-subtitle {
  margin-top: 2px;
  color: #aab6c8;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.nav-item {
  color: #d8e2f0;
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 8px;
}

.nav-item.active {
  background: rgba(47, 128, 237, 0.18);
  color: #ffffff;
}

.nav-item.muted {
  color: #9aa8bb;
}

.side-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 24px;
  color: #b8c4d6;
  font-size: 13px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #94a3b8;
}

.dot.ok {
  background: #22c55e;
}

.dot.idle {
  background: #f59e0b;
}

.content {
  max-width: 1280px;
  width: 100%;
  padding: 30px;
}

.page-hero {
  display: flex;
  justify-content: space-between;
  gap: 22px;
  align-items: stretch;
  margin-bottom: 18px;
  padding: 24px;
  border: 1px solid rgba(34, 158, 217, 0.18);
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(34, 158, 217, 0.12), rgba(21, 115, 71, 0.06)),
    #ffffff;
  box-shadow: var(--shadow);
}

h1, h2, h3, p {
  margin: 0;
}

h1 {
  font-size: 30px;
  letter-spacing: 0;
}

.hero-copy {
  max-width: 660px;
}

.hero-copy p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.6;
}

.eyebrow,
.section-kicker,
.card-kicker {
  display: block;
  color: var(--brand-dark);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-card {
  min-width: 260px;
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.82);
}

.hero-card-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

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

.live-text {
  color: var(--success);
}

.warn-text {
  color: var(--warn);
}

.panel-head p,
.section-title span,
.cell-sub,
.message.muted {
  color: var(--muted);
}

.status-stack,
.actions,
.row-actions,
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.pill,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #edf2f7;
  color: #344054;
  font-size: 12px;
  font-weight: 650;
}

.pill.live,
.tag.channel {
  background: #e7f6ee;
  color: var(--success);
}

.pill.warn {
  background: #fff4df;
  color: var(--warn);
}

.tag.merchant {
  background: #eaf2ff;
  color: var(--brand-dark);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(20, 32, 54, 0.06);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.metric strong {
  font-size: 24px;
}

.metric-note {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.metric-small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px !important;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.88fr) minmax(520px, 1.35fr);
  gap: 16px;
  align-items: start;
}

.panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  min-height: 34px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.14s ease, border-color 0.14s ease, transform 0.14s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.btn.secondary {
  background: #edf4ff;
  color: var(--brand-dark);
  border-color: #c8dcfb;
}

.btn.ghost {
  background: transparent;
}

.btn.tiny {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

code {
  color: #344054;
  background: #f2f4f7;
  padding: 3px 6px;
  border-radius: 5px;
}

.message {
  margin: 14px 20px;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f2f4f7;
}

.message.success {
  background: #e7f6ee;
  color: var(--success);
}

.message.error {
  background: #fff0ee;
  color: var(--danger);
}

.chat-grid {
  display: grid;
  gap: 10px;
  padding: 14px 16px 18px;
}

.chat-card {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.chat-card.is-merchant {
  border-color: #bcd8ff;
}

.chat-card.is-channel {
  border-color: #b7e2c9;
}

.chat-avatar {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: #eaf2ff;
  color: var(--brand-dark);
  font-weight: 800;
}

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

.chat-title-row h3 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
}

.chat-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.chat-actions {
  display: grid;
  gap: 6px;
}

.support-card {
  display: grid;
  gap: 14px;
  margin: 18px;
  padding: 16px;
  border: 1px solid #cfe4f4;
  border-radius: 12px;
  background:
    linear-gradient(135deg, rgba(34, 158, 217, 0.08), rgba(21, 115, 71, 0.05)),
    #ffffff;
}

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

.support-head div {
  display: grid;
  gap: 3px;
}

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

.small-hint {
  margin: 0;
  font-size: 12px;
}

.bot-admin-card {
  border-color: #d4dce8;
  background: var(--panel-soft);
}

.admin-id-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.admin-id-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.admin-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}

.admin-add-form label {
  display: grid;
  gap: 4px;
  flex: 1;
  min-width: 180px;
}

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

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

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

.shift-row {
  display: grid;
  grid-template-columns: 110px 110px minmax(160px, 1fr);
  gap: 10px;
  align-items: end;
}

.route-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.route-toolbar div {
  display: grid;
  gap: 2px;
}

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

.route-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  padding: 18px;
}

.section-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: end;
  margin: 0 0 10px;
}

.section-title h3 {
  font-size: 16px;
}

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

.config-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(20, 32, 54, 0.05);
}

.config-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.config-card-head strong {
  display: block;
  margin-top: 3px;
}

label {
  display: grid;
  gap: 5px;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--text);
  background: #ffffff;
  font: inherit;
}

.field-stack {
  display: grid;
  gap: 10px;
}

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

.config-card > label + label,
.field-grid,
.match-fields {
  margin-top: 10px;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.form-actions {
  padding-top: 4px;
}

.form-actions.toolbar {
  margin-bottom: 14px;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.btn.danger {
  background: #fef3f2;
  color: var(--danger);
  border: 1px solid #fecdca;
}

.btn.danger:hover {
  background: #fee4e2;
}

.empty {
  display: grid;
  gap: 5px;
  margin: 18px 20px;
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcfe;
}

.empty.compact {
  margin: 0;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    padding: 18px;
  }

  .nav {
    display: none;
  }

  .content {
    padding: 18px;
  }

  .page-hero,
  .panel-head {
    display: grid;
  }

  .metric-grid,
  .field-grid,
  .workspace-grid,
  .route-columns,
  .contact-list,
  .shift-row {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .chat-card {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .chat-actions {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.page-hero-compact {
  margin-bottom: 18px;
}

.page-hero-compact .hero-copy p {
  max-width: 520px;
}

.page-hero-compact .hero-copy a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}

.page-hero-compact .hero-copy a:hover {
  text-decoration: underline;
}

.settings-page-panel {
  max-width: 720px;
}

.hero-copy a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: none;
}

.hero-copy a:hover {
  text-decoration: underline;
}

.chat-search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.chat-search input {
  flex: 1;
  max-width: 320px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
}

/* HTMX 加载态 */
.is-loading,
.htmx-request.panel,
.htmx-request#groups-panel,
.htmx-request#chats-panel {
  opacity: 0.72;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.htmx-request .btn {
  cursor: wait;
}

.admin-toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1000;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #152033;
  color: #e8eef8;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}

.admin-toast.show {
  opacity: 1;
  transform: translateY(0);
}
