:root {
  --bg: #f4f5f7; --panel: #ffffff; --panel2: #f7f8fa; --line: #dfe2e7; --text: #1f2328; --muted: #6b7380;
  --accent: #d9822b; --accent2: #b8691c; --accentSoft: #fbeedd; --danger: #d64545; --ok: #2f9e63;
  --drawer: #e9e4da; --drawerLine: #a79f90; --input: #fff;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #16191d; --panel: #1f2328; --panel2: #262b31; --line: #343a42; --text: #e6e8eb; --muted: #959ca7;
  --accent: #e8953a; --accent2: #f0a85a; --accentSoft: #3a2c1c; --danger: #ef6464; --ok: #49c184;
  --drawer: #2c2a26; --drawerLine: #6d665b; --input: #16191d;
  --shadow: 0 1px 2px rgba(0,0,0,.3);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191d; --panel: #1f2328; --panel2: #262b31; --line: #343a42; --text: #e6e8eb; --muted: #959ca7;
    --accent: #e8953a; --accent2: #f0a85a; --accentSoft: #3a2c1c; --danger: #ef6464; --ok: #49c184;
    --drawer: #2c2a26; --drawerLine: #6d665b; --input: #16191d;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
/* The page sits inside the site's header, sidebar menu and footer
   (w3style.css), so every element rule here is scoped to the app (.sf-app),
   and the app fills the window below the site's 43px header. */
/* the site caps body and its header at 1600px wide; this page may use the whole window */
body.sf-page, body.sf-page nav.w3-top { max-width: none; }
.sf-app, .sf-app * { box-sizing: border-box; }
.sf-app { display: flex; flex-direction: column; min-height: 480px;
  /* window less the site header and the footer (its height is set from app.js), so nothing scrolls the page */
  height: calc(100vh - 43px - var(--sf-foot, 0px)); height: calc(100dvh - 43px - var(--sf-foot, 0px));
  background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.sf-app button, .sf-app select, .sf-app input { font: inherit; color: inherit; margin: 0; }
.sf-app button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 5px 10px; cursor: pointer; }
.sf-app button:hover:not(:disabled) { border-color: var(--accent); }
.sf-app button:disabled { opacity: .45; cursor: default; }
.sf-app button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.sf-app button.primary:hover { background: var(--accent2); }
.sf-app button.danger { color: var(--danger); }
.sf-app input[type=number], .sf-app input[type=text], .sf-app select { background: var(--input); border: 1px solid var(--line); border-radius: 5px; padding: 4px 6px; width: 100%; min-width: 0; }
.sf-app input:focus, .sf-app select:focus { outline: 2px solid var(--accentSoft); border-color: var(--accent); }
.sf-app input[type=checkbox] { accent-color: var(--accent); }
/* the site's dark mode restyles every input and select; keep the app's own */
body.dark-mode .sf-app input[type=number], body.dark-mode .sf-app input[type=text], body.dark-mode .sf-app select {
  background-color: var(--input); color: var(--text); border-color: var(--line) !important; }

.topbar { height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { width: 20px; height: 20px; border-radius: 5px; background:
  linear-gradient(var(--accent),var(--accent)) 0 0/9px 9px no-repeat,
  linear-gradient(var(--accent),var(--accent)) 11px 0/9px 20px no-repeat,
  linear-gradient(var(--accent2),var(--accent2)) 0 11px/9px 9px no-repeat; }
.modes { display: flex; gap: 2px; background: var(--panel2); padding: 3px; border-radius: 8px; border: 1px solid var(--line); }
.modes button { border: none; background: transparent; padding: 4px 12px; }
.modes button.active { background: var(--panel); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; }
.spacer { flex: 1; }
.tb-group { display: flex; gap: 6px; align-items: center; }
.tb-group select { width: auto; }
/* Help: a link styled as a button, blue so it stands out against the orange accent */
.sf-app .help-btn { display: inline-flex; align-items: center; gap: 4px; padding: 5px 12px; border-radius: 6px;
  background: #1e6fd9; border: 1px solid #1e6fd9; color: #fff; font-weight: 700; text-decoration: none; white-space: nowrap;
  box-shadow: 0 0 0 2px rgba(30,111,217,.25); }
.sf-app .help-btn:hover { background: #1558b0; border-color: #1558b0; color: #fff; }
.sf-app .help-btn:focus-visible { outline: 2px solid #8cb8f5; outline-offset: 2px; }
:root[data-theme="dark"] .sf-app .help-btn, body.dark-mode .sf-app .help-btn { background: #3d8bf2; border-color: #3d8bf2; box-shadow: 0 0 0 2px rgba(61,139,242,.3); }
:root[data-theme="dark"] .sf-app .help-btn:hover, body.dark-mode .sf-app .help-btn:hover { background: #5a9ef5; border-color: #5a9ef5; }

#app { display: flex; flex: 1; min-height: 0; }
.side { width: 290px; flex: none; background: var(--panel); overflow-y: auto; padding: 10px 12px 40px; }
.side.left { border-right: 1px solid var(--line); }
.side.right { border-left: 1px solid var(--line); width: 310px; }
.stage { flex: 1; position: relative; min-width: 0; }
.view { position: absolute; inset: 0; }
.hidden { display: none !important; }
#svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; cursor: default; }
#threeHost { position: absolute; inset: 0; }

.sf-app h3 { font-family: inherit; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 0 8px; display: flex; align-items: center; gap: 6px; }
.sf-app h3:first-child { margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 6px; }
.row3 { grid-template-columns: 1fr 1fr 1fr; }
.fld { display: flex; flex-direction: column; gap: 2px; }
.fld > span { font-size: 11px; color: var(--muted); }
.fld.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.fld.inline > span { font-size: 12.5px; color: var(--text); }
.fld.inline input[type=number], .fld.inline select { width: 108px; flex: none; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.btns button { flex: 1 1 auto; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.note { font-size: 11.5px; color: var(--muted); margin: 4px 0 8px; }
.warn { color: var(--danger); font-size: 12px; }
.okc { color: var(--ok); }

/* file & export block at the top of the left panel */
.filebox { display: flex; flex-direction: column; gap: 5px; padding-bottom: 10px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.frow { display: flex; align-items: center; gap: 5px; }
.frow > span { width: 58px; flex: none; font-size: 11px; color: var(--muted); }
.frow button { flex: 1 1 0; min-width: 0; padding: 4px 6px; font-size: 12px; white-space: nowrap; }
.fopt { display: flex; align-items: center; gap: 6px; padding-left: 63px; font-size: 12px; color: var(--muted); cursor: pointer; }
.fopt input { margin: 0; }

/* floating add-tray bar over the 2D Layout */
.addbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 2; display: flex; align-items: center; gap: 2px;
  max-width: calc(100% - 20px); overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px; box-shadow: var(--shadow); }
.addbar .lbl { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 6px 0 2px; }
.addbar button { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: none; min-width: 54px; padding: 4px 5px 3px; background: transparent; border-color: transparent; }
.addbar button:hover { background: var(--panel2); }
.addbar .ic { display: flex; align-items: flex-end; gap: 3px; height: 34px; }
.addbar svg { width: 40px; height: 34px; display: block; }
.addbar .hb { width: 4px; border-radius: 2px; background: var(--accent2); opacity: .75; }
.addbar small { font-size: 10.5px; color: var(--muted); white-space: nowrap; line-height: 1.1; }

.traylist { display: flex; flex-direction: column; gap: 2px; }
.traylist .item { display: flex; align-items: center; gap: 8px; padding: 5px 6px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
.traylist .item:hover { background: var(--panel2); }
.traylist .item.sel { background: var(--accentSoft); border-color: var(--accent); }
.traylist .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.traylist .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.traylist .dm { color: var(--muted); font-size: 11px; white-space: nowrap; }
.traylist .item.stk { margin-left: 14px; }
.traylist .item.stk .nm { color: var(--muted); }
.traylist .item.stk.sel .nm { color: inherit; }
.badge { font-size: 10px; padding: 1px 5px; border-radius: 8px; background: var(--danger); color: #fff; }

.stats { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; font-size: 12px; }
.stats b { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

/* section tabs in the Tray Designer's right panel */
.ptabs { display: flex; gap: 2px; background: var(--panel2); padding: 3px; border-radius: 8px; border: 1px solid var(--line); margin: 2px 0 4px; }
.ptabs button { flex: 1 1 auto; border: none; background: transparent; padding: 4px 2px; font-size: 11.5px; white-space: nowrap; }
.ptabs button.active { background: var(--panel); box-shadow: var(--shadow); color: var(--accent); font-weight: 600; }
.ptab-body { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.ptab-body > h3 { margin: 8px 0 2px; }
.ptab-body .subhd { font-weight: 600; margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); }
.ptab-body .subhd.first { border-top: none; padding-top: 0; margin-top: 2px; }
.gripbox { display: flex; flex-direction: column; gap: 6px; }
.griprow { display: flex; align-items: center; gap: 6px; }
.griprow select { flex: 1; }
.griprow button { padding: 3px 8px; }
.tray-grip { stroke: var(--accent2); pointer-events: none; }

details.grp { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
details.grp > summary { cursor: pointer; padding: 8px 10px; font-weight: 600; list-style: none; display: flex; justify-content: space-between; }
details.grp > summary::after { content: '▸'; color: var(--muted); transition: transform .15s; }
details.grp[open] > summary::after { transform: rotate(90deg); }
details.grp > .body { padding: 2px 10px 10px; display: flex; flex-direction: column; gap: 6px; }

.hud { position: absolute; left: 10px; bottom: 10px; background: color-mix(in srgb, var(--panel) 88%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 12px; pointer-events: none; box-shadow: var(--shadow); max-width: calc(100% - 20px); }
.hud:empty { display: none; }
.zoombar { position: absolute; right: 10px; bottom: 10px; display: flex; flex-direction: column; gap: 4px; }
.zoombar button { width: 32px; height: 32px; padding: 0; background: var(--panel); box-shadow: var(--shadow); font-size: 16px; }
.viewbar { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 4px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 4px 8px; box-shadow: var(--shadow); white-space: nowrap; }
.viewbar button { padding: 3px 8px; font-size: 12px; }
.viewbar label { display: flex; align-items: center; gap: 4px; font-size: 12px; margin-left: 6px; }
.viewbar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }

.profile-wrap { display: flex; gap: 8px; align-items: flex-start; }
.profile-wrap svg { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; }
.profile-wrap .cap { font-size: 10.5px; color: var(--muted); text-align: center; }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; font-size: 12.5px; }
.toast.show { opacity: 1; transform: translateX(-50%); }

.sf-app kbd { font: 10.5px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: var(--panel2); }
.help { font-size: 11.5px; color: var(--muted); line-height: 1.7; }

/* SVG */
.drawer-bg { fill: var(--drawer); stroke: var(--drawerLine); }
.ref-grid { stroke: var(--drawerLine); opacity: .18; }
.tray-outline { stroke: rgba(0,0,0,.45); cursor: move; }
:root[data-theme="dark"] .tray-outline { stroke: rgba(255,255,255,.35); }
.tray-inner { fill: none; stroke: rgba(0,0,0,.35); stroke-dasharray: 3 2; pointer-events: none; }
.tray-holes { fill: rgba(0,0,0,.28); pointer-events: none; }
.tray-div { stroke: rgba(0,0,0,.5); pointer-events: none; }
.tray-label { font-weight: 600; fill: #1f2328; pointer-events: none; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: rgba(255,255,255,.7); stroke-width: 3px; stroke-linejoin: round; }
.tray-dims { fill: #3a3f46; pointer-events: none; text-anchor: middle; dominant-baseline: middle; paint-order: stroke; stroke: rgba(255,255,255,.7); stroke-width: 3px; }
.sel-halo { fill: none; stroke: var(--accent); pointer-events: none; }
.sel-edge { fill: none; stroke: var(--accent2); pointer-events: none; }
.tray.bad .tray-outline { stroke: var(--danger); stroke-dasharray: 6 3; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: 1.5px; }
.handle.vtx { fill: var(--accent); stroke: #fff; cursor: grab; }
.handle.vtx.sel { fill: #fff; stroke: var(--danger); stroke-width: 2.5px; }
.handle.mid { fill: #fff; stroke: var(--accent); opacity: .85; cursor: copy; }
.guide { stroke: #1e88e5; stroke-width: 1px; stroke-dasharray: 4 3; pointer-events: none; }
.dim-line { stroke: #1e88e5; stroke-width: 1px; pointer-events: none; }
.dim-text { fill: #1565c0; font-weight: 600; text-anchor: middle; dominant-baseline: middle; pointer-events: none; paint-order: stroke; stroke: var(--drawer); stroke-width: 3px; }
.drawer-dim { fill: var(--muted); text-anchor: middle; dominant-baseline: middle; }
.ruler-tick { stroke: var(--muted); }
.ruler-text { fill: var(--muted); text-anchor: middle; dominant-baseline: middle; }

@media (max-width: 900px) {
  #app { flex-direction: column; height: auto; }
  .side, .side.right { width: 100%; max-height: none; }
  .stage { height: 70vh; flex: none; }
  .topbar { overflow-x: auto; }
  .brand { display: none; }
}
.handle.notch { fill: var(--accent); stroke: #fff; }

/* preset grids (drawer presets in the Drawer tab) */
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.presets button { text-align: left; padding: 6px 8px; font-size: 12px; line-height: 1.25; }
.presets button small { display: block; color: var(--muted); font-size: 10.5px; }
.presets button.on { border-color: var(--accent); background: var(--accentSoft); }
/* obstructions */
.obs-add { display: grid; grid-template-columns: 1fr 1fr; }
.traylist .obs-sw { background: repeating-linear-gradient(45deg, var(--drawerLine) 0 2px, var(--panel2) 2px 5px); border: 1px solid var(--drawerLine); }
/* section cut controls, a second bar under the view bar */
.secbar { top: 52px; }
.secbar select { width: auto; padding: 2px 4px; font-size: 12px; }
.secbar input[type=range] { width: 110px; accent-color: var(--accent); vertical-align: middle; }
.secbar output { display: inline-block; width: 34px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
