:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-strong: #f0f4f2;
  --text: #17211d;
  --muted: #62706a;
  --border: #d9e2dd;
  --accent: #176b5d;
  --accent-dark: #0f4e44;
  --warn: #a5511f;
  --danger: #b42318;
  --success: #18794e;
  --info: #2459a6;
  --shadow: 0 18px 50px rgba(31, 47, 42, 0.1);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.65), rgba(255, 255, 255, 0)),
    var(--bg);
  color: var(--text);
  font-family:
    "Inter", "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 40px;
}

.login-shell {
  width: min(460px, calc(100% - 32px));
  min-height: 100vh;
  display: grid;
  align-items: center;
  margin: 0 auto;
  padding: 32px 0;
}

.login-card {
  padding: 28px;
}

.login-card h1 {
  margin-bottom: 12px;
  font-size: 38px;
  line-height: 1.1;
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.upload-button {
  min-height: 42px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(32px, 5vw, 56px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 8px;
  font-size: 22px;
  line-height: 1.25;
}

h3 {
  margin-bottom: 6px;
  font-size: 20px;
}

.muted {
  color: var(--muted);
  line-height: 1.6;
}

.user-pill,
.status-chip {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

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

.register-panel {
  padding: 24px;
  position: sticky;
  top: 24px;
}

.workspace-panel {
  padding: 26px;
}

.admin-panel {
  margin-top: 20px;
  padding: 24px 26px;
}

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

.stack,
.qc-form,
.admin-form {
  display: grid;
  gap: 16px;
}

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

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

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

label {
  display: grid;
  gap: 8px;
  color: #26332e;
  font-weight: 700;
}

label span {
  font-size: 14px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--text);
  padding: 12px 13px;
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease,
    background 150ms ease;
}

textarea {
  resize: vertical;
  min-height: 120px;
  line-height: 1.55;
}

input:focus,
textarea:focus {
  border-color: var(--accent);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(23, 107, 93, 0.14);
}

input:disabled,
textarea:disabled {
  cursor: not-allowed;
  color: #8b9691;
  background: #f1f4f2;
}

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

.auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.auth-message {
  min-height: 22px;
  margin: 0;
}

.auth-message[data-variant="failed"] {
  color: var(--danger);
}

button,
.download-button,
.nav-button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

button:active,
.download-button:active,
.nav-button:active {
  transform: translateY(1px);
}

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

.small-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.primary,
.download-button {
  background: var(--accent);
  color: #ffffff;
}

.primary:hover:not(:disabled),
.download-button:hover {
  background: var(--accent-dark);
}

.secondary,
.nav-button {
  border-color: var(--border);
  background: var(--surface-strong);
  color: var(--text);
}

.secondary:hover:not(:disabled),
.nav-button:hover {
  background: #e7eeea;
}

.result-box {
  margin-top: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 18px;
  background: #fbfcfb;
}

.result-box > div:first-child {
  min-width: 0;
}

.result-box.failed {
  border-left-color: var(--danger);
}

.result-box.running {
  border-left-color: var(--warn);
}

.result-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.progress-wrap {
  width: min(520px, 100%);
  margin-top: 14px;
}

.progress-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-topline strong {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.progress-track {
  width: 100%;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ece8;
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 180ms ease;
}

.manual-gemini {
  display: grid;
  gap: 12px;
  width: min(520px, 100%);
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.manual-gemini-alert {
  display: grid;
  gap: 4px;
  border: 1px solid rgba(165, 81, 31, 0.28);
  border-radius: 8px;
  background: #fff7ed;
  padding: 12px;
}

.manual-gemini-alert strong {
  color: var(--warn);
}

.manual-gemini-alert p {
  margin-bottom: 0;
}

.history-panel {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.compact-heading {
  margin-bottom: 12px;
}

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

.history-block + .history-block {
  margin-top: 18px;
}

.history-section-title {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px 12px;
}

.history-item strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text);
  font-size: 14px;
}

.history-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.history-json-button {
  justify-self: start;
}

#resultMeta {
  max-width: 100%;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#resultMeta:not(:empty) {
  max-height: 460px;
  overflow: auto;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
}

.check-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.admin-message {
  grid-column: 1 / -1;
  min-height: 22px;
  margin: 0;
}

.admin-message[data-variant="success"] {
  color: var(--success);
}

.admin-message[data-variant="failed"] {
  color: var(--danger);
}

.admin-shell {
  width: min(1120px, calc(100% - 32px));
}

.standalone-admin {
  margin-top: 0;
}

.admin-dashboard {
  display: grid;
  gap: 20px;
  margin-top: 20px;
}

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

.metric-card {
  min-height: 116px;
  display: grid;
  align-content: space-between;
  gap: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  padding: 18px;
  box-shadow: var(--shadow);
}

.metric-card span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.metric-card strong {
  color: var(--text);
  font-size: 34px;
  line-height: 1;
  letter-spacing: 0;
}

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.admin-data-panel {
  padding: 22px;
}

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

.panel-heading-row h2 {
  margin-bottom: 0;
}

.data-badge {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--muted);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.rank-list {
  display: grid;
  gap: 10px;
}

.rank-item {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 10px 12px;
}

.rank-item span {
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-item strong {
  color: var(--info);
  white-space: nowrap;
}

.empty-state {
  margin: 0;
}

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

.recent-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.recent-table th,
.recent-table td {
  border-bottom: 1px solid var(--border);
  padding: 12px 10px;
  text-align: left;
  vertical-align: top;
}

.recent-table th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.recent-table td {
  color: var(--text);
  font-size: 14px;
}

.status-success {
  color: var(--success) !important;
  font-weight: 700;
}

.status-failed {
  color: var(--danger) !important;
  font-weight: 700;
}

.empty-cell {
  color: var(--muted) !important;
  text-align: center !important;
}

@media (max-width: 860px) {
  .topbar,
  .section-heading,
  .result-box {
    flex-direction: column;
    align-items: stretch;
  }

  .layout,
  .qc-form,
  .admin-form {
    grid-template-columns: 1fr;
  }

  .register-panel {
    position: static;
  }

  .result-actions {
    width: 100%;
    justify-content: stretch;
  }

  .result-actions > * {
    width: 100%;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions > * {
    width: 100%;
  }

  .metric-grid,
  .admin-grid {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 94px;
  }

  .metric-card strong {
    font-size: 30px;
  }

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