:root {
  color-scheme: light;
  --bg: #eef2f7;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --blue: #2563eb;
  --green: #0f9f6e;
  --red: #d92d20;
  --shadow: 0 10px 30px rgba(25, 38, 70, .08);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  padding: 11px 16px;
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  outline: 0;
  background: #fff;
}

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

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 30px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.public-unbind .login-panel {
  border-top: 4px solid var(--blue);
}

.eyebrow {
  margin-bottom: 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .12em;
}

.public-unbind-note {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.back-link {
  color: var(--blue);
  font-size: 14px;
  text-align: center;
  text-decoration: none;
}

.back-link:hover {
  text-decoration: underline;
}

h1, h2, p {
  margin: 0;
}

h1 { font-size: 24px; }
h2 { font-size: 18px; }

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.topbar p, .panel-title span, .message {
  color: var(--muted);
  font-size: 13px;
}

.ghost, .secondary {
  background: #e7edf7;
  color: var(--ink);
}

.tabs {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 8px;
  margin-bottom: 18px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.tab-button {
  background: #e7edf7;
  color: var(--ink);
  border: 1px solid transparent;
  flex: 0 0 auto;
  padding: 9px 14px;
}

.tab-button.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  box-shadow: 0 8px 20px rgba(37, 99, 235, .18);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.tab-card {
  width: 100%;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.generator, .unbind {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 14px;
}

.form-grid.compact {
  grid-template-columns: minmax(0, 1fr) 140px;
  align-items: end;
}

.profile-block {
  align-self: stretch;
}

.number-field {
  max-width: 180px;
}

.quota-banner {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  padding: 9px 12px;
  border: 1px solid #cfe0ff;
  border-radius: 8px;
  background: #f5f8ff;
  color: var(--blue);
  font-weight: 700;
}

.choice-block {
  display: grid;
  gap: 8px;
}

.choice-block > span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 36px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
}

.chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

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

.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.date-presets {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.date-preset {
  padding: 8px 12px;
}

.date-preset.active {
  background: var(--blue);
  color: #fff;
}

.result-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #edf1f7;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.card-row button {
  flex: 0 0 auto;
  padding: 7px 10px;
  background: var(--green);
}

pre {
  width: 100%;
  max-width: 100%;
  height: 140px;
  margin: 0;
  overflow: auto;
  white-space: pre;
  word-break: normal;
  color: var(--ink);
  background: #f8fafc;
  border: 1px solid #edf1f7;
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
}

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

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

.stats-insights section {
  min-width: 0;
  border: 1px solid #edf1f7;
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.stats-insights h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.mini-table {
  display: grid;
  gap: 8px;
}

.mini-table div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #edf1f7;
}

.mini-table div:last-child {
  border-bottom: 0;
}

.mini-table span,
.mini-table strong {
  min-width: 0;
  font-size: 12px;
}

.mini-table span {
  color: var(--muted);
}

.mini-table strong {
  text-align: right;
  font-weight: 700;
}

.metric {
  background: #f8fafc;
  border: 1px solid #edf1f7;
  border-radius: 8px;
  padding: 10px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.chart-panel canvas {
  width: 100% !important;
  height: 320px !important;
}

.redpack-chart {
  position: relative;
  height: 320px;
}

.redpack-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.redpack-controls [role="group"] { display: flex; gap: 6px; }
.redpack-controls button[aria-pressed="true"] { background: #2563eb; color: #fff; }
.redpack-notice:empty { display: none; }
.redpack-notice { color: var(--muted); margin: 0 0 12px; }

.chart-stack {
  display: grid;
  gap: 18px;
}

.stats-table-wrap {
  width: 100%;
  max-height: 560px;
  overflow: auto;
  border: 1px solid #edf1f7;
  border-radius: 8px;
}

.stats-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 13px;
}

.stats-table th,
.stats-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #edf1f7;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.stats-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fafc;
}

.inline-cards {
  width: 260px;
  height: 70px;
  padding: 8px;
  font-size: 12px;
}

.admin-table {
  min-width: 640px;
}

.admin-subsection {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid #edf1f7;
}

.access-code-table {
  min-width: 640px;
}

.table-input {
  min-width: 130px;
}

.quota-input {
  min-width: 96px;
}

.role-pill {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  padding: 2px 7px;
  border-radius: 999px;
  color: #2563eb;
  background: #eff6ff;
  font-size: 12px;
  font-weight: 700;
}

.role-pill.subAdmin {
  color: #0f766e;
  background: #ecfdf5;
}

.role-pill.agent {
  color: #7c2d12;
  background: #fff7ed;
}

.inline-quota-actions {
  display: grid;
  grid-template-columns: 86px 86px auto;
  gap: 8px;
  align-items: center;
}

.inline-quota-actions input {
  min-width: 0;
  padding: 7px 8px;
}

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

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

.account-modal {
  display: flex;
  flex-direction: column;
  width: min(720px, 100%);
  max-height: min(760px, calc(100vh - 40px));
  overflow: hidden;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, .26);
}

.modal-title,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid #edf1f7;
}

.modal-actions {
  border-top: 1px solid #edf1f7;
  border-bottom: 0;
  background: #fff;
}

.modal-title h2,
.modal-section h3 {
  margin: 0;
}

.modal-content {
  overflow: auto;
  padding: 18px;
}

.modal-section {
  padding-bottom: 18px;
}

.modal-section + .modal-section {
  padding-top: 18px;
  border-top: 1px solid #edf1f7;
}

.modal-grid,
.quota-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

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

.modal-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 4px;
  margin-top: 12px;
}

.quota-cell {
  padding: 11px 12px;
  border: 1px solid #edf1f7;
  border-radius: 8px;
  background: #f8fafc;
}

.quota-cell span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.quota-cell strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.inline-check input {
  width: auto;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 2px;
  min-width: 220px;
}

.small-button {
  padding: 7px 10px;
}

.error { color: var(--red); }
.success { color: var(--green); }

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

  .workspace {
    padding: 16px;
  }

  .topbar {
    align-items: flex-start;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-insights {
    grid-template-columns: 1fr;
  }

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

  .modal-backdrop {
    align-items: stretch;
    padding: 0;
  }

  .account-modal {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
  }

  .modal-grid,
  .quota-grid {
    grid-template-columns: 1fr;
  }

  .modal-actions {
    position: sticky;
    bottom: 0;
  }
}


#renewKey { resize: vertical; min-height: 130px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
#renewPreview { margin-top: 10px; }
.renew-errors { margin: 8px 0 0; padding-left: 22px; color: var(--red); font-size: 13px; line-height: 1.7; }
#renewResult { display: grid; gap: 12px; min-width: 0; }
#renewBatchInfo { overflow-wrap: anywhere; }
.renew-summary { font-size: 14px; font-weight: 700; }
.renew-table { min-width: 760px; }
.renew-table .renew-license { max-width: 240px; overflow-wrap: anywhere; white-space: normal; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.renew-table .renew-reason { min-width: 180px; max-width: 320px; white-space: normal; overflow-wrap: anywhere; }
.renew-status { font-weight: 700; }
.renew-status-success { color: var(--green); }
.renew-status-failed, .renew-status-unknown { color: var(--red); }
.renew-status-running { color: var(--blue); }
.renew-status-cancelled { color: var(--muted); }
.renew-status-skipped { color: var(--muted); }
.unbind-table { min-width: 560px; }
.unbind { grid-template-columns: minmax(0, 1fr); }
#unbindResult { min-width: 0; overflow-wrap: anywhere; }
