/* ============================================================
   Threads margin gutter — own right-side gutter, separate from
   the notes gutter that lives on the left.
   Manuscript: dedicated grid columns (#editor--thread-connector,
   #editor--threads-margin) with .threads-gutter--column inside.
   Plot (legacy): zero-size overlay anchored to .plot-page-surface.
   ============================================================ */

/* Legacy overlay gutter (plot page) */
.threads-gutter {
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 1;
}

/* Column gutter (manuscript editor shell) */
.threads-gutter--column {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.threads-connector-gutter {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

/* Vertical lane line connecting a thread's first to last marker */
.thread-lane {
  position: absolute;
  width: 4px;
  border-radius: 2px;
  opacity: 0.7;
  transition: opacity 0.15s, filter 0.15s;
  /* top, height, right, and background are set inline per thread */
}

.thread-lane:hover {
  opacity: 1;
  filter: brightness(1.12);
}

/* Horizontal connector from marker to prose */
.thread-margin-stub {
  pointer-events: none;
  border-radius: 1px;
}

/* Round / square markers in the right-hand gutter */
.thread-margin-marker {
  opacity: 0.7;
  transition: opacity 0.15s, filter 0.15s;
}

.thread-margin-marker:hover {
  opacity: 1;
  filter: brightness(1.12);
}

/* Square marker — used for the first and last occurrence of a node tag */
.thread-marker--square {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 1px;
  /* top, right, and background are set inline */
}

/* Circle marker — used for off-works indicator at a given marker position */
.thread-marker--circle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 2px solid currentColor;
  background: transparent;
  /* top, right, and color are set inline */
}

/* Count badge (×N) shown at the first marker when a node is tagged
   multiple times in this work */
.thread-marker--count {
  position: absolute;
  font-size: 9px;
  line-height: 1;
  font-weight: 600;
  font-family: var(--font-ui);
  white-space: nowrap;
  /* top, right, and color are set inline */
}

/* Off-works horizontal stub connecting the lane to the circle marker */
.thread-off-works-stub {
  position: absolute;
  height: 2px;
  /* width, top, right, and background are set inline */
}

/* ============================================================
   Thread planner — page mode (stacked, #threads-view)
   ============================================================ */

/* ── Thread picker cards (replaces pill tabs) ─────────────── */

.thread-tab-strip--cards {
  display: block;
  padding: 0 0 20px;
  margin-bottom: 0;
}

.thread-tab-strip--cards .new-tile--thread {
  aspect-ratio: auto;
  height: 200px;
}

.thread-picker-card-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.thread-picker-card {
  height: 200px;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--raised-bg);
  overflow: hidden;
  text-align: left;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.thread-picker-card--clickable {
  cursor: pointer;
}

.thread-picker-card--clickable:hover {
  border-color: var(--hairline-strong);
}

.thread-picker-card--clickable:hover .thread-picker-card__title {
  color: var(--accent);
}

.thread-picker-card--selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.thread-picker-card--selected .thread-picker-card__title {
  color: var(--accent);
}

.thread-picker-card__inner {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 0 10px;
  padding: 14px 12px 14px 10px;
  height: 100%;
  box-sizing: border-box;
}

.thread-picker-card__rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  min-height: 0;
  padding-top: 3px;
}

.thread-picker-card__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.thread-picker-card__line {
  flex: 0.25;
  width: 2px;
  min-height: 0;

  border-radius: 2px;
  opacity: 0.85;
}

.thread-picker-card__content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.thread-picker-card__title,
.thread-picker-card__desc,
.thread-picker-card__stats,
.thread-picker-card__content .thread-state-badge {
  margin: 0;
}

.thread-picker-card__content > .thread-picker-card__desc,
.thread-picker-card__content > .thread-picker-card__stats,
.thread-picker-card__content > .thread-state-badge {
  border-top: 1px solid var(--hairline);
  padding-top: 8px;
}

.thread-picker-card__content > .thread-picker-card__desc,
.thread-picker-card__content > .thread-picker-card__stats {
  margin-top: 8px;
}

.thread-picker-card__content > .thread-state-badge {
  margin-top: auto;
  align-self: flex-start;
}

.thread-picker-card__title {
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.thread-picker-card__desc {
  flex: 1;
  min-height: 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-dim);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  overflow: hidden;
}

.thread-picker-card__stats {
  font-size: 11.5px;
  color: var(--text-faint);
  letter-spacing: 0.01em;




  padding: 0 2px;
  margin: 0;
}

/* Legacy pill tabs (unused in page mode) */

.thread-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.thread-tab:hover {
  border-color: var(--hairline-strong);
  color: var(--text);
}

.thread-tab--active {
  border-color: var(--tab-color, var(--accent));
  background: color-mix(in srgb, var(--tab-color, var(--accent)) 12%, transparent);
  color: var(--text);
}

.thread-tab__swatch {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ec-thread);
  flex-shrink: 0;
}

.thread-tab__label {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Planner content wrapper ─────────────────────────────────── */

.thread-planner-content {
  padding-bottom: 40px;
}

/* ── Details band (full-width, above timeline) ───────────────── */

.thread-details-band {
  background: var(--raised-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 24px;
  overflow: visible;
}

.thread-details-band__head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  overflow: visible;
}

.thread-details-band__color-field {
  flex-shrink: 0;
  position: relative;
  overflow: visible;
}

.thread-details-band__color-field .thread-colour-mixer {
  flex-shrink: 0;
}

.thread-details-band__name-input {
  flex: 1;
  min-width: 120px;
  font-size: 15px;
  font-weight: 600;
  padding: 5px 8px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  background: var(--input-bg);
}

.thread-details-band__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.thread-details-band__desc-input {
  width: 100%;
  min-height: 56px;
  resize: vertical;
  padding: 7px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-xs);
  background: var(--input-bg);
  font-size: 14px;
  line-height: 1.5;
}

/* Sub-thread reference label (T6.1 — label only, no nesting) */
.thread-sub-label {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 12px;
}

/* Thread state badge */
.thread-state-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  flex-shrink: 0;
}

.thread-state-badge--open {
  background: var(--accent-soft);
  color: var(--accent);
}

.thread-state-badge--resolved {
  background: color-mix(in srgb, #3aad6a 14%, transparent);
  color: #3aad6a;
}

body.theme-light .thread-state-badge--resolved {
  background: color-mix(in srgb, #2a8a52 12%, transparent);
  color: #2a8a52;
}

/* ── Timeline ────────────────────────────────────────────────── */

.thread-timeline {
  position: relative;
}

/*
  The rail holds all rows and carries the vertical thread line as a
  CSS custom-property-coloured left border on a ::before pseudo-element.
  --thread-color is set inline from the thread's colour.
*/
.thread-timeline__rail {
  position: relative;
  padding-left: 52px; /* marker-col (28px) + stub (16px) + gap (8px) */
}

/* Vertical line from first to last marker */
.thread-timeline__rail::before {
  content: "";
  position: absolute;
  left: 13px;   /* center of 28px marker column (28/2 - 1) */
  top: 14px;    /* start at first marker's center */
  bottom: 8px;
  width: 2px;
  background: var(--thread-color, var(--ec-thread, #6b93c4));
}

.thread-timeline__row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin-bottom: 18px;
}

/* Marker column: left-aligned, absolutely positioned in the rail padding */
.thread-timeline__marker-col {
  position: absolute;
  left: -52px;
  top: 0;
  width: 28px;
  display: flex;
  justify-content: center;
}

/* Horizontal stub (marker → node block) */
.thread-timeline__stub {
  width: 16px;
  height: 2px;
  flex-shrink: 0;
  /* align-self: center; */
  background: var(--thread-color, var(--ec-thread, #6b93c4));
  opacity: 0.5;
  margin-left: -27px;
  margin-top: 11px;
  width: 42px;
  margin-right: 10px;
}

/* Empty state inside timeline */
.thread-timeline__empty {
  padding-left: 0;
  padding-top: 8px;
}

/* Dotted continuation below last node when thread is unresolved (T7.2) */
.thread-timeline__continuation {
  position: absolute;
  left: 12px;  /* rail line center */
  bottom: -28px;
  width: 0;
  height: 28px;
  border-left: 2px dashed var(--thread-color, var(--ec-thread, #6b93c4));
  opacity: 0.45;
}

/* Add-node row sits below the rail */
.thread-timeline__add {
  padding-left: 52px;
  margin-top: 10px;
}

/* ── Planner markers (numbered circles / squares) ────────────── */
/*
  ROUND = in-thread node.  SQUARE = off-works node (T7.3/T7.4).
  Both show the planner-position number.
*/

.thread-planner-marker {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--thread-color, var(--ec-thread, #6b93c4));
  flex-shrink: 0;
  z-index: 1;
  position: relative;
}

.thread-planner-marker--round {
  border-radius: 50%;
}

.thread-planner-marker--square {
  border-radius: 3px;
}

.thread-planner-marker__num {
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  line-height: 1;
  user-select: none;
}

/* ── Node block (right of stub) ─────────────────────────────── */

.thread-node-block {
  flex: 1;
  background: var(--raised-bg);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-width: 0;
}

.thread-node-block--done {
  opacity: 0.6;
}

.thread-node-block__head {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.thread-node-block__head-main {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
}

.thread-node-check {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.thread-node-title {
  flex: 1;
  min-width: 80px;
  padding: 2px 6px;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
}

.thread-node-title:focus {
  border-color: var(--accent);
  background: var(--input-bg);
  outline: none;
}

/* "resolve" badge on last node (T2.2) */
.thread-node-last-label {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  letter-spacing: .03em;
}

.thread-node-drag-handle {
  color: var(--text-faint);
  cursor: grab;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: element;
}

.thread-node-drag-handle .ico {
  pointer-events: none;
}

.thread-node-drag-handle:active {
  cursor: grabbing;
}

.thread-node-desc {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text-dim);
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  background: transparent;
  resize: vertical;
  min-height: 2.6em;
}

.thread-node-desc:focus {
  border-color: var(--accent);
  background: var(--input-bg);
  color: var(--text);
  outline: none;
}

.thread-node-block__head .asset-outcome-actions {
  margin-top: 0;
  margin-left: auto;
  gap: 2px;
}

.icon-btn--danger:hover {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
}

.thread-timeline__row.dragging {
  opacity: 0.45;
}

.thread-timeline__row.drop-target .thread-node-block {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Done-row: strike title */
.thread-timeline__row--done .thread-node-title {
  text-decoration: line-through;
  opacity: 0.65;
}

/* ── Tube-line badge tweaks ──────────────────────────────────── */

.thread-tube-badge {
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 999px;
  font-weight: 600;
}

.thread-tube-badge--done {
  background: color-mix(in srgb, #3aad6a 14%, transparent);
  color: #3aad6a;
}

.thread-tube-badge--pending {
  background: var(--accent-soft);
  color: var(--accent);
}

.thread-tube-badge--offworks {
  background: var(--hairline);
  color: var(--text-dim);
}

/* ============================================================
   Panel thread overview + logical map (details panel, §5.1 / §5.2)
   ============================================================ */

.thread-panel-overview {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.thread-panel-overview__desc {
  margin: 0 0 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  color: var(--text);
}

/* Two-column tube-line map (spec §5.2 sketch) */
.thread-tube-map {
  margin-top: 4px;
}

.thread-tube-map__header {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  padding: 0 0 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 4px;
}

.thread-tube-map__body {
  display: flex;
  flex-direction: column;
}

.thread-tube-map__loading {
  font-size: 0.8rem;
  padding: 8px 0;
}

.thread-tube-map__row {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
  padding: 0 4px;
  margin: 0 -4px;
  border-radius: var(--radius-xs, 4px);
  cursor: pointer;
  transition: background 0.12s;
}

.thread-tube-map__row:hover {
  background: var(--hover-bg, rgba(0, 0, 0, 0.04));
}

.thread-tube-map__nodes-col {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  flex-shrink: 0;
  width: 72px;
  min-height: 100%;
  margin-top: 10px;
}

.thread-tube-map__rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  width: 20px;
  align-self: stretch;
  min-height: 100%;
}

.thread-tube-map__marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-ui, sans-serif);
  line-height: 1;
  user-select: none;
  flex-shrink: 0;
  z-index: 1;
  box-sizing: border-box;
}

.thread-tube-map__marker--inworks {
  border-radius: 50%;
  color: #fff;
}

.thread-tube-map__marker--offworks {
  border-radius: 3px;
  border: 2px solid currentColor;
  background: transparent !important;
  color: inherit;
}

.thread-tube-map__connector {
  width: 2px;
  flex: 1 1 auto;
  min-height: 4px;
  opacity: 0.45;
  margin: 0;
}

.thread-tube-map__stub {
  flex: 1;
  height: 2px;
  min-width: 8px;
  margin-top: 7px;
  opacity: 0.55;
  align-self: flex-start;
}

.thread-tube-map__event-col {
  min-width: 0;
  padding: 8px 0;
}

.thread-tube-map__event-title {
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 3px;
  word-break: break-word;
}

.thread-tube-map__event-text {
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
}

.thread-tube-map__event-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.thread-tube-map__row--done .thread-tube-map__event-title {
  opacity: 0.72;
}

/* Legacy tube-line classes (kept for any stale refs) */
.thread-tube-line {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 8px 0;
}

.thread-tube-stop {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  cursor: pointer;
  border-radius: 4px;
}

.thread-tube-stop:hover {
  background: var(--hover-bg, rgba(0, 0, 0, .04));
}

.thread-tube-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
}

.thread-tube-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  display: block;
}

.thread-tube-connector {
  width: 2px;
  flex: 1;
  min-height: 16px;
  opacity: .3;
}

.thread-tube-stop--off-works .thread-tube-dot {
  border: 2px solid currentColor;
  background: transparent;
}

.thread-tube-stop-title {
  font-size: .875rem;
  line-height: 1.3;
  word-break: break-word;
}

.thread-tube-stop-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: .75rem;
  margin-top: 2px;
}
