:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --line: #dce2e7;
  --line-strong: #c8d1d8;
  --text: #17212b;
  --muted: #66737f;
  --green: #176b4d;
  --green-dark: #10533b;
  --blue: #245f9e;
  --amber: #9a6200;
  --red: #b42318;
  --shadow: 0 14px 40px rgba(23, 33, 43, 0.12);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(36, 95, 158, 0.2);
  outline-offset: 1px;
}

[hidden] {
  display: none !important;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background: #edf1f3;
}

.login-panel {
  width: min(390px, 100%);
  padding: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  margin-bottom: 22px;
  border-radius: 6px;
  background: var(--green);
  color: white;
  font-size: 13px;
  font-weight: 800;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--green);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

.login-panel h1 {
  margin-bottom: 26px;
  font-size: 24px;
  line-height: 1.25;
}

.login-panel form,
.form-grid {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #35414c;
  font-size: 13px;
  font-weight: 600;
}

input,
select,
textarea {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  padding: 8px 10px;
}

input::placeholder {
  color: #929ca5;
}

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.icon-button {
  min-height: 36px;
  border-radius: 5px;
  padding: 7px 12px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: white;
}

.primary-button:hover {
  border-color: var(--green-dark);
  background: var(--green-dark);
}

.secondary-button,
.icon-button {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: #35414c;
}

.danger-button {
  border: 1px solid #e8b5af;
  background: #fff5f4;
  color: var(--red);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.text-button {
  min-height: 30px;
  border: 0;
  background: transparent;
  color: var(--blue);
  padding: 4px 6px;
}

.icon-button {
  width: 36px;
  padding: 0;
  font-size: 20px;
  line-height: 1;
}

.full-button {
  width: 100%;
}

.form-error {
  min-height: 18px;
  margin: -6px 0 0;
  color: var(--red);
  font-size: 12px;
  font-weight: 500;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.topbar-inner {
  display: flex;
  width: min(1440px, 100%);
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin: 0 auto;
  padding: 10px 24px;
}

.topbar h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.topbar-actions,
.section-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 22px 24px 48px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.summary-item {
  min-width: 0;
  padding: 15px 17px;
  border-right: 1px solid var(--line);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-item span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  display: block;
  font-size: 22px;
  line-height: 1.2;
}

.license-section,
.activity-section {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  overflow: hidden;
}

.activity-section {
  margin-top: 20px;
}

.section-heading {
  display: flex;
  min-height: 70px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.section-heading h2 {
  margin: 0 0 3px;
  font-size: 17px;
}

.compact-heading {
  min-height: 52px;
}

.compact-heading h2 {
  margin: 0;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.filters {
  display: grid;
  grid-template-columns: 220px 150px minmax(220px, 1fr);
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.filters label {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filters label > span {
  flex: 0 0 auto;
}

.filters input,
.filters select {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 6px 8px;
}

.search-field {
  justify-self: end;
  width: min(380px, 100%);
}

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

table {
  width: 100%;
  min-width: 1060px;
  border-collapse: collapse;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid #e8ecef;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: #f7f9fa;
  color: #53606b;
  font-size: 12px;
  font-weight: 700;
}

td {
  font-size: 13px;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fbfcfc;
}

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

.member-cell small {
  margin-top: 3px;
  color: var(--muted);
}

.status-badge {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border: 1px solid;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 700;
}

.status-active {
  border-color: #a8d4c1;
  background: #edf8f2;
  color: var(--green);
}

.status-paused,
.status-expired {
  border-color: #ebcd91;
  background: #fff9e9;
  color: var(--amber);
}

.status-revoked {
  border-color: #e8b5af;
  background: #fff3f1;
  color: var(--red);
}

.actions-column {
  width: 330px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
}

.row-actions .danger-action {
  color: var(--red);
}

.empty-row td {
  height: 88px;
  color: var(--muted);
  text-align: center;
}

.activity-list {
  max-height: 340px;
  overflow: auto;
}

.activity-row {
  display: grid;
  grid-template-columns: 150px 150px minmax(180px, 1fr) 170px;
  gap: 12px;
  align-items: center;
  min-height: 46px;
  padding: 8px 18px;
  border-bottom: 1px solid #edf0f2;
}

.activity-row:last-child {
  border-bottom: 0;
}

.activity-type {
  color: var(--blue);
  font-weight: 700;
}

.activity-detail,
.activity-time {
  color: var(--muted);
  font-size: 12px;
}

dialog {
  width: min(480px, calc(100vw - 28px));
  max-height: min(760px, calc(100vh - 28px));
  margin: auto;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}

dialog::backdrop {
  background: rgba(21, 30, 38, 0.48);
}

.wide-dialog {
  width: min(680px, calc(100vw - 28px));
}

.dialog-heading,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
}

.dialog-heading {
  border-bottom: 1px solid var(--line);
}

.dialog-heading h2 {
  margin: 0;
  font-size: 17px;
}

.dialog-close {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #596671;
  font-size: 23px;
  line-height: 1;
}

.dialog-close:hover {
  background: #eef2f4;
}

.dialog-body {
  padding: 18px;
}

.dialog-actions {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.codes-output {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  font-family: Consolas, monospace;
  line-height: 1.65;
}

.device-list {
  display: grid;
  gap: 0;
  max-height: 440px;
  padding: 0;
  overflow: auto;
}

.device-row {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 150px auto;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.device-row:last-child {
  border-bottom: 0;
}

.device-row strong,
.device-row small {
  display: block;
}

.device-row small {
  margin-top: 3px;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 40px));
  transform: translateY(16px);
  border-radius: 5px;
  background: #17212b;
  color: white;
  padding: 11px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 900px) {
  .summary-strip {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-item {
    border-bottom: 1px solid var(--line);
  }

  .summary-item:nth-child(2n) {
    border-right: 0;
  }

  .summary-item:last-child {
    border-bottom: 0;
  }

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

  .search-field {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }

  .activity-row {
    grid-template-columns: 110px minmax(130px, 1fr) 150px;
  }

  .activity-detail {
    display: none;
  }
}

@media (max-width: 620px) {
  .topbar-inner,
  .workspace {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar-inner {
    min-height: 64px;
  }

  .summary-strip {
    grid-template-columns: 1fr 1fr;
  }

  .summary-item {
    padding: 12px;
  }

  .summary-item strong {
    font-size: 19px;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-actions {
    width: 100%;
  }

  .section-actions button {
    flex: 1;
  }

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

  .search-field {
    grid-column: auto;
  }

  .activity-row {
    grid-template-columns: 1fr auto;
  }

  .activity-row .activity-member {
    display: none;
  }

  .device-row {
    grid-template-columns: 1fr auto;
  }

  .device-row > div:nth-child(2) {
    display: none;
  }
}
