/* M2GEO scoped for WordPress embed */
#m2geo-app-wrapper { --m2geo-header-h: 64px; position: relative; z-index: 1; isolation: isolate; display: flex; flex-direction: column; width: 100%; max-width: 100%; background: #030712; color: #f3f4f6; }
#m2geo-app-wrapper .m2geo-overlay { position: absolute; }
@media (max-width: 1023px) {
  #m2geo-app-wrapper .side-panel { position: absolute; height: calc(100% - var(--m2geo-header-h) - var(--m2geo-dock-space)); max-height: calc(100% - var(--m2geo-header-h) - var(--m2geo-dock-space)); }
}

        :root {
            --m2geo-header-h: 64px;
            --m2geo-scroll-track: #0b1220;
            --m2geo-scroll-thumb: #1e40af;
            --m2geo-scroll-thumb-hover: #3b82f6;
            --m2geo-safe-bottom: env(safe-area-inset-bottom, 0px);
            --m2geo-browser-bottom: 0px;
            --m2geo-dock-space: 96px;
        }

        #m2geo-app-wrapper { height: calc(100dvh - var(--wp-admin--admin-bar--height, 0px)); min-height: 560px; }
        #m2geo-app-wrapper { overflow: hidden; }

        #m2geo-app-wrapper, #m2geo-app-wrapper * {
            scrollbar-width: thin;
            scrollbar-color: var(--m2geo-scroll-thumb) var(--m2geo-scroll-track);
        }
        #m2geo-app-wrapper::-webkit-scrollbar, #m2geo-app-wrapper *::-webkit-scrollbar { width: 8px; height: 8px; }
        #m2geo-app-wrapper::-webkit-scrollbar-track, #m2geo-app-wrapper *::-webkit-scrollbar-track { background: var(--m2geo-scroll-track); border-radius: 4px; }
        #m2geo-app-wrapper::-webkit-scrollbar-thumb, #m2geo-app-wrapper *::-webkit-scrollbar-thumb { background: var(--m2geo-scroll-thumb); border-radius: 4px; }
        #m2geo-app-wrapper::-webkit-scrollbar-thumb:hover, #m2geo-app-wrapper *::-webkit-scrollbar-thumb:hover { background: var(--m2geo-scroll-thumb-hover); }

        .app-main   { flex: 1 1 auto; min-height: 0; overflow: hidden; }
        .side-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; overflow: hidden; width: 20rem; }

        .panel-scroll {
            flex: 1 1 auto;
            min-height: 0;
            max-height: calc(100vh - var(--m2geo-header-h));
            overflow-y: auto;
            overflow-x: hidden;
            overscroll-behavior: contain;
            scrollbar-gutter: stable;
            -webkit-overflow-scrolling: touch;
            touch-action: pan-y;
            padding-bottom: 24px;
        }

        #sec-bom      { max-height: none !important; min-height: 0 !important; }
        #bom-list     { overflow: visible !important; }
        #sec-docs     { max-height: none !important; overflow: visible !important; }

        .section-head { position: sticky; top: 0; z-index: 5; background: #111827; min-height: 44px; }

        .m2geo-nav-btn, .m2geo-drawer-close {
            display: none;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            border-radius: 10px;
            border: 1px solid rgba(30, 64, 175, 0.45);
            background: #1f2937;
            color: #93c5fd;
            flex-shrink: 0;
        }
        .m2geo-overlay {
            display: none;
            position: fixed;
            top: var(--m2geo-header-h);
            left: 0;
            right: 0;
            bottom: 0;
            background: rgba(2, 6, 23, 0.55);
            z-index: 40;
            pointer-events: none;
        }
        .m2geo-overlay.is-visible { display: block; pointer-events: auto; }
        #canvas-container, #canvas-container canvas { touch-action: none; }
        #viewport-stage { min-width: 0; min-height: 0; z-index: 1; }
        #app-header { z-index: 70; }
        #assembly-dock { z-index: 30; bottom: calc(12px + var(--m2geo-safe-bottom) + var(--m2geo-browser-bottom)); }
        #panel-left, #panel-right { pointer-events: none; visibility: hidden; z-index: 60; }
        #panel-left.is-open, #panel-right.is-open { pointer-events: auto; visibility: visible; }

        @media (min-width: 1024px) {
            #panel-left, #panel-right { pointer-events: auto; visibility: visible; }
        }

        @media (max-width: 1599px) and (min-width: 1280px) {
            .side-panel { width: 17.5rem; }
        }
        @media (max-width: 1279px) and (min-width: 1024px) {
            .side-panel { width: 15.5rem; }
            #app-header { padding-left: 12px; padding-right: 12px; }
            #assembly-dock { width: min(92%, 28rem); padding: 12px 14px; }
        }

        @media (max-width: 1023px) {
            #m2geo-app-wrapper { overflow: hidden; }
            .app-main { flex-direction: row; overflow: hidden; }
            .m2geo-nav-btn, .m2geo-drawer-close { display: inline-flex; }
            .side-panel {
                position: fixed;
                top: var(--m2geo-header-h);
                bottom: auto;
                width: min(20rem, 86vw);
                height: calc(100dvh - var(--m2geo-header-h) - var(--m2geo-dock-space));
                max-height: calc(100dvh - var(--m2geo-header-h) - var(--m2geo-dock-space));
                z-index: 60;
                overflow: hidden;
                box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
                transition: transform 0.25s ease;
                touch-action: pan-y;
            }
            #panel-left { left: 0; transform: translateX(-110%); }
            #panel-right { right: 0; left: auto; border-left-width: 1px; transform: translateX(110%); }
            #panel-left.is-open, #panel-right.is-open { transform: translateX(0); }
            .panel-scroll {
                flex: 1 1 0%;
                min-height: 0;
                height: auto;
                max-height: none;
                overflow-y: scroll;
                -webkit-overflow-scrolling: touch;
                touch-action: pan-y;
                padding-bottom: 24px;
            }
            #canvas-container { height: auto; min-height: 42vh; }
            #view-toolbar { top: 8px; right: 8px; left: auto; width: auto; max-width: calc(100% - 16px); }
            #assembly-dock { width: calc(100% - 16px); max-width: none; padding: 10px 12px; gap: 8px; border-radius: 14px; }
            .m2geo-status-label { display: none; }
        }

        @media (max-width: 767px) {
            #app-header { padding: 8px 10px; gap: 8px; }
            #app-header h1 { font-size: 13px; }
            #app-header h1 span, #app-header p { display: none; }
            #assembly-dock .m2geo-assembly-copy { display: none; }
            #view-toolbar { padding: 4px; gap: 4px; }
            #view-toolbar button { padding: 8px; min-width: 40px; min-height: 40px; }
            .side-panel { width: min(20rem, calc(100vw - 12px)); }
        }

        @media (max-width: 1023px) and (orientation: landscape) {
            #canvas-container { min-height: 0; }
            .side-panel { width: min(18rem, 58vw); }
            #assembly-dock { max-width: 22rem; left: auto; right: 8px; transform: none; width: auto; }
        }

        @media (max-height: 420px) {
            #assembly-dock { padding: 6px 10px; }
            #assembly-dock .space-y-1 { display: none; }
        }

        /* ИСПРАВЛЕНИЕ ПЕЧАТИ: Жесткие правила для корректной генерации PDF (решает проблему белого листа) */
        @media print {
            html, body {
                overflow: visible !important;
                height: auto !important;
                min-height: auto !important;
                display: block !important;
                background-color: #ffffff !important;
                color: #000000 !important;
            }
            #m2geo-app-wrapper > *:not(#print-layer) {
                display: none !important;
            }
            #print-layer {
                display: block !important;
                position: relative !important;
                width: 100%;
                background: white;
            }
            @page {
                margin: 1cm;
            }
        }
    