  .btn3d { transition: transform .12s ease, box-shadow .12s ease, opacity .12s ease; }
  .btn3d:hover:not(:disabled) { transform: translateY(-1px); }
  .btn3d:active:not(:disabled) { transform: translateY(0); }
  .btn3d:disabled { opacity: .38; cursor: not-allowed; }

  /* Draw 页绝不允许任何子元素制造横向滚动。 */
  html, body { width: 100%; max-width: 100%; overflow-x: hidden !important; }
  body { min-width: 0; }
  body.submit-modal-open { overflow: hidden !important; }
  .draw-main, .designer-workspace, .property-panel, .canvas-panel, .budget-panel,
  #canvas-wrapper, #segment-list, .segment-card { min-width: 0 !important; max-width: 100%; }
  #canvas-wrapper > .canvas-container { max-width: 100% !important; }
  #canvas-wrapper { background: #edf7e8 !important; --canvas-tools-top:8px; --canvas-tools-edge:8px; --canvas-tools-height:36px; container-type:inline-size; }
  #canvas-wrapper > .canvas-container { background: transparent !important; position: relative !important; z-index: 2; }
  #canvas-wrapper > .canvas-container canvas { background: transparent !important; }

  /* The quote form is a page-level modal. It must stay above the 2D toolbar,
     the 3D renderer and the sticky site header, regardless of their local
     stacking contexts. */
  #submit-modal {
    z-index: 1000 !important;
    isolation: isolate;
  }
  #submit-modal > [role="document"] {
    position: relative;
    z-index: 1;
  }

  /* Hide obsolete fields even if an older HTML template is served with this stylesheet. */
  #property-panel .param-deco,
  #property-panel [data-i18n="decoLabel"],
  #fence-deco-container, #fence-deco-mobile { display: none !important; }

  /* Shared-cost is a normal fifth fence parameter, not a promotional/callout card. */
  .param-shared-cost { min-width: 0; }
  .shared-cost-heading {
    display: block;
    margin: 0 0 .25rem;
    color: #334155;
    font-size: .75rem;
    font-weight: 800;
    line-height: 1.2;
  }
  .shared-cost-control {
    display: flex;
    align-items: center;
    gap: .65rem;
    width: 100%;
    min-width: 0;
    min-height: 58px;
    padding: .62rem .72rem;
    border: 1px solid #e2e8f0;
    border-radius: .8rem;
    background: #fff;
    color: #334155;
    box-sizing: border-box;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
  }
  .shared-cost-control:hover { border-color: #94a3b8; background: #f8fafc; }
  .shared-cost-control:focus-within { border-color: #10b981; box-shadow: 0 0 0 2px rgba(16,185,129,.14); }
  .shared-cost-control:has(.shared-cost-checkbox:checked) { border-color: #34d399; background: #ecfdf5; }
  .shared-cost-checkbox {
    appearance: none;
    -webkit-appearance: none;
    display: grid;
    place-content: center;
    flex: 0 0 auto;
    width: 1.2rem;
    height: 1.2rem;
    margin: 0;
    border: 2px solid #cbd5e1;
    border-radius: .35rem;
    background: #fff;
    cursor: pointer;
  }
  .shared-cost-checkbox::before {
    content: "";
    width: .48rem;
    height: .28rem;
    border-left: 2px solid #fff;
    border-bottom: 2px solid #fff;
    transform: rotate(-45deg) scale(0);
    transform-origin: center;
    transition: transform .12s ease;
  }
  .shared-cost-checkbox:checked { border-color: #059669; background: #059669; }
  .shared-cost-checkbox:checked::before { transform: rotate(-45deg) scale(1); }
  .shared-cost-copy { display: block; min-width: 0; flex: 1 1 auto; }
  .shared-cost-option { display: block; color: #334155; font-size: .72rem; font-weight: 800; line-height: 1.25; }
  .shared-cost-help { display: block; margin-top: .12rem; color: #64748b; font-size: .62rem; line-height: 1.35; }

  html[data-theme="dark"] .shared-cost-heading { color: #edf7f8; }
  html[data-theme="dark"] .shared-cost-control {
    background: #102630;
    border-color: #365560;
    color: #edf7f8;
  }
  html[data-theme="dark"] .shared-cost-control:hover { background: #15313b; border-color: #4b7180; }
  html[data-theme="dark"] .shared-cost-control:has(.shared-cost-checkbox:checked) {
    background: rgba(5, 150, 105, .16);
    border-color: #34d399;
  }
  html[data-theme="dark"] .shared-cost-checkbox { background: #0b1f27 !important; border-color: #66808a !important; }
  html[data-theme="dark"] .shared-cost-checkbox:checked { background: #059669 !important; border-color: #34d399 !important; }
  html[data-theme="dark"] .shared-cost-option { color: #edf7f8; }
  html[data-theme="dark"] .shared-cost-help { color: #aac1c9; }

html[data-theme="dark"] .material-overview-disclaimer { color: #8fa7b2 !important; }

  .canvas-view-controls {
    position: absolute;
    right: var(--canvas-tools-edge);
    top: var(--canvas-tools-top);
    z-index: 72;
    display: flex;
    align-items: center;
    gap: 5px;
    pointer-events: auto;
  }
  .canvas-history-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    padding: 0;
    border-radius: 9999px;
    border: 1px solid rgba(148,163,184,.45);
    background: rgba(255,255,255,.96);
    color: #334155;
    box-shadow: 0 4px 12px rgba(15,23,42,.12);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: 900 20px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .canvas-history-btn:hover:not(:disabled) { background: #f8fafc; transform: translateY(-1px); }
  .canvas-history-btn:active:not(:disabled) { transform: translateY(0) scale(.96); }
  .canvas-history-btn:disabled { opacity: .34; cursor: default; box-shadow: none; }
  .canvas-clear-btn:not(:disabled) {
    color: #b45309;
    background: rgba(255, 251, 235, .97);
    border-color: rgba(217, 119, 6, .34);
  }
  .canvas-clear-btn:hover:not(:disabled) { background: #fef3c7; }

  .canvas-3d-toggle {
    position: static;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 9999px;
    border: 2px solid rgba(255,255,255,.96);
    background: linear-gradient(180deg, #0f766e 0%, #115e59 100%);
    color: #fff;
    box-shadow: 0 6px 18px rgba(15,118,110,.30), 0 2px 5px rgba(15,23,42,.16);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font: 900 11px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
  }
  .canvas-3d-toggle:hover { transform: translateY(-1px); filter: brightness(1.04); }
  .canvas-3d-toggle:active { transform: translateY(0) scale(.97); }
  .canvas-3d-toggle.active { background: linear-gradient(180deg, #334155 0%, #1e293b 100%) !important; border-color: rgba(255,255,255,.96) !important; color: #fff !important; }

  .draw-toggle-btn {
    position: absolute;
    left: 8px;
    top: 8px;
    z-index: 34;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 9999px;
    border: 1px solid rgba(5,150,105,.38);
    background: rgba(255,255,255,.95);
    color: #475569;
    box-shadow: 0 3px 10px rgba(15,23,42,.10);
    font: 800 10px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .draw-toggle-btn.active {
    border-color: rgba(5,150,105,.55);
    background: rgba(236,253,245,.96);
    color: #047857;
  }
  #canvas-wrapper.drawing-disabled > .canvas-container,
  #canvas-wrapper.drawing-disabled > .canvas-container .upper-canvas,
  #canvas-wrapper.drawing-disabled > .canvas-container .lower-canvas {
    cursor: default;
    touch-action: pan-y pinch-zoom !important;
  }
  .draw-toggle-btn:not(.active) {
    border-color: rgba(100,116,139,.35);
    background: rgba(248,250,252,.96);
    color: #64748b;
  }

  .canvas-house-marker {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    transform-origin: 50% 50%;
    z-index: 12;
    pointer-events: none;
    user-select: none;
    filter: drop-shadow(0 12px 24px rgba(15, 23, 42, 0.10));
    opacity: .92;
  }
  .canvas-house-marker.hidden { display: none !important; }
  .house-toggle-btn {
    position: absolute;
    z-index: 34;
    left: 8px;
    top: 46px;
    min-height: 30px;
    border: 1px solid rgba(5,150,105,.38);
    background: rgba(255,255,255,.95);
    color: #047857;
    border-radius: 9999px;
    padding: 0 10px;
    box-shadow: 0 3px 10px rgba(15,23,42,.10);
    font: 800 10px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
  .house-toggle-btn:not(.active) {
    border-color: rgba(100,116,139,.35);
    background: rgba(248,250,252,.96);
    color: #64748b;
  }

  .canvas-house-card {
    position: relative;
    width: 88px;
    height: 79px;
    display: block;
    overflow: hidden;
    border: 1.5px solid rgba(148, 163, 184, .42);
    border-radius: 14px;
    background: rgba(255,255,255,.72);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.55);
  }
  .house-illustration {
    position: absolute;
    left: 50%;
    top: 45%;
    width: 74px;
    height: 66px;
    transform: translate(-50%, -50%);
    transform-origin: 50% 50%;
  }
  .house-roof {
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border-left: 39px solid transparent;
    border-right: 39px solid transparent;
    border-bottom: 28px solid #62b5d4;
    filter: drop-shadow(0 2px 0 rgba(127, 29, 29, .18));
  }
  .house-chimney {
    position: absolute;
    right: 10px;
    top: 6px;
    width: 9px;
    height: 17px;
    border-radius: 3px 3px 1px 1px;
    background: linear-gradient(180deg, #f59e0b 0%, #b45309 100%);
  }
  .house-body {
    position: absolute;
    left: 13px;
    bottom: 0;
    width: 48px;
    height: 40px;
    border-radius: 10px;
    border: 2px solid rgba(148, 163, 184, .38);
    background: linear-gradient(180deg, rgba(255,255,255,.98) 0%, rgba(248,250,252,.96) 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.75);
  }
  .house-door {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    width: 12px;
    height: 21px;
    border-radius: 7px 7px 3px 3px;
    background: linear-gradient(180deg, #92400e 0%, #78350f 100%);
  }
  .house-door::after {
    content: '';
    position: absolute;
    right: 2px;
    top: 10px;
    width: 2px;
    height: 2px;
    border-radius: 9999px;
    background: #fde68a;
  }
  .house-window {
    position: absolute;
    width: 11px;
    height: 11px;
    border-radius: 4px;
    border: 1px solid rgba(148, 163, 184, .28);
    background: linear-gradient(180deg, #dbeafe 0%, #bfdbfe 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.8);
  }
  .house-window.left { left: 8px; top: 10px; }
  .house-window.right { right: 8px; top: 10px; }
  .house-yard {
    position: absolute;
    left: 50%;
    bottom: 4px;
    transform: translateX(-50%);
    width: min(78%, 86px);
    height: 10px;
    border-radius: 9999px;
    background: linear-gradient(180deg, rgba(134, 239, 172, .95) 0%, rgba(74, 222, 128, .85) 100%);
    border: 1px solid rgba(22, 163, 74, .22);
    box-shadow: inset 0 1px 0 rgba(255,255,255,.6);
  }
  .house-caption {
    position: absolute;
    left: 50%;
    bottom: 3px;
    transform: translateX(-50%);
    padding: 2px 8px;
    border-radius: 9999px;
    background: rgba(255,255,255,.88);
    border: 1px solid rgba(148, 163, 184, .42);
    color: #334155;
    font: 800 9px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: .03em;
    text-transform: uppercase;
    box-shadow: 0 2px 7px rgba(15, 23, 42, .07);
    white-space: nowrap;
  }
  .gate-plan-marker {
    position: absolute;
    z-index: 25;
    pointer-events: none;
    transform-origin: center;
    width: 42px;
    height: 18px;
    border: 2px solid var(--gate-color, #475569);
    border-radius: 4px;
    background: rgba(255,255,255,.18);
    box-shadow: 0 2px 7px rgba(15,23,42,.12);
  }
  .gate-plan-marker::before {
    content: '';
    position: absolute;
    left: 4px;
    bottom: 3px;
    width: calc(100% - 8px);
    height: 2px;
    background: var(--gate-color, #475569);
    transform: rotate(-22deg);
    transform-origin: center;
    border-radius: 9999px;
    opacity: .9;
  }
  .gate-plan-marker.double::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 2px;
    bottom: 2px;
    width: 2px;
    transform: translateX(-50%);
    background: var(--gate-color, #475569);
    border-radius: 9999px;
    opacity: .95;
  }
  .three-preview {
    position: absolute;
    inset: 0;
    z-index: 60;
    display: none;
    overflow: hidden;
    background: linear-gradient(180deg, #65bff3 0%, #b9e5fb 56%, #5b8f4d 57%, #39733d 100%);
    touch-action: none;
  }
  .three-preview.active { display: block; }
  .in-3d #draw-toggle-btn, .in-3d #house-toggle-btn { display:none; }
  .in-3d #length-popup { z-index:75; max-width:calc(100% - 12px); }
  .three-edit-modes, .three-edit-panel {
    position:absolute; z-index:4; display:flex; align-items:center; gap:5px;
    padding:5px; border:1px solid #cbd5e1; border-radius:14px;
    background:rgba(255,255,255,.96); color:#0f172a; box-shadow:0 3px 12px #0f172a20;
  }
  .three-edit-modes { top:var(--canvas-tools-top); left:var(--canvas-tools-edge); height:var(--canvas-tools-height); box-sizing:border-box; padding:2px; gap:2px; border-radius:12px; }
  .three-edit-panel { bottom:10px; left:10px; right:10px; min-height:48px; flex-wrap:wrap; }
  .three-edit-panel[hidden], .three-edit-handle[hidden], .three-edit-panel button[hidden] { display:none; }
  .three-edit-modes button, .three-edit-panel button {
    min-height:38px; padding:6px 10px; border-radius:9px; font-size:12px; font-weight:700;
    color:#0f172a; background:#f1f5f9; touch-action:manipulation;
  }
  .three-edit-modes button[aria-pressed="true"] { background:#0f766e; color:#fff; }
  .three-edit-modes button { min-height:0; height:100%; padding:0 10px; font-size:11px; }
  .three-edit-caption { flex:1 1 90px; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:12px; font-weight:700; line-height:1.25; padding:0 5px; }
  .three-edit-panel button:last-child { color:#b91c1c; font-size:23px; min-width:40px; }
  .three-is-editing .three-preview-hud { bottom:70px; border-radius:10px; }
  .three-edit-handle {
    position:absolute; z-index:3; width:36px; height:36px; transform:translate(-50%,-50%);
    border:2px solid white; border-radius:50%; background:#0891b2; color:white;
    box-shadow:0 1px 8px #0f172a80; font-size:20px; font-weight:800; touch-action:none; cursor:ew-resize;
  }
  .three-edit-modes button:focus-visible, .three-edit-panel button:focus-visible, .three-edit-handle:focus-visible {
    outline:3px solid #06b6d4; outline-offset:3px;
  }
  @media (max-width:767px) {
    .three-edit-caption { flex-basis:100%; }
    .three-is-editing .three-preview-hud { display:none; }
  }
  .three-preview canvas { display: block; width: 100% !important; height: 100% !important; }
  .three-preview-hud {
    position: absolute;
    left: 10px;
    bottom: 10px;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 7px;
    max-width: calc(100% - 20px);
    padding: 6px 9px;
    border-radius: 9999px;
    background: rgba(15,23,42,.76);
    color: #fff;
    backdrop-filter: blur(8px);
    box-shadow: 0 5px 16px rgba(15,23,42,.18);
    font: 700 10px/1.15 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    pointer-events: none;
  }
  .view-mode-btn.active {
    background: #0f766e !important;
    border-color: #0f766e !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(15,118,110,.22);
  }
  .segment-card { overflow: hidden; overflow-wrap: anywhere; }

  .selection-delete-btn {
    position: static;
    z-index: auto;
    min-height: 29px;
    height: 29px;
    width: auto;
    padding: 0 8px;
    border-radius: 10px;
    border: 1px solid rgba(190, 18, 60, .35);
    background: linear-gradient(180deg, #f43f5e 0%, #e11d48 100%);
    color: #fff;
    box-shadow: none;
    font: 900 10px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
  }
  .selection-delete-btn:hover { background: linear-gradient(180deg, #e11d48 0%, #be123c 100%); transform: translateY(-1px); }
  .selection-delete-btn:active { transform: translateY(0) scale(.97); }
  .selection-delete-btn.hidden { display: none !important; }


  /* Fence quick actions are one contextual toolbar, not four unrelated floating pills. */
  .fence-action-toolbar {
    position: absolute;
    z-index: 39;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    flex-wrap: wrap;
    width: max-content;
    max-width: calc(100% - 12px);
    padding: 3px;
    border: 1px solid rgba(148,163,184,.32);
    border-radius: 13px;
    background: rgba(255,255,255,.88);
    backdrop-filter: blur(7px);
    -webkit-backdrop-filter: blur(7px);
    box-shadow: 0 5px 16px rgba(15,23,42,.12);
    user-select: none;
  }
  .fence-action-toolbar.hidden { display: none !important; }
  .fence-action-toolbar .insert-gate-btn,
  .fence-action-toolbar .mirror-fence-btn,
  .fence-action-toolbar .selection-delete-btn {
    position: static !important;
    min-height: 29px;
    height: 29px;
    padding: 0 8px;
    border-width: 1px;
    border-radius: 10px;
    box-shadow: none;
    font-size: 10px;
    line-height: 1;
  }
  .fence-action-toolbar .mirror-fence-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  .fence-action-toolbar.dense .insert-gate-btn,
  .fence-action-toolbar.dense .mirror-fence-btn,
  .fence-action-toolbar.dense .selection-delete-btn { padding-left: 7px; padding-right: 7px; }
  .insert-gate-btn {
    position: absolute;
    z-index: 39;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 9999px;
    border: 2px solid rgba(255,255,255,.96);
    background: linear-gradient(180deg, #10b981 0%, #059669 100%);
    color: #fff;
    box-shadow: 0 5px 16px rgba(5,150,105,.28), 0 2px 5px rgba(15,23,42,.16);
    font: 800 11px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
  }
  .insert-gate-btn:hover { transform: translateY(-1px); filter: brightness(1.03); }
  .insert-gate-btn:active { transform: translateY(0) scale(.97); }
  .insert-gate-btn.hidden { display: none !important; }
  .mirror-fence-btn {
    position: absolute;
    z-index: 31;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 9999px;
    border: 1.5px solid rgba(124,58,237,.45);
    background: linear-gradient(180deg, rgba(255,255,255,.98), rgba(245,243,255,.96));
    color: #6d28d9;
    box-shadow: 0 3px 10px rgba(109,40,217,.15), 0 1px 3px rgba(15,23,42,.10);
    font: 900 10px/1 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    cursor: pointer;
    touch-action: manipulation;
    user-select: none;
    white-space: nowrap;
  }
  .mirror-fence-btn:hover { transform: translateY(-1px); filter: brightness(1.03); }
  .mirror-fence-btn:active { transform: translateY(0) scale(.97); }
  .mirror-fence-btn.hidden { display: none !important; }
  .side-gate-btn {
    background: linear-gradient(180deg, #0ea5e9 0%, #0284c7 100%);
    box-shadow: 0 5px 16px rgba(2,132,199,.25), 0 2px 5px rgba(15,23,42,.15);
  }
  .drive-gate-btn {
    background: linear-gradient(180deg, #f59e0b 0%, #d97706 100%);
    box-shadow: 0 5px 16px rgba(217,119,6,.24), 0 2px 5px rgba(15,23,42,.15);
  }

  .drawing-length-label {
    position: absolute;
    z-index: 35;
    pointer-events: none;
    transform: translate(-50%, -100%);
    min-width: 58px;
    padding: 5px 9px;
    border-radius: 10px;
    background: rgba(15, 23, 42, .92);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .2);
    box-shadow: 0 5px 16px rgba(15, 23, 42, .24);
    font: 800 12px/1.1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    text-align: center;
    white-space: nowrap;
    user-select: none;
  }
  .drawing-length-label.hidden { display: none !important; }

  .smart-guide-layer {
    position: absolute;
    inset: 0;
    z-index: 23;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
  }
  .smart-guide-layer line {
    stroke: #a855f7;
    stroke-width: 1.6;
    stroke-dasharray: 6 4;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 1px 1px rgba(255,255,255,.9));
  }
  .smart-guide-layer circle {
    fill: #a855f7;
    stroke: #fff;
    stroke-width: 1.5;
    vector-effect: non-scaling-stroke;
  }
  .smart-guide-layer text {
    fill: #7e22ce;
    stroke: rgba(255,255,255,.96);
    stroke-width: 4px;
    paint-order: stroke fill;
    font: 800 11px/1 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    text-anchor: middle;
    dominant-baseline: central;
  }
  .smart-guide-layer .smart-closure-ring {
    fill: rgba(16, 185, 129, .18);
    stroke: #059669;
    stroke-width: 2.5;
    stroke-dasharray: none;
    vector-effect: non-scaling-stroke;
  }
  .smart-guide-layer .smart-closure-text {
    fill: #047857;
    stroke: rgba(255,255,255,.98);
  }

  .fence-dimension-layer {
    position: absolute;
    inset: 0;
    z-index: 24;
    pointer-events: none;
    overflow: hidden;
    isolation: isolate;
  }
  .fence-dimension-leader-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    display: block;
    z-index: 1;
  }
  .fence-dimension-leader {
    fill: none;
    stroke: rgba(51, 65, 85, .82);
    stroke-width: 1.55;
    stroke-dasharray: 5 4;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
    filter: drop-shadow(0 1px 0 rgba(255,255,255,.9));
  }
  .fence-dimension-label {
    position: absolute;
    z-index: 3;
    transform: translate(-50%, -50%);
    min-width: 52px;
    padding: 3px 7px;
    border-radius: 9999px;
    border: 1px solid rgba(148, 163, 184, .55);
    background: rgba(255, 255, 255, .92);
    color: #334155;
    box-shadow: 0 2px 8px rgba(15, 23, 42, .10);
    font: 800 10px/1.15 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    text-align: center;
    white-space: nowrap;
    user-select: none;
    pointer-events: auto;
    cursor: pointer;
    touch-action: none;
  }
  .fence-dimension-label.dragging { cursor: grabbing; box-shadow: 0 4px 14px rgba(15, 23, 42, .18); }
  .fence-dimension-label:active { transform: translate(-50%, -50%) scale(.96); }

  .admin-editor-bar { flex: 0 0 auto; }
  .admin-materials { min-width: 0; }
  .material-stats { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .5rem; margin-bottom: .75rem; }
  .material-stat { border: 1px solid #e2e8f0; border-radius: .75rem; background: #fff; padding: .7rem .8rem; }
  .material-stat span { display: block; color: #64748b; font-size: .72rem; }
  .material-stat strong { display: block; color: #0f172a; font-size: 1.1rem; margin-top: .12rem; }
  .material-group { border: 1px solid #e2e8f0; border-radius: .9rem; overflow: hidden; background: #fff; margin-top: .75rem; }
  .material-group-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; background: #f8fafc; border-bottom: 1px solid #e2e8f0; }
  .material-group-head h3 { margin: 0; font-size: .9rem; font-weight: 900; }
  .material-group-head p { margin: .15rem 0 0; color: #64748b; font-size: .72rem; }
  .material-group-head > strong { color: #047857; white-space: nowrap; }
  .material-table-wrap { overflow-x: auto; }
  .material-table { width: 100%; border-collapse: collapse; min-width: 650px; font-size: .76rem; }
  .material-table th, .material-table td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid #f1f5f9; }
  .material-table th { color: #64748b; background: #fff; white-space: nowrap; }
  .material-table th:nth-last-child(-n+3), .material-table td:nth-last-child(-n+3) { text-align: right; white-space: nowrap; }
  .material-warnings { margin-top: .75rem; padding: .8rem 1rem; border: 1px solid #fbbf24; border-radius: .75rem; background: #fffbeb; color: #92400e; font-size: .76rem; }
  .material-warnings ul { margin: .35rem 0 0; padding-left: 1.2rem; }
  .material-empty { padding: 2rem; text-align: center; color: #64748b; }

  .style-card.selected {
    border-color: #059669;
    background-color: #ecfdf5;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.25);
  }

  .ruler-corner { width: 24px; height: 24px; background: #f8fafc; border: 1px solid #e2e8f0; }
  .ruler-top { height: 24px; background: #f8fafc; border-bottom: 1px solid #cbd5e1; }
  .ruler-left { width: 24px; background: #f8fafc; border-right: 1px solid #cbd5e1; }
  .ruler-right { width: 24px; background: #f8fafc; border-left: 1px solid #cbd5e1; }
  .ruler-bottom { height: 24px; background: #f8fafc; border-top: 1px solid #cbd5e1; }

  .segment-card.active-segment {
    border-color: #059669 !important;
    background-color: #f0fdf4 !important;
    box-shadow: 0 0 0 2px rgba(5, 150, 105, 0.3) !important;
  }

  .custom-scrollbar { scrollbar-width: thin; scrollbar-color: #cbd5e1 #f1f5f9; }
  .custom-scrollbar::-webkit-scrollbar { width: 5px; height: 5px; }
  .custom-scrollbar::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 8px; }
  .custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 8px; }
  .custom-scrollbar::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

  /* 关键：预算内容永远不能反向撑大 grid/flex 容器。 */
  .designer-workspace { min-width: 0; }
  .designer-workspace > * { min-width: 0; min-height: 0; }
  .budget-panel {
    min-height: 0 !important;
    max-height: 100%;
    overflow: hidden !important;
    contain: size layout paint;
  }
  .budget-list-scroll {
    min-height: 0 !important;
    max-height: 100%;
    overflow-y: auto !important;
    overflow-x: hidden;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }

  @media (min-width: 1024px) {
    .designer-workspace {
      /* JS subtracts the measured header/toolbar height from the visible screen. */
      grid-template-columns: minmax(180px, 216px) minmax(0, 1fr) minmax(220px, 264px);
      height: var(--drawing-panel-height, calc(100svh - 150px));
      max-height: none;
      grid-template-rows: minmax(0, 1fr);
      overflow: hidden;
    }
    .designer-workspace > * { grid-column: auto; height: 100%; max-height: 100%; overflow: hidden; }
    .canvas-panel { min-height: 0; }
    .budget-panel { height: 100%; overflow-y: auto !important; }
    .budget-panel > .flex-1 { flex-shrink: 0; min-height: 220px; }
  }

  /* 手机：严格单列、无横向滚动；5 个参数压缩成 2 行，为画布释放更多垂直空间。 */
  @media (max-width: 1023px) {
    .draw-main {
      width: 100% !important;
      max-width: 100vw !important;
      padding: .35rem .45rem .6rem !important;
      overflow-x: hidden !important;
    }
    .designer-workspace {
      width: 100% !important;
      max-width: 100% !important;
      display: flex !important;
      flex-direction: column;
      flex: none;
      height: auto;
      gap: .45rem !important;
      overflow: visible;
    }
    .property-panel {
      order: 1;
      width: 100% !important;
      height: auto !important;
      flex: none;
      padding: .5rem !important;
      overflow: hidden !important;
      border-radius: .9rem !important;
    }
    .canvas-panel {
      order: 2;
      width: 100% !important;
      /* Initial visible space; same-width mobile browser chrome changes keep it stable. */
      flex: none;
      height: var(--drawing-panel-height, calc(100svh - 260px)) !important;
      min-height: 0 !important;
      max-height: var(--drawing-panel-height, calc(100svh - 260px)) !important;
      border-radius: .9rem !important;
      padding: .4rem !important;
      overflow: hidden !important;
    }
    .budget-panel {
      order: 3;
      width: 100% !important;
      flex: none;
      height: 300px !important;
      min-height: 300px !important;
      max-height: 300px !important;
      border-radius: .9rem !important;
      padding: .65rem !important;
      overflow: hidden !important;
    }
    .property-heading { display: none; }

    /* 两行等分布局：第一行 Material / Height / Color 各 1/3；第二行 Style / Shared Cost 各 1/2。 */
    #style-fieldset {
      display: grid !important;
      grid-template-columns: repeat(12, minmax(0, 1fr));
      grid-auto-flow: row;
      gap: .3rem .32rem !important;
      overflow: hidden !important;
      padding: 0 !important;
    }
    #style-fieldset > * { margin-top: 0 !important; }
    .param-type { grid-column: span 4; }
    .param-pair { display: contents; }
    .param-pair > .param-block:first-child { grid-column: span 4; }
    .param-pair > .param-block:last-child { grid-column: span 4; }
    .param-style { grid-column: span 6; }
    .param-shared-cost { grid-column: span 6; min-width: 0; }
    .param-block { min-width: 0; }
    .param-block label {
      display: block;
      max-width: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 9px !important;
      margin-bottom: 2px !important;
      line-height: 1.15;
    }
    .param-block select {
      width: 100%;
      max-width: 100%;
      min-width: 0;
      min-height: 30px;
      height: 30px;
      padding: .18rem 1.35rem .18rem .42rem !important;
      font-size: 10px !important;
      border-radius: .58rem !important;
      text-overflow: ellipsis;
    }
    .shared-cost-heading {
      max-width: 100%;
      margin: 0 0 2px !important;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 9px !important;
      line-height: 1.15;
    }
    .param-shared-cost .shared-cost-control {
      display: flex !important;
      align-items: center !important;
      gap: .42rem !important;
      width: 100%;
      max-width: 100%;
      min-height: 30px;
      height: 30px;
      margin: 0 !important;
      padding: .2rem .45rem !important;
      overflow: hidden !important;
      white-space: normal !important;
      border-radius: .58rem !important;
      text-overflow: clip !important;
    }
    .param-shared-cost .shared-cost-checkbox { width: 16px; height: 16px; border-radius: .3rem; }
    .param-shared-cost .shared-cost-option {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 10px !important;
      line-height: 1.1;
    }
    .param-shared-cost .shared-cost-help { display: none !important; }
    .param-shared-cost .shared-cost-copy { min-width: 0; }
    .desktop-option-cards { display: none !important; }
    .mobile-option-select { display: block !important; }
    .canvas-hint { font-size: 9px !important; line-height: 1.2; min-width: 0; }
    #canvas-wrapper { --canvas-tools-top:6px; --canvas-tools-edge:6px; --canvas-tools-height:30px; }
    .canvas-view-controls { gap: 3px; }
    .canvas-history-btn { width: 30px; min-width: 30px; height: 30px; font-size: 18px; }
    #view3d-btn { min-height: 30px; height: 30px; padding: 0 8px !important; font-size: 9px; }
    #view3d-label { display: inline !important; font-size: 9px; white-space: nowrap; }
    #segment-list { flex: 1 1 0%; min-height: 0 !important; max-height: none !important; overflow-x: hidden !important; }
    /* 手机端浮层必须让位给长度标签和拖动区域：视觉按钮压到 28–30px，并通过空隙/位置避让保持可点。 */
    .draw-toggle-btn { left: 6px; top: 6px; min-height: 28px; height: 28px; padding: 0 7px; font-size: 9px; }
    .house-toggle-btn { top: 40px; }
    .selection-delete-btn { min-height: 30px; height: 30px; width: auto; padding: 0 7px; font-size: 9.5px; border-width: 1px; }
    .insert-gate-btn { min-height: 28px; height: 28px; padding: 0 7px; font-size: 9px; border-width: 1.5px; box-shadow: 0 2px 7px rgba(5,150,105,.17), 0 1px 2px rgba(15,23,42,.10); }
    .fence-action-toolbar { gap: 3px; padding: 3px; border-radius: 11px; }
    .fence-action-toolbar .insert-gate-btn, .fence-action-toolbar .mirror-fence-btn, .fence-action-toolbar .selection-delete-btn { min-height: 30px; height: 30px; padding: 0 7px; font-size: 9.5px; border-width: 1px; box-shadow: none; }
    .side-gate-btn { box-shadow: 0 3px 10px rgba(2,132,199,.18), 0 1px 3px rgba(15,23,42,.10); }
    .mirror-fence-btn { min-height: 28px; height: 28px; padding: 0 8px; font-size: 9px; border-width: 1.5px; }
    .house-toggle-btn { min-height: 28px; height: 28px; padding: 0 7px; font-size: 9px; }
    .fence-dimension-label { min-width: 42px; padding: 3px 5px; font-size: 9px; }
    .material-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .material-stat:first-child { grid-column: span 2; }
    #length-popup { max-width: calc(100% - 12px); padding: .5rem !important; gap: .35rem !important; }
    #popup-len-input { width: 4.5rem !important; min-height: 36px; font-size: 16px !important; }

    /* 共享 header 在 draw 页手机端只保留公司入口 + 语言切换，防止右侧动作按钮撑出屏幕。 */
    #site-header header.navbar {
      width: 100% !important;
      max-width: 100vw !important;
      min-width: 0 !important;
      padding-left: .5rem !important;
      padding-right: .5rem !important;
      gap: .2rem !important;
      overflow: hidden !important;
    }
    #site-header header.navbar > .flex-1 {
      flex: 1 1 0% !important;
      min-width: 0 !important;
      margin-right: .2rem !important;
      overflow: hidden !important;
    }
    #site-header header.navbar > .flex-none {
      flex: 0 0 auto !important;
      min-width: 0 !important;
      gap: .2rem !important;
    }
    #site-header header.navbar > .flex-none > a { display: none !important; }
    #site-header header.navbar .join { flex-wrap: nowrap !important; }
    #site-header header.navbar .join .btn {
      min-height: 1.7rem !important;
      height: 1.7rem !important;
      padding-left: .38rem !important;
      padding-right: .38rem !important;
      font-size: 10px !important;
    }
  }

  /* Short landscape screens put parameters beside the canvas, not above it. */
  @media (min-width: 640px) and (max-width: 1023px) and (orientation: landscape) and (max-height: 550px) {
    .designer-workspace {
      display: grid !important;
      grid-template-columns: 190px minmax(0, 1fr);
      grid-template-rows: var(--drawing-panel-height, calc(100svh - 150px)) 300px;
    }
    .property-panel { height: 100% !important; min-height: 0 !important; }
    #style-fieldset { display: block !important; overflow-y: auto !important; }
    #style-fieldset > * { margin-bottom: .4rem; }
    .param-pair { display: grid; grid-template-columns: 1fr 1fr; }
    .param-pair > .param-block { grid-column: auto !important; }
    .budget-panel { grid-column: 1 / -1; }
  }

  /* Use actual canvas width: desktop sidebars can also leave a narrow viewport. */
  @container (max-width:420px) {
    .three-edit-modes { width:82px; height:30px; }
    .three-edit-modes button { flex:1 1 0; min-width:0; padding:0 3px; font-size:10px; }
    .in-3d .canvas-view-controls { gap:3px; align-items:flex-start; }
    .in-3d .canvas-history-btn { width:28px; min-width:28px; height:30px; font-size:17px; }
    .in-3d #view3d-btn { width:36px; min-height:30px; height:30px; padding:0 !important; gap:0; font-size:0; }
    .in-3d #view3d-label { display:none !important; }
    .in-3d #view3d-btn::after { content:'2D'; font-size:11px; }
  }
  @media print {
    #site-header, .admin-editor-bar, .draw-main, .admin-material-actions, body > footer { display: none !important; }
    body { background: #fff !important; }
    .admin-materials { width: 100% !important; margin: 0 !important; border: 0 !important; box-shadow: none !important; }
    .material-group { break-inside: avoid; }
  }


  @media (max-width: 380px) {
    .draw-main { padding-left: .3rem !important; padding-right: .3rem !important; }
    #site-header header.navbar .join .btn { padding-left: .3rem !important; padding-right: .3rem !important; font-size: 9px !important; }
  }

  @media (min-width: 1024px) {
    .mobile-option-select { display: none !important; }
  }

/* v18: 删除动作并入上下文工具条，只保留红色 × 图标，减少手机横向占用。 */
.fence-action-toolbar .selection-delete-btn {
  width: 34px !important;
  min-width: 34px !important;
  padding-left: 0 !important;
  padding-right: 0 !important;
  font-size: 20px !important;
  line-height: 1 !important;
}
@media (max-width: 767px) {
  .fence-action-toolbar .selection-delete-btn {
    width: 30px !important;
    min-width: 30px !important;
    font-size: 18px !important;
  }
}
