:root {
  --bg: #f3f5f2;
  --panel: #ffffff;
  --ink: #1c2420;
  --muted: #5d6b63;
  --line: #d5ddd7;
  --accent: #1f6b55;
  --accent-ink: #ffffff;
  --danger: #9b2c2c;
  --shadow: 0 10px 30px rgba(28, 36, 32, 0.08);
  --radius: 14px;
  font-family: "IBM Plex Sans", "Source Han Sans SC", "Noto Sans SC", "PingFang SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; }
body {
  background:
    radial-gradient(1000px 420px at 10% -10%, rgba(31, 107, 85, 0.12), transparent 60%),
    linear-gradient(180deg, #eef3ef 0%, var(--bg) 40%);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 14px 4px;
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  max-width: 1100px;
  margin: 0 auto;
}
.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
  flex: 1 1 auto;
}
.brand-text { min-width: 0; }
.brand-mark {
  flex: 0 0 auto;
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 700; letter-spacing: 0.04em;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
}
.brand h1 {
  margin: 0;
  font-size: 1.12rem;
  line-height: 1.25;
  word-break: break-word;
}
.brand-tagline {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}
.header-auth {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.header-auth-btn {
  white-space: nowrap;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-weight: 600;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.header-auth-btn--ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.header-user[hidden] { display: none !important; }
.header-user-email {
  max-width: 42vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--muted);
}

.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 8px 12px 28px;
  display: grid;
  gap: 12px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.preview-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: min(58dvh, 520px);
  border-radius: 12px;
  overflow: hidden;
  background: #111814;
  border: 1px solid #243028;
  touch-action: none;
  transition: height 0.2s ease, aspect-ratio 0.2s ease, max-height 0.2s ease;
}
.preview-wrap.cropping {
  aspect-ratio: auto;
  max-height: none;
  height: min(68dvh, 640px);
  overflow: hidden;
  border-color: var(--accent);
}
.preview-stage {
  position: absolute;
  inset: 0;
  transform-origin: center center;
  will-change: transform;
}
.preview-wrap video,
.preview-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #111814;
  display: block;
  position: absolute;
  inset: 0;
  z-index: 1;
}
.preview-wrap > video {
  z-index: 3;
}
.preview-wrap video[hidden],
.preview-stage img[hidden] {
  display: none !important;
}
.placeholder {
  position: absolute; inset: 0;
  z-index: 2;
  display: grid; place-items: center;
  color: #c5d2cb;
  padding: 24px;
  text-align: center;
  font-size: 0.95rem;
  pointer-events: none;
}
.placeholder[hidden] {
  display: none !important;
}
/* iOS Safari: display:none / hidden 的 file input 可能导致选完图不触发 change */
.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
  opacity: 0 !important;
}

.row.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}
.capture .row.actions > * { width: 100%; }
.form .row.actions > * { width: 100%; }
.form .row.actions .primary { grid-column: 1 / -1; }
.pdf-actions {
  grid-template-columns: 1fr 1fr;
}
.pdf-actions .primary { grid-column: 1 / -1; }

button, .file-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #f7faf8;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 10px;
  min-height: 44px;
  font: inherit;
  font-size: 0.92rem;
  line-height: 1.25;
  cursor: pointer;
  text-align: center;
  justify-content: center;
  white-space: normal;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
button.primary, .file-btn.primary-label {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.file-btn {
  background: #f7faf8;
  border-color: var(--line);
  color: var(--ink);
}
.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.text {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
  padding: 4px 8px;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-size: 0.88rem;
  color: var(--muted);
}
label.desc-title input {
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
}
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 44px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #f7faf8;
}
.field-with-template.is-custom select {
  border-color: var(--accent);
}
.field-with-template.is-custom input {
  border-color: var(--accent);
  background: #fff;
}
.field-hint {
  font-size: 0.8rem;
  color: var(--accent);
  margin-top: -2px;
}
.field-hint[hidden] { display: none !important; }
.plate-size-custom {
  display: grid;
  grid-template-columns: 1fr auto 1fr auto;
  gap: 8px;
  align-items: center;
}
.plate-size-custom[hidden] { display: none !important; }
.plate-size-x {
  color: var(--muted);
  font-weight: 600;
}
.plate-size-unit {
  color: var(--muted);
  font-size: 0.9rem;
}
.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.form-row-2 label { margin-bottom: 0; }
.uv-field #uv-nm-custom {
  margin-top: 8px;
}
@media (max-width: 480px) {
  .form-row-2 { grid-template-columns: 1fr; }
}
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: end center;
  padding: 0;
  background: rgba(16, 28, 22, 0.45);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.auth-modal[hidden] { display: none !important; }
.auth-card {
  position: relative;
  width: 100%;
  max-height: min(92dvh, 100%);
  overflow: auto;
  background: var(--panel);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  box-shadow: var(--shadow);
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.auth-card h3 {
  margin: 0 0 8px;
  font-size: 1.15rem;
}
.auth-lead {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}
.limit-card .limit-actions {
  display: grid;
  gap: 10px;
  margin-top: 4px;
}
.limit-card .limit-actions .primary {
  width: 100%;
}
.auth-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  border-radius: 8px;
  padding: 0;
}
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
}
.auth-tab {
  border-radius: 10px;
  background: #f0f4f1;
}
.auth-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.auth-form label { margin-bottom: 10px; }
.auth-form label[hidden] { display: none !important; }
.auth-captcha-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.auth-captcha-field .auth-captcha-row {
  grid-template-columns: 1fr auto auto;
}
.auth-captcha-canvas,
.auth-captcha-image {
  width: 128px;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #eef3ef;
  cursor: pointer;
  padding: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--muted);
}
.auth-captcha-image img,
.auth-captcha-image svg {
  display: block;
  width: 128px;
  height: 42px;
}
.auth-captcha-refresh {
  padding: 10px 12px;
  border-radius: 10px;
  white-space: nowrap;
  min-height: 44px;
}
.auth-submit { width: 100%; margin-top: 4px; min-height: 48px; }
@media (max-width: 420px) {
  .auth-captcha-field .auth-captcha-row {
    grid-template-columns: 1fr auto;
  }
  .auth-captcha-field .auth-captcha-refresh {
    grid-column: 2;
  }
  .auth-captcha-field .auth-captcha-canvas {
    grid-column: 1 / -1;
    width: 100%;
    height: 48px;
  }
}
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 44px;
  font: inherit;
  font-size: 16px; /* 避免 iOS 聚焦时整页缩放 */
  color: var(--ink);
  background: #fcfdfc;
}
textarea {
  resize: vertical;
  min-height: 88px;
  line-height: 1.45;
}

.status {
  min-height: 1.2em;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.status.error { color: var(--danger); }
.status.ok { color: var(--accent); }

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.list-head h2 { margin: 0; }
.list-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 2px;
  margin-left: auto;
}
.list-actions button.text {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.9rem;
  white-space: nowrap;
}
.list-hint {
  margin: 8px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}
.pdf-modal {
  place-items: stretch;
}
.pdf-modal .pdf-card {
  width: 100%;
  height: 100%;
  max-height: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 0;
  border: none;
  box-shadow: none;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
  padding-top: max(12px, env(safe-area-inset-top, 0px));
}
.pdf-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.pdf-card-head h3 { margin: 0; font-size: 1.05rem; }
.pdf-meta {
  margin: 6px 0 8px;
  color: var(--muted);
  font-size: 0.85rem;
}
.pdf-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #525659;
}
.pdf-actions { margin-top: 12px; }

.records {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}
.record {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: #fbfcfb;
  cursor: default;
}
.record.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 107, 85, 0.18);
  background: #f3faf6;
}
.record-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 2px;
  min-height: 40px;
  user-select: none;
}
.record-check input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
.record img {
  order: -1;
  width: 100%;
  height: auto;
  max-height: min(42dvh, 280px);
  aspect-ratio: auto;
  object-fit: contain;
  object-position: center;
  border-radius: 8px;
  background: #111814;
  display: block;
}
.record-body {
  min-width: 0;
  display: grid;
  gap: 8px;
}
.record h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--ink);
}
.record-fields {
  margin: 0;
  display: grid;
  gap: 6px;
}
.record-field {
  display: grid;
  grid-template-columns: 4.5em 1fr;
  gap: 8px;
  align-items: start;
  font-size: 0.9rem;
  line-height: 1.4;
}
.record-field dt {
  margin: 0;
  color: var(--accent);
  font-weight: 600;
}
.record-field dd {
  margin: 0;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
}
.record-field dd.is-empty {
  color: #9aa89f;
  font-style: italic;
}
.record .meta {
  font-size: 0.78rem;
  color: #7a8a81;
}
.record .side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.record .side .download {
  background: #eef6f2;
  border-color: #b7d0c4;
  color: var(--accent);
}
.record .side .del {
  grid-column: 1 / -1;
}
.record .danger {
  color: var(--danger);
  border-color: #efc2c2;
  background: #fff7f7;
}

.crop-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  cursor: grab;
}
.crop-layer.panning { cursor: grabbing; }
.crop-layer[hidden] { display: none !important; }
.crop-zoom-label {
  font-size: 0.86rem;
  color: var(--muted);
  align-self: center;
  margin-left: 4px;
}
.crop-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.crop-dim {
  fill: rgba(0, 0, 0, 0.55);
  fill-rule: evenodd;
}
.crop-poly {
  fill: rgba(255, 255, 255, 0.06);
  stroke: #f5f8f6;
  stroke-width: 2;
  vector-effect: non-scaling-stroke;
}
.crop-handle {
  position: absolute;
  width: 28px;
  height: 28px;
  margin: 0;
  padding: 0;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);
  /* transform 由 JS 设置：translate + 随缩放补偿 */
  cursor: grab;
  z-index: 6;
  touch-action: none;
}
.crop-handle:active { cursor: grabbing; background: #2a8f72; }
.crop-actions { margin-top: 8px; }

.record-field {
  grid-template-columns: 1fr;
  gap: 2px;
}
.crop-handle {
  width: 40px;
  height: 40px;
}

/* 手机竖屏：进一步压缩顶栏与说明 */
@media (max-width: 640px) {
  .brand-tagline { display: none; }
  .header-auth-btn { padding: 7px 10px; font-size: 0.82rem; }
  .header-user-email { max-width: 28vw; }
  .placeholder {
    font-size: 0.88rem;
    padding: 16px;
  }
  .auth-close {
    width: 44px;
    height: 44px;
  }
}

/* 平板 / 桌面：恢复更宽松布局 */
@media (min-width: 641px) {
  .top { padding: 22px 20px 8px; }
  .brand { gap: 14px; }
  .brand-mark {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    font-size: 1rem;
  }
  .brand h1 { font-size: 1.35rem; }
  .brand-tagline { font-size: 0.92rem; }
  .layout { padding: 12px 16px 40px; gap: 16px; }
  .panel { padding: 16px; }
  .panel h2 { font-size: 1.05rem; }
  .preview-wrap {
    aspect-ratio: 4 / 3;
    max-height: none;
  }
  .preview-wrap.cropping {
    height: min(78vh, 760px);
  }
  .row.actions {
    display: flex;
    flex-wrap: wrap;
  }
  .capture .row.actions > *,
  .form .row.actions > * { width: auto; }
  .form .row.actions .primary { grid-column: auto; }
  button, .file-btn {
    border-radius: 999px;
    padding: 10px 14px;
    min-height: 0;
  }
  .auth-modal {
    place-items: center;
    padding: 20px;
  }
  .auth-card {
    width: min(420px, 100%);
    max-height: none;
    border-radius: var(--radius);
    border-bottom: 1px solid var(--line);
    padding: 22px 20px 18px;
  }
  .auth-captcha-row,
  .auth-captcha-field .auth-captcha-row {
    grid-template-columns: 1fr auto auto;
  }
  .auth-captcha-canvas {
    width: 120px;
    height: 44px;
  }
  .pdf-modal { place-items: center; padding: 20px; }
  .pdf-modal .pdf-card {
    width: min(920px, 100%);
    height: auto;
    max-height: min(92vh, 960px);
    border-radius: var(--radius);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    padding: 16px;
  }
  .pdf-frame { min-height: 55vh; }
  .pdf-actions {
    display: flex;
    flex-wrap: wrap;
  }
  .pdf-actions .primary { grid-column: auto; }
  .record {
    grid-template-columns: 148px 1fr;
    gap: 14px;
    padding: 12px;
  }
  .record img {
    order: 0;
    width: 148px;
    max-height: 220px;
  }
  .record-field {
    grid-template-columns: 4.5em 1fr;
    gap: 8px;
  }
  .record .side {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .record .side .del { grid-column: auto; }
  .crop-handle {
    width: 28px;
    height: 28px;
  }
  textarea { min-height: 110px; }
}

@media (min-width: 900px) {
  .layout {
    grid-template-columns: 1.1fr 0.9fr;
    grid-template-areas:
      "capture form"
      "list list";
  }
  .capture { grid-area: capture; }
  .form { grid-area: form; }
  .list { grid-area: list; }
}
