/* Keep the viewer and its optional registration footer inside the visible WebView. */
html { overscroll-behavior: none; }
body {
  position: fixed;
  top: var(--workspace-viewport-top, 0px);
  left: var(--workspace-viewport-left, 0px);
  width: var(--workspace-viewport-width, 100%);
  height: 100%;
  height: var(--workspace-viewport-height, 100dvh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow: clip;
}
body > #viewer {
  flex: 1 1 0px;
  min-width: 0;
  overflow: hidden;
  overflow: clip;
}
/* These full-screen child workspaces have inline sizing from the model loader. */
body > :is(#floorWorkspace, #formworkShellFrame) {
  inset: var(--workspace-viewport-top, 0px) auto auto var(--workspace-viewport-left, 0px) !important;
  width: var(--workspace-viewport-width, 100%) !important;
  height: var(--workspace-viewport-height, 100%) !important;
}
#viewer {
  --tool-ink: #21474c;
  --tool-accent: #126c60;
  --tool-active: #e1f2ed;
  --tool-line: #ccd9d6;
  --tool-safe-top: env(safe-area-inset-top, 0px);
  --tool-height: 54px;
  --help-width: 53px;
}

/* The fixed help button has its own space outside the scrolling row. */
#viewer > #quantityTopTools {
  position: absolute;
  top: 0;
  left: 0;
  right: calc(var(--help-width) + env(safe-area-inset-right, 0px));
  height: calc(var(--tool-height) + var(--tool-safe-top));
  box-sizing: border-box;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  padding: var(--tool-safe-top) 4px 0 max(4px, env(safe-area-inset-left, 0px));
  border: 0;
  border-bottom: 1px solid var(--tool-line);
  background: #fff;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
  pointer-events: auto;
}
#quantityTopTools::-webkit-scrollbar,
#quantityBottomTools::-webkit-scrollbar { display: none; }

#viewer > #quantityTopTools > :is(.inspection-tools, .header-actions) {
  flex: none;
  align-items: center;
  gap: 3px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}
#viewer > #quantityTopTools > .viewer-title {
  flex: 0 0 auto;
  max-width: min(35vw, 390px);
  margin-right: auto;
  padding-inline: 8px;
}
#quantityTopTools .viewer-title h1 { max-width: 100%; }

#quantityTopTools :is(.inspection-tools,.header-actions) > :is(button,a,.workspace-mode-current),
#viewer > #help-btn,
#quantityBottomTools button {
  box-sizing: border-box;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 47px;
  min-width: 48px;
  margin: 0;
  padding: 3px 7px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--tool-ink);
  box-shadow: none;
  font: 550 13px/1.15 system-ui, sans-serif;
  white-space: nowrap;
  text-align: center;
  text-decoration: none;
  touch-action: pan-x;
}
#quantityTopTools :is(.inspection-tools,.header-actions) > :is(button,a,.workspace-mode-current) {
  width: auto;
  flex: none;
}
#quantityTopTools :is(.inspection-tools,.header-actions) > [hidden] { display: none; }
#quantityTopTools :is(.inspection-tools,.header-actions) > :is(button,a) > svg,
#viewer > #help-btn > svg,
#quantityBottomTools button > svg {
  display: block;
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* These controls replace their text or are created after the model has loaded. */
#quantityTopTools :is(#isolate-btn, #formworkShellButton, #shellConcreteButton,.workspace-mode-current)::before {
  content: "";
  display: block;
  width: 20px;
  height: 20px;
  flex: none;
  background: currentColor;
  -webkit-mask: var(--tool-glyph) center / contain no-repeat;
  mask: var(--tool-glyph) center / contain no-repeat;
}
#quantityTopTools #isolate-btn {
  --tool-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Cpath d='M3 8V3h5m8 0h5v5m0 8v5h-5m-8 0H3v-5m9-11 6 3.5v7L12 19l-6-3.5v-7zM6 8.5l6 3.5 6-3.5M12 12v7'/%3E%3C/svg%3E");
}
#quantityTopTools :is(#formworkShellButton,.workspace-mode-current) {
  --tool-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Cpath d='M3 7l10-4 8 4v11l-10 4-8-4zM3 7l8 4 10-4M11 11v11M7 10v7m8-6v7m3-8v6'/%3E%3C/svg%3E");
}
#quantityTopTools #shellConcreteButton {
  --tool-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='black' stroke-width='1.7' stroke-linejoin='round' viewBox='0 0 24 24'%3E%3Cpath d='m3 8 10-5 8 4v10l-10 5-8-4zM3 8l8 4 10-5m-10 5v10'/%3E%3C/svg%3E");
}
#quantityTopTools #shellSaveButton::after { content: "保存"; }
#quantityShareDialog { width: min(350px, calc(100% - 28px)); color: var(--tool-ink, #21474c); }
#quantityShareDialog input { display: block; width: 100%; margin: 4px 0 10px; padding: 8px; font: inherit; }
#quantityShareDialog .quantity-share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
#quantityShareDialog button:not([data-close]), #quantityShareDialog a { min-height: 42px; padding: 6px 12px; }
#quantityShareDialog [hidden] { display: none; }

#viewer > #help-btn {
  position: absolute;
  z-index: 3;
  top: 0;
  right: 0;
  width: calc(var(--help-width) + env(safe-area-inset-right, 0px));
  height: calc(var(--tool-height) + var(--tool-safe-top));
  padding: var(--tool-safe-top) env(safe-area-inset-right, 0px) 0 0;
  border-radius: 0;
  border-bottom: 1px solid var(--tool-line);
  background: #fff;
  color: var(--tool-accent);
  touch-action: manipulation;
  cursor: pointer;
}
#viewer.editing-source-mesh > #help-btn { display: none; }
#viewer > #viewNav { top: calc(var(--tool-height) + var(--tool-safe-top) + 7px); }
#quantityOrientation {
  position: absolute;
  z-index: 1;
  left: max(4px, env(safe-area-inset-left, 0px));
  bottom: calc(55px + env(safe-area-inset-bottom, 0px));
  width: 60px;
  height: 60px;
  pointer-events: none;
}
#viewer > #layers-panel { top: calc(var(--tool-height) + var(--tool-safe-top) + 6px); }

#viewer > .bottom {
  bottom: 0;
  left: 0;
  right: 0;
}
/* Popups remain siblings of the scrolling nav and can use the whole canvas. */
#viewer > #selection-actions {
  position: absolute;
  inset: auto;
  display: inline-flex;
  align-items: stretch;
  width: max-content;
  height: max-content;
  min-height: 0;
  max-height: none;
  padding: 2px;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--tool-line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 3px 10px #203e4826;
}
#viewer > #selection-actions[hidden],
#quantity-selection-window[hidden] { display: none; }
#viewer > #selection-actions > button {
  box-sizing: border-box;
  flex: 0 1 auto;
  min-width: 0;
  min-height: 34px;
  padding: 3px clamp(5px, 1.8vw, 10px);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #204454;
  font: inherit;
  font-size: 14px;
  white-space: nowrap;
}
#viewer > #selection-actions > button + button { border-left: 1px solid var(--tool-line); }
#viewer > #selection-actions > #selection-grip { cursor: grab; touch-action: none; color: #65857f; }
#viewer > #selection-actions > button[aria-pressed=true] { background: #16665f; color: #fff; }
#quantity-selection-window {
  position: absolute;
  z-index: 3;
  box-sizing: border-box;
  pointer-events: none;
  border: 1px solid #398df2;
  background: #398df226;
}
#quantity-selection-window.crossing { border: 1px dashed #12956b; background: #12956b26; }
#viewer :is(#selection-actions,#layers-panel,#measurement-actions,#quantity-actions-menu,#hidden-panel) {
  box-sizing: border-box;
  max-width: calc(100% - 16px);
}
#viewer #quantityBottomTools {
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  width: 100%;
  gap: 4px;
  padding: 3px max(6px, env(safe-area-inset-right, 0px)) max(3px, env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
  border: 0;
  border-top: 1px solid var(--tool-line);
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
  touch-action: pan-x;
}
#viewer #quantityBottomTools .hidden-control { display: contents; }
#viewer #quantityBottomTools button {
  flex: 1 0 52px;
  height: 47px;
  min-width: 52px;
  max-width: 78px;
  width: auto;
  max-height: none;
  padding: 3px 5px;
  border-radius: 7px;
}
#viewer #quantityBottomTools #hidden-toggle svg { width: 20px; height: 20px; transform: none; }
#viewer #quantityTopTools :is(button,a):focus-visible,
#viewer #quantityBottomTools button:focus-visible,
#viewer > #help-btn:focus-visible { outline: 2px solid var(--tool-accent); outline-offset: -2px; }
#viewer #quantityTopTools :is(button[aria-pressed=true],button[aria-expanded=true],.workspace-mode-current),
#viewer #quantityBottomTools :is(button.active,button[aria-expanded=true]) {
  background: var(--tool-active);
  color: var(--tool-accent);
  box-shadow: inset 0 -2px var(--tool-accent);
}
#viewer #quantityTopTools button:disabled:not(.workspace-mode-current),
#viewer #quantityBottomTools button:disabled { opacity: .45; }
#viewer #quantityTopTools .workspace-mode-current { opacity: 1; }
@media (min-width: 720px) {
  #viewer #quantityBottomTools { justify-content: center; }
}

#viewer .quantity-tool-window {
  position: absolute;
  inset: auto;
  transform: none;
  box-sizing: border-box;
  width: min(264px, calc(100% - 12px));
  min-width: 0;
  max-width: none;
  height: auto;
  margin: 0;
  padding: 6px 8px;
  overflow: auto;
  overscroll-behavior: contain;
  pointer-events: auto;
  border: 1px solid var(--tool-line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 4px 15px #153e4321;
  color: var(--tool-ink);
  font-size: 13px;
  line-height: 1.3;
}
#viewer .quantity-tool-window[data-tool-covered] { visibility: hidden; pointer-events: none; }
#viewer .quantity-tool-grip {
  position: relative;
  min-height: 32px;
  margin: 0;
  padding-inline-start: 12px;
  touch-action: none;
  user-select: none;
  cursor: grab;
}
#viewer .quantity-tool-grip:active { cursor: grabbing; }
#viewer .quantity-tool-grip::before {
  content: '';
  position: absolute;
  inset-inline-start: 0;
  inset-block-start: 50%;
  transform: translateY(-50%);
  width: 7px;
  height: 15px;
  background: radial-gradient(circle, #8eaba5 1px, transparent 1.4px) 0 0 / 4px 5px;
}
#viewer .quantity-tool-grip strong { font-size: 14px; color: var(--tool-ink); }
#viewer .quantity-tool-window :is(.selection-heading,.hidden-heading,.annotation-heading,.measurement-actions-heading) {
  display: flex;
  align-items: center;
  gap: 3px;
  min-height: 32px;
}
#viewer .quantity-tool-window :is(.selection-heading,.hidden-heading,.annotation-heading,.measurement-actions-heading) button {
  flex: none;
  min-width: 32px;
  min-height: 32px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--tool-ink);
  font-size: 17px;
}
#viewer #quantity-stat-title { flex: none; }
#viewer .selection-heading #part-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
#viewer .quantity-metric-controls { display: grid; gap: 2px; }
#viewer :is(.collapsed,.browse-face-mode) .quantity-metric-controls { display: none; }
#viewer .quantity-scope-options { display: flex; gap: 4px; }
#viewer .quantity-scope-options button { flex: 1; min-height: 32px; border: 1px solid var(--tool-line); border-radius: 6px; color: var(--tool-ink); background: #fff; font: inherit; }
#viewer .quantity-tool-window :is(.quantity-scope-options,.measurement-action-list) button[aria-pressed=true] { border-color: #98c6ba; color: #0b6154; background: var(--tool-active); }
#viewer .quantity-label-options { display: flex; flex-wrap: wrap; align-items: center; gap: 0 9px; }
#viewer .quantity-label-options label, #viewer .measurement-dimensions-option { display: inline-flex; align-items: center; gap: 4px; min-height: 30px; margin: 0; padding: 0; background: transparent; color: var(--tool-ink); font-size: 12px; }
#viewer .quantity-label-options input, #viewer .measurement-dimensions-option input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--tool-accent); }
#viewer .quantity-tool-window .quantity-body { padding-block: 0; }
#viewer .quantity-tool-window :is(.quantity-actions,.measure-actions,.annotation-buttons,.hidden-tools,.measurement-action-list) button {
  min-height: 32px; padding: 4px 7px; border-radius: 6px; font-size: 13px;
}
#viewer .quantity-tool-window .measurement-action-list button { background: #f0f5f4; color: var(--tool-ink); }
#viewer .quantity-tool-window .measurement-action-list span { font-size: 12px; }
#viewer .quantity-tool-window :is(.hidden-tools,.hidden-list,.measure-actions,.annotation-buttons) { margin-top: 4px; gap: 4px; }
#viewer .quantity-tool-window #hidden-search { min-width: 0; height: 32px; min-height: 32px; font-size: 16px; }
#viewer .quantity-tool-window .quantity-values strong { font-size: 16px; }

#viewer #selection { padding: 4px 9px; font-size: 15px; }
#viewer #selection .selection-heading { gap: 5px; }
#viewer #selection .selection-heading strong { font-size: 17px; }
#viewer #selection #part-name { font-size: 14px; }
#viewer #selection .quantity-stat-tools {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 8px;
}
#viewer #selection:not(.collapsed):not(.browse-face-mode) .quantity-metric-controls { display: contents; }
#viewer #selection.collapsed .quantity-stat-tools { display: none; }
#viewer #selection .quantity-scope-options { grid-area: 1 / 1; margin: 0; }
#viewer #selection .quantity-label-options { grid-row: 2; grid-column: 1 / -1; gap: 0 12px; }
#viewer #selection .quantity-stat-tools:has(.face-mode-bar[hidden]),
#viewer #selection.face-mode .quantity-stat-tools { grid-template-columns: minmax(0, 1fr); column-gap: 0; }
#viewer #selection .face-mode-bar {
  grid-area: 1 / 2; gap: 6px; margin: 0; padding: 0; border: 0;
}
#viewer #selection:not(.face-mode) #face-level-label { display: none; }
#viewer #selection.face-mode .face-mode-bar { grid-column: 1 / -1; grid-row: auto; }
#viewer #selection .quantity-scope-options button,
#viewer #selection #face-level-action,
#viewer #selection .quantity-actions button {
  min-height: 34px; padding: 3px 8px; font: inherit; white-space: nowrap;
}
#viewer #selection .quantity-label-options label { min-height: 32px; font-size: 15px; }
#viewer #selection .quantity-values strong { font-size: 21px; overflow-wrap: anywhere; }
#viewer #selection .quantity-values span,
#viewer #selection #face-level-label,
#viewer #selection :is(.object-area-status,.quantity-details p,.object-name,.object-metric,.face-edge-hint,.quantity-hint) { font-size: 14px; }

#help {
  box-sizing: border-box;
  width: min(430px, calc(100% - 20px));
  height: min(78vh, 600px);
  height: min(78dvh, 600px);
  max-height: calc(100% - 16px);
  padding: 12px 16px;
  border: 1px solid #c6d7d4;
  border-radius: 14px;
  color: #173e45;
}
#help[open] { display: flex; flex-direction: column; gap: 7px; overflow: hidden; }
#help [hidden] { display: none !important; }
#help .dialog-title { flex: none; }
#help .dialog-title h2 { margin: 0; color: #173e45; font-size: 20px; }
#help #close-help { min-width: 44px; min-height: 44px; color: #195750; }
#quantity-help-search {
  flex: none; box-sizing: border-box; width: 100%; min-height: 42px; padding: 7px 10px;
  color: #173e45; background: white; border: 1px solid #aec7c4; border-radius: 7px; font: inherit; font-size: 16px;
}
#quantity-help-scroll { flex: 1 1 auto; min-height: 0; overflow: auto; overscroll-behavior: contain; overflow-wrap: anywhere; }
#help .guide-group { margin: 0; border: 0; border-bottom: 1px solid #d9e4e1; border-radius: 0; background: transparent; padding: 0; }
#help .guide-group summary { padding: 12px 2px; color: #145f57; font-size: 15px; line-height: 1.45; font-weight: 650; cursor: pointer; }
#help .guide-group summary:focus-visible { outline: 2px solid #137369; outline-offset: -2px; }
#help dl { margin: 0 0 12px; }
#help .guide-entry + .guide-entry { margin-top: 12px; }
#help dt { color: #173e45; font-size: 14px; font-weight: 700; }
#help dd { margin: 3px 0 0; color: #354f56; font-size: 14px; line-height: 1.55; }
#help #got-it { flex: none; width: 100%; min-height: 42px; margin: 0; padding: 8px 12px; background: #116e63; color: white; }
