:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f7f7f7;
  --ink: #171717;
  --muted: #666666;
  --faint: #8f8f8f;
  --line: #e6e6e6;
  --line-strong: #d4d4d4;
  --accent: #0070f3;
  --accent-soft: #eef6ff;
  --green: #1a8f5a;
  --green-soft: #ecfdf3;
  --red: #d93036;
  --red-soft: #fff2f2;
  --amber: #a16207;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 10px 30px rgba(0, 0, 0, .04);
  --sans: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI Variable Text", "Segoe UI", sans-serif;
  --mono: "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI Variable Text", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
.ribao-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin: 18px 0; }
.ribao-card h2 { margin: 0 0 12px; font-size: 18px; }
.ribao-card .button-row { flex-wrap: wrap; }
.ribao-card input[type="file"] { display: block; width: 100%; max-width: 620px; margin: 12px 0; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
.ribao-warning { color: var(--red); white-space: pre-wrap; overflow-wrap: anywhere; }
#ribao-result { white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-logs-toolbar { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; margin: 22px 0 12px; }
.admin-logs-toolbar label { display: grid; gap: 8px; min-width: 220px; max-width: 100%; }
.admin-logs-toolbar select { max-width: 100%; }
.admin-logs-toolbar .button-row { flex-wrap: wrap; }
.admin-log-hint { color: var(--muted); font-size: 12px; }
#admin-log-status { overflow-wrap: anywhere; }
#admin-log-view { overflow-wrap: anywhere; min-height: 320px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--ink);
  background: rgba(255, 255, 255, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(180%);
}
.brand, .top-actions, .button-row, .title-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.brand::after {
  content: "Control Center";
  padding-left: 12px;
  color: var(--faint);
  border-left: 1px solid var(--line);
  font-size: 12px;
  font-weight: 400;
}
.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  color: #fff;
  background: #111;
  border-radius: 12px;
  font-weight: 700;
  letter-spacing: -.05em;
}
.brand-mark.small {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 11px;
}
.top-actions { color: var(--muted); font-size: 13px; }
.status-pill {
  padding: 5px 10px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 12px;
}
.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #a3a3a3;
}
.status-pill.online { color: var(--green); background: var(--green-soft); border-color: #c9f0db; }
.status-pill.online::before { background: var(--green); box-shadow: 0 0 0 3px rgba(26,143,90,.12); }

.app-shell {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  min-height: calc(100vh - 64px);
}
.sidebar {
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  padding: 22px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.sidebar::before {
  content: "工作台";
  display: block;
  padding: 0 10px 9px;
  color: var(--faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
}
.nav-item {
  position: relative;
  width: 100%;
  padding: 9px 10px 9px 32px;
  margin: 2px 0;
  text-align: left;
  color: #555;
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 13px;
  transition: background .15s, color .15s;
}
.nav-item::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 50%;
  width: 8px;
  height: 8px;
  border: 1.5px solid #999;
  border-radius: 2px;
  transform: translateY(-50%);
}
.nav-item:hover { color: var(--ink); background: #f5f5f5; }
.nav-item.active { color: var(--ink); background: #ededed; font-weight: 600; }
.nav-item.active::before { background: var(--ink); border-color: var(--ink); box-shadow: inset 0 0 0 2px #ededed; }

.content { min-width: 0; padding: 54px clamp(28px, 5vw, 72px) 90px; }
.page { display: none; width: min(1180px, 100%); margin: 0 auto; }
.page.active { display: block; animation: enter .18s ease-out; }
@keyframes enter { from { opacity: 0; transform: translateY(4px); } }

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.12;
  font-weight: 600;
  letter-spacing: -.045em;
}
.eyebrow {
  margin: 0 0 10px;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .08em;
}
.lead { max-width: 660px; margin: 10px 0 32px; color: var(--muted); font-size: 14px; }

.hero-card {
  min-height: 188px;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 40px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.hero-card .label, .hero-card small { display: block; color: var(--muted); }
.hero-card .label { font-size: 12px; font-weight: 500; }
.hero-card strong {
  display: block;
  margin: 0;
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -.04em;
}
.bot-state-row { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.hero-state-dot { width: 10px; height: 10px; flex: 0 0 auto; border-radius: 50%; background: #a3a3a3; box-shadow: 0 0 0 4px rgba(163,163,163,.12); }
.hero-state-dot.online { background: var(--green); box-shadow: 0 0 0 4px rgba(26,143,90,.12); }
.bot-meta-grid { display: flex; flex-wrap: wrap; gap: 12px 32px; margin-top: 24px; }
.bot-meta-grid > div { min-width: 160px; }
.meta-label, .meta-value { display: block; }
.meta-label { margin-bottom: 4px; color: var(--faint); font-size: 11px; font-weight: 500; letter-spacing: .02em; }
.meta-value { color: var(--ink); font-family: var(--mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.bot-actions { padding-left: 28px; border-left: 1px solid var(--line); }
.bot-actions button { min-width: 76px; }

.primary, .secondary, .danger, .ghost, .mini {
  min-height: 36px;
  padding: 7px 13px;
  border-radius: 7px;
  font-weight: 500;
  transition: border-color .15s, background .15s, transform .1s;
}
.primary:active, .secondary:active, .danger:active, .ghost:active, .mini:active { transform: translateY(1px); }
.primary { color: white; background: #171717; border: 1px solid #171717; }
.primary:hover { background: #333; }
.secondary { color: var(--ink); background: white; border: 1px solid var(--line-strong); }
.secondary:hover, .ghost:hover, .mini:hover { border-color: #999; background: #fafafa; }
.danger { color: var(--red); background: white; border: 1px solid #f0b8bb; }
.danger:hover { background: var(--red-soft); border-color: var(--red); }
.ghost { color: var(--muted); background: transparent; border: 1px solid var(--line); }
.ghost.dark { color: var(--ink); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.stats-grid article, .admin-summary article {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.stats-grid span, .stats-grid small, .admin-summary span { display: block; color: var(--muted); }
.stats-grid strong, .admin-summary strong {
  display: block;
  margin: 8px 0 2px;
  font-family: var(--mono);
  font-size: 23px;
  font-weight: 500;
  letter-spacing: -.04em;
}
.mention-card { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.mention-card > small { grid-column: 1 / -1; margin-top: 11px; }
.switch { position: relative; display: inline-flex; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.stats-grid .switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #d4d4d4;
  transition: background .18s;
}
.stats-grid .switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
  transition: transform .18s;
}
.switch input:checked + .switch-track { background: var(--ink); }
.switch input:checked + .switch-track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 2px white, 0 0 0 4px var(--accent); }

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin: 42px 0 18px;
  padding-top: 30px;
  border-top: 1px solid var(--line);
}
.section-heading h2 { margin: 4px 0 0; font-size: 24px; font-weight: 550; letter-spacing: -.035em; }
.section-heading > p { margin: 0; color: var(--muted); font-size: 13px; }

.guide-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 28px 0;
}
.guide-steps article {
  display: flex;
  gap: 14px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.guide-steps article > span { color: var(--accent); font: 12px/1.5 var(--mono); }
.guide-steps h2 { margin: 0 0 8px; font-size: 16px; font-weight: 550; letter-spacing: -.02em; }
.guide-steps p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }

.command-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.command-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.command-card > div { display: flex; align-items: center; gap: 10px; }
.command-card > div > code { color: var(--accent); font-size: 14px; font-weight: 600; }
.command-card > div > span { font-size: 14px; font-weight: 550; }
.command-card p { margin: 14px 0 8px; color: var(--ink); font-size: 13px; }
.command-card small { color: var(--muted); line-height: 1.55; }
code { font-family: var(--mono); }

.password-card {
  max-width: 560px;
  margin-top: 26px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.password-card label { display: block; margin-bottom: 16px; }
.password-card label > span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 500; }
.password-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  padding-top: 4px;
}
.password-actions span { color: var(--muted); font-size: 13px; }

.config-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.field > span, .inline-form label span { font-size: 13px; font-weight: 500; }
.input-action-row { display: flex; align-items: stretch; gap: 8px; }
.input-action-row input { min-width: 180px; }
.input-action-row button { flex: 0 0 auto; white-space: nowrap; }
.field small { min-height: 18px; color: var(--faint); font-size: 12px; }
.field.span-2 { grid-column: 1 / -1; }
.field.check { flex-direction: row; align-items: center; }

input, textarea, select {
  width: 100%;
  padding: 9px 11px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #aaa; }
input:hover, textarea:hover, select:hover { border-color: #aaa; }
input:focus, textarea:focus, select:focus { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
input[type="checkbox"] { width: 15px; height: 15px; accent-color: #171717; }
input[readonly] { color: var(--muted); background: var(--surface-2); cursor: not-allowed; }
textarea { resize: vertical; }
textarea.compact-notice { height: 40px; min-height: 40px; }

.sticky-actions {
  position: sticky;
  bottom: 16px;
  z-index: 5;
  margin-top: 18px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.sticky-actions span { margin-right: auto; color: var(--muted); font-size: 12px; }

.inline-form {
  margin: 28px 0 16px;
  padding: 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.inline-form label { min-width: 116px; flex: 1; }
.inline-form label:first-child { flex: 2.4; }
.inline-form label span { display: block; margin-bottom: 6px; }

.bulk-form {
  margin: -4px 0 16px;
  padding: 16px;
  background: #f7f7f7;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.bulk-form[hidden] { display: none; }
.bulk-form label > span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 500; }
.bulk-form textarea { min-height: 150px; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.bulk-form > div { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 10px; }
.bulk-form small { color: var(--muted); }

.schedule-form { align-items: flex-end; }
.schedule-form .schedule-text { flex: 2.2; }
.schedule-form textarea { min-height: 76px; resize: vertical; }
.schedule-form .schedule-mention { flex: 0 0 100px; min-width: 100px; }
.schedule-form .schedule-mention input { width: 20px; height: 20px; margin: 12px 0; }

.section-tabs {
  display: inline-flex;
  gap: 4px;
  margin: 20px 0 8px;
  padding: 4px;
  background: #f1f1f1;
  border-radius: 10px;
}
.section-tab {
  padding: 9px 22px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 7px;
}
.section-tab.active { color: #fff; background: #171717; }
.push-tab-panel[hidden] { display: none; }
#refresh-push-records { visibility: hidden; }
#push-records-table .push-content {
  min-width: 260px;
  max-width: 520px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #fafafa;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .03em;
}
tbody tr { transition: background .12s; }
tbody tr:hover { background: #fafafa; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { max-width: 420px; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 54px; color: var(--faint); text-align: center; }
.link-danger { padding: 4px 0; color: var(--red); background: transparent; border: 0; }

.title-row { justify-content: space-between; }
.log-view {
  min-height: 560px;
  max-height: 70vh;
  margin-top: 24px;
  padding: 20px;
  overflow: auto;
  color: #d4d4d4;
  background: #0a0a0a;
  border: 1px solid #242424;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font: 12px/1.7 var(--mono);
  white-space: pre-wrap;
}
.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  max-width: 360px;
  padding: 11px 14px;
  color: white;
  background: #171717;
  border: 1px solid #333;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: #9f1f24; border-color: #c83e43; }

.admin-only { display: none; }
.admin-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 230px));
  gap: 12px;
  margin: 0 0 16px;
}
.tenant-name { font-weight: 600; }
.tenant-meta { display: block; color: var(--faint); font: 11px/1.5 var(--mono); }
.mono-cell { font: 12px/1.5 var(--mono); white-space: nowrap; }
.audit-event {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--soft);
  font-size: 12px;
  white-space: nowrap;
}
.event-login { border-color: #a7f3d0; background: #ecfdf5; color: #047857; }
.event-offline { border-color: #e5e7eb; background: #f9fafb; color: #6b7280; }
.event-register { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.state-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border-radius: 50%;
  background: #aaa;
}
.state-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(26,143,90,.12); }
.table-actions { display: flex; flex-wrap: wrap; gap: 5px; }
.mini { min-height: 29px; padding: 4px 8px; color: var(--ink); background: white; border: 1px solid var(--line); font-size: 12px; }
.mini.danger-text { color: var(--red); }

#customers-table .table-actions { min-width: 290px; max-width: 440px; }
#customers-table td:nth-child(3) { max-width: 250px; white-space: normal; overflow-wrap: anywhere; }
#audits-table.audit-records { table-layout: fixed; min-width: 660px; }
#audits-table.audit-records th:nth-child(1) { width: 180px; }
#audits-table.audit-records th:nth-child(2) { width: 175px; }
#audits-table.audit-records th:nth-child(3) { width: 145px; }
#audits-table.audit-records td { white-space: normal; overflow-wrap: anywhere; }
#audits-table .audit-event { max-width: 100%; white-space: normal; }
.audit-detail-preview { display: block; margin-bottom: 6px; }
.admin-dialog { width: min(560px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 26px; color: var(--ink); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 24px 80px #0003; overflow: auto; }
.admin-dialog::backdrop { background: #0006; }
.admin-dialog h2 { margin: 0 0 10px; font-size: 22px; }
.dialog-lead { margin: 0 0 22px; color: var(--muted); overflow-wrap: anywhere; }
.dialog-fields { display: grid; gap: 16px; min-width: 0; }
.dialog-fields label { display: grid; gap: 8px; }
.dialog-fields small { color: var(--faint); line-height: 1.6; }
.dialog-error { color: var(--red); white-space: pre-wrap; overflow-wrap: anywhere; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog-actions button { min-height: 38px; min-width: 76px; }
.audit-detail-full { margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font: inherit; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
  background-color: #fafafa;
  background-image:
    linear-gradient(#ededed 1px, transparent 1px),
    linear-gradient(90deg, #ededed 1px, transparent 1px);
  background-size: 40px 40px;
}
.login-body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, rgba(250,250,250,.2) 0, #fafafa 68%);
  pointer-events: none;
}
.login-card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  padding: 34px;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 70px rgba(0,0,0,.08);
}
.login-card h1 { margin-top: 16px; font-size: 28px; }
.login-card .muted { margin: 9px 0 26px; color: var(--muted); }
.login-card label { display: block; margin: 14px 0; font-size: 13px; font-weight: 500; }
.login-card input { margin-top: 6px; }
.wide { width: 100%; margin-top: 8px; }
.error { min-height: 21px; margin-bottom: 0; color: var(--red); text-align: center; font-size: 12px; }
.error.success { color: var(--green); }
.form-foot { margin: 18px 0 0; color: var(--muted); text-align: center; font-size: 12px; }
.form-foot a { color: var(--ink); font-weight: 600; text-decoration: none; }
.form-foot a:hover { text-decoration: underline; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 64px;
    z-index: 20;
    width: 100%;
    height: auto;
    padding: 8px 12px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar::before { display: none; }
  .nav-item { width: auto; min-width: max-content; margin: 0; padding: 8px 12px; }
  .nav-item::before { display: none; }
  .content { padding: 34px 18px 64px; }
  .config-grid, .stats-grid, .guide-steps, .command-grid { grid-template-columns: 1fr; }
  .field.span-2 { grid-column: auto; }
  .hero-card, .inline-form, .section-heading { align-items: stretch; flex-direction: column; }
  .hero-card { min-height: auto; }
  .hero-card { grid-template-columns: 1fr; gap: 24px; }
  .bot-actions { padding: 20px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .button-row { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .topbar { padding: 0 14px; }
  .brand::after, #account-name { display: none; }
  .top-actions { gap: 7px; }
  .login-card { padding: 26px 22px; }
  .admin-summary { grid-template-columns: 1fr 1fr; }
  h1 { font-size: 30px; }
}
