/* =============================================================================
   materials.css  —  Endeavos Online SOW
   Material assignment dialog, material legend overlay (ANSYS-style),
   and material tag sprites (bubble labels + SVG leader lines).
============================================================================= */

/* ── Custom material dropdown ────────────────────────────────────────────── */
.mat-custom-select {
  width: 100%;
  border: 1.5px solid var(--line-strong);
  border-radius: 8px;
  padding: 9px 11px;
  font-family: var(--font-label);
  font-size: var(--t-label);
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  box-sizing: border-box;
}
.mat-custom-select:hover { border-color: var(--orange); }
.mat-custom-select.open   { border-color: var(--orange); border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.mat-sel-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.mat-sel-arrow {
  margin-left: auto;
  flex-shrink: 0;
  width: 10px;
  height: 6px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%235b626c' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
  background-position: center;
}

.mat-select-dropdown {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1.5px solid var(--orange);
  border-top: none;
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  z-index: 200;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
}
.mat-drop-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  font-size: var(--t-label);
  cursor: pointer;
  color: var(--ink);
}
.mat-drop-item:hover { background: var(--orange-soft); }
.mat-drop-item.selected { background: rgba(232,116,30,0.08); font-weight: var(--w-option); }
.mat-drop-item.special { color: var(--ink); }
.mat-drop-divider { height: 1px; background: var(--line); margin: 4px 0; }
.mat-drop-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}

/* ── Material dialog (right side of viewer) ──────────────────────────────── */
#mat-dialog {
  position: absolute;
  top: 50%; right: 230px;
  transform: translateY(-50%);
  background: #fff;
  border: 1.5px solid rgba(232,116,30,0.4);
  border-radius: 12px;
  padding: 18px;
  width: 310px;
  z-index: 25;
  display: none;
  flex-direction: column;
  gap: 11px;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
  max-height: calc(100% - 40px);
  overflow-y: auto;
  font-family: var(--font-label);
}
#mat-dialog.show { display: flex; }

/* .mat-dlg-hint removed — the intro paragraph it styled moved into the (i)
   help popup in the dialog header (see base.css, "Dialog header + opt-in help"). */

.mat-dlg-label {
  font-size: var(--t-label);
  font-weight: var(--w-label);
  color: var(--ink);
  margin-bottom: 5px;
}

.mat-dlg-opts { display: flex; flex-direction: column; gap: 8px; }

/* ── Optional section ────────────────────────────────────────────────────── */
.mat-optional-section { margin-top: 10px; }
.mat-optional-divider {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; color: var(--ink-soft); font-size: var(--t-body);
}
.mat-optional-divider::before,
.mat-optional-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* Material Color row — label + swatch on one line */
.mat-color-row { display: flex; align-items: center; gap: 10px; }
.mat-color-row label { font-size: var(--t-label); font-weight: var(--w-label); color: var(--ink); flex: 1; }

input[type="color"] {
  width: 34px; height: 26px;
  border: 1.5px solid var(--line);
  border-radius: 5px;
  background: none;
  cursor: pointer;
  padding: 2px;
}

/* Dialog save/cancel buttons */
.mat-dlg-btns { display: flex; gap: 8px; justify-content: center; }
.mat-btn-save {
  padding: 0 18px;
  height: 32px;
  min-width: 80px;
  background: var(--orange); border: none;
  border-radius: 7px; color: #fff;
  font-family: var(--font-btn); font-weight: var(--w-option); font-size: var(--t-label);
  cursor: pointer; box-sizing: border-box;
}
.mat-btn-save:hover { background: var(--accent2); }
.mat-btn-cancel {
  padding: 0 18px;
  height: 32px;
  min-width: 80px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px; color: var(--ink);
  font-family: var(--font-btn); font-weight: var(--w-option); font-size: var(--t-label);
  cursor: pointer; box-sizing: border-box;
}
.mat-btn-cancel:hover { border-color: var(--ink-soft); }

/* ── Material legend — floats beside left panel on step 3 ────────────────── */
#mat-legend {
  position: absolute;
  top: 12px; left: 248px;
  z-index: 8;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(232,116,30,0.25);
  border-radius: 10px;
  padding: 10px 18px 14px;
  display: none;
  /* Wider than the original 220px: material rows can now carry an inline
     "(Repeat Analysis)" note alongside the name and the NL/User Data badges. */
  min-width: 290px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.10);
  pointer-events: none;
}
#mat-legend.show { display: block; }

#legend-items {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 2px;
}
#legend-items::-webkit-scrollbar { width: 5px; }
#legend-items::-webkit-scrollbar-track { background: rgba(0,0,0,0.05); border-radius: 4px; }
#legend-items::-webkit-scrollbar-thumb { background: rgba(232,116,30,0.4); border-radius: 4px; }

.leg-title {
  font-size: var(--t-body);
  font-weight: var(--w-label);
  color: var(--orange);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid rgba(232,116,30,0.2);
  font-family: "Archivo", sans-serif;
}

/* Legend table rows — uses HTML <table> for guaranteed column alignment */
.leg-row { display: contents; }
.leg-userdata-badge {
  font-size: var(--t-body);
  font-weight: var(--w-option);
  color: var(--orange);
  padding: 1px 7px;
  border-radius: 4px;
  background: rgba(232,116,30,0.12);
  white-space: nowrap;
}

/* ── Material stats bar (below legend table) ─────────────────────────────── */
.mat-stats-divider {
  height: 1px;
  background: rgba(232,116,30,0.18);
  margin: 10px 0 8px;
}
.mat-stats-row {
  display: flex;
  gap: 6px;
}
.mat-stat-pill {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 4px 5px;
  border-radius: 8px;
  border: 1px solid transparent;
}
.mat-stat-num {
  font-family: "Archivo", sans-serif;
  font-size: 18px;
  font-weight: var(--w-label);
  line-height: 1;
}
.mat-stat-lbl {
  font-family: var(--font-hint);
  font-size: 9px;
  font-weight: var(--w-option);
  text-transform: uppercase;
  letter-spacing: .04em;
  text-align: center;
  line-height: 1.2;
}
/* Total — orange */
.mat-stat-total {
  background: rgba(232,116,30,0.08);
  border-color: rgba(232,116,30,0.22);
}
.mat-stat-total .mat-stat-num { color: var(--orange); }
.mat-stat-total .mat-stat-lbl { color: var(--orange); }
/* Non-Linear — amber */
.mat-stat-nl {
  background: rgba(217,119,6,0.08);
  border-color: rgba(217,119,6,0.22);
}
.mat-stat-nl .mat-stat-num { color: var(--warn); }
.mat-stat-nl .mat-stat-lbl { color: var(--warn); }
/* Endeavos Pick — green */
.mat-stat-endvs {
  background: rgba(31,157,99,0.08);
  border-color: rgba(31,157,99,0.22);
}
.mat-stat-endvs .mat-stat-num { color: var(--ok); }
.mat-stat-endvs .mat-stat-lbl { color: var(--ok); }

/* ── Material tag sprites (floating labels on the 3D model) ──────────────── */
.mat-sprite {
  position: absolute;
  pointer-events: none;
  z-index: 7;
}
.mat-bubble {
  background: #ffffff;
  color: #1a1a1a;
  border: 2px solid #2b2f36;
  font-size: var(--t-label);
  font-weight: var(--w-option);
  padding: 7px 12px 8px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  cursor: grab;
  pointer-events: all;
  user-select: none;
  font-family: var(--font-ui);
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  transition: box-shadow .15s;
  width: max-content;
  min-width: var(--bubble-min-w, 250px);
  max-width: var(--bubble-max-w, 440px);
}
/* Title sets the bubble width, but must WRAP rather than run past it: with
   white-space:nowrap the text ignored the bubble's max-width and painted over
   the border — a part name past ~36 characters spilled outside. min-width still
   holds the floor for short titles, so nothing narrows.
   overflow-wrap:anywhere is for a single token with no spaces (long underscored
   part names), which would otherwise still overflow. */
.mat-bubble-title  { font-weight: var(--w-label); font-size: var(--t-label); white-space: normal; overflow-wrap: anywhere; display: flex; align-items: center; gap: 6px; }
.mat-bubble-swatch { display: inline-block; width: 11px; height: 11px; border-radius: 2px; border: 1px solid rgba(0,0,0,0.2); flex-shrink: 0; }
/* NL and upload badge stay on one line but don't stretch the bubble */
.mat-bubble-nl     { font-weight: var(--w-body); font-size: var(--t-body); opacity: 0.9; white-space: nowrap; }
.mat-bubble-upload { font-weight: var(--w-body); font-size: var(--t-body); opacity: 0.9; white-space: nowrap; }
/* Data text: contributes to the bubble's auto-width (along with the title), wraps naturally */
.mat-bubble-data   { font-weight: var(--w-body); font-size: var(--t-body); opacity: 0.85; white-space: normal; box-sizing: border-box; }
/* Dotted section divider */
.mat-bubble-sep    { width: 100%; height: 0; border-top: 1.5px dotted rgba(43,47,54,0.45); margin: 4px 0; }
.mat-bubble:hover { box-shadow: 0 3px 14px rgba(232,116,30,.45); }
.mat-bubble:active { cursor: grabbing; }

/* Edit pencil — appears on bubble hover, top-right corner */
.mat-edit-btn {
  position: absolute;
  top: -9px; right: -9px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--orange);
  color: var(--orange);
  font-size: var(--t-arrow);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.mat-sprite:hover .mat-edit-btn { display: flex; }

/* Delete × — appears on bubble hover, top-left corner */
.mat-delete-btn {
  position: absolute;
  top: -9px; left: -9px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid var(--danger);
  color: var(--danger);
  font-size: var(--t-body);
  font-weight: var(--w-label);
  line-height: 1;
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 1px 4px rgba(0,0,0,.12);
  transition: background .12s, color .12s;
}
.mat-delete-btn:hover { background: var(--danger); color: #fff; }
.mat-sprite:hover .mat-delete-btn { display: flex; }

/* ── "Add another material to this part" ─────────────────────────────────── */
.mat-add-row { margin-top: 4px; }
/* Muted while applying the first material, and for multi-part tags. Styled
   rather than hidden so the option is discoverable before it is usable. */
.mat-add-row.is-muted .chk { opacity: 0.45; cursor: not-allowed; }
.mat-add-row.is-muted input { cursor: not-allowed; }

/* ── Material list inside a multi-material bubble ─────────────────────────── */
.mat-mat-list {
  font-family: var(--font-entered);
  font-size: var(--t-body);
  color: var(--ink);
  line-height: 1.55;
}
.mat-mat-row { display: flex; align-items: center; gap: 5px; }
.mat-mat-num { flex-shrink: 0; }
.mat-mat-sw {
  width: 9px; height: 9px; border-radius: 2px;
  flex-shrink: 0; margin: 0;
}
.mat-mat-name { flex: 1; }
/* 2px, not 6: the markup now carries a real space before this span (so the
   gap survives into the PDF), and 6px on top of it read as a gap. */
.mat-mat-note { margin-left: 2px; font-size: var(--t-hint); color: var(--ink-soft); }
/* Per-row controls stay hidden until the bubble is hovered, matching the
   tag-level buttons — and so they never appear in a snapshot. */
.mat-mat-edit, .mat-mat-del {
  display: none;
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
  color: var(--c-muted);
  padding: 0 1px;
}
.mat-mat-del:hover { color: var(--orange); }
.mat-sprite:hover .mat-mat-edit,
.mat-sprite:hover .mat-mat-del { display: inline; }
