:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687385;
  --line: #dde3ea;
  --green: #16845f;
  --green-soft: #e6f4ee;
  --red: #bd3c37;
  --red-soft: #fdeceb;
  --blue: #2563eb;
  --blue-soft: #e8eefc;
  --amber: #a15c06;
  --amber-soft: #fff3db;
  --shadow: 0 16px 36px rgba(28, 39, 54, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.login-view {
  min-height: calc(100vh - 80px);
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.app-view[hidden],
.login-view[hidden] {
  display: none;
}

body.is-staff .admin-only-field {
  display: none !important;
}

.topbar,
.section-head,
.metrics,
.wechat-row,
.fallback-card,
.api-box,
.dialog-head,
.dialog-actions,
.account-box,
.user-row {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  font-size: 20px;
  line-height: 1.25;
}

.account-box {
  min-width: min(360px, 100%);
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.account-box strong,
.account-box span {
  display: block;
}

.account-box span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.view-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e9eef5;
}

.view-tabs[hidden],
.control-view[hidden],
.data-view[hidden] {
  display: none;
}

.view-tab {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.view-tab.is-active {
  background: #fff;
  color: var(--blue);
  border-color: var(--line);
  box-shadow: 0 2px 8px rgba(28, 39, 54, 0.08);
}

.metrics {
  display: grid;
  grid-template-columns: 180px 1fr 180px;
  gap: 12px;
  margin-bottom: 16px;
}

.metric {
  min-height: 82px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 24px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr 330px;
  gap: 16px;
  align-items: start;
}

.main-stack,
.data-view {
  display: grid;
  gap: 16px;
}

.side-stack {
  display: grid;
  gap: 16px;
  position: sticky;
  top: 18px;
}

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

.main-panel,
.side-panel {
  padding: 18px;
}

.logs-panel {
  padding: 18px;
}

.section-head {
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.section-head.compact {
  margin-bottom: 14px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.icon-btn {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.primary-btn {
  background: var(--blue);
  color: #fff;
}

.ghost-btn {
  border-color: var(--line);
}

.danger-btn {
  color: var(--red);
  border-color: #f1b9b5;
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  min-width: 36px;
  padding: 0;
  border-color: var(--line);
}

.wechat-list,
.user-list,
.fallback-list,
.interval-list {
  display: grid;
  gap: 10px;
}

.wechat-row {
  min-height: 108px;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.wechat-row.is-ready {
  border-color: #9dd8bf;
  background: var(--green-soft);
}

.wechat-row.is-muted {
  opacity: 0.7;
}

.avatar {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-weight: 800;
  flex: 0 0 auto;
}

.avatar.fallback {
  background: var(--amber-soft);
  color: var(--amber);
}

.wechat-main {
  min-width: 0;
  flex: 1;
}

.wechat-main strong,
.fallback-card strong,
.user-row strong {
  display: block;
  font-size: 17px;
  overflow-wrap: anywhere;
}

.wechat-main span,
.fallback-card span,
.user-row span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.status-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.status-pill.ready {
  color: var(--green);
  background: #d7efe5;
}

.status-pill.closed {
  color: var(--red);
  background: var(--red-soft);
}

.status-pill.info {
  color: var(--blue);
  background: var(--blue-soft);
}

.status-pill.muted {
  color: var(--muted);
  background: #eef1f4;
}

.row-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, auto));
  gap: 8px;
  justify-content: end;
}

.toggle,
.check-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-weight: 700;
}

.toggle input,
.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--green);
}

.fallback-card,
.user-row {
  gap: 12px;
  min-height: 78px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.user-row {
  justify-content: space-between;
}

.api-box {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.tools-panel .api-box:first-child {
  margin-top: 0;
}

.api-box span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.api-box input {
  max-width: 90px;
  min-height: 34px;
}

.stats-box strong {
  font-size: 22px;
}

.stats-box small {
  color: var(--muted);
  font-weight: 700;
}

code {
  display: inline-block;
  max-width: 100%;
  padding: 5px 7px;
  border-radius: 6px;
  background: #eef2f7;
  color: #243145;
  overflow-wrap: anywhere;
}

dialog {
  width: min(500px, calc(100% - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background: rgba(23, 32, 42, 0.44);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
  background: #fff;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dialog-head {
  justify-content: space-between;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.18);
  border-color: var(--blue);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dialog-actions {
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

.dialog-actions.left {
  justify-content: flex-start;
  margin-top: -4px;
}

.interval-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 10px;
  align-items: end;
}

.claim-log-list,
.daily-stats-list {
  display: grid;
  gap: 8px;
}

.claim-log-row,
.daily-stat-row {
  display: grid;
  grid-template-columns: 1.3fr 1fr 0.7fr 1fr 1fr 0.7fr;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}

.claim-log-row.header,
.daily-stat-row.header {
  min-height: 36px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 800;
}

.claim-log-row span,
.daily-stat-row span {
  overflow-wrap: anywhere;
}

.stat-name-cell strong,
.stat-name-cell small {
  display: block;
}

.stat-name-cell small {
  margin-top: 3px;
  color: var(--muted);
  font-weight: 700;
}

.daily-stat-row {
  grid-template-columns: 1fr 1.2fr 0.7fr 0.7fr 0.9fr 0.9fr 0.8fr 0.8fr auto;
}

.daily-stat-row input {
  min-height: 34px;
  padding: 0 8px;
}

.stats-filters {
  display: grid;
  grid-template-columns: 160px 160px 220px;
  gap: 10px;
  align-items: end;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
  font-weight: 700;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(18px);
  min-width: 180px;
  max-width: calc(100% - 32px);
  padding: 11px 14px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
  .shell {
    width: min(100% - 20px, 680px);
    padding-top: 18px;
  }

  .topbar,
  .layout {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .side-stack {
    position: static;
  }

  .wechat-row {
    display: grid;
    grid-template-columns: 46px 1fr;
  }

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

  .claim-log-row,
  .claim-log-row.header,
  .daily-stat-row,
  .daily-stat-row.header {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 520px) {
  h1 {
    font-size: 24px;
  }

  .section-head {
    align-items: stretch;
    display: grid;
  }

  .primary-btn,
  .ghost-btn,
  .danger-btn {
    width: 100%;
  }

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