.lab-modes {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0 0 17px;
  padding: 4px;
  border: 1px solid var(--rule);
  border-radius: 11px;
  background: #edf2ea;
}
.lab-modes button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 17px;
  min-height: 41px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 650;
  font-size: .99rem;
  line-height: 1.35;
  color: var(--muted);
}
.lab-modes button:hover { color: var(--ink); }
.lab-modes button[aria-pressed="true"] {
  background: #fff;
  color: var(--green);
  border-color: #bccfc2;
  box-shadow: 0 1px 3px #23463912;
}
.lab-modes button svg, .photo-actions button svg { height: 18px; width: 18px; flex: none; }

.photo-panel, .photo-result { scroll-margin-top: 16px; }
.photo-header { padding: 21px 24px 17px; border-bottom: 1px solid var(--rule); }
.photo-header h2, .result-copy h2, .print-dialog h2 { font-size: 1.3rem; }
.photo-header p, .result-copy p, .print-dialog p { color: var(--muted); margin: 6px 0 0; }
.photo-layout {
  display: grid;
  grid-template-columns: minmax(0, .89fr) minmax(0, 1.11fr);
  align-items: start;
  gap: clamp(22px, 3.4vw, 44px);
  padding: clamp(16px, 2.2vw, 26px);
}
.photo-layout:has(.photo-form[hidden]) { grid-template-columns: minmax(0, 1fr); }
.photo-source, .photo-form, .result-copy { min-width: 0; }
.photo-drop {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 202px;
  padding: 14px;
  border: 1.5px dashed #93b3a1;
  border-radius: 12px;
  background-color: #f0f5ef;
  background-image: radial-gradient(#abc1b48f .8px, transparent .9px);
  background-size: 18px 18px;
}
.photo-drop.dragging, .photo-drop.drag-over, .photo-drop[data-dragging="true"] {
  background-color: #d8ebdd;
  border-color: var(--green);
  outline: 2px solid #91b5a1;
  outline-offset: -4px;
}
.photo-empty { display: grid; justify-items: center; gap: 9px; padding: 18px 10px; color: #355a49; text-align: center; }
.photo-empty > svg, .photo-empty > .icon {
  display: block;
  width: 52px;
  height: 52px;
  padding: 11px;
  border-radius: 15px;
  background: #e0ece1;
  color: var(--green);
}
.photo-empty svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.photo-empty > svg { width: 52px; height: 52px; }
.photo-empty p { margin: 0; font-weight: 600; }
#photo-preview {
  display: block;
  width: 100%;
  max-height: clamp(240px, 38vw, 430px);
  object-fit: contain;
  border-radius: 6px;
}
#photo-preview:not([src]), #photo-preview[src=""] { display: none; }
.photo-drop:has(#photo-preview[src]:not([hidden]):not([src=""])) {
  min-height: 0;
  padding: 8px;
  border-style: solid;
  border-color: var(--rule);
}
.photo-actions, .candidate-list { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.photo-actions { margin-top: 12px; }
.photo-button, .photo-primary, .photo-actions button, .candidate-list button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 43px;
  padding: 8px 14px;
  border: 1px solid #a7bdaf;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .94rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
}
.photo-primary, .photo-actions .photo-primary, .photo-source #pick-photo {
  color: white; background: var(--green); border-color: var(--green);
}
.photo-button:not(:disabled):hover, .photo-actions button:not(:disabled):hover,
.candidate-list button:not(:disabled):hover { background: #eff5ed; border-color: var(--green); }
.photo-primary:not(:disabled):hover, .photo-actions .photo-primary:not(:disabled):hover,
.photo-source #pick-photo:not(:disabled):hover { background: #10493f; color: white; }
.photo-panel button:disabled, .photo-result button:disabled, .print-dialog button:disabled { cursor: default; opacity: .55; }
.photo-help, .photo-note, #photo-status, #candidate-status, #measure-help {
  margin: 8px 0 0;
  font-size: .94rem;
  line-height: 1.6;
  color: var(--muted);
}
.photo-note { padding: 9px 12px; border-left: 3px solid #92b597; background: #f1f6ee; }
#photo-status:empty, #candidate-status:empty, .photo-error:empty { display: none; }
.photo-error, #photo-status.photo-error, #candidate-status.photo-error {
  margin: 0; color: #903b26; font-weight: 600;
}

.photo-form { display: grid; align-content: start; gap: 15px; }
.photo-form h3 { margin: 0; font-size: 1.15rem; line-height: 1.4; letter-spacing: -.04em; }
.photo-form #photo-dimensions { display: grid; gap: 12px; }
.photo-form #sample-values { margin: 0; }
.photo-form > .photo-help, .photo-form > .photo-note, #candidate-status { margin: 0; }
.candidate-list { gap: 6px; }
.candidate-list:empty { display: none; }
.candidate-list button {
  min-height: 38px;
  padding: 6px 12px;
  border-color: #c3d2c6;
  border-radius: 20px;
  font-size: .9rem;
}
.candidate-list button[aria-pressed="true"], .candidate-list button.selected {
  color: #164f40;
  background: #e2efe4;
  border-color: #62927e;
}
.photo-field { display: grid; gap: 6px; min-width: 0; color: var(--ink); font-size: .96rem; font-weight: 650; }
.photo-field select, .photo-field input {
  width: 100%;
  min-width: 0;
  min-height: 45px;
  padding: 8px 11px;
  border: 1px solid #9eb4a6;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
}
.photo-field select {
  appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m3 6 5 5 5-5' fill='none' stroke='%23345e4f' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 15px;
}
.photo-field input[aria-invalid="true"] { border-color: #a44831; }
.photo-field :is(select, input):focus-visible { outline: 3px solid #ba6e1d; outline-offset: 2px; }
.dimension-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 125px), 1fr)); gap: 11px; }
.unit-mode { min-width: 0; margin: 0; padding: 0; border: 0; }
.unit-mode legend { margin-bottom: 5px; padding: 0; font-size: .96rem; font-weight: 650; }
.unit-mode label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  margin: 2px 5px 2px 0;
  padding: 6px 10px;
  border: 1px solid var(--rule);
  border-radius: 7px;
  color: var(--muted);
  font-size: .94rem;
  cursor: pointer;
}
.unit-mode label:has(input:checked) { border-color: #6c9780; background: #eaf3e9; color: var(--ink); }
.unit-mode input { accent-color: var(--green); margin: 0; width: 16px; height: 16px; }
.measure-guide { padding: 12px 16px; border: 1px solid #d6e1d5; border-radius: 10px; background: #f5f8f1; }
#measure-picture svg { display: block; width: 100%; max-width: 280px; height: auto; margin-inline: auto; }
#measure-help { margin: 6px 0 0; }
.photo-form > .photo-primary { justify-self: start; padding-inline: 18px; }
.photo-result {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 17px;
  margin: 17px 0;
  padding: 16px 19px;
  border: 1px solid #afc7b6;
  border-radius: 12px;
  background: #e8f1e5;
}
.photo-result > img { display: block; width: 74px; height: 74px; object-fit: contain; border: 1px solid var(--rule); border-radius: 8px; background: white; }
.result-copy { flex: 1 1 250px; }
.photo-result .photo-actions { margin: 0; }
.print-dialog {
  width: min(570px, calc(100% - 28px));
  max-height: calc(100vh - 42px);
  max-height: calc(100dvh - 42px);
  padding: clamp(16px, 4vw, 25px);
  overflow: auto;
  border: 1px solid var(--rule);
  border-radius: 14px;
  background: #f9fbf6;
  color: var(--ink);
  box-shadow: 0 16px 56px #10382e35;
}
.print-dialog::backdrop { background: #183d34a8; }
.sheet-preview {
  display: grid;
  place-items: center;
  margin: 14px 0;
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: #e6ede5;
}
.sheet-preview svg {
  display: block;
  width: auto;
  max-width: 100%;
  height: clamp(190px, 44vh, 430px);
  background: white;
  box-shadow: 0 1px 5px #1a43322b;
}
.print-pages { display: none; }

@media (max-width: 740px) {
  .photo-layout { grid-template-columns: minmax(0, 1fr); gap: 20px; }
  .photo-form:not([hidden]) { padding-top: 17px; border-top: 1px solid var(--rule); }
  .photo-drop { min-height: 166px; }
  #photo-preview { max-height: 290px; }
  .photo-header { padding: 16px; }
  .photo-result { padding: 14px; }
  .result-copy { flex-basis: 150px; }
  .photo-result .photo-actions { width: 100%; }
}
@media (max-width: 460px) {
  .lab-modes { display: flex; width: 100%; }
  .lab-modes button { flex: 1 1 110px; padding-inline: 5px; }
  .photo-actions button, .photo-actions .photo-button { flex: 1 1 auto; }
  .photo-form > .photo-primary { justify-self: stretch; }
  .dimension-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .photo-result > img { width: 60px; height: 60px; }
}

@page solidNetSheet { size: A4 portrait; margin: 0; }
@media print {
  html:has(body.printing-net), body.printing-net {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: 0 !important;
    background: white !important;
  }
  body.printing-net { page: solidNetSheet; }
  body.printing-net > :not(.print-pages), body.printing-net dialog::backdrop { display: none !important; }
  body.printing-net .print-pages { display: block !important; margin: 0; padding: 0; }
  .print-pages .print-sheet {
    display: block;
    margin: 0;
    padding: 0;
    width: 210mm;
    height: 297mm;
    overflow: hidden;
    line-height: 0;
    break-inside: avoid;
    break-after: auto;
    box-shadow: none;
    border: 0;
  }
  .print-sheet + .print-sheet { page-break-before: always; break-before: page; }
  .print-sheet > svg { display: block; width: 210mm; height: 297mm; }
}
