:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1b2533;
  --muted: #6b7688;
  --line: #e3e8f0;
  --brand: #136f63;
  --brand-dark: #0d554c;
  --danger: #b42318;
  --warning: #b86e00;
  --ok: #167647;
  --shadow: 0 12px 30px rgba(18, 31, 53, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button:hover,
.button:hover {
  background: var(--brand-dark);
}

.ghost {
  background: #eef3f7;
  color: var(--text);
}

.ghost:hover {
  background: #dfe7ef;
}

.danger {
  color: var(--danger);
}

.danger:hover {
  background: #fde8e7;
}

.text-link {
  justify-self: center;
  color: var(--brand);
  font-weight: 700;
}

.text-link:hover {
  color: var(--brand-dark);
}

.small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.full {
  width: 100%;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(19, 111, 99, 0.12), transparent 36%),
    var(--bg);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #111827;
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.brand,
.login-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand span,
.login-title p {
  display: block;
  margin: 2px 0 0;
  color: #9ca3af;
  font-size: 13px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 900;
}

.sidebar nav {
  display: grid;
  gap: 10px;
}

.nav-section {
  display: grid;
  gap: 8px;
}

.nav-section-title {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border-radius: 6px;
  color: #f9fafb;
  background: rgba(255, 255, 255, 0.06);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0;
  cursor: pointer;
  user-select: none;
}

.nav-section-title::-webkit-details-marker {
  display: none;
}

.nav-section-title:hover {
  background: rgba(255, 255, 255, 0.1);
}

.nav-chevron {
  color: #9ca3af;
  font-size: 12px;
  transition: transform 0.18s ease;
}

.nav-section[open] .nav-chevron {
  transform: rotate(180deg);
}

.nav-section-items {
  display: grid;
  gap: 6px;
  padding: 4px 0 2px 10px;
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  margin-left: 12px;
}

.sidebar nav a {
  padding: 11px 12px;
  border-radius: 6px;
  color: #d1d5db;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.content {
  padding: 28px;
  min-width: 0;
}

.login-card {
  width: min(440px, 100%);
  padding: 30px;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-title {
  margin-bottom: 24px;
}

.login-title h1,
.page-head h1,
.panel h2 {
  margin: 0;
}

.login-title h1 {
  font-size: 24px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-head p {
  margin: 6px 0 0;
  color: var(--muted);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(18, 31, 53, 0.04);
}

.metric {
  padding: 18px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.panel {
  margin-bottom: 18px;
  overflow: hidden;
}

.panel.narrow {
  max-width: 720px;
}

.panel-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head-row,
.generated-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-head h2 {
  font-size: 17px;
}

.stack,
.grid-form {
  padding: 20px;
}

.stack {
  display: grid;
  gap: 14px;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr)) auto;
  align-items: end;
  gap: 14px;
}

.filter-form {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) repeat(4, minmax(130px, 1fr)) auto auto;
  align-items: end;
  gap: 14px;
  padding: 20px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  background: #fff;
  font: inherit;
}

.small-input {
  width: 86px;
  min-height: 30px;
  padding: 5px 7px;
  font-size: 12px;
}

.medium-input {
  width: 150px;
  min-height: 30px;
  padding: 5px 7px;
  font-size: 12px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(19, 111, 99, 0.18);
  border-color: var(--brand);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f8fafc;
  font-size: 12px;
  letter-spacing: 0;
}

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef3f7;
  font-family: Consolas, "Courier New", monospace;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #e8eef5;
  color: #3b4656;
  font-size: 12px;
  font-weight: 700;
}

.badge.active,
.badge.success {
  background: #e7f6ec;
  color: var(--ok);
}

.badge.unused {
  background: #eef3f7;
}

.badge.banned,
.badge.fail,
.badge.disabled {
  background: #fde8e7;
  color: var(--danger);
}

.badge.expired,
.badge.pending,
.badge.retry,
.badge.sending {
  background: #fff4df;
  color: var(--warning);
}

.badge.sent,
.badge.debug {
  background: #e7f6ec;
  color: var(--ok);
}

.badge.owner {
  background: #e7f6ec;
  color: var(--ok);
}

.badge.draft,
.badge.beta {
  background: #fff4df;
  color: var(--warning);
}

.badge.published,
.badge.stable {
  background: #e7f6ec;
  color: var(--ok);
}

.badge.user {
  background: #eef3f7;
  color: #3b4656;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.email-users-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.email-users-table {
  min-width: 1320px;
  table-layout: fixed;
}

.email-users-table th:nth-child(1) { width: 70px; }
.email-users-table th:nth-child(2) { width: 270px; }
.email-users-table th:nth-child(3) { width: 120px; }
.email-users-table th:nth-child(4) { width: 330px; }
.email-users-table th:nth-child(5) { width: 190px; }
.email-users-table th:nth-child(6) { width: 210px; }
.email-users-table th:nth-child(7) { width: 290px; }

.email-users-table td {
  vertical-align: top;
}

.license-users-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.license-users-table {
  min-width: 1420px;
  table-layout: fixed;
}

.license-users-table th:nth-child(1) { width: 180px; }
.license-users-table th:nth-child(2) { width: 190px; }
.license-users-table th:nth-child(3) { width: 110px; }
.license-users-table th:nth-child(4) { width: 280px; }
.license-users-table th:nth-child(5) { width: 96px; }
.license-users-table th:nth-child(6) { width: 210px; }
.license-users-table th:nth-child(7) { width: 420px; }

.license-users-table td {
  vertical-align: top;
}

.license-users-table td strong,
.license-users-table td small,
.machine-stack,
.date-stack {
  display: grid;
  gap: 5px;
}

.license-users-table td small,
.date-stack span {
  color: var(--muted);
  font-size: 12px;
}

.machine-stack code {
  width: fit-content;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.license-user-form {
  display: grid;
  gap: 8px;
}

.license-user-form label {
  font-size: 12px;
}

.license-user-form input {
  min-height: 34px;
  padding: 7px 9px;
}

.license-user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cell-id {
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.user-main-cell,
.status-cell,
.ip-cell,
.date-cell {
  min-width: 0;
}

.user-main-cell strong {
  display: block;
  word-break: break-all;
}

.user-main-cell span,
.user-main-cell em,
.ip-cell span,
.date-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.45;
  word-break: break-word;
}

.user-main-cell span,
.user-main-cell em,
.status-cell .muted-left,
.ip-cell span + span,
.date-cell span + span {
  margin-top: 6px;
}

.machine-cell {
  min-width: 0;
}

.machine-head {
  margin-bottom: 8px;
}

.machine-list {
  display: grid;
  gap: 6px;
}

.machine-item {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: start;
  gap: 6px;
}

.machine-index {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 24px;
}

.machine-item code {
  display: block;
  white-space: normal;
  word-break: break-all;
  line-height: 1.45;
}

.email-user-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.email-user-actions .medium-input {
  grid-column: 1 / -1;
  width: 100%;
}

.email-user-actions button {
  width: 100%;
  white-space: nowrap;
}

.email-user-actions button[value="reset_machine"] {
  grid-column: 1 / -1;
}

.batch-actions,
.copy-cell {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.copy-cell code {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.small-select {
  width: auto;
  min-height: 30px;
  padding: 5px 28px 5px 8px;
  font-size: 12px;
}

.compact-filter {
  grid-template-columns: minmax(240px, 1.4fr) repeat(2, minmax(130px, 1fr)) auto auto;
}

.update-upload-form {
  grid-template-columns: repeat(4, minmax(170px, 1fr)) auto;
}

.update-filter-form {
  grid-template-columns: minmax(240px, 1.4fr) repeat(3, minmax(130px, 1fr)) auto auto;
}

.wide-field {
  grid-column: 1 / span 4;
}

[hidden] {
  display: none !important;
}

.field-tip {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.upload-method {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
}

.radio-card {
  min-height: 82px;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 10px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--text);
}

.radio-card input {
  width: auto;
  margin-top: 3px;
}

.radio-card span {
  display: grid;
  gap: 5px;
}

.radio-card strong {
  font-size: 14px;
}

.radio-card em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 500;
  line-height: 1.45;
}

.upload-hint {
  align-self: center;
  color: var(--warning);
  font-size: 13px;
  font-weight: 700;
}

.upload-modal[hidden] {
  display: none;
}

.upload-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.upload-dialog {
  width: min(520px, 100%);
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.22);
}

.upload-dialog-head,
.upload-dialog-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.upload-dialog h2 {
  margin: 0;
  font-size: 18px;
}

.upload-dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.upload-dialog p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.upload-dialog-head strong {
  color: var(--brand);
  font-size: 28px;
}

.upload-progress {
  height: 12px;
  margin: 18px 0 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8eef5;
}

.upload-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
  transition: width 0.16s ease;
}

.upload-dialog-meta {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.upload-dialog .upload-dialog-tip {
  margin-top: 14px;
  color: var(--warning);
}

.upload-chip[hidden] {
  display: none;
}

.upload-chip {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 51;
  width: min(340px, calc(100vw - 36px));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(15, 23, 42, 0.18);
}

.upload-chip button {
  width: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  justify-content: stretch;
  padding: 13px 14px;
  border-radius: 0;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.upload-chip button:hover {
  background: #f8fafc;
}

.upload-chip span,
.upload-chip em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-chip span {
  font-weight: 800;
}

.upload-chip strong {
  color: var(--brand);
}

.upload-chip em {
  grid-column: 1 / span 2;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 600;
}

.upload-chip-progress {
  height: 5px;
  background: #e8eef5;
}

.upload-chip-progress span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--brand);
  transition: width 0.16s ease;
}

.form-grid-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.check-field,
.check-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}

.check-field input,
.check-inline input {
  width: auto;
}

.check-inline {
  min-height: 30px;
  font-size: 12px;
}

.muted-left {
  color: var(--muted);
  font-size: 12px;
}

.alert {
  margin-bottom: 16px;
  padding: 12px 14px;
  border-radius: 6px;
  font-weight: 700;
}

.alert.error {
  background: #fde8e7;
  color: var(--danger);
}

.alert.success {
  background: #e7f6ec;
  color: var(--ok);
}

.muted {
  color: var(--muted);
  text-align: center;
}

.key-output {
  min-height: 180px;
  margin: 20px;
  width: calc(100% - 40px);
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
}

.generated-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.sr-copy-source {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.generated-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: 10px;
  padding: 20px;
}

.generated-key {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
  overflow: hidden;
}

.generated-key span {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  background: #f1f5f9;
  border-right: 1px solid var(--line);
  font-size: 12px;
  font-weight: 800;
}

.generated-key code {
  justify-self: start;
  margin: 0 10px;
  max-width: calc(100% - 20px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  color: var(--muted);
  font-size: 13px;
}

.pager div {
  display: flex;
  gap: 8px;
}

.disabled,
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.api-list {
  display: grid;
  gap: 10px;
  padding: 20px;
}

.distribution-metrics {
  grid-template-columns: repeat(5, minmax(150px, 1fr));
}

.distribution-shortcuts {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.shortcut-card {
  min-height: 104px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(18, 31, 53, 0.04);
}

.shortcut-card:hover {
  border-color: rgba(19, 111, 99, 0.28);
  background: #fbfefd;
}

.shortcut-card strong {
  font-size: 16px;
}

.shortcut-card span,
.panel-tip {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.panel-tip {
  padding: 0 20px 20px;
}

.distribution-form {
  grid-template-columns: repeat(4, minmax(170px, 1fr)) auto;
}

.distribution-order-form {
  grid-template-columns: repeat(4, minmax(170px, 1fr));
}

.distribution-profile-form {
  grid-template-columns: repeat(4, minmax(170px, 1fr)) auto;
}

.distribution-order-form button {
  justify-self: start;
}

.permission-grid {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.permission-grid > div {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.referral-public {
  min-height: 100vh;
  display: grid;
  place-items: center;
  gap: 18px;
  padding: 28px;
}

.referral-download-card {
  width: min(520px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.referral-download-card h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.3;
}

.referral-download-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.referral-file-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.referral-file-meta span {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.referral-file-meta strong {
  flex: none;
  color: var(--brand);
}

.referral-download-button {
  width: 100%;
}

.referral-hero,
.referral-info,
.referral-images figure {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(18, 31, 53, 0.04);
}

.referral-hero {
  display: grid;
  gap: 14px;
  padding: 28px;
}

.referral-hero h1 {
  margin: 0;
  font-size: 30px;
}

.referral-hero p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.referral-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.referral-info {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.referral-info div {
  display: grid;
  gap: 8px;
  padding: 18px;
  background: #fff;
}

.referral-info strong {
  color: var(--muted);
  font-size: 13px;
}

.referral-info span {
  font-size: 18px;
  font-weight: 800;
}

.referral-images {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 18px;
}

.referral-images figure {
  margin: 0;
  padding: 18px;
}

.referral-images img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8fafc;
}

.referral-images figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .metrics,
  .grid-form,
  .filter-form,
  .distribution-shortcuts,
  .distribution-form,
  .distribution-order-form,
  .distribution-profile-form,
  .referral-info,
  .referral-images {
    grid-template-columns: 1fr 1fr;
  }

  .panel-head-row,
  .generated-head,
  .pager {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .content {
    padding: 18px;
  }

  .page-head {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .grid-form,
  .filter-form,
  .distribution-shortcuts,
  .distribution-form,
  .distribution-order-form,
  .distribution-profile-form,
  .referral-info,
  .referral-images {
    grid-template-columns: 1fr;
  }

  .generated-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

.copy-cell.copied,
.generated-key.copied {
  border-color: rgba(22, 118, 71, 0.34);
  background: #f0fbf4;
}

.copy-btn.copied {
  background: #e7f6ec;
  color: var(--ok);
}

.generated-key .copy-btn {
  margin-right: 10px;
}
