/* Garment measurement UI. Palette: pattern paper, cutting-mat green, tape-measure yellow. */

:root {
  --paper: #f5f6f3;
  --surface: #ffffff;
  --ink: #1d2321;
  --ink-soft: #56605c;
  --line: #d5dad5;
  --mat: #24463c;
  --mat-ink: #f2f5f1;
  --mat-grid: rgba(242, 245, 241, 0.09);
  --tape: #e9b824;
  --tape-ink: #2a2306;
  /* Marks drawn on the tape: same in both themes, since the tape stays yellow. */
  --mark-real: #2a2306;
  --mark-measured: #1d5a47;
  --mark-band: rgba(29, 90, 71, 0.28);
  --good: #2e7d4f;
  --warn: #a8690f;
  --bad: #b3261e;
  --info: #2f5f8a;
  --good-bg: #e3f1e8;
  --warn-bg: #f8ecd5;
  --bad-bg: #f7e1df;
  --info-bg: #e2ebf4;
  --focus: #2f5f8a;
  --radius: 6px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #161b19;
    --surface: #1e2522;
    --ink: #e6eae7;
    --ink-soft: #a3ada8;
    --line: #34403b;
    --mat: #1f3d34;
    --mat-ink: #e6eae7;
    --tape: #e9b824;
    --good: #6cc48f;
    --warn: #e2a64a;
    --bad: #f08a80;
    --info: #8db7e0;
    --good-bg: #1f3a2a;
    --warn-bg: #3d2f17;
    --bad-bg: #432421;
    --info-bg: #1f3044;
    --focus: #8db7e0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

/* Layout rules (display: grid/flex) must not resurrect hidden elements. */
[hidden] { display: none !important; }

a { color: inherit; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

h1, h2, h3 {
  font-stretch: 75%;
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
}
h1 { font-size: 2.25rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.125rem; font-stretch: 87.5%; }

/* -- top bar: the cutting mat ------------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(16px, calc((100vw - 1240px) / 2));
  background-color: var(--mat);
  background-image:
    linear-gradient(var(--mat-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--mat-grid) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--mat-ink);
}

.brand {
  font-size: 1.25rem;
  font-stretch: 75%;
  font-weight: 700;
  text-decoration: none;
}

.topnav {
  display: flex;
  align-items: center;
  gap: 20px;
}
.topnav a:not(.button) {
  text-decoration: none;
  padding: 4px 0;
  border-bottom: 2px solid transparent;
}
.topnav a[aria-current="page"]:not(.button) { border-bottom-color: var(--tape); }

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}
main:focus { outline: none; }

/* -- buttons and form controls ------------------------------------------------------ */

.button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  background: var(--mat);
  color: var(--mat-ink);
}
.button:disabled { opacity: 0.55; cursor: progress; }
.button-tape { background: var(--tape); color: var(--tape-ink); }
.button-quiet { background: transparent; color: var(--ink); border-color: var(--line); }
.button-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.button-danger:hover:not(:disabled) { background: var(--bad-bg); }

label { font-weight: 600; }

input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
}
textarea { min-height: 96px; resize: vertical; }
input[aria-invalid="true"] { border-color: var(--bad); }

.field { display: grid; gap: 6px; }
.field-hint { color: var(--ink-soft); font-size: 0.875rem; margin: 0; }
.field-error { color: var(--bad); font-size: 0.875rem; margin: 6px 0 0; }
.field .field-error { margin: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.unit-input { position: relative; }
.unit-input input { padding-right: 40px; }
.unit-input span {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-soft);
  pointer-events: none;
}

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }

/* Actual measurements: the unit switch sits next to the block title. */
.measure-block { display: grid; gap: 10px; }
.measure-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.measure-title { font-weight: 600; }

.unit-switch {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 2px;
}
.unit-switch legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
}
.unit-switch input { position: absolute; opacity: 0; pointer-events: none; }
.unit-switch label {
  padding: 4px 14px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--ink-soft);
  cursor: pointer;
}
.unit-switch input:checked + label { background: var(--mat); color: var(--mat-ink); }
.unit-switch input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 1px; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.choice { display: flex; gap: 20px; flex-wrap: wrap; }
.choice label { font-weight: 400; display: inline-flex; gap: 8px; align-items: center; }

/* Segmentation method: one radio per method, with its explanation below the name. */
.method-choice { display: grid; gap: 12px; margin-top: 12px; }
.method-option { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; }
.method-option input { margin-top: 3px; }
.method-option label { font-weight: 600; cursor: pointer; }
.method-option .field-hint { margin-top: 2px; }

/* -- page header ---------------------------------------------------------------------- */

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-head p { margin: 4px 0 0; color: var(--ink-soft); }
.back { display: inline-block; margin-bottom: 8px; color: var(--ink-soft); }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }

/* -- state badges ------------------------------------------------------------------------- */

.state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--info-bg);
  color: var(--info);
}
.state-success { background: var(--good-bg); color: var(--good); }
.state-partial, .state-unreliable { background: var(--warn-bg); color: var(--warn); }
.state-failed, .state-error { background: var(--bad-bg); color: var(--bad); }
.state-not_processed, .state-unknown { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }
.state-queued::before, .state-running::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.delta { font-weight: 700; white-space: nowrap; }
.delta-good { color: var(--good); }
.delta-warn { color: var(--warn); }
.delta-bad { color: var(--bad); }
.muted { color: var(--ink-soft); }

/* -- list ---------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 0.875rem; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
th.group { text-align: center; color: var(--ink); border-bottom-color: color-mix(in srgb, var(--line) 50%, transparent); padding-bottom: 2px; }
th.sub { font-weight: 400; font-size: 0.8125rem; padding-top: 2px; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
.garment-table tbody tr { cursor: pointer; }
.garment-table tbody tr:hover { background: color-mix(in srgb, var(--tape) 10%, transparent); }
.garment-table a { font-weight: 600; text-decoration: none; }
.garment-table a:hover { text-decoration: underline; }
.pair { white-space: nowrap; }

.empty {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
}
.empty p { margin: 0 0 16px; color: var(--ink-soft); }

/* -- upload ----------------------------------------------------------------------------------- */

.upload {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.dropzone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 420px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  padding: 24px;
  cursor: pointer;
}
.dropzone.dragging { border-color: var(--tape); background: color-mix(in srgb, var(--tape) 12%, var(--surface)); }
.dropzone.has-file { padding: 8px; }
.dropzone img { max-width: 100%; max-height: 70vh; border-radius: 4px; display: block; }
.dropzone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.dropzone-text strong { display: block; font-size: 1.125rem; margin-bottom: 4px; }
.dropzone-meta { margin-top: 8px; color: var(--ink-soft); font-size: 0.875rem; }

.form-stack { display: grid; gap: 20px; }

.notice {
  border-left: 4px solid var(--bad);
  background: var(--bad-bg);
  padding: 12px 16px;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.notice p { margin: 0; }
.notice-warn { border-left-color: var(--warn); background: var(--warn-bg); }
.notice-info { border-left-color: var(--info); background: var(--info-bg); }
.notice label { display: inline-flex; gap: 8px; align-items: center; margin-top: 8px; }

/* -- detail -------------------------------------------------------------------------------------- */

.detail {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}
.detail > * { min-width: 0; }
.detail > :first-child { position: sticky; top: 16px; }
.detail section + section { margin-top: 32px; }
.detail h2 { margin-bottom: 12px; }

.figure-main {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
}
.figure-zoom { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: zoom-in; }
.figure-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 4px 8px;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

/* One button, two faces: the active unit is filled. */
.unit-toggle {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}
.unit-toggle span { padding: 3px 12px; border-radius: 4px; color: var(--ink-soft); }
.unit-toggle span.on { background: var(--mat); color: var(--mat-ink); }
.unit-toggle:hover span:not(.on) { color: var(--ink); }
.figure-main img { display: block; width: 100%; height: auto; border-radius: 4px; }
.figure-main figcaption { padding: 8px 4px 0; color: var(--ink-soft); font-size: 0.875rem; }

.waiting {
  display: grid;
  place-items: center;
  min-height: 320px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  padding: 24px;
}
.waiting p { margin: 8px 0 0; color: var(--ink-soft); }

/* The tape measure: one per real measurement. */
.tapes { display: grid; gap: 24px; }
.tape-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.tape-head h3 { font-size: 1.25rem; }
.tape-values { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 10px; font-size: 0.9375rem; }
.tape-values span { color: var(--ink-soft); }
.tape-values strong { color: var(--ink); }
.tape-delta { font-size: 1.5rem; font-stretch: 75%; }

.tape {
  position: relative;
  height: 56px;
  border-radius: 3px;
  background: var(--tape);
  color: var(--tape-ink);
  overflow: hidden;
  box-shadow: inset 0 -2px 0 rgba(42, 35, 6, 0.18);
}
.tape-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 8px;
  background: rgba(42, 35, 6, 0.45);
}
.tape-tick-in { height: 18px; background: rgba(42, 35, 6, 0.85); }
.tape-tick-half { height: 12px; background: rgba(42, 35, 6, 0.7); }
.tape-tick-quarter { height: 8px; }
.tape-tick-eighth { height: 5px; background: rgba(42, 35, 6, 0.35); }
.tape-num {
  position: absolute;
  top: 20px;
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 600;
}
.tape-band {
  position: absolute;
  top: 0;
  bottom: 0;
  background: var(--mark-band);
}
.tape-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  transform: translateX(-50%);
}
.tape-mark-real { background: var(--mark-real); }
.tape-mark-measured { background: var(--mark-measured); width: 4px; }
.tape-mark-measured::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-bottom-color: var(--mark-measured);
}
.tape-legend { display: flex; gap: 16px; margin-top: 6px; font-size: 0.8125rem; color: var(--ink-soft); }
/* Legend keys: a scrap of tape with the mark on it. */
.tape-legend i {
  display: inline-block;
  width: 16px;
  height: 12px;
  margin-right: 6px;
  vertical-align: -1px;
  border-radius: 2px;
  background-color: var(--tape);
}
.tape-legend .k-real { background-image: linear-gradient(90deg, transparent 6px, var(--mark-real) 6px 9px, transparent 9px); }
.tape-legend .k-measured { background-image: linear-gradient(90deg, transparent 6px, var(--mark-measured) 6px 10px, transparent 10px); }
.tape-legend .k-band { background-image: linear-gradient(90deg, transparent 3px, var(--mark-band) 3px 13px, transparent 13px); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.facts dt { color: var(--ink-soft); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 1px 10px; font-size: 0.8125rem; }

.notes { white-space: pre-wrap; margin: 0; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.thumb {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.8125rem;
  text-align: left;
  cursor: zoom-in;
}
.thumb img { width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--paper); border-radius: 3px; }
.thumb:hover { border-color: var(--ink-soft); }

.gallery-section { margin-top: 40px; }
.gallery-section h2 { margin-bottom: 12px; }
.gallery-section h3 { margin: 20px 0 10px; color: var(--ink-soft); }

/* -- sign-in dialog --------------------------------------------------------------------------------- */

#login {
  width: min(440px, calc(100vw - 32px));
  padding: 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
#login::backdrop { background: rgba(10, 14, 12, 0.75); }
#login h2 { margin: 0; }
#login p { margin: 0; }

/* -- lightbox -------------------------------------------------------------------------------------- */

#lightbox {
  width: min(1200px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
#lightbox::backdrop { background: rgba(10, 14, 12, 0.75); }
.lightbox-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.lightbox-bar span { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
#lightbox-img { display: block; max-width: 100%; max-height: calc(100vh - 110px); margin: 0 auto; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--mat);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner, .state-queued::before, .state-running::before { animation: none; }
}

/* -- small screens ----------------------------------------------------------------------------------- */

@media (max-width: 860px) {
  .upload, .detail { grid-template-columns: 1fr; }
  .detail > :first-child { position: static; }
  .dropzone { min-height: 260px; }
  h1 { font-size: 1.75rem; }
}
@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; }
  .field-row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* -- annotation tool ------------------------------------------------------------------------- */

.annot-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 24px;
  align-items: start;
}
.annot-main { min-width: 0; }
.annot-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.annot-check { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; margin-left: 8px; }
.annot-stage {
  position: relative;
  height: calc(100vh - 320px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #2b302e;
  overflow: hidden;
}
.annot-canvas { display: block; cursor: crosshair; touch-action: none; }
.annot-keys { font-size: 0.8125rem; margin: 8px 0 0; }

.annot-panel { display: grid; gap: 16px; position: sticky; top: 16px; }
.annot-current {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.annot-current h3 { font-size: 1.125rem; margin: 2px 0 4px; }
.annot-kicker { margin: 0; font-size: 0.8125rem; }
.annot-help-text { margin: 0 0 10px; font-size: 0.875rem; }
.annot-current .actions .button { padding: 4px 10px; font-size: 0.8125rem; }

.annot-sketch { width: 96px; height: auto; }
.sketch-outline { fill: color-mix(in srgb, var(--ink) 8%, transparent); stroke: var(--ink-soft); stroke-width: 1.5; }
.sketch-dot { fill: var(--surface); stroke: var(--ink-soft); stroke-width: 1.5; }
.sketch-dot.placed { fill: var(--good); stroke: var(--good); }
.sketch-dot.hidden { fill: var(--line); stroke: var(--ink-soft); }
.sketch-dot.auto { fill: var(--info-bg); stroke: var(--info); }
.sketch-dot.current { fill: var(--tape); stroke: var(--tape-ink); stroke-width: 2; }

.annot-progress { margin: 0; font-weight: 600; }
.annot-list h3 { font-size: 0.875rem; color: var(--ink-soft); margin: 10px 0 4px; font-stretch: 100%; }
.annot-list ol { margin: 0; padding-left: 26px; }
.annot-list li { margin: 1px 0; }
.annot-list li::marker { color: var(--ink-soft); font-size: 0.8125rem; }
.annot-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 3px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  cursor: pointer;
}
.annot-row:hover { background: color-mix(in srgb, var(--tape) 12%, transparent); }
li.current .annot-row { border-color: var(--tape); background: color-mix(in srgb, var(--tape) 22%, transparent); font-weight: 600; }
li[data-state="placed"] .annot-state { color: var(--good); font-weight: 700; }
li[data-state="hidden"] .annot-state { color: var(--ink-soft); font-size: 0.8125rem; }
li[data-state="auto"] .annot-state { color: var(--info); font-size: 0.8125rem; }
li[data-state="todo"] .annot-state { color: var(--warn); font-size: 0.8125rem; }
.annot-save { align-items: center; }
.annot-save-state.unsaved { color: var(--warn); font-weight: 600; }

@media (max-width: 980px) {
  .annot-layout { grid-template-columns: 1fr; }
  .annot-panel { position: static; }
  .annot-stage { height: 70vh; }
}

/* -- measurement from the user's points (garment page) -- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.detail .section-head h2 { margin-bottom: 0; }
.annot-result-wait { display: flex; align-items: center; gap: 12px; padding: 16px; margin-bottom: 12px; border: 1px dashed var(--line); border-radius: var(--radius); }
.annot-result-wait p { margin: 0; }
.annot-result-counts { margin: 0 0 10px; font-size: 0.875rem; }
.table-note { margin: 6px 0 0; font-size: 0.8125rem; }
td.changed { font-weight: 700; }
.annot-rotate { display: inline-flex; align-items: center; gap: 6px; }
.annot-rot-label { min-width: 3.2em; text-align: center; font-variant-numeric: tabular-nums; font-size: 0.875rem; }
