:root {
  --bg: #262626;
  --fg: #f2f2f2;
  --muted: #a3a3a3;
  --primary: #1677ff;
  --surface: #2f2f2f;
  --surface-2: #3a3a3a;
  --danger: #ff4d4f;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell,
    "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    sans-serif;
}

.page {
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px 32px;
}

.page--stack {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.page--form {
  padding-bottom: 100px;
}

h1 {
  margin: 0;
  font-size: 1.35rem;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.req {
  color: var(--danger);
}

.stack {
  display: grid;
  gap: 12px;
}

.section {
  background: var(--surface);
  border-radius: 12px;
  padding: 16px;
  margin-top: 12px;
}

.section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.section--origin {
  display: grid;
  gap: 12px;
  margin-top: 0;
}

.draft-banner + .section--origin {
  margin-top: 12px;
}

.form-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #3a3a3a;
  background: #1f1f1f;
  color: var(--fg);
  font-size: 16px;
}

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

.step-indicator {
  margin: 6px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.wizard-form {
  flex: 1;
}

.wizard-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, var(--bg) 24%, var(--bg));
  max-width: 520px;
  margin: 0 auto;
}

.wizard-nav-btn {
  flex: 1;
  margin: 0 !important;
}

/* Mobile file upload (superuser-style) */
.file-upload-field {
  display: grid;
  gap: 8px;
}

.file-upload-field-label {
  font-size: 14px;
}

.file-upload-tile {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 16px 12px;
  border-radius: 12px;
  border: 1px dashed #6b6b6b;
  background: #1f1f1f;
}

.file-upload-tile:focus-within {
  border-color: var(--primary);
  border-style: solid;
}

.file-upload-native {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px;
}

.file-upload-face {
  pointer-events: none;
  text-align: center;
}

.file-upload-cta {
  font-weight: 700;
  font-size: 15px;
}

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

.file-upload-summary.has-file {
  color: var(--fg);
  font-weight: 600;
}

.face-preview-wrap {
  display: flex;
  justify-content: center;
}

.face-preview {
  border-radius: 8px;
  border: 1px solid #444;
  background: #1a1a1a;
  position: relative;
  overflow: hidden;
}

.face-preview--form {
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

.face-preview__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
}

/* Lab grid (mobile) */
.lab-grid {
  display: grid;
  gap: 10px;
}

.lab-row {
  display: grid;
  grid-template-columns: 1.2fr repeat(3, 1fr);
  gap: 8px;
  align-items: center;
}

.lab-row--head span:not(:first-child) {
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

.lab-label {
  font-size: 0.9rem;
}

.lab-row input {
  width: 100%;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid #3a3a3a;
  background: #1f1f1f;
  color: var(--fg);
  font-size: 16px;
}

.skin-hint {
  margin-bottom: 8px;
}

.skin-tone-fieldset {
  border: 1px solid #4a4a4a;
  border-radius: 10px;
  padding: 14px 12px;
}

.skin-tone-grid {
  display: grid;
  gap: 10px;
  justify-content: center;
}

.skin-tone-grid--cols-3 {
  grid-template-columns: repeat(3, minmax(64px, 80px));
}

.skin-tone-grid--cols-4 {
  grid-template-columns: repeat(4, minmax(56px, 72px));
}

.skin-tone-grid--cols-6 {
  grid-template-columns: repeat(3, minmax(56px, 1fr));
}

@media (min-width: 400px) {
  .skin-tone-grid--cols-6 {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

.skin-tone-option {
  display: grid;
  justify-items: center;
  cursor: pointer;
}

.skin-tone-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.skin-tone-swatch {
  width: 100%;
  max-width: 52px;
  aspect-ratio: 1;
  border-radius: 50%;
  background-image: var(--orb-image);
  background-size: cover;
  background-position: center;
  transition: transform 120ms ease;
}

.skin-tone-option input:checked + .skin-tone-swatch {
  transform: scale(1.16);
  box-shadow: 0 0 0 2px var(--primary);
}

.status {
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}

.status.is-error {
  color: #ff9c9c;
}

.status.is-ok {
  color: #8fd18f;
}

.primary {
  padding: 14px 16px;
  border: none;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled {
  opacity: 0.55;
}

.btn-secondary {
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid #555;
  background: transparent;
  color: var(--fg);
  font-size: 1rem;
  cursor: pointer;
}

.draft-banner {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #3a3220;
  color: #f5e6b8;
  font-size: 0.85rem;
}

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.is-open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border-radius: 12px;
  padding: 20px;
  max-width: 400px;
  width: 100%;
}

.modal-box h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.modal-box p {
  margin: 0 0 16px;
  white-space: pre-line;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions .primary {
  width: auto;
}

body.modal-open {
  overflow: hidden;
}

.modal-box__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-box__head h2 {
  margin: 0;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}

.modal-box__msg {
  margin: 0 0 16px;
  color: var(--muted);
}

.modal-box--edit {
  max-width: min(480px, 100%);
  max-height: min(92vh, 720px);
  display: flex;
  flex-direction: column;
  padding: 0;
}

.modal-box--edit .modal-box__head,
.modal-box--edit .modal-actions--edit {
  flex-shrink: 0;
  padding: 16px 20px;
}

.modal-box__body.report-edit-body {
  overflow-y: auto;
  padding: 0 20px 12px;
  flex: 1;
  min-height: 0;
}

.modal-actions--edit {
  border-top: 1px solid #444;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.edit-modal-status {
  margin: 0;
  white-space: pre-line;
  line-height: 1.45;
  width: 100%;
}

.modal-actions__row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
}

.modal-actions__row .primary {
  width: auto;
  min-width: 96px;
}

.modal-actions__row .primary:disabled {
  opacity: 0.75;
  cursor: wait;
}

.btn-danger {
  background: #c62828;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.file-upload-tile--compact {
  min-height: 72px;
}

/* Report: wide page, each card ~1/3 row width */
.report-page.researcher-page {
  max-width: 960px;
  padding-top: 24px;
}

.researcher-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px 12px;
  margin-bottom: 12px;
}

.researcher-header__lead {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  min-width: 0;
}

.researcher-header__lead h1 {
  margin: 0;
  font-size: clamp(20px, 3vw, 30px);
  min-width: 0;
}

.researcher-header__actions {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px 14px;
  min-width: 0;
}

.researcher-header__signed-in {
  font-size: 14px;
  color: rgba(245, 245, 245, 0.62);
  line-height: 1.35;
  text-align: right;
  max-width: min(52vw, 420px);
  overflow-wrap: anywhere;
}

.researcher-header__actions .btn {
  min-height: 44px;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  background: var(--surface-2);
  color: var(--fg);
  width: auto;
  max-width: 100%;
}

.researcher-header__actions .btn-secondary {
  background: var(--surface-2);
  color: var(--fg);
}

.report-status {
  margin-top: 12px;
}

.report-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  min-height: 1.25rem;
}

.report-meta__count {
  margin: 0;
  flex: 1;
  min-width: 0;
  text-align: left;
}

.report-nav-link {
  appearance: none;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--primary, #1677ff);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 4px;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
}

.report-nav-link:hover {
  color: #4096ff;
  text-decoration: none;
}

.history-doc {
  margin-top: 16px;
}

.report-export-link {
  appearance: none;
  margin: 0;
  border: none;
  background: transparent;
  color: var(--primary, #1677ff);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 6px 4px;
  cursor: pointer;
  flex-shrink: 0;
  text-align: right;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.report-export-link:hover {
  color: #4096ff;
}

.report-export-link:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.report-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 12px 0 4px;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: 10px;
}

.report-filters__label {
  font-size: 0.9rem;
  color: var(--fg);
  white-space: nowrap;
}

.report-filters__select {
  flex: 1;
  min-width: 200px;
  max-width: 420px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #4a4a4a;
  background: #1f1f1f;
  color: var(--fg);
  font-size: 0.95rem;
}

/* Fixed card width (no wrap): Type China | ITA + origin|time + 20px padding ≈ 10.5rem */
.report-doc {
  --report-card-width: 10.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, var(--report-card-width));
  gap: 12px;
  margin-top: 12px;
  justify-content: start;
}

.report-card {
  width: var(--report-card-width);
  max-width: var(--report-card-width);
  box-sizing: border-box;
  background: var(--surface);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.report-card:hover {
  background: #383838;
}

.report-page--guest .report-card:hover {
  background: var(--surface);
}

.report-page--guest .report-card__face-actions {
  display: none !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.report-card__row--guest {
  justify-content: center;
}

.report-login-form {
  display: grid;
  gap: 12px;
}

.report-login-field {
  display: grid;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.report-login-field input {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid #555;
  background: #1f1f1f;
  color: var(--fg);
  font-size: 1rem;
}

.report-login-form .modal-actions {
  margin-top: 4px;
  padding-top: 0;
  border-top: none;
}

.report-card__face-shell {
  position: relative;
  width: 100%;
  max-width: 120px;
  margin: 0 auto;
}

.report-card__face {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #2a2a2a;
  position: relative;
  overflow: hidden;
}

.report-card__face--pending {
  background: linear-gradient(110deg, #2a2a2a 8%, #353535 18%, #2a2a2a 33%);
  background-size: 200% 100%;
  animation: report-face-shimmer 1.2s ease-in-out infinite;
}

@keyframes report-face-shimmer {
  to {
    background-position-x: -200%;
  }
}

.face-preview__img--card {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center center;
  display: block;
  transition: opacity 0.35s ease;
}

.face-preview__img--card:not(.face-preview__img--hd) {
  image-rendering: auto;
}

.report-card__face--hd .face-preview__img--card {
  image-rendering: -webkit-optimize-contrast;
}

.report-card__face-actions {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 4px 5px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.report-card__face-shell:hover .report-card__face-actions,
.report-card__face-shell:focus-within .report-card__face-actions {
  opacity: 1;
  pointer-events: auto;
}

.report-card__face-btn {
  pointer-events: auto;
  border: none;
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.72);
  color: #eee;
}

.report-card__face-btn--delete {
  color: #ff6b6b;
}

.report-card__face-btn--edit {
  color: #e0e0e0;
}

.report-card__face-btn--history {
  color: #9ecbff;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 12px;
}

.history-list__item {
  padding: 12px 14px;
  border-radius: 10px;
  background: #2a2a2a;
  display: grid;
  gap: 8px;
}

.history-list__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.history-list__title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}

.history-list__changes {
  display: grid;
  gap: 8px;
  font-size: 0.85rem;
  line-height: 1.45;
}

.history-list__footer {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.history-list__restore {
  font-size: 0.82rem;
  padding: 6px 10px;
  flex-shrink: 0;
}

.history-change--text {
  margin: 0;
  color: #d0d0d0;
}

.history-change__field {
  font-weight: 600;
  color: #eee;
}

.history-change__old {
  color: #b0b0b0;
  text-decoration: line-through;
  text-decoration-color: rgba(255, 255, 255, 0.25);
}

.history-change__new {
  color: #e8f4ff;
}

.history-change__arrow {
  color: var(--muted);
}

.history-change--image {
  display: grid;
  gap: 6px;
}

.history-change__photos {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.history-change__photo {
  margin: 0;
  width: 88px;
}

.history-change__photo img {
  width: 88px;
  height: 88px;
  object-fit: cover;
  border-radius: 6px;
  background: #1a1a1a;
  display: block;
}

.history-change__photo figcaption {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
}

.history-change__arrow--photos {
  font-size: 1.1rem;
}

.history-change__photo-removed {
  font-size: 0.85rem;
  color: #ff9a9a;
}

@media (hover: none) {
  .report-card__face-actions {
    opacity: 1;
    pointer-events: auto;
  }
}

.report-card__body {
  display: grid;
  gap: 5px;
  font-size: 0.72rem;
  line-height: 1.35;
}

.report-card__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

.report-card__row--top {
  position: relative;
  justify-content: center;
  min-height: 1.35em;
}

.report-card__top-line {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  transition: opacity 0.15s ease;
}

.report-card__top-line--ita {
  position: absolute;
  left: 0;
  right: 0;
  opacity: 0;
  pointer-events: none;
}

.report-page--authed .report-card:hover .report-card__top-line--type {
  opacity: 0;
}

.report-page--authed .report-card:hover .report-card__top-line--ita {
  opacity: 1;
}

.report-page--guest .report-card__top-line--type {
  opacity: 1;
}

@media (hover: none) {
  .report-card__row--top {
    justify-content: space-between;
    min-height: 1.35em;
  }

  .report-card__top-line--type {
    opacity: 1;
  }

  .report-card__top-line--ita {
    position: static;
    opacity: 1;
    pointer-events: auto;
    justify-content: flex-end;
  }
}

.metric-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--fg);
}

.metric-hint {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
}

.report-card__time {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  flex-shrink: 0;
}

.report-card__origin {
  margin: 0;
  font-size: 0.7rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.report-card__face--catalog.report-card__face--empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
}

.report-card__placeholder {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.report-card__image-path {
  margin: 0;
  font-size: 0.65rem;
  line-height: 1.3;
  color: var(--muted);
  word-break: break-all;
  max-height: 3.9em;
  overflow: hidden;
}

.report-card__badge {
  margin: 0 0 4px;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
}

