:root {
  --navy: #14253d;
  --navy-2: #203753;
  --ink: #172334;
  --muted: #607086;
  --line: #d8e0e8;
  --line-strong: #b9c5d3;
  --page: #f3f6f8;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --teal: #087f73;
  --teal-soft: #e6f5f2;
  --green: #16734b;
  --green-soft: #e8f6ee;
  --orange: #a45a08;
  --orange-soft: #fff3dc;
  --red: #b42318;
  --red-soft: #fdebea;
  --shadow: 0 10px 24px rgb(20 37 61 / 7%);
  --radius: 8px;
  --sans: "Microsoft YaHei", "PingFang SC", "Segoe UI", system-ui, sans-serif;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--page); scroll-behavior: smooth; }
body { margin: 0; color: var(--ink); background: var(--page); font: 15px/1.6 var(--sans); }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .52; }
:focus-visible { outline: 3px solid rgb(8 127 115 / 35%); outline-offset: 2px; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: -9999px; top: 0; z-index: 30; padding: 8px 14px; color: #fff; background: var(--navy); }
.skip-link:focus { left: 12px; }

.topbar { min-height: 72px; display: flex; align-items: center; justify-content: space-between; gap: 24px;
  padding: 14px clamp(20px, 4vw, 64px); color: #fff; background: var(--navy); }
.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; color: var(--navy); background: #b9ece4;
  border-radius: 7px; font: 800 18px/1 var(--mono); }
.eyebrow, .section-kicker { margin: 0; font: 700 10px/1.3 var(--mono); letter-spacing: .12em; }
.topbar .eyebrow { color: #a7c3d5; }
.topbar h1 { margin: 2px 0 0; color: #fff; font-size: 19px; line-height: 1.25; letter-spacing: 0; }
.service-state { display: flex; align-items: center; gap: 8px; color: #c8d5e3; font-size: 13px; white-space: nowrap; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9baabc; }
.status-dot.ok { background: #6bd2a0; }
.status-dot.bad { background: #ffad9d; }
.status-dot.idle { background: #e6ba5b; }

.auth-backdrop { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px;
  background: rgb(20 37 61 / 72%); }
.auth-dialog { width: min(390px, 100%); padding: 28px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 24px 70px rgb(0 0 0 / 25%); }
.auth-mark { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 17px; color: var(--teal);
  background: var(--teal-soft); border-radius: 50%; }
.auth-dialog h2 { margin: 4px 0 5px; color: var(--navy); font-size: 23px; line-height: 1.25; }
.auth-dialog .section-kicker { color: var(--teal); }
.auth-copy { margin: 0 0 18px; color: var(--muted); font-size: 13px; }
.auth-dialog label { display: block; margin-bottom: 6px; color: var(--navy-2); font-size: 13px; font-weight: 700; }
.auth-dialog input { width: 100%; min-height: 42px; padding: 8px 11px; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; }
.auth-dialog input:focus { outline: 3px solid rgb(8 127 115 / 18%); border-color: var(--teal); }
.auth-dialog .primary-button { margin-top: 13px; }
.auth-error { margin: 10px 0 0; color: var(--red); font-size: 12px; }

.page-shell { width: min(1440px, 100%); margin: 0 auto; padding: 28px clamp(20px, 4vw, 64px) 48px; }
.intro-band { display: flex; justify-content: space-between; align-items: end; gap: 28px; padding: 0 0 22px; border-bottom: 1px solid var(--line); }
.intro-band .section-kicker, .panel .section-kicker { color: var(--teal); }
.intro-band h2 { margin: 4px 0 0; color: var(--navy); font-size: clamp(24px, 3vw, 34px); line-height: 1.22; letter-spacing: 0; }
.boundary-note { display: flex; align-items: flex-start; gap: 9px; max-width: 420px; padding: 10px 12px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); font-size: 13px; }
.boundary-note p { margin: 0; }
.note-icon { display: grid; place-items: center; flex: none; width: 19px; height: 19px; color: #fff; background: var(--teal); border-radius: 50%; font: 700 12px/1 var(--serif, Georgia); }

.workspace { display: grid; grid-template-columns: minmax(300px, 370px) minmax(0, 1fr); gap: 18px; align-items: start; padding-top: 20px; }
.panel { min-width: 0; padding: 22px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 12px; margin-bottom: 17px; }
.panel-heading h2 { margin: 3px 0 0; color: var(--navy); font-size: 20px; line-height: 1.25; }
.format-hint { color: var(--muted); font: 11px/1.4 var(--mono); text-align: right; }

.drop-zone { display: grid; place-items: center; min-height: 230px; padding: 26px 18px; color: var(--muted); border: 1px dashed var(--line-strong); border-radius: var(--radius); background: var(--surface-alt); text-align: center; transition: border-color .16s, background .16s; }
.drop-zone:hover, .drop-zone:focus-visible, .drop-zone.dragging { color: var(--teal); border-color: var(--teal); background: var(--teal-soft); }
.upload-glyph { display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 11px; color: var(--teal); background: #d4efeb; border-radius: 50%; }
.drop-zone strong { color: var(--ink); font-size: 15px; }
.drop-zone span { margin-top: 3px; font-size: 12px; }
.selected-file { display: flex; align-items: center; gap: 11px; margin-top: 14px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-alt); }
.file-thumb { width: 48px; height: 48px; flex: none; overflow: hidden; background: #e8edf2; border-radius: 5px; }
.file-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-meta { min-width: 0; display: grid; gap: 1px; }
.file-meta strong { overflow: hidden; color: var(--ink); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.file-meta span { color: var(--muted); font-size: 11px; }
.file-meta .file-ready { color: var(--green); }
.icon-button { display: grid; place-items: center; flex: none; width: 32px; height: 32px; margin-left: auto; padding: 0; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: 5px; }
.icon-button:hover { color: var(--red); background: var(--red-soft); border-color: #f4c1bc; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; border-radius: 6px; font-weight: 700; transition: background .15s, border-color .15s, color .15s; }
.primary-button { width: 100%; margin-top: 16px; color: #fff; background: var(--teal); border: 1px solid var(--teal); }
.primary-button:hover:not(:disabled) { background: #07675e; border-color: #07675e; }
.secondary-button { padding: 0 15px; color: var(--navy); background: #fff; border: 1px solid var(--line-strong); }
.secondary-button:hover { background: var(--surface-alt); border-color: var(--navy-2); }
.upload-error { margin-top: 12px; padding: 9px 11px; color: var(--red); background: var(--red-soft); border: 1px solid #f2c1bc; border-radius: 6px; font-size: 13px; }
.boundary-details { margin-top: 18px; color: var(--muted); border-top: 1px solid var(--line); }
.boundary-details summary { padding-top: 14px; color: var(--navy-2); cursor: pointer; font-size: 13px; font-weight: 700; list-style: none; }
.boundary-details summary::-webkit-details-marker { display: none; }
.boundary-details summary::after { content: "+"; float: right; color: var(--teal); font: 700 18px/1 var(--mono); }
.boundary-details[open] summary::after { content: "−"; }
.boundary-details ul { margin: 10px 0 0; padding-left: 18px; font-size: 12px; }
.boundary-details li + li { margin-top: 5px; }

.result-panel { min-height: 610px; }
.result-heading { align-items: center; margin-bottom: 18px; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.verdict-chip, .review-flag { display: inline-flex; align-items: center; min-height: 27px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.verdict-chip.idle { color: var(--muted); background: #edf1f5; }
.verdict-chip.good { color: var(--green); background: var(--green-soft); }
.verdict-chip.defect { color: var(--red); background: var(--red-soft); }
.verdict-chip.review, .verdict-chip.unusable { color: var(--orange); background: var(--orange-soft); }
.result-empty { display: grid; place-items: center; min-height: 465px; padding: 30px; color: var(--muted); text-align: center; }
.empty-icon { display: grid; place-items: center; width: 72px; height: 72px; margin-bottom: 14px; color: var(--teal); background: var(--teal-soft); border-radius: 50%; }
.result-empty strong { color: var(--navy); font-size: 16px; }
.result-empty span { margin-top: 3px; font-size: 13px; }
.result-summary { display: flex; justify-content: space-between; gap: 18px; padding: 0 0 15px; }
.result-reason { margin: 0; color: var(--ink); font-size: 15px; font-weight: 700; }
.result-meta { display: flex; flex-wrap: wrap; gap: 7px 16px; margin-top: 5px; color: var(--muted); font: 11px/1.5 var(--mono); }
.review-flag { align-self: start; color: var(--orange); background: var(--orange-soft); }
.image-stage { position: relative; display: grid; place-items: center; min-height: 290px; overflow: hidden; background: #edf1f4; border: 1px solid var(--line); border-radius: 6px; }
.image-stage img { display: block; max-width: 100%; max-height: 560px; object-fit: contain; }
.image-stage canvas { position: absolute; left: 0; top: 0; width: 0; height: 0; pointer-events: none; }
.image-loading { position: absolute; inset: 0; display: grid; place-items: center; align-content: center; gap: 9px; color: var(--navy); background: rgb(248 250 252 / 90%); font-weight: 700; }
.spinner { width: 22px; height: 22px; border: 3px solid #c5d3df; border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.image-caption { padding: 7px 2px 0; color: var(--muted); font-size: 12px; }
.subsection-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 21px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.subsection-heading h3 { margin: 0; color: var(--navy); font-size: 15px; }
.subsection-heading span { color: var(--muted); font: 11px/1.4 var(--mono); }
.defect-list { display: grid; gap: 9px; padding-top: 10px; }
.defect-item { display: grid; grid-template-columns: 7px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-alt); }
.defect-bar { width: 7px; min-height: 48px; border-radius: 4px; background: var(--red); }
.defect-item.review .defect-bar { background: var(--orange); }
.defect-name { color: var(--ink); font-weight: 800; }
.defect-evidence { margin: 3px 0 0; color: var(--muted); font-size: 12px; line-height: 1.55; }
.defect-tags { display: flex; flex-wrap: wrap; justify-content: end; gap: 5px; }
.defect-tag { padding: 2px 6px; color: var(--muted); background: #edf1f5; border-radius: 4px; font: 10px/1.45 var(--mono); white-space: nowrap; }
.defect-tag.high { color: var(--green); background: var(--green-soft); }
.defect-tag.review { color: var(--orange); background: var(--orange-soft); }
.no-defect { display: flex; align-items: center; gap: 10px; margin-top: 21px; padding: 13px 14px; color: var(--green); background: var(--green-soft); border: 1px solid #b9e3ca; border-radius: 6px; }
.check-icon { display: grid; place-items: center; width: 23px; height: 23px; flex: none; color: #fff; background: var(--green); border-radius: 50%; font-weight: 800; }
.no-defect strong, .no-defect span { display: block; }
.no-defect span { margin-top: 2px; color: #477761; font-size: 12px; }
.result-footer { margin-top: 19px; padding-top: 12px; color: var(--muted); border-top: 1px solid var(--line); font-size: 12px; }
.request-error { display: grid; gap: 6px; margin-top: 18px; padding: 15px; color: var(--red); background: var(--red-soft); border: 1px solid #f2c1bc; border-radius: 6px; }
.request-error strong { color: var(--red); }
.request-error p { margin: 0; color: #7b3a35; font-size: 13px; }
.request-error .secondary-button { justify-self: start; margin-top: 5px; }

.page-footer { display: flex; justify-content: space-between; gap: 16px; width: min(1440px, 100%); margin: 0 auto; padding: 0 clamp(20px, 4vw, 64px) 28px; color: var(--muted); font: 11px/1.5 var(--mono); }

@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
  .upload-panel { order: 0; }
  .result-panel { order: 1; }
  .result-empty { min-height: 280px; }
}
@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; gap: 10px; }
  .service-state { font-size: 12px; }
  .intro-band { align-items: flex-start; flex-direction: column; gap: 15px; }
  .boundary-note { max-width: none; }
  .panel { padding: 17px; }
  .page-shell { padding-top: 20px; }
  .result-summary { flex-direction: column; gap: 8px; }
  .review-flag { align-self: start; }
  .defect-item { grid-template-columns: 7px minmax(0, 1fr); }
  .defect-tags { grid-column: 2; justify-content: start; }
  .page-footer { flex-direction: column; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
