/*
 * Press Brake Tonnage Calculator
 * "Shop Instrument" design system, shared with the sibling TMW fab tools:
 * gunmetal surfaces, a single torch-orange accent, DRO/caliper readouts,
 * Space Grotesk + JetBrains Mono + Inter. All rules are namespaced under .tmwbf.
 * Retune the whole look from the CSS variables at the top.
 */

.tmwbf {
    /* ---- 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;   /* input + diagram cards */
    --panel-2:   #202730;   /* limits card (a touch lighter) */
    --field:     #11151b;   /* input wells */
    --dro:       #0c0f13;   /* DRO panel (darkest) */
    --line:      #2c333d;   /* borders */
    --line-soft: #222932;
    --warn-bg:   #3a2a16;   /* warning banner */
    --warn-ink:  #ffce9c;
    --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;
    display: flex;
    flex-direction: column;
    color-scheme: dark;
}

/* ---- Light theme: flip the surfaces, keep the torch-orange accent.
   The diagram and DRO stay dark on purpose (they read as instrument displays). ---- */
.tmwbf[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;
}
.tmwbf *, .tmwbf *::before, .tmwbf *::after { box-sizing: border-box; }

/* Stacking order of the top-level blocks (lets focus float the limits panel up). */
.tmwbf-head   { order: 0; }
.tmwbf-grid   { order: 1; }
.tmwbf-limits { order: 2; }
.tmwbf-foot   { order: 3; }

/* ===================== HEADER CHROME ===================== */
.tmwbf-head { margin: 0 0 20px; }
.tmwbf-topbar {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 12px; margin-bottom: 12px;
}
.tmwbf-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);
}
.tmwbf-eyebrow b { color: var(--muted); font-weight: 600; }
/* The orange diamond marker (a rotated square). Reused on section titles. */
.tmwbf-spark { width: 9px; height: 9px; background: var(--heat); transform: rotate(45deg); flex: none; }

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

/* Tools cluster (units, theme, print) */
.tmwbf-tools { display: inline-flex; align-items: center; gap: 8px; }
.tmwbf-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;
}
.tmwbf .tmwbf-icon svg { width: 18px; height: 18px; display: block; }
/* Force the line-icon rendering past any theme-level svg fill/stroke rules. */
.tmwbf .tmwbf-icon svg,
.tmwbf .tmwbf-icon svg * {
    fill: none !important;
    stroke: currentColor !important;
    stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
.tmwbf-icon:hover { color: var(--heat); border-color: var(--heat); }
.tmwbf-icon:focus-visible { outline: 2px solid var(--heat); outline-offset: 1px; }

/* Section title with the orange diamond (matches "◆ Inputs" on the sibling tool). */
.tmwbf-panel-title {
    display: flex; align-items: center; gap: 10px;
    margin: 0 0 14px; font-family: var(--font-head);
    font-size: 1.15rem; font-weight: 600; color: var(--ink);
}

/* Two columns on wide screens, single column on narrow. */
.tmwbf-grid {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    gap: clamp(14px, 2.2vw, 22px);
    align-items: start;
    margin-bottom: 14px;
}

/* ---- Input panel ---- */
.tmwbf-inputs {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}

/* Compact two-up field grid: numbers no longer sprawl full width. */
.tmwbf-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 14px;
    align-items: start;
}
.tmwbf-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.tmwbf-field--full { grid-column: 1 / -1; }

.tmwbf-field > label {
    font-size: 0.92rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--ink);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 16px minimum font on fields stops iOS Safari auto-zoom on focus. */
.tmwbf input[type="number"],
.tmwbf select {
    width: 100%;
    font-size: 16px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    color: var(--ink);
    font-family: var(--font-mono);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.tmwbf select { font-family: var(--font-body); }
/* The native dropdown list: force readable contrast per theme. */
.tmwbf select option { background: #1e2329; color: #eef1f4; }
.tmwbf select optgroup { background: #1e2329; color: #98a2ad; font-style: normal; font-weight: 600; }
.tmwbf[data-theme="light"] select option { background: #ffffff; color: #1b2430; }
.tmwbf[data-theme="light"] select optgroup { background: #ffffff; color: #5d6b7a; }
.tmwbf input[type="number"]:focus,
.tmwbf select:focus {
    outline: none;
    border-color: var(--heat);
    box-shadow: 0 0 0 3px rgba(255, 106, 44, 0.18);
}
.tmwbf input:disabled { background: #0c0f12; color: var(--faint); }

/* Units toggle (INCH/MM, lives in the header tools cluster) */
.tmwbf-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; height: 38px; }
.tmwbf-unit {
    appearance: none; border: 0; background: var(--field); color: var(--muted);
    font-family: var(--font-head); font-size: 0.78rem; font-weight: 600; letter-spacing: 0.06em;
    padding: 0 15px; cursor: pointer;
}
.tmwbf-unit + .tmwbf-unit { border-left: 1px solid var(--line); }
.tmwbf-unit.is-active { background: var(--heat); color: #1a1206; }
.tmwbf-unit:focus-visible { outline: 2px solid var(--heat); outline-offset: 1px; }

.tmwbf-check {
    display: flex; align-items: center; gap: 7px;
    font-size: 0.9rem; font-weight: 500; color: var(--muted);
    margin-top: 6px; cursor: pointer;
}
.tmwbf-check input { width: auto; accent-color: var(--heat); }

/* ---- Info "i" popups ---- */
.tmwbf-info {
    display: inline-flex; align-items: center; justify-content: center;
    width: 17px; height: 17px; flex: none;
    border: 1px solid var(--line); border-radius: 50%;
    font-family: var(--font-head); font-size: 11px; font-weight: 700; font-style: normal;
    color: var(--muted); cursor: help; position: relative; user-select: none;
    line-height: 1;
}
.tmwbf-info:hover, .tmwbf-info:focus { color: var(--heat); border-color: var(--heat); outline: none; }
.tmwbf-info::after {
    content: attr(data-tip);
    position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
    width: 260px; max-width: 72vw;
    background: #0b0e11; color: var(--ink);
    border: 1px solid var(--line); border-radius: 8px;
    padding: 10px 12px; font-family: var(--font-body); font-size: 0.84rem; font-weight: 400;
    line-height: 1.4; text-align: left; letter-spacing: 0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    opacity: 0; visibility: hidden; transition: opacity 0.12s ease; z-index: 30; pointer-events: none;
}
.tmwbf-info::before {
    content: ""; position: absolute; bottom: calc(100% + 2px); left: 50%; transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: var(--line);
    opacity: 0; visibility: hidden; transition: opacity 0.12s ease; z-index: 31;
}
.tmwbf-info:hover::after, .tmwbf-info:focus::after,
.tmwbf-info:hover::before, .tmwbf-info:focus::before { opacity: 1; visibility: visible; }

/* ---- Output column (diagram + tonnage) ---- */
.tmwbf-output { display: flex; flex-direction: column; gap: 14px; }

.tmwbf-diagram {
    background: #0c0f13; border: 1px solid var(--line);
    border-radius: var(--radius); padding: 8px;
}
.tmwbf-diagram svg { width: 100%; height: auto; display: block; }

.tmwbf-block-title {
    margin: 0 0 12px; font-family: var(--font-head);
    font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600;
    color: var(--muted);
}

/* DRO (force). Stays a dark instrument panel in both themes, so its label/unit
   text is pinned to fixed light values rather than the theme-aware tokens. */
.tmwbf-dro { background: var(--dro); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.tmwbf-dro .tmwbf-block-title { color: #8b96a3; }
.tmwbf-dro-primary { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.tmwbf-readout { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tmwbf-readout-label {
    font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
    display: flex; align-items: center; gap: 6px;
}
.tmwbf-readout-value { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 1.3rem; line-height: 1.1; }
.tmwbf-readout-value em { font-style: normal; font-size: 0.72em; margin-left: 3px; }

.tmwbf-dro .tmwbf-readout-label { color: #8b96a3; }
.tmwbf-dro .tmwbf-readout-value { color: var(--heat); }
.tmwbf-dro .tmwbf-readout-value em { color: #8b96a3; }
.tmwbf-readout--hero .tmwbf-readout-value { font-size: 2.1rem; font-weight: 600; }

.tmwbf-dro-secondary {
    display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px;
    padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.07);
}

/* Bend Setup & Limits: full-width card below the top row, flowing across the width. */
.tmwbf-limits { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.tmwbf-limits-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 16px 20px;
}
.tmwbf-limits .tmwbf-readout-label { color: var(--muted); }
.tmwbf-limits .tmwbf-readout-value { color: var(--ink); }
.tmwbf-limits .tmwbf-readout-value em { color: var(--muted); }
.tmwbf-readout--wide { grid-column: span 2; }
.tmwbf-limits-note { margin: 14px 0 0; font-size: 0.84rem; line-height: 1.5; color: var(--muted); max-width: 90ch; }

/* Focus: float the limits panel above the grid and ring the focused block. */
.tmwbf[data-focus="limits"] .tmwbf-limits { order: 1; }
.tmwbf[data-focus="limits"] .tmwbf-grid   { order: 2; }
.tmwbf[data-focus="tonnage"] .tmwbf-dro,
.tmwbf[data-focus="limits"] .tmwbf-limits { box-shadow: inset 0 0 0 1px var(--heat); }

/* Warning banner */
.tmwbf-warn {
    margin-top: 14px; background: var(--warn-bg); color: var(--warn-ink);
    border: 1px solid #5a4322; border-radius: 8px; padding: 10px 12px;
    font-size: 0.88rem; font-weight: 500;
}

/* Footer */
.tmwbf-foot {
    display: flex; flex-wrap: wrap; gap: 8px;
    margin-top: 16px; padding-top: 13px; border-top: 1px solid var(--line-soft);
    font-size: 0.82rem; color: var(--muted);
}
.tmwbf-foot a { color: var(--heat); text-decoration: none; }
.tmwbf-foot a:hover { text-decoration: underline; }

/* Responsive */
@media (max-width: 760px) {
    .tmwbf-grid { grid-template-columns: 1fr; }
    .tmwbf-dro-primary { grid-template-columns: 1fr; }
    .tmwbf-limits-grid { grid-template-columns: 1fr; }
    .tmwbf-readout--wide { grid-column: auto; }
    .tmwbf-readout--hero .tmwbf-readout-value { font-size: 1.7rem; }
}
@media (max-width: 420px) {
    .tmwbf-fields { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .tmwbf * { transition: none !important; animation: none !important; }
}

/* ---- Print / save-as-PDF ---- */
@media print{
  .tmwbf{ font-size:10px !important; line-height:1.3 !important; }
  .tmwbf-head,.tmwbf-tools,.tmwbf-info,.tmwbf-diagram,.tmwbf-foot,.tmwbf-sub{ display:none !important; }
  .tmwbf-grid{ display:grid !important; grid-template-columns:1fr 1fr !important; gap:8px !important; align-items:start !important; }
  .tmwbf-inputs,.tmwbf-output,.tmwbf-dro,.tmwbf-limits{ border:1px solid #999 !important; padding:7px !important; margin:0 0 8px !important; break-inside:avoid !important; }
  .tmwbf-output{ border:0 !important; padding:0 !important; }
  .tmwbf-limits{ grid-column:1 / -1 !important; }
  .tmwbf-panel-title,.tmwbf-block-title{ font-size:12px !important; margin:0 0 6px !important; }
  .tmwbf-fields,.tmwbf-field,.tmwbf-field label,.tmwbf-field select,.tmwbf-field input{ font-size:10px !important; }
  .tmwbf-readout-label{ font-size:8px !important; }
  .tmwbf-readout-value{ font-size:12px !important; color:#000 !important; }
  .tmwbf-readout--hero .tmwbf-readout-value{ font-size:18px !important; }
}
