:root {
  --ink: #1f2937;
  --muted: #52607a;
  --tertiary: #8190ac;
  --line: #d9e1ee;
  --line-strong: #b9c5d9;
  --surface: #ffffff;
  --surface-alt: #fafbfe;
  --canvas: #f5f7fb;
  --navy: #1a2b5c;
  --navy-2: #121f44;
  --blue: #2d5dae;
  --blue-dark: #1a3e7a;
  --blue-soft: #eef3fb;
  --cyan: var(--blue);
  --cyan-soft: var(--blue-soft);
  --orange: #e6a817;
  --orange-soft: #fdf4dc;
  --green: #5aa73a;
  --green-ink: #3f7d26;
  --green-soft: #eef7e7;
  --green-bar: #d3e8c6;
  --red: #d04545;
  --red-soft: #fbe7e7;
  --magenta: #e6a817;
  --shadow-sm: 0 1px 2px rgb(26 43 92 / 6%), 0 2px 8px rgb(26 43 92 / 4%);
  --shadow-md: 0 8px 24px rgb(26 43 92 / 10%), 0 2px 6px rgb(26 43 92 / 6%);
  --shadow-lg: 0 16px 40px rgb(26 43 92 / 14%);
  --shadow: var(--shadow-md);
  --ease: cubic-bezier(.2, 0, 0, 1);
  font-family: Inter, "Myomo Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #f5f7f9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    radial-gradient(circle at 10% 0%, rgb(45 93 174 / 7%), transparent 34rem),
    var(--canvas);
  overflow-x: hidden;
}

button, select, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.app-header {
  height: 76px;
  padding: 0 clamp(22px, 4vw, 64px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: linear-gradient(90deg, var(--green) 0 76%, var(--green-bar) 76% 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: var(--ink);
  text-decoration: none;
}

.brand-logo { width: 150px; height: auto; display: block; }
.brand-divider { width: 1px; height: 34px; background: var(--line); }
.brand-product strong { display: block; color: var(--navy); font-size: 17px; letter-spacing: -.02em; }
.brand-product small { display: block; margin-top: 2px; color: var(--muted); font-size: 10px; letter-spacing: .04em; }

.privacy-note {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}
.privacy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

main { min-height: calc(100vh - 76px); }

.upload-view {
  width: min(1280px, calc(100% - 40px));
  margin: 0 auto;
  padding: clamp(40px, 6vw, 72px) 0 44px;
  display: grid;
  grid-template-columns: minmax(360px, .95fr) minmax(410px, 1.05fr);
  gap: clamp(28px, 4vw, 52px);
  align-items: stretch;
}

.hero-copy {
  min-height: 540px;
  padding: clamp(40px, 5vw, 64px);
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow: hidden;
  border-radius: 14px;
  color: white;
  background: linear-gradient(90deg, var(--navy) 0%, var(--blue) 100%);
  box-shadow: var(--shadow-md);
}
.hero-copy::before { content: ""; position: absolute; inset: 0; background: radial-gradient(circle at 88% 18%, rgb(90 167 58 / 28%), transparent 48%); }
.hero-copy::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--green); }
.hero-copy > * { position: relative; }
.eyebrow { margin: 0 0 10px; color: var(--green-ink); font-size: 11px; line-height: 1.2; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.hero-copy .eyebrow { color: var(--green-bar); }
.hero-copy h1 { margin: 0; font-size: clamp(44px, 5vw, 66px); line-height: 1.02; letter-spacing: -.045em; color: white; }
.hero-copy h1 span { color: #b9e2a6; }
.hero-copy > p:last-child { max-width: 520px; margin: 28px 0 0; color: rgb(255 255 255 / 82%); font-size: 16px; line-height: 1.68; }

.upload-card {
  padding: clamp(24px, 3vw, 36px);
  border: 1px solid var(--line);
  border-top: 3px solid var(--green);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.step-heading { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.step-heading > span { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: #fff; background: linear-gradient(180deg, #3f73c4, var(--blue)); box-shadow: 0 3px 0 var(--blue-dark); font-weight: 800; }
.step-heading h2 { margin: 0; color: var(--navy); font-size: 19px; letter-spacing: -.02em; }
.step-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.drop-zone {
  min-height: 275px;
  padding: 34px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1.5px dashed var(--line-strong);
  border-radius: 10px;
  background: var(--surface-alt);
  cursor: pointer;
  transition: border-color .15s var(--ease), transform .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease);
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 0 0 3px rgb(45 93 174 / 12%); transform: translateY(-2px); }
.upload-icon { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 10px; color: var(--blue); background: #fff; box-shadow: var(--shadow-sm); }
.upload-icon svg { width: 31px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 1.7; }
.drop-zone strong { font-size: 16px; }
.drop-zone > span:not(.upload-icon) { margin-top: 6px; color: var(--muted); font-size: 13px; }
.drop-zone em { margin-top: 18px; padding: 6px 10px; border-radius: 999px; color: var(--green-ink); background: var(--green-soft); font-size: 10px; font-style: normal; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }

.upload-options { margin-top: 20px; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; align-items: center; }
.upload-options label { color: var(--ink); font-size: 12px; font-weight: 750; }
.upload-options select { min-width: 0; padding: 10px 32px 10px 12px; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: white; outline: none; transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.upload-options select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgb(45 93 174 / 18%); }
.upload-options span { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }

.workflow-strip {
  grid-column: 1 / -1;
  margin-top: clamp(20px, 4vw, 54px);
  padding: 22px clamp(22px, 4vw, 40px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--muted);
}
.workflow-strip div { display: flex; align-items: center; gap: 10px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.workflow-strip b { color: var(--blue); }
.workflow-strip i { height: 1px; flex: 1; max-width: 90px; margin: 0 10px; background: var(--line); }

.loading-view { min-height: calc(100vh - 76px); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px; text-align: center; }
.scanner-animation { width: 180px; height: 220px; position: relative; display: grid; place-items: center; margin-bottom: 26px; overflow: hidden; border: 1px solid var(--line); border-top: 3px solid var(--green); border-radius: 14px; background: #fff; box-shadow: var(--shadow-md); }
.scan-figure[hidden] { display: none; }
.fig-hand { height: 150px; width: auto; fill: none; stroke: var(--line-strong); stroke-width: 14; stroke-linejoin: round; stroke-linecap: round; }
.fig-arm { height: 128px; width: auto; fill: var(--line-strong); stroke: none; }
.scan-line { position: absolute; left: 16px; right: 16px; height: 2px; z-index: 2; background: var(--green); box-shadow: 0 0 18px 6px rgb(90 167 58 / 22%); animation: scan 2.15s ease-in-out infinite; }
@keyframes scan { 0%, 100% { top: 25px; } 50% { top: 192px; } }
.loading-view h2 { margin: 4px 0 22px; color: var(--navy); font-size: 28px; letter-spacing: -.035em; }
.progress-track { width: min(390px, 80vw); height: 6px; overflow: hidden; border-radius: 999px; background: var(--line); }
.progress-track span { display: block; width: 15%; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), #5b8ad6); transition: width .5s var(--ease); }
.loading-view > p:last-child { color: var(--muted); font-size: 12px; }

.result-view { width: min(1540px, calc(100% - 36px)); margin: 0 auto; padding: 28px 0 60px; }
.result-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 22px; }
.result-toolbar > div { display: flex; align-items: center; gap: 13px; }
.result-toolbar > div:first-child, .result-toolbar > div:first-child > div { min-width: 0; }
.result-toolbar > div:first-child { flex: 1 1 auto; }
.result-toolbar h1 { margin: 0; max-width: 620px; overflow: hidden; color: var(--navy); font-size: 24px; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.result-toolbar .eyebrow { margin-bottom: 3px; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); background: white; box-shadow: var(--shadow-sm); cursor: pointer; font-size: 22px; transition: border-color .15s var(--ease), color .15s var(--ease), box-shadow .15s var(--ease); }
.icon-button:hover { border-color: var(--blue); color: var(--blue); box-shadow: 0 2px 8px rgb(45 93 174 / 12%); }
.toolbar-actions { justify-content: flex-end; }
.button { padding: 11px 18px; border-radius: 8px; border: 1px solid transparent; cursor: pointer; font-size: 12px; font-weight: 700; transition: transform .15s var(--ease), opacity .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease); }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(2px); }
.button:disabled { opacity: .42; cursor: not-allowed; }
.button-primary { color: white; background: linear-gradient(180deg, #3f73c4, var(--blue)); box-shadow: 0 3px 0 var(--blue-dark), 0 4px 10px rgb(45 93 174 / 18%); }
.button-primary:active:not(:disabled) { box-shadow: 0 1px 0 var(--blue-dark), 0 2px 6px rgb(45 93 174 / 18%); }
.button-secondary { color: var(--navy); border-color: var(--line); background: white; box-shadow: var(--shadow-sm); }
.button-secondary:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }

.status-banner { min-height: 74px; margin-bottom: 22px; padding: 14px 18px; display: flex; align-items: center; gap: 13px; border: 1px solid #edd99e; border-left: 4px solid var(--orange); border-radius: 10px; background: var(--orange-soft); }
.status-banner.pass { border-color: #cfe3c2; border-left-color: var(--green); background: var(--green-soft); }
.status-banner.reject { border-color: #efc4c4; border-left-color: var(--red); background: var(--red-soft); }
.status-symbol { width: 32px; height: 32px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; color: white; background: var(--orange); font-weight: 900; }
.status-banner.pass .status-symbol { background: var(--green); }
.status-banner.reject .status-symbol { background: var(--red); }
.status-banner strong { font-size: 14px; }
.status-banner p { margin: 3px 0 0; color: #76561f; font-size: 12px; }
.status-banner.pass p { color: var(--green-ink); }
.status-banner.reject p { color: #8e4240; }
.run-id { margin-left: auto; padding: 6px 9px; border: 1px solid rgb(26 43 92 / 7%); border-radius: 6px; color: var(--muted); background: rgb(255 255 255 / 72%); font: 600 10px ui-monospace, SFMono-Regular, Menlo, monospace; }

.result-grid { display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 22px; align-items: start; min-width: 0; }
.viewer-card, .detail-card { border: 1px solid var(--line); border-radius: 10px; background: white; box-shadow: var(--shadow-sm); }
.viewer-card { min-width: 0; overflow: hidden; position: sticky; top: 96px; }
.viewer-bar { min-height: 58px; padding: 9px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.viewer-tabs { display: flex; gap: 5px; }
.viewer-tab { padding: 9px 12px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-size: 11px; font-weight: 700; transition: color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease); }
.viewer-tab:hover { color: var(--blue); background: var(--blue-soft); }
.viewer-tab.active { color: var(--navy); background: var(--blue-soft); box-shadow: inset 0 2px 0 var(--green); }
.zoom-controls { flex: 0 0 auto; display: flex; align-items: center; gap: 4px; }
.zoom-controls > span { margin-right: 3px; color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.zoom-controls button { min-width: 30px; height: 30px; padding: 0 8px; border: 1px solid var(--line); color: var(--navy); background: white; cursor: pointer; font-size: 16px; font-weight: 800; transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease); }
.zoom-controls button:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); }
.zoom-controls button:first-of-type { border-radius: 8px 0 0 8px; }
.zoom-controls button + button { margin-left: -5px; }
.zoom-controls button:last-of-type { border-radius: 0 8px 8px 0; }
.zoom-controls button:disabled { color: #aeb6c0; background: #f4f6f7; cursor: not-allowed; }
#zoom-reset { min-width: 54px; font-size: 10px; }
.canvas-shell { min-height: 520px; height: calc(100vh - 250px); max-height: 760px; position: relative; overflow: auto; overscroll-behavior: contain; background: #e8ecf3; }
.canvas-stage { min-width: 100%; min-height: 100%; display: grid; place-items: center; }
#image-canvas, #artifact-image { display: block; flex: 0 0 auto; max-width: none; max-height: none; object-fit: contain; }
#image-canvas { cursor: crosshair; touch-action: none; }
#image-canvas.dragging { cursor: grabbing; }
.canvas-hint { position: sticky; z-index: 2; float: right; right: 12px; bottom: 12px; width: max-content; max-width: calc(100% - 24px); margin: -42px 12px 12px auto; padding: 7px 10px; border-radius: 6px; color: white; background: rgb(26 43 92 / 86%); font-size: 10px; pointer-events: none; }
.legend { min-height: 52px; padding: 12px 16px; display: flex; align-items: center; flex-wrap: wrap; gap: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.legend > span { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 2px var(--blue-soft); }
.legend-dot.derived { background: var(--orange); box-shadow: 0 0 0 2px var(--orange-soft); }
.legend-dot.operator { background: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.legend button { margin-left: auto; padding: 0; border: 0; color: var(--blue); background: transparent; cursor: pointer; font-size: 10px; font-weight: 750; }
.legend button:disabled { color: #aeb6c0; cursor: not-allowed; }

.detail-column { display: flex; flex-direction: column; gap: 14px; }
.detail-card { padding: 20px; }
.card-title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.card-title-row h2 { margin: 0; color: var(--navy); font-size: 17px; letter-spacing: -.02em; }
.badge, .unit-pill { padding: 6px 9px; border-radius: 999px; font-size: 9px; font-weight: 850; text-transform: uppercase; letter-spacing: .07em; }
.badge.review { color: #a37810; background: var(--orange-soft); }
.badge.pass { color: var(--green-ink); background: var(--green-soft); }
.badge.reject { color: var(--red); background: var(--red-soft); }
.unit-pill { color: var(--blue); background: var(--blue-soft); }
.mini-summary { margin: 18px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); border-top: 1px solid var(--line); }
.mini-summary div { padding: 14px 8px 0 0; }
.mini-summary dt { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .05em; }
.mini-summary dd { margin: 4px 0 0; color: var(--navy); font-size: 12px; font-weight: 750; }
.warning-card { border-color: #f0d9ad; background: #fffaf2; }
.warning-card ul { margin: 0; padding-left: 18px; color: #76561f; font-size: 11px; line-height: 1.55; }
.warning-card li + li { margin-top: 5px; }

.measurements-list { margin-top: 14px; }
.measurement-row { padding: 11px 0; display: grid; grid-template-columns: 39px 1fr auto; gap: 10px; align-items: center; border-top: 1px solid #edf0f3; }
.measurement-label { width: 34px; height: 28px; display: grid; place-items: center; border-radius: 6px; color: var(--navy); background: var(--blue-soft); font-size: 10px; font-weight: 850; }
.measurement-copy strong { display: block; font-size: 11px; line-height: 1.25; }
.measurement-copy small { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.measurement-value { text-align: right; }
.measurement-value strong { display: block; color: var(--navy); font-size: 14px; font-variant-numeric: tabular-nums; }
.measurement-value small { display: inline-flex; align-items: center; gap: 4px; margin-top: 3px; color: var(--orange); font-size: 8px; font-weight: 800; text-transform: uppercase; }
.measurement-value small::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.measurement-value small.pass { color: var(--green); }
.measurement-value small.reject { color: var(--red); }

.evidence-card { padding: 0; }
.evidence-card summary { padding: 17px 20px; display: flex; justify-content: space-between; align-items: center; list-style: none; cursor: pointer; }
.evidence-card summary::-webkit-details-marker { display: none; }
.evidence-card summary b { display: block; font-size: 12px; }
.evidence-card summary small { display: block; margin-top: 3px; color: var(--muted); font-size: 9px; font-weight: 400; }
.evidence-list { padding: 0 20px 18px; border-top: 1px solid var(--line); }
.evidence-row { padding: 10px 0; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #edf0f3; font-size: 10px; }
.evidence-row:last-child { border-bottom: 0; }
.evidence-row span { color: var(--muted); }
.evidence-row b { text-align: right; font-weight: 750; }

.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.export-button { padding: 12px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--navy); background: white; text-decoration: none; font-size: 10px; font-weight: 750; transition: border-color .15s var(--ease), color .15s var(--ease), background .15s var(--ease), box-shadow .15s var(--ease); }
.export-button:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-soft); box-shadow: var(--shadow-sm); }
.export-button span { color: var(--blue); font-weight: 900; }
.export-button.wide { grid-column: 1 / -1; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 360px; padding: 13px 16px; border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 10px; color: var(--navy); background: white; box-shadow: var(--shadow-lg); font-size: 12px; font-weight: 600; opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity .2s var(--ease), transform .2s var(--ease); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { color: white; border-color: var(--red); background: var(--red); }

button:focus-visible,
a:focus-visible,
select:focus-visible,
.drop-zone:focus-within {
  outline: none;
  box-shadow: 0 0 0 3px rgb(45 93 174 / 24%);
}

@media (max-width: 1100px) {
  .result-grid { grid-template-columns: 1fr; }
  .viewer-card { position: static; }
  .detail-column { display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .measurements-card { grid-row: span 3; }
}

@media (max-width: 780px) {
  .app-header { height: 66px; padding: 0 18px; }
  .brand-logo { width: 118px; }
  .brand-divider { height: 28px; }
  .brand-product strong { font-size: 14px; }
  .brand-product small { display: none; }
  .privacy-note { display: none; }
  main { min-height: calc(100vh - 66px); }
  .upload-view { width: min(100% - 28px, 560px); padding-top: 38px; grid-template-columns: 1fr; gap: 30px; }
  .hero-copy { min-height: 390px; padding: 38px 28px; }
  .hero-copy h1 { font-size: 42px; }
  .hero-copy > p:last-child { font-size: 14px; }
  .workflow-strip { display: none; }
  .result-view { width: min(calc(100% - 20px), 680px); }
  .result-toolbar { align-items: flex-start; gap: 8px; }
  .toolbar-actions .button-primary { display: none; }
  .toolbar-actions { flex: 0 0 auto; }
  .toolbar-actions .button-secondary { padding: 10px 11px; }
  .status-banner { align-items: flex-start; }
  .run-id { display: none; }
  .detail-column { display: flex; }
  .canvas-shell { min-height: 380px; height: 70vh; max-height: 70vh; }
  .viewer-bar { padding: 8px; align-items: stretch; flex-direction: column; }
  .viewer-tabs { overflow-x: auto; }
  .viewer-tab { white-space: nowrap; }
  .zoom-controls { align-self: flex-end; padding-right: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
