/* Canvas-first Cross-Section Designer (matches main Struc2D floating dock UX) */
#sectionDesigner {
  position: fixed;
  inset: 0;
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  overflow: hidden;
  background: var(--bg-canvas);
  color: var(--text-main);
  border: 0;
}
#sectionDesigner[open] {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}
#sectionDesigner::backdrop { background: rgba(4, 9, 18, .72); }

/* Slim single-row top bar */
#sectionDesigner .sd-header {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  min-height: 46px;
  padding: max(5px, var(--safe-top)) max(10px, var(--safe-right)) 5px max(8px, var(--safe-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  z-index: 5;
}
#sectionDesigner h2 { font-size: 16px; font-weight: 700; margin: 0; white-space: nowrap; }
#sectionDesigner h3 { font-size: 15px; font-weight: 700; margin: 0; }
#sdTargetBadge { margin-right: auto; }
#sectionDesigner .sd-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
#sectionDesigner .sd-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--primary);
  white-space: nowrap;
}
#sectionDesigner .sd-badge[data-tone="hole"] {
  background: rgba(217, 119, 6, 0.14);
  color: #b45309;
  border-color: #d97706;
}
body.dark #sectionDesigner .sd-badge[data-tone="hole"] {
  color: #fbbf24;
  border-color: #f59e0b;
}
#sectionDesigner .sd-badge[data-tone="edit"] {
  background: rgba(124, 58, 237, 0.14);
  color: #6d28d9;
  border-color: #7c3aed;
}
body.dark #sectionDesigner .sd-badge[data-tone="edit"] {
  color: #c4b5fd;
  border-color: #a78bfa;
}

/* Ultra-slim section tabs strip */
#sectionDesigner .sd-tabbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 34px;
  padding: 3px max(8px, var(--safe-right)) 3px max(8px, var(--safe-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border-subtle);
  overflow: hidden;
  z-index: 4;
}
#sectionDesigner .sd-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#sectionDesigner .sd-tabs::-webkit-scrollbar { display: none; }
#sectionDesigner .sd-tab {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 26px;
  min-height: 26px;
  padding: 0 6px 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--surface-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  cursor: pointer;
}
#sectionDesigner .sd-tab[aria-selected=true] {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}
#sectionDesigner .sd-tab-input {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  width: 7.5em;
  min-height: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  color: var(--text-main);
  background: var(--surface);
}
#sectionDesigner .sd-tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  min-height: 18px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  line-height: 1;
  opacity: .7;
  cursor: pointer;
}
#sectionDesigner .sd-tab-close:hover {
  opacity: 1;
  background: rgba(128, 128, 128, 0.18);
}
#sectionDesigner .sd-tab-add {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 999px;
  flex-shrink: 0;
  font-size: 16px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Full-bleed canvas stage */
#sectionDesigner .sd-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-canvas);
}
#sdCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}
#sdCanvas.sd-drawing { cursor: crosshair; }
#sdCanvas.sd-pan { cursor: grab; }
#sdCanvas.sd-panning { cursor: grabbing; }
#sdCanvas.sd-handle { cursor: grab; }

/* Base controls */
#sectionDesigner button,
#sectionDesigner select,
#sectionDesigner input[type=number],
#sectionDesigner input[type=text] {
  font: inherit;
  font-size: 13px;
  min-height: 32px;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  background: var(--surface-secondary);
}
#sectionDesigner button, #sectionDesigner select { cursor: pointer; }
#sectionDesigner button:disabled { opacity: .4; cursor: default; }
#sectionDesigner button:not(:disabled):hover,
#sectionDesigner button[aria-pressed=true] {
  border-color: var(--primary);
  background-color: var(--primary-light);
}
#sectionDesigner .sd-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-secondary);
}
#sectionDesigner button.sd-primary {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
  font-weight: 650;
  padding: 4px 12px;
  border-radius: 999px;
}
#sectionDesigner button.sd-primary:not(:disabled):hover {
  background: #1e40af;
  border-color: #1e40af;
}
#sectionDesigner button.sd-accent-btn,
#sectionDesigner button.sd-chip-primary {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 650;
}
#sectionDesigner button.sd-chip-primary {
  border-radius: 999px;
  padding: 4px 12px;
  box-shadow: var(--shadow-md);
}
#sectionDesigner button.sd-chip-ghost {
  border-radius: 999px;
  padding: 4px 11px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
#sectionDesigner input[type=number] {
  width: 5.2em;
  font-family: var(--font-mono);
}
#sectionDesigner label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  white-space: nowrap;
}
#sectionDesigner :focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Top-left floating units + angle + hint */
#sectionDesigner .sd-top-left {
  position: absolute;
  top: 8px;
  left: max(8px, var(--safe-left));
  right: 54px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  pointer-events: none;
  z-index: 3;
}
#sectionDesigner .sd-top-left > * { pointer-events: auto; }
#sectionDesigner .sd-pill-select,
#sectionDesigner .sd-pill-btn {
  min-height: 28px;
  height: 28px;
  padding: 2px 7px;
  font-size: 12px;
  font-weight: 650;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
#sectionDesigner .sd-hint-pill {
  pointer-events: none;
  max-width: 100%;
  padding: 3px 9px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sectionDesigner .sd-hint-pill:empty { display: none; }

/* Top-right floating canvas controls rail */
#sectionDesigner .sd-rail {
  position: absolute;
  top: 8px;
  right: max(8px, var(--safe-right));
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-md);
  z-index: 3;
}
#sectionDesigner .sd-rail-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
}
#sectionDesigner .sd-rail-btn[aria-pressed=true] {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* Floating error toast */
#sectionDesigner .sd-status-toast {
  position: absolute;
  top: 44px;
  left: 50%;
  transform: translateX(-50%);
  max-width: min(440px, calc(100% - 24px));
  margin: 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  box-shadow: var(--shadow-lg);
  z-index: 6;
}

/* Live measurement badge */
#sdMeasure {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, -50%);
  padding: 3px 8px;
  border: 1px solid currentColor;
  border-radius: var(--radius-sm);
  color: #a65309;
  background: var(--surface);
  font: 600 12px var(--font-mono);
  white-space: nowrap;
  pointer-events: none;
}
body.dark #sdMeasure { color: #fbbf24; }

/* Bottom-left scale & coordinates chips */
#sectionDesigner .sd-bottom-meta {
  position: absolute;
  left: max(8px, var(--safe-left));
  bottom: calc(68px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  pointer-events: none;
  z-index: 2;
}
#sdScale, #sdPosition {
  padding: 2px 7px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
}
#sdPosition:empty { display: none; }

/* Floating contextual panels stack (floats cleanly above bottom dock) */
#sectionDesigner .sd-float-stack {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(68px + var(--safe-bottom));
  width: min(440px, calc(100% - 16px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  z-index: 4;
}
#sectionDesigner .sd-float-stack > * { pointer-events: auto; }
#sectionDesigner .sd-action-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
}
#sectionDesigner .sd-action-strip[hidden],
#sectionDesigner .sd-float-pill[hidden],
#sectionDesigner .sd-float-card[hidden],
#sectionDesigner .sd-card-body[hidden],
#sectionDesigner .sd-card-row[hidden] { display: none; }

#sectionDesigner .sd-float-pill {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
  padding: 5px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
}
#sectionDesigner .sd-arc-pill {
  border-color: var(--primary);
}
#sectionDesigner .sd-float-card {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
}
#sectionDesigner .sd-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
#sectionDesigner .sd-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: auto;
  flex-shrink: 0;
}
#sectionDesigner .sd-head-actions button[hidden] { display: none; }
#sectionDesigner #sdMoveBase,
#sectionDesigner #sdMirrorBase {
  flex: 1 1 auto;
}
#sectionDesigner .sd-card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#sectionDesigner .sd-card-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}
#sectionDesigner .sd-bar-label {
  font-size: 12.5px;
  font-weight: 650;
  color: var(--text-main);
}
#sectionDesigner .sd-mini-btn {
  min-height: 28px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
}
#sectionDesigner .sd-mini-close {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 999px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}
#sectionDesigner .sd-seg {
  display: inline-flex;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-secondary);
}
#sectionDesigner .sd-seg button {
  min-height: 28px;
  border: 0;
  border-radius: 0;
  border-right: 1px solid var(--border-subtle);
  padding: 2px 9px;
  font-size: 12px;
}
#sectionDesigner .sd-seg button:last-child { border-right: 0; }
#sectionDesigner .sd-seg button[aria-pressed=true] {
  background: #1d4ed8;
  color: #fff;
  font-weight: 650;
}
#sectionDesigner .sd-dirpad {
  display: inline-flex;
  gap: 4px;
  flex: 1;
}
#sectionDesigner .sd-dirpad button {
  flex: 1;
  min-width: 36px;
  min-height: 34px;
  font-size: 16px;
  font-weight: 700;
  padding: 2px 6px;
}
#sectionDesigner #sdStepDist { width: 5.5em; }
#sectionDesigner .sd-chips button {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  border-radius: 999px;
}

/* Floating Bottom Tool Dock (matches main Struc2D #toolDock) */
#sdDock {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(10px + var(--safe-bottom));
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  max-width: calc(100% - 14px);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 95%, transparent);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  z-index: 5;
}
#sectionDesigner .sd-dock-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-width: 50px;
  height: 44px;
  min-height: 44px;
  padding: 3px 6px;
  border: 1px solid transparent;
  border-radius: 11px;
  background: transparent;
  color: var(--text-muted);
}
#sectionDesigner .sd-dock-btn span {
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
}
#sectionDesigner .sd-dock-btn[aria-pressed=true] {
  background: #1d4ed8;
  border-color: #1d4ed8;
  color: #fff;
}
#sectionDesigner .sd-dock-btn[aria-pressed=true]:hover {
  background: #1e40af;
}

/* Settings, Templates & Shapes Sheet */
#sectionDesigner .sd-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 9, 18, .45);
  z-index: 8;
}
#sectionDesigner .sd-sheet {
  position: absolute;
  top: 8px;
  right: max(8px, var(--safe-right));
  width: min(320px, calc(100% - 16px));
  max-height: calc(100% - 20px);
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  z-index: 9;
}
#sectionDesigner .sd-sheet[hidden],
#sectionDesigner .sd-sheet-backdrop[hidden] { display: none; }
#sectionDesigner .sd-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
}
#sectionDesigner .sd-sheet-body {
  padding: 10px 12px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
#sectionDesigner .sd-sheet-section { display: flex; flex-direction: column; gap: 6px; }
#sectionDesigner .sd-sheet-row { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; }
#sectionDesigner .sd-sheet-label { flex-direction: column; align-items: stretch; gap: 4px; width: 100%; font-weight: 600; }
#sectionDesigner .sd-sheet-sub { font-size: 12px; font-weight: 650; color: var(--text-muted); }
#sectionDesigner #sdGrid { width: 5em; }
#sectionDesigner .sd-corners { display: flex; flex-wrap: wrap; gap: 5px; }
#sectionDesigner .sd-corners button { font-size: 11.5px; font-family: var(--font-mono); min-height: 28px; }
#sectionDesigner .sd-shape {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  padding-top: 6px;
  border-top: 1px solid var(--border-subtle);
}
#sectionDesigner .sd-shape:first-child { border-top: 0; padding-top: 0; }
#sectionDesigner .sd-shape span { flex: 1; min-width: 110px; font-size: 12.5px; }

/* Results dialog */
#sdResultDialog {
  margin: auto;
  width: min(550px, calc(100% - 24px));
  max-width: none;
  max-height: 90%;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
#sdResultDialog::backdrop { background: rgba(4, 9, 18, .6); }
#sectionDesigner .sd-result-body { padding: 10px 14px 14px; }
#sectionDesigner .sd-axis-key { color: var(--text-muted); margin-bottom: 8px; font-size: 13px; }
#sdResultStatus { color: var(--danger); margin: 0; font-size: 13px; }
#sdResults { display: grid; row-gap: 2px; }
#sdResults div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, auto);
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  padding: 4px 0;
}
#sdResults dt { color: var(--text-muted); }
#sdResults dd { text-align: right; font-family: var(--font-mono); user-select: text; overflow-wrap: anywhere; }
#sectionDesigner .sd-profile { display: grid; justify-items: start; gap: 8px; padding-top: 11px; }

/* Compact phones (<= 780px): keep scale/coords at top-left below units so they never collide with bottom floating cards */
@media (max-width: 780px) {
  #sectionDesigner .sd-bottom-meta {
    top: 42px;
    bottom: auto;
    flex-direction: row;
    flex-wrap: wrap;
    max-width: calc(100% - 64px);
  }
}
@media (max-width: 420px) {
  #sectionDesigner .sd-dock-btn { min-width: 46px; padding: 3px 4px; }
  #sectionDesigner .sd-hint-pill { max-width: calc(100vw - 175px); }
  #sectionDesigner input[type=number] { width: 4.5em; }
}
@media (max-width: 360px) {
  #sectionDesigner .sd-dock-btn { min-width: 42px; height: 42px; min-height: 42px; }
  #sectionDesigner h2 { font-size: 14.5px; }
}
