/* The thread matcher shares the app theme without changing other workspaces. */
#view-threads [hidden],
.threads-dialog [hidden] {
  display: none !important;
}

#view-threads .threads-heading {
  gap: 20px;
  align-items: flex-start;
}

#view-threads .threads-heading p {
  max-width: 650px;
  line-height: 1.8;
}

#view-threads .threads-top-actions,
#view-threads .threads-tools,
#view-threads .threads-pagination,
.threads-dialog .threads-dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

#view-threads .threads-top-actions {
  padding-top: 12px;
  justify-content: flex-end;
}

#view-threads .threads-top-actions button,
#view-threads .threads-tools button,
#view-threads .threads-manager-toolbar > button,
#view-threads .threads-pagination button,
.threads-dialog .threads-dialog-actions button {
  padding: 9px 14px;
  font-size: 12px;
  gap: 8px;
}

#view-threads .threads-tabs {
  overflow-x: auto;
  gap: 28px;
}

#view-threads .threads-tabs button {
  flex-shrink: 0;
}

#view-threads .threads-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  align-items: start;
  gap: 24px;
}

#view-threads .threads-workspace > .card,
#view-threads .threads-settings > *,
#view-threads .threads-library-controls > *,
.threads-dialog .threads-settings > *,
.threads-dialog .threads-form-grid > * {
  min-width: 0;
}

#view-threads .threads-card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

#view-threads .threads-card-heading h2 {
  font-size: 15px;
}

#view-threads .threads-card-heading small {
  color: var(--muted);
  text-align: right;
}

#view-threads .threads-library-controls {
  display: block;
  margin-bottom: 18px;
}

#view-threads label.threads-library-controls,
#view-threads .threads-library-controls label,
#view-threads .threads-settings label,
.threads-dialog .threads-settings label,
.threads-dialog label {
  font-size: 12px;
}

#view-threads label .inline-select,
.threads-dialog label .inline-select {
  margin-top: 8px;
}

#view-threads .threads-library-controls input,
#view-threads .threads-library-controls select,
#view-threads .threads-settings input,
#view-threads .threads-settings select,
#view-threads .threads-manager-toolbar input,
#view-threads .threads-manager-toolbar select,
.threads-dialog .threads-settings input,
.threads-dialog .threads-settings select {
  min-width: 0;
  padding: 9px 10px;
  font-size: 12px;
}

#view-threads .threads-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 310px;
  padding: 28px 20px;
  border: 1px dashed #cbd5c0;
  border-radius: 10px;
  background: #f8f9f5;
  text-align: center;
  cursor: pointer;
}

#view-threads .threads-upload.dragover {
  border-color: var(--green);
  background: var(--pale);
}

#view-threads .threads-upload > span:first-child {
  font-size: 30px;
  color: #66835d;
}

#view-threads .threads-upload h3 {
  font-size: 15px;
}

#view-threads .threads-upload p,
#view-threads .threads-upload small {
  font-size: 12px;
  color: var(--muted);
}

#view-threads .threads-upload button {
  margin-top: 8px;
  padding: 8px 18px;
  font-size: 12px;
}

#view-threads .threads-canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 250px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f6f4ed;
  line-height: 0;
}

#view-threads #threads-canvas {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  cursor: crosshair;
  touch-action: none;
}

#view-threads .threads-empty {
  display: grid;
  place-items: center;
  gap: 10px;
  min-height: 190px;
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: #f8f9f5;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

#view-threads .threads-empty p {
  font-size: 12px;
}

#view-threads .threads-tools {
  margin-top: 14px;
}

#view-threads .threads-tools > small {
  margin-left: auto;
  color: var(--muted);
}

#view-threads .threads-status {
  min-height: 22px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 12px;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

#view-threads .threads-status.error {
  color: #a14439;
}

#view-threads .threads-results {
  display: grid;
  gap: 14px;
  max-height: 720px;
  overflow-y: auto;
  padding: 1px 4px 1px 1px;
}

#view-threads .threads-match-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

#view-threads .threads-marker-heading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 12px;
  font-size: 12px;
}

#view-threads .threads-marker-heading small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

#view-threads .threads-marker-heading button {
  margin-left: auto;
  padding: 3px 6px;
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

#view-threads .threads-color-dot,
.threads-dialog .threads-color-dot {
  display: inline-block;
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 1px solid #253c3326;
  border-radius: 50%;
}

#view-threads .threads-candidates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}

#view-threads .threads-candidate,
#view-threads .threads-library-color {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 7px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcf9;
  text-align: left;
}

#view-threads .threads-candidate:hover,
#view-threads .threads-library-color:hover {
  border-color: #91a58a;
  background: var(--pale);
}

#view-threads .threads-candidate.selected,
#view-threads .threads-candidate.active,
#view-threads .threads-candidate[aria-pressed="true"],
#view-threads .threads-library-color.selected,
#view-threads .threads-library-color[aria-pressed="true"] {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green);
  background: var(--pale);
}

#view-threads .threads-swatch,
.threads-dialog .threads-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  flex-shrink: 0;
  margin-bottom: 8px;
  border-radius: 5px;
  overflow: hidden;
}

#view-threads .threads-swatch-heading,
.threads-dialog .threads-swatch-heading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  width: 100%;
  padding: 8px 3px;
  background: #fbfcf9;
  text-align: center;
}

#view-threads .threads-chip,
.threads-dialog .threads-chip {
  width: 25px;
  height: 25px;
  border: 1px solid #253c3326;
  border-radius: 50%;
}

#view-threads .threads-strip,
.threads-dialog .threads-strip {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
  height: 215px;
  padding: 5px;
  background: #fff;
}

#view-threads .threads-swatch img,
.threads-dialog .threads-swatch img {
  display: block;
  width: auto;
  height: auto;
  max-width: min(100%, 96px);
  max-height: 205px;
  object-fit: contain;
}

#view-threads .threads-solid-strip,
.threads-dialog .threads-solid-strip {
  display: block;
  width: 28px;
  height: 205px;
  border-radius: 3px;
}

#view-threads .threads-photo-note,
.threads-dialog .threads-photo-note {
  width: 100%;
  padding: 5px 2px;
  background: #fbfcf9;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

#view-threads .threads-candidate strong,
#view-threads .threads-library-color strong {
  display: block;
  width: 100%;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#view-threads .threads-candidate small,
#view-threads .threads-library-color small {
  display: block;
  width: 100%;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

#view-threads .threads-delta {
  display: block;
  margin-top: 6px;
  color: #698158;
  font-size: 10px;
}

#view-threads .threads-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
  margin-top: 16px;
  padding: 12px 14px;
  border: 1px solid #dfe7d7;
  border-radius: 8px;
  background: var(--pale);
  color: var(--green);
  font-size: 12px;
  overflow-wrap: anywhere;
}

#view-threads .threads-manager-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 20px;
}

#view-threads .threads-manager-toolbar label {
  flex: 1 1 170px;
  min-width: 0;
  font-size: 12px;
}

#view-threads .threads-manager-toolbar > button {
  flex-shrink: 0;
  min-height: 39px;
}

#view-threads .threads-library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 12px;
}

#view-threads .threads-library-color .threads-strip {
  height: 190px;
}
#view-threads .threads-library-color .threads-swatch img { max-height: 180px; }
#view-threads .threads-library-color .threads-solid-strip { height: 180px; }

#view-threads .threads-pagination {
  justify-content: center;
  margin-top: 20px;
  color: var(--muted);
  font-size: 12px;
}

#view-threads .threads-settings,
.threads-dialog .threads-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 22px;
  margin: 18px 0;
}

#view-threads .threads-settings small,
.threads-dialog .threads-settings small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

.threads-dialog {
  width: min(760px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: 90vh;
  max-height: 90dvh;
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  color: var(--ink);
}

.threads-dialog button {
  position: static;
  font-size: inherit;
}

.threads-dialog img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: none;
}

.threads-dialog .threads-swatch { grid-column: 1 / -1; width: 150px; justify-self: center; }
.threads-dialog .threads-strip { height: 440px; }
.threads-dialog .threads-swatch img { max-height: 430px; }
.threads-dialog .threads-solid-strip { height: 430px; }

.threads-dialog .threads-dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
}

.threads-dialog .threads-dialog-header h2 {
  font-size: 17px;
}

.threads-dialog .threads-dialog-header > button {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 7px;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.threads-dialog .threads-dialog-header > button:hover {
  background: var(--pale);
}

.threads-dialog .threads-dialog-body {
  padding: 22px 24px;
}

.threads-dialog .threads-dialog-body > p {
  margin-bottom: 16px;
  font-size: 12px;
}

.threads-dialog .threads-dialog-actions {
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--line);
  background: #fbfcf9;
}

.threads-dialog .threads-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.threads-dialog label {
  min-width: 0;
}

.threads-dialog input,
.threads-dialog select,
.threads-dialog textarea {
  min-width: 0;
  max-width: 100%;
  font-size: 12px;
}

.threads-dialog input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
}

.threads-dialog input[type="color"] {
  height: 42px;
  padding: 4px;
}

.threads-dialog input[type="file"] {
  padding: 8px;
  overflow: hidden;
}

.threads-dialog .threads-grid-preview {
  display: grid;
  grid-template-columns: repeat(var(--threads-grid-columns, 4), minmax(0, 1fr));
  gap: 4px;
  margin-top: 18px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8f9f5;
}

.threads-dialog .threads-grid-cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
  font-size: 11px;
}

.threads-dialog .threads-grid-cell img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.threads-dialog .threads-grid-cell.selected,
.threads-dialog .threads-grid-cell[aria-pressed="true"] {
  border-color: var(--green);
  box-shadow: 0 0 0 1px var(--green);
}

@media (max-width: 900px) {
  #view-threads .threads-workspace {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  #view-threads .threads-heading {
    flex-wrap: wrap;
    gap: 8px;
  }

  #view-threads .threads-top-actions {
    padding-top: 0;
    justify-content: flex-start;
  }

  #view-threads .threads-results {
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 500px) {
  #view-threads .threads-top-actions {
    gap: 8px;
  }

  #view-threads .threads-top-actions button,
  #view-threads .threads-tools button {
    padding: 8px 10px;
    font-size: 11px;
  }

  #view-threads .threads-settings,
  .threads-dialog .threads-settings,
  .threads-dialog .threads-form-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #view-threads .threads-card-heading {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  #view-threads .threads-upload {
    min-height: 245px;
    padding: 22px 14px;
  }

  #view-threads .threads-canvas-wrap {
    min-height: 180px;
  }

  #view-threads .threads-match-card {
    padding: 10px;
  }

  #view-threads .threads-candidates {
    gap: 6px;
  }

  #view-threads .threads-candidate {
    padding: 5px;
  }

  #view-threads .threads-swatch {
    margin-bottom: 6px;
  }

  #view-threads .threads-candidate strong {
    font-size: 11px;
  }

  #view-threads .threads-candidate small,
  #view-threads .threads-delta {
    font-size: 9px;
  }

  #view-threads .threads-library-grid {
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 8px;
  }

  #view-threads .threads-library-color .threads-strip { height: 190px; }

  #view-threads .threads-marker-heading {
    flex-wrap: wrap;
    row-gap: 4px;
  }

  #view-threads .threads-tools > small {
    flex-basis: 100%;
    margin-left: 0;
  }

  .threads-dialog .threads-dialog-header,
  .threads-dialog .threads-dialog-body {
    padding: 16px;
  }

  .threads-dialog .threads-dialog-actions {
    padding: 14px 16px;
    gap: 8px;
  }

  .threads-dialog .threads-dialog-actions button {
    white-space: normal;
  }
}

.threads-plan-dialog {
  width: min(900px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: 80vh;
  max-height: 80dvh;
  overflow: hidden;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--ink);
  background: #fbfcf9;
}
.threads-plan-dialog::backdrop { background: #172a24a6; }
.threads-plan-dialog .threads-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.threads-plan-dialog[open], .threads-photo-dialog[open] { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; gap: 12px; }
.threads-plan-dialog .threads-preview-image-wrap, .threads-photo-dialog .threads-preview-image-wrap { min-height: 0; overflow: auto; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); }
.threads-plan-dialog #threads-plan-image { display: block; max-width: 100%; width: auto; height: auto; object-fit: contain; max-height: calc(80vh - 210px); max-height: calc(80dvh - 210px); }
.threads-plan-dialog #threads-plan-image:not([src]) { display: none; }
.threads-plan-dialog #threads-plan-status, .threads-photo-dialog p { margin: 0; overflow-wrap: anywhere; }
.threads-plan-dialog .threads-summary { margin-top: 0; }
#view-threads .threads-records-stats { margin: 16px 0; padding: 16px; background: var(--pale); border-radius: 8px; color: var(--green); }
#view-threads .threads-records-stats span { margin-left: 20px; font-size: 26px; }
#view-threads #threads-records-daily { margin-bottom: 16px; max-height: 380px; overflow: auto; }
#view-threads #threads-records-daily summary { padding: 12px 0; cursor: pointer; }
#view-threads .threads-record-download { color: var(--green); white-space: nowrap; }
#view-threads .threads-swatch [hidden], .threads-dialog .threads-swatch [hidden] { display: none !important; }
.threads-plan-dialog button { position: static; font-size: inherit; }

#view-threads .threads-calibration-notice { margin-bottom: 14px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--pale); overflow-wrap: anywhere; }
#view-threads .threads-calibration-notice .threads-top-actions { justify-content: flex-start; gap: 6px; }
#view-threads .threads-calibration-notice button { padding: 7px 10px; font-size: 11px; }

#view-threads .threads-solid-strip.threads-reference-block, .threads-dialog .threads-solid-strip.threads-reference-block { width: 28px; }

/* 候选卡片：照片下方只保留线号与色差，不显示待核说明（页面顶部已有统一提示） */
#view-threads .threads-candidate .threads-photo-note { display: none; }
#view-threads .threads-code-line { font-weight: 600; color: #284438; }

/* 画线标注与方案信息 */
#view-threads #threads-annotate.active { background: #345c48; color: #fff; border-color: #345c48; }
#view-threads .threads-plan-meta { display: flex; gap: 12px; margin: 10px 0 4px; flex-wrap: wrap; }
#view-threads .threads-plan-meta label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); flex: 1; min-width: 110px; }
#view-threads .threads-plan-meta input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; background: #fff; }

/* 候选线样查看独立于选线，两个预览均限制在视口内。 */
#view-threads .threads-candidate-item { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
#view-threads .threads-candidate-item .threads-candidate { width: 100%; flex: 1; }
#view-threads .threads-photo-open { width: 100%; padding: 6px 3px; font-size: 11px; text-align: center; }
#view-threads .threads-candidate img { cursor: zoom-in; }
.threads-photo-dialog { width: min(560px, calc(100vw - 32px)); max-width: calc(100vw - 32px); max-height: 80vh; max-height: 80dvh; overflow: hidden; padding: 22px; border: 1px solid var(--line); border-radius: 14px; color: var(--ink); background: #fbfcf9; }
.threads-photo-dialog[open] { grid-template-rows: auto auto minmax(0, 1fr) auto auto; }
.threads-photo-dialog::backdrop { background: #172a24a6; }
.threads-photo-dialog .threads-card-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.threads-photo-dialog button { position: static; font-size: inherit; }
.threads-photo-dialog #threads-photo-image { display: block; width: 100%; height: min(460px, calc(80vh - 210px)); height: min(460px, calc(80dvh - 210px)); max-width: 100%; max-height: none; object-fit: contain; }
@media (max-width: 600px) {
  .threads-plan-dialog, .threads-photo-dialog { padding: 16px; }
  .threads-plan-dialog .threads-card-heading h2, .threads-photo-dialog .threads-card-heading h2 { font-size: 15px; }
  .threads-plan-dialog .threads-summary button { width: 100%; }
}
