/*
 * NestCut Cutlist Optimizer
 * "Shop Instrument" design system, shared with the sibling TMW fab tools
 * (press brake tonnage, etc.): gunmetal surfaces, a single torch-orange
 * accent, DRO-style readouts, Space Grotesk + JetBrains Mono + Inter.
 * Dark by default with a light toggle. All rules are namespaced under .nco.
 * Retune the whole look from the CSS variables at the top.
 */

.nco {
  /* ---- Tunable tokens (dark, matches sibling TMW tools) ---- */
  --heat:      #ff6a2c;   /* torch-orange weld-heat accent */
  --heat-dim:  #c4501d;
  --ink:       #eef1f4;   /* primary text */
  --muted:     #9aa3ad;   /* labels, hints */
  --faint:     #6c7681;   /* tick marks, deemphasized */
  --base:      #0e1115;   /* outer wrapper (gunmetal) */
  --panel:     #1a1f27;   /* cards */
  --panel-2:   #202730;   /* secondary card */
  --field:     #11151b;   /* input wells */
  --dro:       #0c0f13;   /* instrument panel (darkest) */
  --line:      #2c333d;   /* borders */
  --line-soft: #222932;
  --warn-bg:   #3a2a16;
  --warn-ink:  #ffce9c;
  --mat:       #eef1f4;   /* cut-diagram mat (kept light in both themes) */
  --radius:    12px;
  --font-head: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  width: 100%;
  box-sizing: border-box;
  color: var(--ink);
  background: var(--base);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(14px, 2.4vw, 24px);
  font-family: var(--font-body);
  line-height: 1.5;
  color-scheme: dark;
}

/* ---- Light theme: flip the surfaces, keep the torch-orange accent.
   The yield readout and the cut diagrams stay dark/instrument on purpose. ---- */
.nco[data-theme="light"] {
  --ink:       #1b2430;
  --muted:     #5d6b7a;
  --faint:     #9aa6b2;
  --base:      #eef0f3;
  --panel:     #ffffff;
  --panel-2:   #f4f6f8;
  --field:     #ffffff;
  --line:      #d6dbe1;
  --line-soft: #e4e8ec;
  color-scheme: light;
}
.nco *, .nco *::before, .nco *::after { box-sizing: border-box; }

/* ===================== HEADER CHROME ===================== */
.nco-head { margin: 0 0 18px; }
.nco-topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
.nco-eyebrow {
  display: inline-flex; align-items: center; gap: 9px;
  font-family: var(--font-head);
  font-size: 0.74rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--heat);
}
.nco-eyebrow b { color: var(--muted); font-weight: 600; }
/* orange diamond marker (rotated square), reused on section titles */
.nco-spark { width: 9px; height: 9px; background: var(--heat); transform: rotate(45deg); flex: none; }

.nco-title {
  margin: 0 0 8px; font-family: var(--font-head);
  font-size: clamp(1.5rem, 3.2vw, 2.1rem); font-weight: 700; line-height: 1.1;
  color: var(--ink); letter-spacing: -0.01em;
}
.nco-sub { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.55; }

/* tools cluster (theme, print) */
.nco-tools { display: inline-flex; align-items: center; gap: 8px; }
.nco-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none; cursor: pointer;
  padding: 0; margin: 0; min-width: 0; appearance: none; line-height: 1;
  background: var(--field); color: var(--muted);
  border: 1px solid var(--line); border-radius: 9px;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.nco .nco-icon svg { width: 18px; height: 18px; display: block; }
.nco .nco-icon svg, .nco .nco-icon svg * {
  fill: none !important; stroke: currentColor !important;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.nco-icon:hover { color: var(--heat); border-color: var(--heat); }
.nco-icon:focus-visible { outline: 2px solid var(--heat); outline-offset: 1px; }

/* ===================== PANELS / CARDS ===================== */
.nco-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.nco-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
/* section title: spark diamond + label, head font */
.nco-eyebrow.nco-section,
.nco-card-head .nco-eyebrow {
  font-family: var(--font-head);
  font-size: 1.02rem; font-weight: 600; letter-spacing: 0.02em; text-transform: none;
  color: var(--ink);
}
.nco-note { color: var(--muted); font-size: 0.82rem; }
.nco-help { color: var(--muted); font-size: 0.86rem; margin: 0 0 14px; line-height: 1.55; }
.nco-help code, .nco-foot code, .nco-csv code {
  font-family: var(--font-mono); font-size: .9em; background: var(--field);
  border: 1px solid var(--line); padding: 1px 5px; border-radius: 4px; color: var(--ink);
}

/* ---- settings grid ---- */
.nco-settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.nco-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.nco-field label { font-size: 0.82rem; font-weight: 600; letter-spacing: .02em; color: var(--muted); }
.nco-field-check { flex-direction: row; align-items: center; gap: 9px; align-self: end; padding-bottom: 9px; }
.nco-field-check label { font-size: 0.92rem; color: var(--ink); font-weight: 500; }

/* 16px min on fields avoids iOS zoom-on-focus */
.nco input[type=text], .nco input[type=number], .nco textarea {
  width: 100%; font-size: 16px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--field); color: var(--ink); font-family: var(--font-mono);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.nco input:focus, .nco textarea:focus {
  outline: none; border-color: var(--heat); box-shadow: 0 0 0 3px rgba(255,106,44,.18);
}
.nco input[type=checkbox] { width: auto; accent-color: var(--heat); }
.nco-field-check input { width: auto; }

/* ---- data tables ---- */
.nco-tablewrap { overflow-x: auto; }
.nco-grid { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.nco-grid th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 600; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.nco-grid td { padding: 5px 8px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.nco-grid th.nco-c, .nco-grid td.nco-c { text-align: center; }
.nco-grid input { font-family: var(--font-mono); font-size: 14px; padding: 7px 9px; min-width: 68px; }
.nco-grid input.nco-lbl { font-family: var(--font-body); min-width: 96px; }
.nco-grid input[type=checkbox] { min-width: 0; }
.nco-act { width: 36px; text-align: center; }
.nco-rm {
  border: 1px solid var(--line); background: var(--field); color: var(--heat);
  width: 26px; height: 26px; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1;
}
.nco-rm:hover { border-color: var(--heat); }

/* ---- reorder controls (stock): up arrow / drag grip / down arrow ---- */
.nco-drag-h { width: 30px; padding: 7px 2px 7px 6px !important; }
.nco-reorder { width: 30px; text-align: center; vertical-align: middle; padding: 3px 2px 3px 6px !important; white-space: nowrap; }
.nco-reorder .nco-mv {
  display: block; margin: 0 auto; width: 21px; height: 15px; padding: 0;
  border: 1px solid var(--line); background: var(--field); color: var(--muted);
  border-radius: 4px; cursor: pointer; font-size: 8px; line-height: 1;
}
.nco-reorder .nco-mv:hover:not(:disabled) { color: var(--heat); border-color: var(--heat); }
.nco-reorder .nco-mv:disabled { opacity: .3; cursor: default; }
.nco-reorder .nco-mv:focus-visible { outline: 2px solid var(--heat); outline-offset: 1px; }
.nco-drag {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 20px; margin: 2px auto; border-radius: 4px;
  cursor: grab; color: var(--faint); touch-action: none;
}
.nco-drag:hover { color: var(--heat); }
.nco-drag:active { cursor: grabbing; }
.nco-drag svg circle { fill: currentColor; }
.nco-row-dragging td { opacity: .45; background: var(--panel-2); }
.nco-drop-before td { box-shadow: inset 0 2px 0 0 var(--heat); }
.nco-drop-after td { box-shadow: inset 0 -2px 0 0 var(--heat); }
.nco-noselect { user-select: none; -webkit-user-select: none; }

/* ---- CSV details ---- */
.nco-csv { margin-top: 14px; }
.nco-csv summary { cursor: pointer; color: var(--heat); font-size: 0.88rem; font-weight: 600; }
.nco-csv textarea { margin-top: 8px; font-size: 13px; }

/* ---- buttons ---- */
.nco-btn, .nco-btn-primary, .nco-btn-ghost { font-family: var(--font-head); cursor: pointer; border-radius: 9px; font-weight: 600; }
.nco-btn { border: 1px solid var(--line); background: var(--field); color: var(--ink); padding: 10px 16px; font-size: 0.9rem; }
.nco-btn:hover { border-color: var(--heat); color: var(--heat); }
.nco-btn-primary { border: 0; background: var(--heat); color: #1a1206; padding: 11px 22px; font-size: 0.95rem; letter-spacing: .02em; }
.nco-btn-primary:hover { background: var(--heat-dim); }
.nco-btn-ghost { border: 1px solid var(--line); background: var(--field); color: var(--muted); padding: 7px 13px; font-size: 0.82rem; }
.nco-btn-ghost:hover { color: var(--heat); border-color: var(--heat); }
.nco-btnrow { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.nco-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 0 0 14px; align-items: center; }

/* ===================== RESULTS ===================== */
.nco-results-card { padding: 18px; }
.nco-results-head { margin-bottom: 14px; }

/* yield readout: dark instrument (DRO), stays dark in both themes */
.nco-stats {
  display: grid; grid-template-columns: 1.4fr 1fr 1fr 1fr 1fr; gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.nco-stat { background: var(--dro); color: #eef2f5; padding: 16px; }
.nco-stat .nco-k { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: #8b96a3; }
.nco-stat .nco-v { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: 600; margin-top: 4px; color: #fff; }
.nco-stat .nco-v small { font-size: 0.6em; color: #8b96a3; font-weight: 400; }
.nco-stat .nco-v-sm { font-size: 1.1rem; }
.nco-hero { background: linear-gradient(180deg, #14181e, #0c0f13); }
.nco-hero .nco-v { font-size: 2.4rem; color: var(--heat); letter-spacing: -.01em; }
.nco-hero .nco-v small { color: var(--heat-dim); }
.nco-stat.is-warn .nco-v { color: #ff8a82; }

.nco-breakdown { color: var(--muted); font-size: 0.84rem; margin: 12px 2px 0; font-family: var(--font-mono); }

.nco-unplaced { margin-top: 16px; border: 1px solid #5a4322; background: var(--warn-bg); border-radius: 8px; padding: 12px 14px; }
.nco-unplaced h3 { margin: 0 0 6px; font-size: 0.9rem; color: var(--warn-ink); font-family: var(--font-head); }
.nco-unplaced ul { margin: 0; padding-left: 18px; font-family: var(--font-mono); font-size: 0.82rem; color: var(--warn-ink); }
.nco-msg { padding: 11px 14px; border-radius: 8px; font-size: 0.9rem; margin-top: 12px; }
.nco-msg.is-err { background: var(--warn-bg); border: 1px solid #5a4322; color: var(--warn-ink); }

/* per-sheet cut ticket */
.nco-sheet { border: 1px solid var(--line); border-radius: 10px; margin-top: 18px; overflow: hidden; background: var(--panel-2); }
.nco-sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 11px 16px; background: var(--dro); color: #fff; border-bottom: 2px solid var(--heat);
}
.nco-sheet-id { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.nco-sheet-no { font-weight: 700; font-size: 0.95rem; font-family: var(--font-head); letter-spacing: .02em; }
.nco-sheet-no .nco-of { color: #8b96a3; font-weight: 400; }
.nco-sheet-name { font-family: var(--font-mono); font-size: 0.8rem; color: #aebac4; }
.nco-sheet-meta { font-family: var(--font-mono); font-size: 0.8rem; color: #aebac4; }
.nco-sheet-meta b { color: var(--heat); }
.nco-sheet-meta .nco-dot { color: #5b6b78; }
/* the drawing sits on a light "mat" in both themes so the shop drawing reads like paper */
.nco-sheet-draw { padding: 16px; background: var(--mat); overflow: auto; }
.nco-sheet-draw svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }

/* SVG element classes (drawing is on the light mat; colors pinned, not theme-aware) */
.nco-plabel { font-family: var(--font-mono); text-anchor: middle; dominant-baseline: central; }
.nco-pdim { font-family: var(--font-mono); text-anchor: middle; dominant-baseline: central; opacity: .92; }
.nco-sheetdim { font-family: var(--font-mono); fill: #5f6c77; text-anchor: middle; }
.nco-offcut { font-family: var(--font-mono); fill: #7a8893; text-anchor: middle; dominant-baseline: central; }

/* legend */
.nco-legend { display: flex; flex-wrap: wrap; gap: 12px; padding: 10px 16px 14px; font-size: 0.78rem; color: var(--muted); align-items: center; background: var(--panel-2); }
.nco-sw { display: inline-flex; align-items: center; gap: 6px; }
.nco-box { width: 14px; height: 14px; border-radius: 3px; border: 1px solid rgba(0,0,0,.25); display: inline-block; }
.nco-box-offcut { background: #fff; background-image: repeating-linear-gradient(45deg, #c2cbd3 0 1.3px, transparent 1.3px 7px); }

/* footer */
.nco-foot {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 4px; padding-top: 13px; border-top: 1px solid var(--line-soft);
  font-size: 0.82rem; color: var(--muted); line-height: 1.6;
}

/* ===================== PRINT ===================== */
@media print {
  @page { margin: 0.5in; }
  .nco { background: #fff; color: #000; border: 0; padding: 0; --ink:#000; --muted:#333; }
  .nco-head, .nco-card:not(.nco-results-card), .nco-actions, .nco-foot, .nco-tools { display: none !important; }
  .nco-results-card { border: 0; padding: 0; margin: 0; background: #fff; }
  .nco-results-head { display: none !important; }
  .nco-stats { grid-template-columns: repeat(5, 1fr); break-inside: avoid; page-break-inside: avoid; }
  .nco-stat, .nco-hero, .nco-sheet-head,
  .nco-part, .nco-sheet-draw svg, .nco-sheet-draw svg rect {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .nco-sheet { break-inside: avoid; page-break-inside: avoid; border: 1px solid #000; margin-top: 10px; }
  .nco-sheet-draw { break-inside: avoid; page-break-inside: avoid; background: #fff; padding: 8px; }
  .nco-sheet-head { padding: 7px 12px; }
  .nco-legend { padding: 5px 12px 7px; }
  .nco-breakdown { margin-top: 8px; }
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 760px) {
  .nco-stats { grid-template-columns: 1fr 1fr; }
  .nco-hero { grid-column: 1 / -1; }
}
@media (max-width: 460px) {
  .nco-title { font-size: 1.5rem; }
  .nco-stat .nco-v { font-size: 1.25rem; }
  .nco-hero .nco-v { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) { .nco * { transition: none !important; animation: none !important; } }
