/* ============================================================
   TipBeam Web — Engineer's Notebook aesthetic
   Design tokens ported from the AHK Builder reference project.
   ============================================================ */

:root {
  /* Color tokens */
  --bg: #fbf8f3;
  --bg-grain: #f7f2e9;
  --surface: #ffffff;
  --ink: #1f1a17;
  --ink-soft: #4a423c;
  --muted: #8b817a;
  --muted-light: #b3a89e;
  --border: #e5dcce;
  --border-soft: #f0e8db;

  /* Accents */
  --primary: #b8451f;      /* rust */
  --primary-hover: #9c3a1a;
  --primary-soft: #fceee5;
  --primary-tint: #fff7f1;
  --amber: #b8861f;
  --amber-soft: #fdf3dd;
  --teal: #1d6e7e;
  --teal-soft: #e6f0f2;
  --danger: #a83b2f;
  --success: #3a7d4f;

  /* Typography */
  --font-display: 'Fraunces', 'Cambria', Georgia, serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  /* Spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* Radius */
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 12px;
  --r-full: 999px;

  /* Shadows (warm-tinted) */
  --shadow-sm: 0 1px 2px rgba(31, 26, 23, 0.04), 0 1px 3px rgba(31, 26, 23, 0.05);
  --shadow-md: 0 4px 12px rgba(31, 26, 23, 0.06), 0 2px 4px rgba(31, 26, 23, 0.04);
  --shadow-lg: 0 12px 28px rgba(31, 26, 23, 0.10), 0 4px 10px rgba(31, 26, 23, 0.04);
}

/* === Reset === */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(184, 134, 31, 0.025) 0%, transparent 40%),
    radial-gradient(circle at 88% 76%, rgba(29, 110, 126, 0.022) 0%, transparent 45%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
/* Full-height flex column so header + main + footer fit the viewport exactly
   (no hardcoded heights → no slight overflow). Panels scroll internally. */
html { height: 100%; overflow: hidden; }
body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

/* === Typography === */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  font-variation-settings: "opsz" 30;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 var(--space-3);
}
h1 { font-size: 1.35rem; font-variation-settings: "opsz" 40; letter-spacing: -0.02em; }
h2 {
  font-size: 0.78rem;
  font-family: var(--font-body);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
h3 {
  font-size: 0.95rem;
  font-family: var(--font-body);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: var(--space-2);
}
.hint {
  color: var(--muted);
  font-size: 0.82rem;
  margin: var(--space-2) 0;
  line-height: 1.5;
}
code, kbd, .mono { font-family: var(--font-mono); font-size: 0.85em; }
kbd {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--r-sm);
  padding: 1px 6px;
  font-size: 0.78em;
  color: var(--ink);
  box-shadow: 0 1px 0 var(--border-soft);
}
.hidden { display: none !important; }

/* === Header === */
header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-3) var(--space-5);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
/* Mobile-only chrome — hidden on desktop, shown in the ≤640px block.
   .btn.menu-btn keeps specificity above the .btn display rule. */
.btn.menu-btn { display: none; }
.header-menu { display: none; }
.mobile-tabs { display: none; }
#orientToggleTop { display: none; }   /* orient toggle lives in the diagram panel on desktop */
#unitToggle .lbl-abbr { display: none; }   /* full "IMPERIAL/METRIC" on desktop */
#inspector { margin-top: var(--space-4); }
.btn.diagram-help-btn { display: none; }    /* mobile-only "?" (desktop shows the inline hint + legend) */
.sheet-close { display: none; }
.help-list { margin: 0 0 var(--space-3); padding-left: 1.1rem; font-size: 0.86rem; color: var(--ink-soft); line-height: 1.7; }
.brand { display: flex; align-items: baseline; gap: var(--space-3); }
.brand h1 { margin: 0; font-size: 1.4rem; font-weight: 600; font-variation-settings: "opsz" 48; }
.brand .version {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: var(--r-sm);
  letter-spacing: 0.02em;
  font-weight: 500;
}
.header-actions { display: flex; gap: var(--space-3); align-items: center; }
.header-actions .group { display: flex; gap: var(--space-2); }
.header-actions .divider { width: 1px; height: 22px; background: var(--border); }

/* Unit toggle segmented control */
.unit-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.unit-toggle button {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  padding: 6px 12px;
  border: none;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s ease;
}
.unit-toggle button.active { background: var(--ink); color: var(--bg); }

/* === Buttons === */
.btn {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--ink-soft); background: var(--bg-grain); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08), inset 0 1px 0 rgba(255,255,255,0.12);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-subtle { color: var(--muted); border-color: transparent; }
.btn-subtle:hover { color: var(--ink); background: var(--bg-grain); border-color: var(--border-soft); }
.btn-sm { padding: 4px 9px; font-size: 0.78rem; }
.row { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }

/* === Layout === */
header { flex: 0 0 auto; }
main {
  flex: 1 1 auto;
  min-height: 0;               /* allow the grid/panels to shrink & scroll */
  display: grid;
  grid-template-columns: minmax(360px, 440px) 1fr;
  gap: var(--space-4);
  padding: var(--space-4);
}
.panel { min-height: 0; }      /* grid items scroll internally instead of growing main */
.panel {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--space-5);
  overflow: auto;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.panel-scroll { flex: 1; overflow: auto; min-height: 0; }

/* === Labels & inputs === */
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin: var(--space-3) 0;
  color: var(--ink-soft);
  letter-spacing: 0.005em;
}
input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  margin-top: var(--space-1);
  font-family: var(--font-body);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-tint);
}
/* Equalize control heights (native <select> is a couple px taller than
   <input> otherwise). box-sizing:border-box is set globally. */
input[type="text"], input[type="number"], select { height: 36px; }
textarea { resize: vertical; min-height: 52px; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-2) var(--space-3); margin: var(--space-2) 0; }
.field-grid label { margin: 0; }
.field-unit { position: relative; }
.field-unit .unit-suffix {
  position: absolute; right: 10px; bottom: 8px;
  font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted-light);
  pointer-events: none;
}
.checkbox-row {
  display: flex; align-items: center; gap: var(--space-2);
  margin-top: var(--space-3); color: var(--ink-soft); font-size: 0.85rem; cursor: pointer;
}
.checkbox-row input { width: auto; margin: 0; flex-shrink: 0; }

/* === Empty state === */
.empty-state {
  text-align: center; padding: var(--space-5) var(--space-3);
  color: var(--muted); font-style: italic; font-size: 0.85rem;
}
.welcome-mark {
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; margin: 0 auto var(--space-4);
  border-radius: var(--r-md); background: var(--bg-grain);
  border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.welcome-mark svg { width: 28px; height: 28px; stroke: var(--primary); }

/* === Member / load list cards === */
.card-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.card {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  padding: var(--space-3);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.card:hover { border-color: var(--muted-light); }
.card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-tint); }
.members-notice {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2);
  background: var(--amber-soft); border: 1px solid #e6cf94; color: #7a5a12;
  border-radius: var(--r-md); padding: var(--space-2) var(--space-3);
  font-size: 0.8rem; margin-bottom: var(--space-3);
}
.members-notice button { margin-left: auto; }
.card.has-error { border-color: var(--danger); }
.card.has-error .card-index { background: var(--danger); }
input.invalid, select.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(168, 59, 47, 0.13); }
.load-problem { display: flex; gap: 5px; color: var(--danger); font-size: 0.78rem; margin-top: var(--space-2); line-height: 1.4; }
.card.inactive { opacity: 0.55; }
.card-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-1); }
.card-index {
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600;
  background: var(--ink); color: var(--bg);
  width: 20px; height: 20px; border-radius: var(--r-full);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.card-title { font-weight: 600; font-size: 0.9rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-sub { font-family: var(--font-mono); font-size: 0.76rem; color: var(--muted); }
.card-controls { display: flex; gap: var(--space-1); margin-left: auto; }
.icon-btn {
  border: none; background: none; cursor: pointer; color: var(--muted-light);
  width: 24px; height: 24px; border-radius: var(--r-sm); font-size: 0.9rem;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  transition: all 0.12s ease; font-family: var(--font-mono);
}
.icon-btn:hover { background: var(--bg-grain); color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); }

/* === Beam diagram === */
.diagram-wrap {
  position: relative;
  background: var(--bg-grain);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--space-4) var(--space-3);
  margin-bottom: var(--space-4);
  overflow-x: auto;
}
.diagram-warn {
  position: absolute;
  top: var(--space-2);
  left: 50%;
  transform: translateX(-50%);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--amber-soft);
  border: 1px solid #e6cf94;
  color: #7a5a12;
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  pointer-events: none;
  z-index: 5;
}
.zoom-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.zoom-btn {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 600;
  width: 28px; height: 28px;
  padding: 0;
  justify-content: center;
  line-height: 1;
}
.zoom-level { font-family: var(--font-mono); font-size: 0.75rem; color: var(--muted); min-width: 42px; text-align: center; }
.zoom-hint { font-size: 0.72rem; color: var(--muted-light); margin-left: auto; }
#beamSvg { width: 100%; height: auto; display: block; font-family: var(--font-mono); touch-action: none; }
#beamSvg.panning { cursor: grabbing; }
/* Vertical beam: fill the panel (width + height) so there's room to zoom/pan;
   preserveAspectRatio="xMidYMid meet" centers the tall content. */
#beamSvg.vertical { width: 100%; height: min(70vh, 720px); }
.beam-line { stroke: var(--ink); stroke-width: 5; }
.beam-member-fill { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.hit { fill: transparent; cursor: pointer; }
.hit.hovered { stroke: var(--primary); stroke-width: 1.25; stroke-dasharray: 4 2; rx: 2; }
.hit.draggable { cursor: ew-resize; }
#beamSvg.vertical .hit.draggable { cursor: ns-resize; }
#beamSvg.dragging, #beamSvg.dragging .hit { cursor: grabbing; }
.joint-glyph.selected { filter: drop-shadow(0 0 3px var(--primary)); }
.joint-glyph { stroke: var(--ink); stroke-width: 1.5; fill: var(--surface); pointer-events: none; }
.joint-glyph.support { fill: var(--ink); }
.load-arrow { stroke: var(--primary); stroke-width: 1.75; fill: none; }
.load-arrow.inactive { stroke: var(--muted-light); stroke-dasharray: 3 3; }
.load-fill { fill: var(--primary-soft); stroke: var(--primary); stroke-width: 1; }
.load-fill.inactive { fill: var(--bg-grain); stroke: var(--muted-light); }
.load-label { fill: var(--primary); font-size: 7px; font-weight: 600; }
.load-label.inactive { fill: var(--muted-light); }
.dim-line { stroke: var(--muted-light); stroke-width: 0.75; }
.dim-text { fill: var(--muted); font-size: 9px; }
.diagram-total { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; color: var(--ink-soft); text-align: center; margin-top: var(--space-2); }
.diagram-total:empty { display: none; }
.diagram-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); font-size: 0.74rem; color: var(--muted); margin-top: var(--space-2); }
.diagram-legend span { display: inline-flex; align-items: center; gap: 5px; }

/* === Bearing picker chips === */
.bearing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-2); margin-top: var(--space-2); }
.bearing-chip {
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--space-2) var(--space-3); cursor: pointer; text-align: center;
  background: var(--surface); transition: all 0.15s ease;
}
.bearing-chip:hover { border-color: var(--muted-light); }
.bearing-chip.active { border-color: var(--primary); background: var(--primary-tint); }
.bearing-chip .bc-glyph { font-size: 1.2rem; line-height: 1; }
.bearing-chip .bc-name { font-size: 0.76rem; font-weight: 600; margin-top: 4px; }

/* === Document / parameters fields === */
.header-field { display: grid; grid-template-columns: 1fr 1.3fr; gap: var(--space-2); align-items: center; margin-bottom: 6px; }
.header-field label { margin: 0; font-family: var(--font-mono); font-size: 0.72rem; color: var(--muted); }
.header-field input { margin-top: 0; padding: 4px 8px; font-size: 0.8rem; }

/* === Tabs === */
.tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-3); border-bottom: 1px solid var(--border-soft); }
.tab {
  border: none; background: none; cursor: pointer; padding: var(--space-2) var(--space-3);
  font-family: var(--font-body); font-size: 0.82rem; font-weight: 600; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Build panel footer + bottom tab bar */
.build-footer {
  border-top: 1px solid var(--border-soft);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
}
.tabs-bottom {
  display: flex;
  gap: 0;
  margin-top: var(--space-3);
  border-top: 1px solid var(--border);
  border-bottom: none;
}
.tabs-bottom .tab {
  flex: 1;
  text-align: center;
  border-bottom: none;
  border-top: 2px solid transparent;
  margin: -1px 0 0;
  padding: var(--space-3) var(--space-2) var(--space-2);
}
.tabs-bottom .tab.active { color: var(--primary); border-top-color: var(--primary); border-bottom-color: transparent; }

/* === Modal === */
.modal {
  position: fixed; inset: 0; background: rgba(31, 26, 23, 0.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-content {
  background: var(--surface); padding: var(--space-5); border-radius: var(--r-lg);
  min-width: 360px; max-width: 480px; width: 90%; max-height: 85vh; overflow: auto;
  display: flex; flex-direction: column; gap: var(--space-2);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
}
.modal-content h3 {
  font-family: var(--font-display); font-size: 1.15rem; font-weight: 600;
  font-variation-settings: "opsz" 36; margin: 0 0 var(--space-2); letter-spacing: -0.01em;
}
.modal-wide { max-width: 640px; }
.modal-content { position: relative; }
.modal-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 1.3rem;
  line-height: 1;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg-grain); color: var(--ink); }
.param-warn {
  background: var(--amber-soft);
  border: 1px solid #ead7a8;
  border-radius: var(--r-md);
  padding: var(--space-3);
  font-size: 0.82rem;
  line-height: 1.5;
  color: var(--ink-soft);
  margin-bottom: var(--space-3);
}
.param-warn strong { color: var(--ink); }

/* === Footer === */
.app-credit { flex: 0 0 auto; text-align: center; margin: 0; padding: var(--space-1) var(--space-4) var(--space-2); }
.app-credit a {
  font-family: var(--font-body); font-size: 0.72rem; font-weight: 600;
  color: var(--muted-light); letter-spacing: 0.01em; text-decoration: none; transition: color 0.15s ease;
}
.app-credit a:hover { color: var(--muted); }

/* === Diagram hover tooltip === */
.diagram-tip {
  position: fixed;
  z-index: 160;
  pointer-events: none;            /* must not intercept hit-testing */
  background: var(--ink);
  color: var(--bg);
  font-size: 0.75rem;
  line-height: 1.4;
  padding: 6px 9px;
  border-radius: var(--r-sm);
  box-shadow: var(--shadow-md);
  max-width: 280px;
}

/* === Diagram overlap chooser popup === */
.hit-popup {
  position: fixed;
  z-index: 150;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  min-width: 180px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.hit-popup-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 2px var(--space-2) var(--space-1);
}
.hit-popup-item {
  text-align: left;
  border: none;
  background: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--ink);
  padding: 6px var(--space-2);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.hit-popup-item:hover { background: var(--bg-grain); }

/* === DXF import modal === */
.dxf-drop {
  border: 2px dashed var(--border-strong, var(--border));
  border-radius: var(--r-md);
  background: var(--bg-grain);
  padding: var(--space-6) var(--space-5);
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dxf-drop.dragover { border-color: var(--primary); background: var(--primary-soft, #fdeee7); }
.link-btn { border: none; background: none; padding: 0; font: inherit; color: var(--primary); text-decoration: underline; cursor: pointer; }
.link-btn:hover { text-decoration: none; }
.dxf-drop-mark { font-size: 1.6rem; color: var(--muted); margin-bottom: var(--space-2); }
.dxf-drop .hint { text-align: left; max-width: 60ch; margin: var(--space-4) auto 0; }
.dxf-file-row {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.dxf-file-row #dxfFileName { font-size: 0.85rem; font-weight: 600; }
.dxf-units-label { display: inline-flex; align-items: center; gap: var(--space-2); margin: 0; font-size: 0.8rem; }
.dxf-units-label select { height: 34px; width: auto; }
.dxf-file-row .btn { margin-left: auto; }
.dxf-checks { list-style: none; padding: 0; margin: 0 0 var(--space-4); display: grid; gap: 6px; }
.dxf-check { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.dxf-check summary {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 9px var(--space-3); cursor: pointer; font-size: 0.85rem; font-weight: 600;
  list-style: none;
}
.dxf-check summary::-webkit-details-marker { display: none; }
.dxf-check .chev { margin-left: auto; color: var(--muted); font-size: 0.7rem; transition: transform 0.15s ease; }
.dxf-check details[open] .chev { transform: rotate(90deg); }
.dxf-check-details { padding: 0 var(--space-3) var(--space-3) 34px; font-size: 0.78rem; color: var(--ink-soft); }
.dxf-check-details div { margin-top: 3px; }
.dxf-mark { width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; flex: none; }
.dxf-mark.pass { background: #dff2e4; color: #1e7d43; }
.dxf-mark.warn { background: var(--amber-soft, #f7ecd3); color: #7a5a12; }
.dxf-mark.fail { background: #f7dcd7; color: #b3402f; }
.dxf-diagrams { display: grid; gap: var(--space-2); margin-bottom: var(--space-3); }
.dxf-card {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-2) var(--space-3);
  align-items: center;
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: var(--space-3); background: var(--surface); cursor: pointer;
  text-align: left; width: 100%; font-family: var(--font-body);
}
.dxf-card.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.dxf-card.fail { opacity: 0.62; cursor: not-allowed; }
.dxf-card svg { display: block; width: 190px; max-width: 34vw; height: 44px; }
.dxf-card-title { font-size: 0.85rem; font-weight: 600; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.dxf-card-sub { font-size: 0.76rem; color: var(--muted); margin-top: 2px; }
.dxf-card-msgs { grid-column: 1 / -1; font-size: 0.75rem; color: var(--ink-soft); }
.dxf-card-msgs .bad { color: #b3402f; }
.dxf-card-msgs .note { color: #7a5a12; }
.dxf-badge {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 7px; border-radius: 99px;
}
.dxf-badge.pass { background: #dff2e4; color: #1e7d43; }
.dxf-badge.warn { background: var(--amber-soft, #f7ecd3); color: #7a5a12; }
.dxf-badge.fail { background: #f7dcd7; color: #b3402f; }
.dxf-badge.axis { background: var(--bg-grain); color: var(--muted); text-transform: none; }

/* === Sign-in gate ===
   Fixed rather than a flow child: <body> is a flex column, so a static gate
   would become a flex item. It carries its own scroll because html/body are
   both overflow:hidden and the MFA / waitlist cards are tall. z-index clears
   the toast (200), tooltip/hit-popup (160/150) and modals (100). */
.auth-gate {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: flex-start; justify-content: center;
  overflow: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg);
  padding: var(--space-6) var(--space-4);
  padding-bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
}
.auth-card { width: 100%; max-width: 420px; margin: auto; display: flex; flex-direction: column; align-items: center; gap: var(--space-5); }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--space-2); }
.auth-brand h1 { font-family: var(--font-display); font-size: 1.6rem; margin: 0; color: var(--ink); }
.auth-brand .version {
  font-family: var(--font-mono); font-size: 0.7rem; letter-spacing: 0.02em;
  color: var(--primary); background: var(--primary-soft);
  padding: 3px 9px; border-radius: var(--r-full);
}
.auth-clerk { width: 100%; display: flex; justify-content: center; }
.auth-msg {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-md);
  padding: var(--space-5); text-align: center;
}
/* Opts out of the global h2 treatment (uppercase panel-header style + rule). */
.auth-title {
  font-family: var(--font-display); font-size: 1.05rem; font-weight: 600;
  text-transform: none; letter-spacing: normal; color: var(--ink);
  display: block; border-bottom: none; padding-bottom: 0;
  margin: 0 0 var(--space-3);
}
.auth-body { font-size: 0.86rem; line-height: 1.55; color: var(--ink-soft); margin: 0; }
.auth-body code { font-family: var(--font-mono); font-size: 0.8rem; background: var(--bg-grain); padding: 1px 5px; border-radius: var(--r-sm); }
.auth-actions { display: flex; gap: var(--space-2); justify-content: center; flex-wrap: wrap; margin-top: var(--space-4); }
.auth-actions:empty { display: none; }
.auth-busy { display: flex; align-items: center; justify-content: center; gap: var(--space-2); font-size: 0.86rem; color: var(--muted); margin: 0; }
.auth-spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: none;
  border: 2px solid var(--border); border-top-color: var(--primary);
  animation: auth-spin 0.7s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .auth-spinner { animation-duration: 2.4s; } }

/* Nothing of the builder shows until an entitled user is confirmed. */
body.auth-pending > header,
body.auth-pending > main,
body.auth-pending > #mobileTabs,
body.auth-pending > footer { display: none; }

.user-button { display: inline-flex; align-items: center; min-width: 28px; }

/* === Toast === */
.toast {
  position: fixed; bottom: var(--space-5); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: var(--space-3) var(--space-5);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg); font-size: 0.85rem; z-index: 200;
  opacity: 0; transition: opacity 0.2s ease; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.error { background: var(--danger); }

@media (max-width: 1080px) {
  html, body { height: auto; overflow: auto; }   /* small screens: let the whole page scroll */
  main { grid-template-columns: 1fr; }
}

/* Phone pass: bigger touch targets, single-column fields, full-screen modal. */
@media (max-width: 640px) {
  html, body { height: 100vh; height: 100dvh; overflow: hidden; }   /* dvh tracks the iOS URL bar; fit onscreen so scrolling doesn't fight diagram gestures */
  .app-credit { display: none; }
  header { flex-wrap: wrap; gap: var(--space-2); padding: var(--space-2) var(--space-3); }
  .brand h1 { font-size: 1.15rem; }
  .header-actions { width: 100%; flex-wrap: wrap; gap: var(--space-2); }
  main { padding: var(--space-3); gap: var(--space-3); }
  .panel { padding: var(--space-4); }
  .btn { padding: 10px 14px; }
  .btn-sm { padding: 7px 11px; }
  input[type="text"], input[type="number"], select { height: 42px; font-size: 16px; }  /* 16px avoids iOS focus-zoom */
  .field-pair, .field-grid { grid-template-columns: 1fr; }
  .icon-btn { width: 34px; height: 34px; }
  .card-controls { gap: var(--space-1); }
  .bearing-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
  .bearing-chip { padding: var(--space-3) var(--space-2); }
  .tabs-bottom .tab { padding: var(--space-4) var(--space-2) var(--space-3); }  /* taller tap target */
  body[data-mv="diagram"] #orientToggleTop { display: inline-flex; }   /* orient toggle only on the Diagram tab */
  #unitToggle .lbl-full { display: none; }
  #unitToggle .lbl-abbr { display: inline; }
  /* Interaction hint + legend move into the "?" popup */
  .zoom-hint { display: none; }
  #diagramPanel .diagram-legend { display: none; }
  .btn.diagram-help-btn { display: inline-flex; justify-content: center; margin-left: auto; width: 34px; height: 34px; padding: 0; font-size: 1rem; font-weight: 700; }
  /* Bearing detail = bottom sheet that slides up when a joint is selected */
  #inspector {
    position: fixed; left: 0; right: 0; bottom: 48px; z-index: 55; margin: 0;
    background: var(--surface); border: 1px solid var(--border); border-bottom: none;
    border-radius: var(--r-lg) var(--r-lg) 0 0; box-shadow: 0 -8px 24px rgba(31, 26, 23, 0.16);
    padding: var(--space-4); max-height: 58vh; max-height: 58dvh; overflow: auto;
    /* Closed: fully offscreen AND visibility:hidden — the sheet is short when
       empty, so a %-translate alone leaves a white sliver covering the tabs. */
    transform: translateY(calc(115% + 80px)); visibility: hidden;
    transition: transform 0.22s ease, visibility 0s linear 0.22s;
  }
  #inspector.sheet-open { transform: translateY(0); visibility: visible; transition: transform 0.22s ease; }
  #inspectorEmpty { display: none; }
  body:not([data-mv="diagram"]) #inspector { display: none; }
  .sheet-close { display: inline-flex; align-items: center; justify-content: center; float: right; width: 30px; height: 30px; margin-top: -4px; border: none; background: none; color: var(--muted); font-size: 1.4rem; line-height: 1; border-radius: var(--r-sm); cursor: pointer; }
  .sheet-close:active { background: var(--bg-grain); }
  #diagramPanel > h2 { display: none; }   /* frees the title row (and its in-panel orient toggle) */
  #diagramPanel { padding: var(--space-3); }
  .diagram-wrap { padding: var(--space-2); }
  /* Diagram tab = flex column sized to the visible viewport: the beam area
     flexes, so the zoom bar and the Overall line always stay onscreen above
     the tab bar (no fixed vh heights that overflow behind the iOS URL bar). */
  body[data-mv="diagram"] main { display: flex; flex-direction: column; padding-bottom: calc(48px + env(safe-area-inset-bottom, 0px)); }
  body[data-mv="diagram"] #diagramPanel { flex: 1; min-height: 0; }
  body[data-mv="diagram"] .diagram-wrap { flex: 1; min-height: 0; margin-bottom: var(--space-2); }
  body[data-mv="diagram"] #beamSvg, body[data-mv="diagram"] #beamSvg.vertical { height: 100%; }
  /* Parameters modal becomes a full-screen sheet */
  .modal-content { min-width: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }

  /* Header: collapse actions into a toggle menu; keep the unit toggle visible. */
  .header-actions > .group, .header-actions > .divider, #exportBtn { display: none; }
  .btn.menu-btn { display: inline-flex; margin-left: auto; }   /* push to the far right */
  .header-menu:not(.hidden) {
    display: flex; flex-direction: column; gap: var(--space-1);
    position: absolute; top: 100%; right: var(--space-3); left: var(--space-3);
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
    box-shadow: var(--shadow-lg); padding: var(--space-2); z-index: 60;
  }
  .header-menu button {
    width: 100%; text-align: left; border: none; background: none; cursor: pointer;
    font-family: var(--font-body); font-size: 0.95rem; color: var(--ink);
    padding: 11px var(--space-3); border-radius: var(--r-sm);
  }
  .header-menu button:hover { background: var(--bg-grain); }

  /* Three bottom tabs (Members / Loads / Diagram) show one section at a time. */
  #buildTabs { display: none; }
  main { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
  body[data-mv="diagram"] #buildPanel { display: none; }
  body:not([data-mv="diagram"]) #diagramPanel { display: none; }
  .mobile-tabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(31, 26, 23, 0.06);
    padding-bottom: env(safe-area-inset-bottom, 0px);   /* clear the home indicator */
  }
  .mobile-tabs button {
    flex: 1; border: none; background: none; cursor: pointer;
    font-family: var(--font-body); font-size: 0.82rem; font-weight: 600; color: var(--muted);
    padding: var(--space-3) var(--space-2); border-top: 2px solid transparent; margin-top: -1px;
  }
  .mobile-tabs button.active { color: var(--primary); border-top-color: var(--primary); }
  .app-credit { margin-bottom: 52px; }
}
