:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --line: #e5e7eb;
  --text: #202123;
  --muted: #6b7280;
  --accent-soft: #f3f4f6;
  --accent-blue: #2563eb;
  --danger: #b91c1c;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: linear-gradient(180deg, #f7f7f8 0%, #f5f7fb 100%);
}
a { color: inherit; text-decoration: none; }

.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card,
.panel-card,
.metric-card,
.sub-card,
.trend-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(460px, 100%);
  padding: 32px;
}

.login-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.login-brand strong {
  display: block;
  font-size: 22px;
}

.login-brand small,
.sidebar-brand small {
  color: var(--muted);
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: #10a37f;
}

.brand-dot.large {
  width: 14px;
  height: 14px;
}

.login-head {
  margin-bottom: 24px;
}

.login-head h1 {
  margin: 0;
  font-size: 30px;
}

.lead {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.stack {
  display: grid;
  gap: 14px;
}

label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  color: var(--text);
}

input:focus,
select:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

button,
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 14px;
  border: none;
  border-radius: 12px;
  background: #111827;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

button.secondary,
.button-link.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

button.danger {
  background: #ef4444;
}

button:disabled,
.button-link:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.block {
  width: 100%;
}

.admin-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  background: #fff;
  border-right: 1px solid var(--line);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 10px 16px;
  border-bottom: 1px solid var(--line);
}

.sidebar-brand strong {
  display: block;
  font-size: 18px;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.sidebar-nav a {
  display: block;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--text);
  border: 1px solid transparent;
  transition: background .16s ease, border-color .16s ease;
}

.sidebar-nav a.active {
  background: var(--accent-soft);
  border-color: var(--line);
}

.sidebar-nav a:hover {
  background: #f9fafb;
}

.sidebar-nav a span {
  display: block;
  font-weight: 700;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
}

.content-area {
  padding: 28px;
  max-width: 1600px;
}

.page-head,
.section-head,
.page-actions,
.toolbar-form,
.toolbar-actions,
.bulk-controls,
.bulk-meta,
.split-fields,
.trend-summary,
.trend-head,
.trend-select-wrap,
.actions,
.modal-head {
  display: flex;
  gap: 12px;
  align-items: center;
}

.page-head,
.section-head,
.trend-head {
  justify-content: space-between;
  align-items: flex-start;
}

.page-head {
  margin-bottom: 20px;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 8px;
  color: var(--accent-blue);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-size: 36px;
  line-height: 1.08;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.metric-grid,
.content-grid {
  display: grid;
  gap: 16px;
}

.dashboard-metrics,
.metric-grid.mini {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric-grid {
  margin-bottom: 18px;
}

.metric-card {
  padding: 18px;
}

.metric-label {
  display: inline-flex;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #374151;
  font-size: 12px;
  font-weight: 700;
}

.metric-card strong {
  display: block;
  margin-top: 14px;
  font-size: 32px;
}

.metric-small {
  font-size: 18px !important;
  line-height: 1.45;
}

.metric-card small,
.section-note,
.trend-summary small {
  color: var(--muted);
}

.panel-card {
  padding: 20px;
  margin-bottom: 18px;
}

.trend-panel {
  padding: 22px;
}

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

.trend-card {
  padding: 18px;
  min-width: 0;
}

.trend-summary {
  gap: 16px;
}

.trend-summary strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.trend-bar-chart {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(44px, 1fr));
  gap: 12px;
  align-items: end;
  min-height: 240px;
  margin-top: 16px;
}

.trend-bar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.bar-value {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.bar-track {
  width: 100%;
  height: 160px;
  border-radius: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  border: 1px solid #edf0f4;
}

.bar-fill {
  width: 100%;
  border-radius: 12px 12px 0 0;
  min-height: 4px;
}

.bar-fill.activation {
  background: #2563eb;
}

.bar-fill.validation {
  background: #10a37f;
}

.bar-label {
  font-size: 11px;
  color: var(--muted);
}

.chart-empty {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}

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

.toolbar-form input {
  flex: 1 1 260px;
}

.toolbar-form select {
  flex: 0 0 180px;
}

.bulk-panel {
  display: grid;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfbfc;
}

.bulk-meta {
  justify-content: space-between;
}

.bulk-meta span {
  color: var(--muted);
  font-size: 13px;
}

.bulk-controls select {
  flex: 0 0 220px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
}

table {
  width: 100%;
  min-width: 960px;
  border-collapse: collapse;
  background: #fff;
}

th,
td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  vertical-align: top;
}

th {
  background: #f9fafb;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: .04em;
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  justify-content: center;
  min-width: 88px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.unused {
  background: #eef2f7;
  color: #475569;
}

.badge.active {
  background: #ecfdf5;
  color: #047857;
}

.badge.exhausted,
.badge.expired {
  background: #fef2f2;
  color: #b91c1c;
}

.badge.disabled {
  background: #e5e7eb;
  color: #111827;
}

.text-link {
  color: #2563eb;
  font-weight: 700;
}

.cell-meta {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.mono {
  font-family: Consolas, "Courier New", monospace;
  word-break: break-all;
}

.empty {
  text-align: center;
  color: var(--muted);
}

.compact-actions {
  gap: 8px;
  flex-wrap: nowrap;
}

.mini-button {
  min-height: 34px;
  padding: 7px 12px;
  font-size: 13px;
}

.hidden-form {
  display: none;
}

.hidden {
  display: none !important;
}

.alert {
  margin-bottom: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #dbeafe;
  background: #eff6ff;
  color: #1d4ed8;
}

.alert.error {
  border-color: #fecaca;
  background: #fef2f2;
  color: var(--danger);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(15, 23, 42, .42);
  z-index: 1000;
}

.modal-backdrop.show {
  display: flex;
}

.modal-card {
  width: min(980px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .18);
  padding: 22px;
}

.sub-card {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfbfc;
}

.sub-card h3 {
  margin-bottom: 14px;
}

.icon-close {
  min-height: 36px;
  min-width: 36px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.result-box {
  min-height: 220px;
  margin: 16px 0 0;
  padding: 16px;
  overflow: auto;
  border-radius: 14px;
  background: #0f172a;
  color: #dbeafe;
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.test-page-head {
  max-width: 1440px;
}

.test-console-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(460px, 1fr));
  gap: 22px;
  align-items: start;
  max-width: 1440px;
  width: 100%;
}

.test-card {
  padding: 28px;
}

.test-card .section-head {
  margin-bottom: 18px;
}

.test-card .result-box {
  min-height: 260px;
}

.pagination {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: flex-end;
  margin-top: 16px;
  color: var(--muted);
}

.sort-note {
  margin: 12px 0 0;
}

@media (max-width: 1180px) {
  .dashboard-metrics,
  .metric-grid.mini,
  .content-grid.two,
  .dashboard-trend-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-layout {
    grid-template-columns: 210px minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

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

  .dashboard-metrics,
  .metric-grid.mini,
  .content-grid.two,
  .dashboard-trend-grid,
  .test-console-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .content-area,
  .login-shell {
    padding: 18px;
  }

  .page-head,
  .page-actions,
  .toolbar-form,
  .toolbar-actions,
  .bulk-controls,
  .bulk-meta,
  .split-fields,
  .trend-summary,
  .trend-head,
  .trend-select-wrap,
  .modal-head,
  .pagination {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-form input,
  .toolbar-form select {
    flex: 1 1 auto;
  }

  .compact-actions {
    flex-direction: column;
  }
}
