:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei UI", sans-serif;
  font-size: 15px;
  color: #202a2a;
  background: #f3f6f5;
  --ink: #202a2a;
  --muted: #667272;
  --line: #d7dfdd;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --accent: #147d76;
  --accent-dark: #0f625d;
  --accent-soft: #e5f3f1;
  --blue: #2e6da4;
  --amber: #a4650b;
  --amber-soft: #fff2d8;
  --red: #b24242;
  --red-soft: #fbe9e7;
  --shadow: 0 10px 28px rgba(33, 51, 49, 0.08);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: #f3f6f5; color: var(--ink); letter-spacing: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a, select { -webkit-tap-highlight-color: transparent; }
code { font-family: "Cascadia Mono", Consolas, monospace; font-size: 0.88em; overflow-wrap: anywhere; }

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto minmax(260px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand, .login-brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; min-width: 0; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 7px; background: #147d76; color: #fff; font-weight: 800; font-size: 13px; flex: 0 0 auto; }
.brand strong, .login-brand strong { display: block; font-size: 15px; }
.brand small, .login-brand small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.topnav { display: flex; align-items: center; gap: 4px; }
.topnav a { padding: 9px 12px; border-radius: 6px; text-decoration: none; color: #43504f; font-weight: 600; white-space: nowrap; }
.topnav a:hover { background: #edf2f0; color: var(--ink); }
.logout-form { justify-self: end; display: flex; align-items: center; gap: 10px; }
.account { color: var(--muted); font-size: 13px; }

.page-shell { width: min(1240px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 64px; }
.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-heading h1 { font-size: clamp(24px, 3vw, 34px); line-height: 1.16; margin: 3px 0 6px; }
.eyebrow { margin: 0; color: var(--accent); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.heading-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.heading-actions select { min-width: 190px; }

.button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
}
.button.primary { background: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); }
.button.secondary { background: #fff; color: var(--ink); border-color: #bfcac7; }
.button.secondary:hover, .button.ghost:hover { border-color: #95a6a2; background: #f6f8f7; }
.button.ghost { background: transparent; color: #4d5a58; border-color: transparent; }
.button.danger { background: var(--red); color: #fff; }
.button.full { width: 100%; }
.button:disabled { opacity: 0.5; cursor: not-allowed; }
.text-link { color: var(--accent-dark); font-weight: 700; text-decoration: none; }

input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #bdc8c5;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
  outline: none;
}
textarea { resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(20, 125, 118, 0.12); }

.notice { padding: 12px 14px; border-radius: 6px; margin-bottom: 18px; border: 1px solid; }
.notice.success { color: #175e48; background: #e8f5ef; border-color: #b9dfcf; }
.notice.error { color: #8f2f2f; background: var(--red-soft); border-color: #e7b7b2; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 34px; }
.metric { min-height: 108px; padding: 18px; border: 1px solid var(--line); border-top: 3px solid #7f8d8a; border-radius: 8px; background: var(--surface); }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 12px; font-size: 30px; line-height: 1; }
.metric.active { border-top-color: var(--accent); }
.metric.warning { border-top-color: #d39132; }
.metric.danger { border-top-color: var(--red); }

.section-block { margin-top: 34px; }
.section-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; margin-bottom: 13px; }
.section-heading h2 { margin: 0; font-size: 18px; }
.section-heading p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.product-card { display: block; padding: 17px; border: 1px solid var(--line); border-radius: 8px; background: #fff; text-decoration: none; min-width: 0; }
.product-card:hover { border-color: #98aaa6; box-shadow: var(--shadow); }
.product-card-top { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 8px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #27a07f; flex: 0 0 auto; }
.product-card > code { color: var(--muted); }
.product-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 18px 0 0; }
.product-card dl div { border-top: 1px solid #e6ebe9; padding-top: 10px; }
.product-card dt { color: var(--muted); font-size: 12px; }
.product-card dd { margin: 4px 0 0; font-weight: 700; }

.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #e5ebe9; text-align: left; vertical-align: middle; }
th { color: #5c6967; background: #f6f8f7; font-size: 12px; font-weight: 700; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfc; }
.cell-sub { display: block; color: var(--muted); margin-top: 3px; }
.machine-code { white-space: nowrap; color: #374745; }
.table-action { text-align: right; }
.table-action a { color: var(--accent-dark); font-weight: 700; text-decoration: none; }
.empty-cell, .empty-state { color: var(--muted); text-align: center; padding: 30px; }

.status { display: inline-flex; align-items: center; min-height: 26px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status.active { color: #17664f; background: var(--accent-soft); }
.status.expired { color: #87570d; background: var(--amber-soft); }
.status.revoked { color: #903838; background: var(--red-soft); }
.status.large { min-height: 32px; padding: 5px 12px; font-size: 13px; }

.form-surface, .activation-output { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 24px; box-shadow: var(--shadow); }
.compact-form { max-width: 820px; }
.field-grid { display: grid; gap: 18px; }
.field-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-grid label, .form-stack label { display: grid; gap: 7px; color: #3f4d4b; font-size: 13px; font-weight: 700; }
.span-two { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.filter-bar { display: grid; grid-template-columns: 220px minmax(240px, 1fr) auto auto; gap: 10px; margin-bottom: 15px; align-items: center; }

.detail-grid { max-width: 940px; }
.detail-list { margin: 0; display: grid; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.detail-list.columns { grid-template-columns: 1fr 1fr; margin-top: 18px; }
.detail-list div { min-height: 66px; padding: 13px 16px; border-bottom: 1px solid #e5ebe9; }
.detail-list.columns div { border-right: 1px solid #e5ebe9; }
.detail-list div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 12px; }
.detail-list dd { margin: 6px 0 0; font-weight: 650; overflow-wrap: anywhere; }
.activation-output textarea { font-family: "Cascadia Mono", Consolas, monospace; font-size: 13px; background: #f7f9f8; }
.danger-zone { display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-top: 28px; padding: 18px 20px; border: 1px solid #e7b7b2; border-radius: 8px; background: #fffafa; }
.danger-zone h2 { margin: 0; font-size: 16px; }
.danger-zone p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef3f1; }
.login-panel { width: min(420px, 100%); padding: 30px; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.login-panel h1 { margin: 30px 0 20px; font-size: 24px; }
.form-stack { display: grid; gap: 16px; }
.login-meta { margin: 24px 0 0; padding-top: 18px; border-top: 1px solid #e5ebe9; color: var(--muted); font-size: 12px; text-align: center; }

@media (max-width: 900px) {
  .topbar { grid-template-columns: 1fr auto; padding: 10px 18px; }
  .topnav { order: 3; grid-column: 1 / -1; overflow-x: auto; justify-content: center; }
  .logout-form { grid-column: 2; grid-row: 1; }
  .account { display: none; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .product-grid { grid-template-columns: repeat(2, 1fr); }
  .filter-bar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 620px) {
  .page-shell { width: min(100% - 24px, 1240px); padding-top: 24px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .heading-actions { width: 100%; justify-content: flex-start; }
  .heading-actions select, .heading-actions .button { flex: 1 1 100%; }
  .metric-grid, .product-grid, .field-grid.two, .detail-list.columns { grid-template-columns: 1fr; }
  .span-two { grid-column: 1; }
  .metric { min-height: 96px; }
  .filter-bar { grid-template-columns: 1fr; }
  .form-surface, .activation-output { padding: 18px; }
  .danger-zone { align-items: flex-start; flex-direction: column; }
  .danger-zone .button { width: 100%; }
  .topnav { justify-content: flex-start; }
}
