:root {
  --ink: #17211a;
  --muted: #69766e;
  --line: #d8ded8;
  --panel: #fbfcf8;
  --paper: #f2f5ee;
  --side: #101713;
  --accent: #0f7a55;
  --accent-2: #b44b2a;
  --warn: #a16207;
  --bad: #b42318;
  --ok: #16845b;
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 14px/1.5 "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea {
  font: inherit;
}
code {
  background: #e8ede6;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 5px;
}

.app-shell {
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: var(--side);
  color: #e6ece7;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 8px 20px;
  border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 6px;
  background: #d8f3dc;
  color: #0d3b2a;
  font-weight: 800;
  letter-spacing: 0;
}
.brand small, .topbar p, table small, .muted {
  color: var(--muted);
  display: block;
}
.sidebar .brand small { color: #9eb0a5; }
.nav {
  display: grid;
  gap: 5px;
  margin-top: 18px;
}
.nav a {
  padding: 9px 10px;
  border-radius: 6px;
  color: #bdcbc2;
}
.nav a.active, .nav a:hover {
  background: #213029;
  color: #fff;
}
.workspace {
  padding: 18px 22px 34px;
  min-width: 0;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
.topbar h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.2;
}
.topbar p { margin: 2px 0 0; }
.topbar-user {
  display: flex;
  gap: 10px;
  align-items: center;
  white-space: nowrap;
}

.panel, .metric, .chat-panel, .contact-side, .conversation-list, .account-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.panel {
  padding: 14px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.panel h2, .chat-head h2, .contact-side h2 {
  margin: 0;
  font-size: 16px;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.metric {
  padding: 13px;
}
.metric span {
  color: var(--muted);
}
.metric strong {
  display: block;
  font-size: 27px;
  line-height: 1.1;
  margin: 5px 0;
}
.split {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(0, 1fr);
  gap: 12px;
}
.policy-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.diagnostic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px;
}
.diagnostic-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 11px;
}
.diagnostic-card span, .diagnostic-card small {
  display: block;
  color: var(--muted);
}
.diagnostic-card strong {
  display: block;
  margin: 3px 0;
}
.ok-text { color: var(--ok); }
.bad-text { color: var(--bad); }
.log-text {
  max-width: 520px;
  overflow-wrap: anywhere;
}
.log-command {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #17211a;
  color: #edf5ef;
  border-radius: 6px;
  padding: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  align-content: start;
}
.form-grid .wide, .form-grid .panel-head, .form-grid button, .form-grid p {
  grid-column: 1 / -1;
}
label {
  display: grid;
  gap: 5px;
  color: #314138;
  font-weight: 700;
}
input, select, textarea {
  width: 100%;
  border: 1px solid #cbd5cf;
  background: #fff;
  color: var(--ink);
  border-radius: 6px;
  padding: 9px 10px;
  min-height: 38px;
}
textarea { resize: vertical; }
button, .primary, .ghost {
  border: 0;
  border-radius: 6px;
  padding: 9px 12px;
  cursor: pointer;
  min-height: 36px;
}
.primary {
  color: #fff;
  background: var(--accent);
  font-weight: 800;
}
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.inline-filter {
  display: flex;
  justify-content: flex-end;
  margin: -4px 0 12px;
}
.inline-filter label {
  grid-template-columns: auto 220px;
  align-items: center;
}

table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: #4a5a51;
  font-size: 12px;
  text-transform: uppercase;
}
.badge {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px 8px;
  background: #ece7d4;
  color: var(--warn);
  font-weight: 800;
  font-size: 12px;
}
.badge.ok { background: #dff3e8; color: var(--ok); }
.badge.bad { background: #fde2df; color: var(--bad); }
.tag {
  display: inline-flex;
  margin: 0 4px 4px 0;
  border-radius: 5px;
  padding: 2px 7px;
  background: color-mix(in srgb, var(--tag, #2563eb) 14%, white);
  color: var(--tag, #2563eb);
  border: 1px solid color-mix(in srgb, var(--tag, #2563eb) 35%, white);
  font-weight: 700;
}

.materials {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.material {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 11px;
}
.material div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.material p { margin-bottom: 0; }

.inbox {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 260px;
  gap: 12px;
  min-height: calc(100vh - 118px);
}
.account-workspace {
  display: grid;
  grid-template-columns: 220px 280px minmax(0, 1fr) 260px;
  gap: 12px;
  min-height: calc(100vh - 118px);
}
.account-list {
  padding: 8px;
  overflow: auto;
}
.account-row {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: 7px;
  border: 1px solid transparent;
}
.account-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #314138;
}
.account-row.active, .account-row:hover {
  background: #fff;
  border-color: var(--line);
}
.conversation-list {
  padding: 8px;
  overflow: auto;
}
.conversation {
  display: grid;
  gap: 3px;
  padding: 10px;
  border-radius: 7px;
  border: 1px solid transparent;
}
.conversation span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #314138;
}
.conversation.active, .conversation:hover {
  background: #fff;
  border-color: var(--line);
}
.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.chat-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}
.chat-head p { margin: 2px 0 0; color: var(--muted); }
.messages {
  padding: 12px;
  overflow: auto;
  display: grid;
  gap: 10px;
  align-content: start;
}
.bubble {
  max-width: 76%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}
.bubble p { margin: 0 0 4px; }
.bubble small { color: var(--muted); }
.bubble.outbound {
  justify-self: end;
  background: #e3f4eb;
  border-color: #bee3ce;
}
.reply-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.quick button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.contact-side {
  padding: 13px;
}
.contact-side dl { display: grid; gap: 10px; }
.contact-side dt { color: var(--muted); }
.contact-side dd { margin: 0; font-weight: 700; }
.empty {
  padding: 28px;
  color: var(--muted);
}
.notice {
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 12px;
  background: #e9f6ef;
  border: 1px solid #bfe5cd;
}
.notice.error {
  background: #fee8e5;
  border-color: #f5b3aa;
  color: var(--bad);
}
.auth-notice {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.auth-notice p {
  margin: 3px 0 0;
  color: #314138;
}
.auth-notice .mini-form {
  display: flex;
  gap: 6px;
}
.error-list {
  margin: 8px 0 14px;
  padding-left: 18px;
  color: var(--bad);
}
.api-config {
  margin-bottom: 12px;
}
.batch-auth {
  margin-top: 12px;
}
.batch-import {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.table-actions {
  min-width: 260px;
}
.table-actions, .table-actions form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.mini-form {
  flex-wrap: nowrap !important;
}
.mini-form input {
  width: 112px;
  min-height: 34px;
  padding: 7px 8px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: #0f1713;
  padding: 22px;
}
.login-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.1fr .9fr;
  background: #f5f7f1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #d6ddd5;
}
.login-copy {
  padding: 34px;
  background: #dfeadd;
}
.login-copy h1 {
  font-size: 34px;
  line-height: 1.12;
  margin: 22px 0 10px;
}
.login-copy dl { display: grid; gap: 12px; margin-top: 28px; }
.login-copy dt { font-weight: 800; }
.login-copy dd { margin: 2px 0 0; color: #435149; }
.login-forms {
  padding: 24px;
  display: grid;
  gap: 12px;
}
.login-form {
  padding: 34px;
  display: grid;
  gap: 14px;
  align-content: center;
}
.login-form.compact {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.login-form.compact h2 {
  margin: 0;
  font-size: 18px;
}
.bot-login {
  background: #eef6ef;
}
.install-note {
  margin: 0;
}

@media (max-width: 980px) {
  .app-shell, .split, .inbox, .account-workspace, .policy-grid, .login-panel {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
  }
  .nav {
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  }
  .bubble {
    max-width: 100%;
  }
}
