* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: #17202a;
  background: #f4f6f8;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  height: 56px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #111827;
  color: #ffffff;
}

.brand {
  color: #ffffff;
  font-weight: 700;
  text-decoration: none;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions form {
  margin: 0;
}

.nav-btn {
  min-height: 40px;
  border-radius: 6px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.shell {
  width: min(1360px, calc(100vw - 32px));
  margin: 80px auto 48px;
}

.login-panel,
.panel {
  background: #ffffff;
  border: 1px solid #dfe5ec;
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
}

.login-panel {
  width: min(420px, 100%);
  margin: 80px auto;
}

h1 {
  margin: 0;
  font-size: 20px;
}

.panel {
  margin-top: 18px;
}

.panel-head,
.page-head,
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-head {
  margin-bottom: 18px;
}

.group-head {
  align-items: flex-start;
}

.group-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.group-title-row h1 {
  overflow-wrap: anywhere;
}

.group-edit-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) auto auto;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.group-edit-form[hidden] {
  display: none;
}

.group-head > div:first-child span {
  display: block;
  margin-top: 6px;
  color: #64748b;
  font-size: 13px;
}

.back {
  display: inline-block;
  color: #2563eb;
  text-decoration: none;
  margin-bottom: 6px;
}

.metrics,
.summary-grid,
.mini-metrics {
  display: grid;
  gap: 12px;
}

.metrics {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.mini-metrics {
  width: min(820px, 100%);
  grid-template-columns: repeat(6, minmax(96px, 1fr));
}

.metrics div,
.metric-link,
.summary-grid div,
.mini-metrics div {
  min-height: 92px;
  background: #ffffff;
  border: 1px solid #dfe5ec;
  border-radius: 8px;
  padding: 16px;
}

.metric-link {
  color: inherit;
  text-decoration: none;
}

.summary-grid div,
.mini-metrics div {
  min-height: 76px;
  background: #f8fafc;
}

.summary-grid .match {
  border-color: #86efac;
  background: #f0fdf4;
}

.summary-grid .mismatch {
  border-color: #fca5a5;
  background: #fef2f2;
}

.metrics span,
.summary-grid span,
.mini-metrics span {
  display: block;
  color: #64748b;
  font-size: 13px;
}

.metrics strong,
.summary-grid strong,
.mini-metrics strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
}

.summary-grid strong,
.mini-metrics strong {
  font-size: 24px;
}

.text-strong {
  overflow-wrap: anywhere;
  font-size: 24px !important;
}

.form-grid,
.account-form,
.settings-form {
  display: grid;
  gap: 12px;
}

.account-form {
  grid-template-columns: 1.15fr 1fr 1.1fr 1fr 1fr auto;
  align-items: end;
}

.settings-form {
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  align-items: end;
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 12px;
}

.settings-form.single {
  grid-template-columns: 1fr 1fr;
}

label span {
  display: block;
  color: #475569;
  font-size: 13px;
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  background: #ffffff;
}

textarea {
  resize: vertical;
}

.form-hint {
  margin: 6px 0 0;
  color: #64748b;
  font-size: 12px;
  line-height: 1.45;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.import-file-field {
  min-height: 100px;
  display: flex;
  align-items: flex-start;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 10px;
  background: #ffffff;
}

.import-file-field input {
  min-height: 0;
  border: 0;
  padding: 0;
}

.import-file-field input:focus {
  outline: 0;
}

.group-field {
  position: relative;
  align-self: end;
}

.group-select-button {
  width: 100%;
  min-height: 40px;
  justify-content: space-between;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #17202a;
  font-weight: 400;
  text-align: left;
}

.group-select-button[aria-expanded="true"] {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.group-select-arrow {
  color: #475569;
  font-size: 16px;
}

.group-menu {
  position: absolute;
  z-index: 60;
  top: 64px;
  left: 0;
  right: 0;
  padding: 6px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 18px 36px rgba(15, 23, 42, 0.16);
}

.group-menu[hidden] {
  display: none;
}

.group-create-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 8px;
}

.group-menu .group-create-row {
  margin-top: 0;
}

.group-create-row input {
  min-width: 0;
}

.group-create-row button {
  min-width: 84px;
}

.field-message {
  display: block;
  margin-top: 4px;
  color: #166534;
  font-size: 12px;
}

.field-message:empty {
  display: none;
}

.field-message.error {
  color: #b91c1c;
}

.group-option-list {
  display: grid;
  gap: 4px;
  max-height: 220px;
  margin-top: 6px;
  overflow-y: auto;
}

.group-option {
  width: 100%;
  min-height: 34px;
  justify-content: flex-start;
  background: transparent;
  color: #17202a;
  text-align: left;
}

.group-option:hover {
  background: #eff6ff;
}

.group-option[aria-selected="true"] {
  color: #ffffff;
  background: #2563eb;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #93c5fd;
  border-color: #2563eb;
}

.wide {
  grid-column: span 2;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.check input {
  width: 18px;
  min-height: 18px;
  height: 18px;
}

.check span {
  margin: 0;
}

button,
.link-btn {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

.primary {
  color: #ffffff;
  background: #2563eb;
}

.secondary,
.link-btn {
  color: #0f172a;
  background: #e2e8f0;
}

.ghost {
  color: #ffffff;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.mini-btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.danger {
  color: #ffffff;
  background: #dc2626;
}

.source-mini {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 14px;
}

.source-mini div {
  min-height: 54px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.source-mini span {
  display: block;
  color: #64748b;
  font-size: 12px;
}

.source-mini strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.equal-table {
  table-layout: fixed;
}

.equal-table th,
.equal-table td {
  text-align: center;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.contribution-table {
  min-width: 620px;
}

.recent-source-table {
  min-width: 760px;
}

.region-table {
  min-width: 760px;
}

.table-edit-form {
  display: grid;
  grid-template-columns: minmax(130px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

th,
td {
  border-bottom: 1px solid #e5e7eb;
  padding: 10px 8px;
  text-align: left;
  font-size: 14px;
}

th {
  color: #475569;
  background: #f8fafc;
  font-weight: 600;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  color: #334155;
  background: #e2e8f0;
}

.pill.ok {
  color: #065f46;
  background: #d1fae5;
}

.pill.warn {
  color: #92400e;
  background: #fef3c7;
}

.pill.off {
  color: #7f1d1d;
  background: #fee2e2;
}

.log-list,
.compact-list {
  display: grid;
  gap: 8px;
}

.log-row,
.compact-list div {
  display: grid;
  grid-template-columns: 150px 150px 110px 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #ffffff;
}

.log-row p,
.compact-list em {
  margin: 0;
  color: #475569;
  font-style: normal;
}

.compact-list div {
  grid-template-columns: 1fr auto;
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
}

.mono {
  font-family: Consolas, "Courier New", monospace;
}

.empty {
  color: #64748b;
  text-align: center;
  padding: 24px;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.flash {
  border-radius: 6px;
  padding: 10px 12px;
  background: #e0f2fe;
  color: #075985;
}

.flash.error {
  background: #fee2e2;
  color: #991b1b;
}

.flash.success {
  background: #dcfce7;
  color: #166534;
}

.danger-zone {
  border-color: #fecaca;
}

@media (max-width: 1100px) {
  .account-form,
  .settings-form,
  .settings-form.single,
  .inline-form,
  .table-edit-form,
  .split,
  .group-head {
    grid-template-columns: 1fr;
  }

  .group-head {
    display: grid;
  }

  .mini-metrics {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  .wide {
    grid-column: auto;
  }

  .group-edit-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0 14px;
  }

  .shell {
    width: min(100vw - 20px, 1360px);
    margin-top: 72px;
  }

  .panel-head,
  .page-head {
    align-items: stretch;
    flex-direction: column;
  }
}
