:root {
  color-scheme: light;
  --ink: #111827;
  --muted: #667085;
  --line: #d8dee8;
  --surface: #ffffff;
  --canvas: #f4f6f8;
  --primary: #087f6b;
  --primary-dark: #066455;
  --danger: #b42318;
  --warning: #b54708;
  --focus: #2563eb;
  --radius: 7px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--canvas); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-size: 14px;
  line-height: 1.5;
}

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

button { cursor: pointer; }

[hidden] { display: none !important; }

.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;
}

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

.auth-panel {
  width: min(100%, 380px);
  padding: 36px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.24);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-bottom: 24px;
  border-radius: 6px;
  color: white;
  background: var(--primary);
  font-size: 20px;
  font-weight: 800;
}

.brand-mark.small { width: 34px; height: 34px; margin: 0; font-size: 16px; }

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
}

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

h1 { margin-bottom: 6px; font-size: 27px; line-height: 1.2; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 19px; line-height: 1.3; letter-spacing: 0; }
h3 { margin-bottom: 0; font-size: 15px; letter-spacing: 0; }
.muted { color: var(--muted); }

.stack-form { display: grid; gap: 16px; margin-top: 28px; }

label { display: grid; gap: 6px; color: #344054; font-weight: 650; }

input, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #c7cfdb;
  border-radius: 6px;
  outline: none;
}

input:focus, select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.button {
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 750;
}

.button:disabled { cursor: wait; opacity: 0.58; }
.button.primary { color: white; background: var(--primary); }
.button.primary:hover { background: var(--primary-dark); }
.button.secondary { color: #344054; background: white; border-color: #c7cfdb; }
.button.secondary:hover { background: #f8fafc; }
.button.danger { color: var(--danger); background: white; border-color: #f0b6b1; }
.button.danger:hover { background: #fff4f3; }
.button.wide { width: 100%; }

.form-error { min-height: 21px; margin: -6px 0 0; color: var(--danger); font-size: 13px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  color: white;
  background: #111827;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

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

.brand-lockup { display: flex; align-items: center; gap: 11px; }
.brand-lockup strong { display: block; font-size: 15px; }
.brand-lockup span { display: block; color: #9da7b7; font-size: 11px; }

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: inherit;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  font-size: 20px;
}

.icon-button:hover { background: rgba(255, 255, 255, 0.08); }
.icon-button.subtle { color: #475467; border-color: var(--line); background: white; }
.icon-button.subtle:hover { background: #f8fafc; }

.workspace { width: min(1180px, 100%); margin: 0 auto; padding: 28px 24px 72px; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat {
  min-height: 86px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat span { display: block; color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin-top: 5px; font-size: 26px; line-height: 1; }

.tool-panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.generator-grid {
  display: grid;
  grid-template-columns: 130px 160px 130px minmax(180px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.generate-button { min-width: 112px; }

.records-section { margin-top: 28px; }
.records-heading { margin-bottom: 12px; }

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 420px) 150px;
  gap: 10px;
  margin-bottom: 12px;
}

.filters input, .filters select { min-height: 40px; }

.table-wrap {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td { padding: 13px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid #e7ebf0; }
th { color: #667085; background: #f8fafb; font-size: 11px; font-weight: 800; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
th:nth-child(1) { width: 19%; }
th:nth-child(2) { width: 11%; }
th:nth-child(3) { width: 8%; }
th:nth-child(4) { width: 9%; }
th:nth-child(5) { width: 17%; }
th:nth-child(6) { width: 25%; }
th:nth-child(7) { width: 11%; }

.key-hint { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 13px; font-weight: 700; }
.cell-note { overflow: hidden; color: #475467; text-overflow: ellipsis; white-space: nowrap; }
.cell-muted { color: var(--muted); }

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-unused { color: #344054; background: #edf0f4; }
.status-active { color: #05603a; background: #d9f5e8; }
.status-expired { color: var(--warning); background: #fff0d5; }
.status-revoked { color: var(--danger); background: #fee4e2; }

.row-action {
  min-height: 34px;
  padding: 6px 10px;
  color: #344054;
  background: white;
  border: 1px solid #c7cfdb;
  border-radius: 5px;
  font-weight: 700;
}

.row-action:hover { background: #f5f7fa; }
.empty-state { padding: 42px 16px; text-align: center; color: var(--muted); }
.record-count { margin: 10px 2px 0; color: var(--muted); font-size: 12px; }

.dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 28px));
  padding: 22px;
  color: var(--ink);
  background: var(--surface);
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.3);
}

.dialog::backdrop { background: rgba(17, 24, 39, 0.68); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.dialog .icon-button { flex: 0 0 auto; color: #475467; border-color: var(--line); }
.dialog-note { margin: 12px 0 16px; color: var(--muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

.generated-list { max-height: 370px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.generated-item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid #e7ebf0; }
.generated-item:last-child { border-bottom: 0; }
.generated-item code { min-width: 0; flex: 1; overflow-wrap: anywhere; color: #1d2939; font-size: 13px; font-weight: 750; }
.copy-one { width: 34px; height: 34px; flex: 0 0 auto; color: #475467; background: white; border: 1px solid #c7cfdb; border-radius: 5px; }

.manage-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 18px 0; }
.summary-item { padding: 11px; background: #f7f9fb; border: 1px solid #e1e6ed; border-radius: 6px; }
.summary-item span { display: block; color: var(--muted); font-size: 11px; }
.summary-item strong { display: block; margin-top: 4px; font-size: 13px; overflow-wrap: anywhere; }
.inline-form { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: end; padding: 16px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.subsection-heading { margin: 18px 0 10px; }
.device-list { display: grid; gap: 8px; max-height: 250px; overflow: auto; }
.device-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 11px; border: 1px solid var(--line); border-radius: 6px; }
.device-item strong, .device-item span { display: block; overflow-wrap: anywhere; }
.device-item span { color: var(--muted); font-size: 11px; }
.device-empty { padding: 18px; color: var(--muted); text-align: center; background: #f8fafb; border-radius: 6px; }
.device-item .button { min-height: 34px; padding: 5px 9px; font-size: 12px; }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  max-width: min(360px, calc(100% - 36px));
  padding: 11px 14px;
  color: white;
  background: #111827;
  border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 860px) {
  .generator-grid { grid-template-columns: repeat(3, 1fr); }
  .note-field { grid-column: 1 / 3; }
  .generate-button { width: 100%; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  th:nth-child(3), td:nth-child(3), th:nth-child(6), td:nth-child(6) { display: none; }
  th:nth-child(1) { width: 26%; }
  th:nth-child(2) { width: 15%; }
  th:nth-child(4) { width: 14%; }
  th:nth-child(5) { width: 25%; }
  th:nth-child(7) { width: 20%; }
}

@media (max-width: 620px) {
  .topbar-inner { padding: 10px 16px; }
  .workspace { padding: 18px 14px 60px; }
  .stats-grid { gap: 8px; }
  .stat { min-height: 74px; padding: 13px; }
  .stat strong { font-size: 23px; }
  .tool-panel { padding: 16px; }
  .generator-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .note-field { grid-column: 1 / -1; }
  .generate-button { grid-column: 1 / -1; }
  .filters { grid-template-columns: 1fr 132px; }

  .table-wrap { overflow: visible; background: transparent; border: 0; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody { display: grid; gap: 9px; }
  tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px 12px;
    padding: 13px;
    background: white;
    border: 1px solid var(--line);
    border-radius: var(--radius);
  }
  tbody tr:hover { background: white; }
  tbody td { display: block !important; padding: 0; border: 0; }
  tbody td:nth-child(1) { grid-column: 1; grid-row: 1; }
  tbody td:nth-child(2) { grid-column: 2; grid-row: 1; text-align: right; }
  tbody td:nth-child(3) { grid-column: 1; grid-row: 2; color: var(--muted); font-size: 12px; }
  tbody td:nth-child(3)::before { content: "时长 "; }
  tbody td:nth-child(4) { grid-column: 2; grid-row: 2; color: var(--muted); font-size: 12px; text-align: right; }
  tbody td:nth-child(4)::before { content: "设备 "; }
  tbody td:nth-child(5) { grid-column: 1 / -1; grid-row: 3; color: var(--muted); font-size: 12px; }
  tbody td:nth-child(5)::before { content: "到期 "; }
  tbody td:nth-child(6) { grid-column: 1; grid-row: 4; display: block !important; font-size: 12px; }
  tbody td:nth-child(7) { grid-column: 2; grid-row: 4; text-align: right; }
  .cell-note { white-space: normal; }
  .dialog { padding: 18px; }
  .dialog-actions .button { flex: 1; }
  .manage-summary { grid-template-columns: 1fr; }
  .summary-item { display: grid; grid-template-columns: 90px 1fr; align-items: center; }
  .summary-item strong { margin: 0; }
}

@media (max-width: 390px) {
  .auth-panel { padding: 28px 22px; }
  .filters { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
