/*
 * TMW Weld Strength Calculator
 * "Shop Instrument" design system, shared with the sibling TMW fab tools
 * (NestCut, Press Brake Tonnage): gunmetal surfaces, a single torch-orange
 * accent, DRO-style readouts, Space Grotesk + JetBrains Mono + Inter.
 * Dark by default with a light toggle. All rules namespaced under .wsc.
 * Retune the whole look from the CSS variables at the top.
 */

.wsc {
  /* ---- 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 */
  --field-2:   #2c3540;   /* interactive controls: clearly lighter than the card so they read as controls */
  --ctrl-line: #4b5663;   /* control borders (well above --line for contrast) */
  --dro:       #0c0f13;   /* instrument panel (darkest) */
  --line:      #2c333d;   /* borders */
  --line-soft: #222932;
  --warn-bg:   #3a2a16;
  --warn-ink:  #ffce9c;
  --ok-bg:     #16301f;
  --ok-ink:    #9fe6b4;
  --mat:       #eef1f4;   /* weld-section 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 surfaces, keep torch-orange. DRO + weld section stay dark. ---- */
.wsc[data-theme="light"] {
  --ink:       #1b2430;
  --muted:     #5d6b7a;
  --faint:     #9aa6b2;
  --base:      #eef0f3;
  --panel:     #ffffff;
  --panel-2:   #f4f6f8;
  --field:     #ffffff;
  --field-2:   #ffffff;
  --ctrl-line: #c2cad3;
  --line:      #d6dbe1;
  --line-soft: #e4e8ec;
  color-scheme: light;
}
.wsc *, .wsc *::before, .wsc *::after { box-sizing: border-box; }

/* ===================== HEADER CHROME ===================== */
.wsc-head { margin: 0 0 18px; }
.wsc-topbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
.wsc-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);
}
.wsc-eyebrow b { color: var(--muted); font-weight: 600; }
.wsc-spark { width: 9px; height: 9px; background: var(--heat); transform: rotate(45deg); flex: none; }

.wsc-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;
}
.wsc-sub { margin: 0; color: var(--muted); font-size: 1rem; line-height: 1.55; }

.wsc-tools { display: inline-flex; align-items: center; gap: 8px; }
.wsc-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;
}
.wsc .wsc-icon svg { width: 18px; height: 18px; display: block; }
.wsc .wsc-icon svg, .wsc .wsc-icon svg * {
  fill: none !important; stroke: currentColor !important;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.wsc-icon:hover { color: var(--heat); border-color: var(--heat); }
.wsc-icon:focus-visible { outline: 2px solid var(--heat); outline-offset: 1px; }

/* Imperial / Metric segmented toggle in the top bar */
.wsc-units { display: inline-flex; height: 38px; border: 1px solid var(--ctrl-line); border-radius: 9px; overflow: hidden; background: var(--field-2); }
.wsc-units button {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font-family: var(--font-head); font-weight: 600; font-size: 0.82rem; letter-spacing: .03em;
  color: var(--muted); padding: 0 13px; min-width: 42px; line-height: 36px;
  transition: background .12s ease, color .12s ease;
}
.wsc-units button + button { border-left: 1px solid var(--ctrl-line); }
.wsc-units button:hover { color: var(--ink); }
.wsc-units button.is-active { background: var(--heat); color: #1a1206; }
.wsc-units button:focus-visible { outline: 2px solid var(--heat); outline-offset: -2px; }

/* ===================== PANELS / CARDS ===================== */
.wsc-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.wsc-card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 14px;
}
.wsc-card-head .wsc-eyebrow {
  font-family: var(--font-head);
  font-size: 1.02rem; font-weight: 600; letter-spacing: 0.02em; text-transform: none;
  color: var(--ink);
}
.wsc-note { color: var(--muted); font-size: 0.82rem; }
.wsc-help { color: var(--muted); font-size: 0.86rem; margin: 0 0 14px; line-height: 1.55; }
.wsc-help code, .wsc-foot 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);
}

/* ---- field grid ---- */
.wsc-grid-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px 16px; align-items: start; }
.wsc-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.wsc-field label {
  font-size: 0.82rem; font-weight: 600; letter-spacing: .02em; color: var(--muted);
  display: inline-flex; align-items: flex-start; gap: 6px; line-height: 1.3; min-height: 2.1em;
}
.wsc-field-check { flex-direction: row; align-items: center; gap: 10px; padding-top: 4px; grid-column: 1 / -1; }
.wsc-field-check label { font-size: 0.92rem; color: var(--ink); font-weight: 500; min-height: 0; align-items: center; }
.wsc-hidden { display: none !important; }

/* ---- geometry: inputs on the left, live joint preview on the right ---- */
.wsc-geo { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(380px, 1.05fr); gap: 18px; align-items: start; }
.wsc-geo-fields { min-width: 0; }
.wsc-geo .wsc-grid-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.wsc-preview {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  background: var(--panel-2); position: sticky; top: 12px;
}
.wsc-preview-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 16px; background: var(--dro); color: #fff; border-bottom: 2px solid var(--heat);
}
.wsc-preview-head .wsc-pt { font-family: var(--font-head); font-weight: 700; font-size: 0.95rem; letter-spacing: .02em; }
.wsc-preview-head .wsc-pm { font-family: var(--font-mono); font-size: 0.78rem; color: #aebac4; }
.wsc-preview-body { padding: 16px; background: var(--mat); min-height: 300px; display: flex; align-items: center; }
.wsc-preview-body svg { display: block; width: 100%; height: auto; }
@media (max-width: 860px) {
  .wsc-geo { grid-template-columns: 1fr; }
  .wsc-preview { position: static; }
}

/* 16px min on fields avoids iOS zoom-on-focus */
.wsc input[type=text], .wsc input[type=number], .wsc select {
  width: 100%; font-size: 16px; padding: 9px 11px;
  border: 1px solid var(--ctrl-line); border-radius: 8px;
  background-color: var(--field-2); color: var(--ink); font-family: var(--font-mono);
  transition: border-color .12s ease, box-shadow .12s ease;
}
.wsc input::placeholder { color: var(--faint); }
.wsc select {
  font-family: var(--font-body); cursor: pointer;
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23c2cbd4' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 11px center;
}
.wsc input:focus, .wsc select:focus {
  outline: none; border-color: var(--heat); box-shadow: 0 0 0 3px rgba(255,106,44,.18);
}
/* keep dropdown + input lettering near-white in the dark theme, and style the open list */
.wsc[data-theme="dark"] select,
.wsc[data-theme="dark"] input[type=text],
.wsc[data-theme="dark"] input[type=number] { color: #f7f9fb; }
.wsc[data-theme="dark"] select { font-weight: 500; }
.wsc select option { background-color: #1c222b; color: #f7f9fb; }
.wsc input[type=checkbox] { width: auto; accent-color: var(--heat); }
.wsc-field-check input { width: auto; }

/* ---- info "i" tooltip ---- */
.wsc-i {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; flex: none; cursor: pointer; position: relative;
  border: 1px solid var(--line); border-radius: 50%; background: var(--field);
  color: var(--muted); font-family: var(--font-head); font-size: 10px; font-weight: 700; line-height: 1;
}
.wsc-i:hover, .wsc-i.is-open { color: var(--heat); border-color: var(--heat); }
.wsc-tip {
  position: absolute; z-index: 30; left: 0; top: calc(100% + 7px);
  width: max-content; max-width: 260px;
  background: var(--dro); color: #e6ebf0; border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 11px; font-family: var(--font-body); font-size: 0.8rem; line-height: 1.45;
  font-weight: 400; letter-spacing: 0; text-transform: none; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  white-space: normal;
}

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

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

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

/* two-column layout: readout + section diagram */
.wsc-result-row { display: grid; grid-template-columns: 1fr; gap: 16px; }

/* weld cross-section diagram, on a light mat in both themes (reads like a shop drawing) */
.wsc-draw { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel-2); margin-top: 16px; }
.wsc-draw-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--dro); color: #fff; border-bottom: 2px solid var(--heat);
}
.wsc-draw-head .wsc-dt { font-weight: 700; font-size: 0.9rem; font-family: var(--font-head); letter-spacing: .02em; }
.wsc-draw-head .wsc-dm { font-family: var(--font-mono); font-size: 0.78rem; color: #aebac4; }
.wsc-draw-body { padding: 16px; background: var(--mat); overflow: auto; }
.wsc-draw-body svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }

/* checks list */
.wsc-checks { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.wsc-check {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px; border-radius: 8px; font-size: 0.9rem;
  background: var(--panel-2); border: 1px solid var(--line-soft); color: var(--ink);
}
.wsc-check .wsc-cb { font-family: var(--font-mono); font-weight: 700; color: var(--heat); flex: none; }
.wsc-check.is-gov { border-color: var(--heat); }
.wsc-check small { color: var(--muted); }

.wsc-msg { padding: 11px 14px; border-radius: 8px; font-size: 0.9rem; margin-top: 12px; }
.wsc-msg.is-err { background: var(--warn-bg); border: 1px solid #5a4322; color: var(--warn-ink); }
.wsc-msg.is-warn { background: var(--warn-bg); border: 1px solid #5a4322; color: var(--warn-ink); }
.wsc-msg.is-ok { background: var(--ok-bg); border: 1px solid #2c5a3a; color: var(--ok-ink); }

.wsc-breakdown { color: var(--muted); font-size: 0.84rem; margin: 14px 2px 0; font-family: var(--font-mono); line-height: 1.7; }

/* plain-language one-liner above the readout */
.wsc-plain {
  margin: 0 0 14px; padding: 12px 14px; border-radius: 8px;
  background: var(--panel-2); border: 1px solid var(--line-soft);
  color: var(--ink); font-size: 0.95rem; line-height: 1.5;
}
.wsc-plain b { color: var(--heat); }
.wsc-hero .wsc-sub2 { font-family: var(--font-mono); font-size: 0.74rem; color: #8b96a3; margin-top: 3px; }

/* print summary (off-screen; shown only when printing) */
.wsc-print-only { display: none; }
.wsc-print-card { font-family: var(--font-body); color: #000; }
.wsc-print-card .wsc-phead { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; border-bottom: 2px solid #000; padding-bottom: 6px; margin-bottom: 10px; }
.wsc-print-card h3 { font-family: var(--font-head); font-size: 15px; margin: 0; }
.wsc-print-card .wsc-pmeta { font-size: 10px; color: #444; margin: 1px 0 0; }
.wsc-print-card .wsc-pgov { font-family: var(--font-mono); font-size: 19px; font-weight: 700; text-align: right; white-space: nowrap; }
.wsc-print-card .wsc-pgov span { font-size: 11px; font-weight: 600; }
.wsc-print-card .wsc-pcols { display: flex; gap: 14px; align-items: flex-start; }
.wsc-print-card .wsc-pcol { flex: 1 1 0; min-width: 0; }
.wsc-print-card .wsc-pcol.wsc-pdraw { flex: 0 0 2in; }
.wsc-print-card .wsc-psec { font-family: var(--font-head); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; margin: 0 0 4px; }
.wsc-print-card table { width: 100%; border-collapse: collapse; font-size: 10.5px; }
.wsc-print-card td { padding: 2px 6px 2px 0; vertical-align: top; }
.wsc-print-card td.k { color: #444; width: 46%; }
.wsc-print-card td.v { font-family: var(--font-mono); font-weight: 600; }
.wsc-print-card .wsc-pdraw svg { width: 2in; height: auto; }
.wsc-print-card .wsc-pnote { font-size: 9px; color: #333; margin-top: 10px; line-height: 1.45; }

/* footer */
.wsc-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.4in; size: letter portrait; }
  .wsc { background: #fff !important; color: #000 !important; border: 0; padding: 0; box-shadow: none; }
  .wsc-head, .wsc-card, .wsc-actions, .wsc-foot, .wsc-tools { display: none !important; }
  .wsc-print-only { display: block !important; }
  .wsc-print-card, .wsc-print-card * { color: #000 !important; background: transparent !important; }
  .wsc-print-card svg, .wsc-print-card svg * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

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