﻿/* ============================================================
   MOBILE STYLES ג€” max-width: 768px
   ============================================================ */
@media (max-width: 768px) {

    /* --- Layout: hide desktop sidebars, full-screen canvas --- */
    body {
        display: block;
        height: 100dvh;
        overflow: hidden;
    }

    #sidebar,
    #left-sidebar {
        display: none !important;
    }

    #top-bar {
        display: none !important;
    }

    /* --- Prevent black flash on touch (WebGL canvas tap highlight) --- */
    #canvas-container,
    #canvas-container canvas {
        -webkit-tap-highlight-color: transparent !important;
        touch-action: pan-x pan-y !important;
        -webkit-touch-callout: none !important;
        user-select: none !important;
        -webkit-user-select: none !important;
    }

    /* --- Mobile top bar: view mode switcher --- */
    #mobile-top-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 44px;
        background: rgba(255,255,255,0.97);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
        border-bottom: 1px solid var(--border);
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 0 12px;
        z-index: 500;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    }
    .mobile-view-tab {
        flex: 1;
        height: 32px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg-light);
        color: var(--text-light);
        font-size: 0.72rem;
        font-weight: 600;
        font-family: inherit;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        transition: all 0.2s;
        -webkit-tap-highlight-color: transparent;
    }
    .mobile-view-tab i { font-size: 0.8rem; }
    .mobile-view-tab.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }

    #canvas-container {
        position: fixed;
        top: 88px;
        left: 0;
        width: 100vw;
        height: calc(100dvh - 88px - 60px);
        z-index: 1;
        cursor: default !important;
    }

    /* Hide desktop floating toolbar and quick-calc on mobile */
    #bottom-floating-toolbar,
    #btn-quick-calc {
        display: none !important;
        opacity: 0 !important;
        visibility: hidden !important;
        pointer-events: none !important;
    }

    /* Column quick-edit: hidden on mobile ג€” replaced by #mobile-col-bar */
    #column-quick-edit {
        display: none !important;
    }

    /* ===== MOBILE COLUMN BAR ===== */
    /* Horizontal strip above the bottom nav, shown when cell panels are open */
    #mobile-col-bar {
        position: fixed;
        bottom: calc(60px + env(safe-area-inset-bottom));
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid var(--border);
        box-shadow: 0 -3px 16px rgba(0,0,0,0.10);
        z-index: 491;
        display: flex;
        flex-direction: column;
        padding: 0 0 14px 0;
        transform: translateY(100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #mobile-col-bar.open {
        transform: translateY(0);
    }

    /* Each row inside the bar */
    .mcb-row {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        padding: 0 6px;
        gap: 2px;
        height: 54px;
    }
    /* Row 2 separator line */
    .mcb-row2-sep {
        display: none; /* replaced by border-top on row2 */
    }
    .mcb-row2 {
        border-top: 1px solid var(--border);
        background: #fafafa;
        height: 46px;
    }

    /* Checkbox row inside bar */
    .mcb-checkbox-row {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 5px;
        font-size: 0.7rem;
        font-weight: 600;
        color: var(--text-dark);
        cursor: pointer;
        flex-shrink: 0;
    }
    .mcb-checkbox-row input[type="checkbox"] {
        width: 16px;
        height: 16px;
        cursor: pointer;
        accent-color: var(--accent);
    }

    /* Group: label + stepper */
    .mcb-group {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 1px;
        flex: 1;
        min-width: 0;
    }
    .mcb-label {
        font-size: 0.55rem;
        font-weight: 700;
        color: var(--text-light);
        text-transform: uppercase;
        letter-spacing: 0.3px;
        white-space: nowrap;
    }
    .mcb-stepper {
        display: flex;
        flex-direction: row;
        align-items: center;
        gap: 2px;
    }
    .mcb-btn {
        width: 26px;
        height: 26px;
        border-radius: 6px;
        border: 1px solid var(--border);
        background: var(--bg-light);
        font-size: 0.75rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dark);
        flex-shrink: 0;
        font-family: inherit;
        transition: all 0.15s;
    }
    .mcb-btn:active { transform: scale(0.88); background: var(--highlight); }
    .mcb-val {
        width: 34px;
        border: 1px solid var(--border);
        border-radius: 5px;
        background: var(--bg-light);
        text-align: center;
        font-size: 0.8rem;
        font-weight: 700;
        color: var(--primary);
        padding: 2px 1px;
        -moz-appearance: textfield;
        font-family: inherit;
    }
    .mcb-val::-webkit-inner-spin-button,
    .mcb-val::-webkit-outer-spin-button { -webkit-appearance: none; }

    /* Vertical divider between groups */
    .mcb-divider {
        width: 1px;
        height: 36px;
        background: var(--border);
        flex-shrink: 0;
    }

    /* No-plinth toggle button */
    .mcb-toggle {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 4px 6px;
        border: 1.5px solid var(--border);
        border-radius: 8px;
        background: var(--bg-light);
        cursor: pointer;
        font-size: 0.55rem;
        font-weight: 700;
        color: var(--text-dark);
        font-family: inherit;
        white-space: nowrap;
        flex-shrink: 0;
        transition: all 0.18s;
        min-width: 44px;
        height: 40px;
    }
    .mcb-toggle i { font-size: 0.9rem; color: var(--text-light); }
    .mcb-toggle.active {
        border-color: var(--accent);
        background: #fffbeb;
        color: var(--primary);
    }
    .mcb-toggle.active i { color: var(--accent); }
    .mcb-toggle:active { transform: scale(0.92); }

    /* --- Mobile Overlay --- */
    #mobile-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.45);
        z-index: 400;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }
    #mobile-overlay.active { display: block; }

    /* --- Bottom Navigation Bar --- */
    #mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: calc(60px + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, 0.97);
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.08);
        display: flex;
        align-items: stretch;
        justify-content: space-around;
        z-index: 500;
    }

    .mobile-nav-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        background: transparent !important;
        border: none !important;
        padding: 6px 4px;
        font-size: 0.62rem;
        font-weight: 600;
        color: #64748b !important;
        cursor: pointer;
        transition: color 0.2s;
        font-family: inherit;
        position: relative;
        -webkit-tap-highlight-color: transparent;
        text-decoration: none;
    }
    .mobile-nav-btn span {
        color: #64748b !important;
        font-size: 0.62rem;
        font-weight: 600;
        line-height: 1.2;
        display: block;
    }
    .mobile-nav-btn i {
        font-size: 1.25rem;
        color: #64748b !important;
        transition: transform 0.2s;
        display: block;
    }
    .mobile-nav-btn.active {
        color: var(--secondary) !important;
    }
    .mobile-nav-btn.active span {
        color: var(--secondary) !important;
    }
    .mobile-nav-btn.active i {
        color: var(--secondary) !important;
        transform: translateY(-2px);
    }
    .mobile-nav-btn.active::after {
        content: '';
        position: absolute;
        top: 0;
        left: 20%;
        right: 20%;
        height: 3px;
        background: var(--secondary);
        border-radius: 0 0 4px 4px;
    }

    /* Cart badge on nav */
    .mobile-cart-badge {
        position: absolute;
        top: 6px;
        right: calc(50% - 18px);
        background: var(--danger);
        color: white;
        font-size: 0.6rem;
        font-weight: 800;
        min-width: 16px;
        height: 16px;
        border-radius: 8px;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 4px;
        line-height: 1;
    }

    /* --- Bottom Sheet Panels --- */
    .mobile-panel {
        position: fixed;
        bottom: calc(60px + env(safe-area-inset-bottom));
        left: 0;
        right: 0;
        max-height: 80dvh;
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.15);
        z-index: 450;
        display: flex;
        flex-direction: column;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }
    .mobile-panel.open {
        transform: translateY(0);
    }

    .mobile-panel-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 16px 20px 12px;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }
    .mobile-panel-header h3 {
        margin: 0;
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--primary);
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .mobile-panel-close {
        background: var(--bg-light);
        border: none;
        width: 32px;
        height: 32px;
        border-radius: 50%;
        font-size: 1rem;
        cursor: pointer;
        color: var(--text-light);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background 0.2s, color 0.2s;
    }
    .mobile-panel-close:hover { background: #fee2e2; color: var(--danger); }

    .mobile-panel-body {
        overflow-y: auto;
        padding: 16px 20px;
        flex: 1;
        -webkit-overflow-scrolling: touch;
    }

    /* Drag indicator pill at top of sheets */
    .mobile-panel::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 0;
        flex-shrink: 0;
    }

    /* --- Mobile View Buttons --- */
    .mobile-view-btns {
        display: flex;
        gap: 8px;
        margin-bottom: 16px;
    }
    .mobile-view-btns .view-btn {
        flex: 1;
        justify-content: center;
        padding: 10px 6px;
        font-size: 0.82rem;
        border: 1px solid var(--border);
        border-radius: 10px;
    }
    .mobile-view-btns .view-btn.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }

    /* --- Mobile Action Row --- */
    .mobile-action-row {
        display: flex;
        gap: 8px;
        margin-bottom: 12px;
    }
    .mobile-action-btn {
        flex: 1;
        padding: 12px 8px;
        border: 1.5px solid var(--border);
        border-radius: var(--radius-sm);
        background: var(--bg-light);
        font-size: 0.84rem;
        font-weight: 700;
        color: var(--text-dark);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        font-family: inherit;
        transition: all 200ms cubic-bezier(0.4,0,0.2,1);
        position: relative; overflow: hidden;
    }
    .mobile-action-btn:hover {
        border-color: var(--secondary);
        color: var(--secondary);
        background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
        transform: translateY(-2px);
        box-shadow: 0 4px 12px rgba(37,99,235,0.2);
    }
    .mobile-action-btn:active { transform: scale(0.97); }
    .mobile-action-btn.danger {
        border-color: rgba(239,68,68,0.4);
        color: var(--danger);
        background: linear-gradient(135deg, #fff1f2 0%, #fee2e2 100%);
    }
    .mobile-action-btn.danger:hover {
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        color: white; border-color: transparent;
        box-shadow: 0 4px 12px rgba(239,68,68,0.3);
    }

    /* --- Mobile Checkbox Row --- */
    .mobile-checkbox-row {
        display: flex;
        align-items: center;
        gap: 10px;
        font-size: 0.9rem;
        font-weight: 500;
        color: var(--text-dark);
        cursor: pointer;
        padding: 10px 0;
    }
    .mobile-checkbox-row input[type="checkbox"] {
        width: 20px;
        height: 20px;
        accent-color: var(--secondary);
        cursor: pointer;
        flex-shrink: 0;
    }

    /* --- Mobile Dimension Row (stepper) --- */
    .mobile-dim-row {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 10px 0;
        border-bottom: 1px solid var(--bg-main);
    }
    .mobile-dim-row:last-child { border-bottom: none; }
    .mobile-dim-label {
        font-size: 0.9rem;
        font-weight: 600;
        color: var(--text-dark);
        flex: 1;
    }
    .mobile-stepper {
        display: flex;
        align-items: center;
        gap: 8px;
        background: var(--bg-light);
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 4px 6px;
    }
    .mobile-stepper button {
        width: 34px;
        height: 34px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: white;
        font-size: 1.1rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dark);
        transition: all 0.2s;
        flex-shrink: 0;
    }
    .mobile-stepper button:hover { border-color: var(--secondary); color: var(--secondary); background: var(--highlight); }
    .mobile-stepper button:active { transform: scale(0.92); }
    .mobile-stepper input[type="number"] {
        width: 52px;
        border: none;
        background: transparent;
        text-align: center;
        font-size: 1rem;
        font-weight: 700;
        color: var(--primary);
        outline: none;
        -moz-appearance: textfield;
        font-family: inherit;
    }
    .mobile-stepper input[type="number"]::-webkit-outer-spin-button,
    .mobile-stepper input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
    .mobile-stepper span.unit {
        font-size: 0.78rem;
        color: var(--text-light);
        font-weight: 500;
    }

    /* --- Mobile Section Title --- */
    .mobile-section-title {
        font-size: 0.78rem;
        font-weight: 700;
        color: var(--text-light);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin: 14px 0 8px;
    }

    /* --- Cell Sheet --- */
    #mobile-cell-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
        z-index: 490;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
    }
    #mobile-cell-sheet.open {
        transform: translateY(0);
    }
    #mobile-cell-sheet::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 0;
    }

    /* --- Col Sheet --- */
    #mobile-col-sheet {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        max-height: calc(100dvh - 88px);
        background: white;
        border-radius: 20px 20px 0 0;
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
        z-index: 490;
        transform: translateY(100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }
    #mobile-col-sheet.open {
        transform: translateY(0);
    }
    #mobile-col-sheet::before {
        content: '';
        display: block;
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 0;
        flex-shrink: 0;
    }
    /* Scrollable inner body of col sheet */
    #mobile-col-sheet > div:not(.mobile-sheet-handle):not(.mobile-panel-header) {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }

    /* --- Mobile Cell Buttons Grid --- */
    .mobile-cell-btns {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
        margin-bottom: 10px;
    }
    .mobile-cell-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 10px 4px;
        border: 2px solid var(--border);
        border-radius: 12px;
        background: var(--bg-light);
        cursor: pointer;
        font-size: 0.68rem;
        font-weight: 600;
        color: var(--text-dark);
        font-family: inherit;
        transition: all 0.2s;
        min-height: 64px;
    }
    .mobile-cell-btn i { font-size: 1.2rem; color: var(--text-light); }
    .mobile-cell-btn:hover { border-color: var(--secondary); background: var(--highlight); }
    .mobile-cell-btn:hover i { color: var(--secondary); }
    .mobile-cell-btn.active {
        border-color: var(--secondary);
        background: #eff6ff;
        color: var(--primary);
    }
    .mobile-cell-btn.active i { color: var(--secondary); }

    /* --- Topbar price + add widget (replaces old FAB) --- */
    #mobile-topbar-price {
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
        flex-shrink: 0 !important;
        background: #f0fdf4 !important;
        border: 1px solid #86efac !important;
        border-radius: 8px !important;
        padding: 0 8px 0 4px !important;
        height: 32px !important;
    }
    #mobile-topbar-price-val {
        font-size: 0.78rem !important;
        font-weight: 800 !important;
        color: #16a34a !important;
        white-space: nowrap !important;
    }
    #mobile-topbar-add-btn {
        background: #16a34a !important;
        color: white !important;
        border: none !important;
        border-radius: 6px !important;
        width: 52px !important;
        height: 24px !important;
        font-size: 0.8rem !important;
        cursor: pointer !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        font-family: inherit !important;
        gap: 4px !important;
    }
    #mobile-topbar-add-btn:active { transform: scale(0.93) !important; }

    /* --- Materials grid: 5 columns on mobile --- */
    #mobile-panel-materials .materials-flat-grid {
        display: grid !important;
        grid-template-columns: repeat(5, 1fr) !important;
        gap: 8px !important;
    }
    #mobile-panel-materials .mat-item {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        gap: 3px !important;
    }
    #mobile-panel-materials .material-btn {
        width: 44px !important;
        height: 44px !important;
        border-radius: 8px !important;
    }
    #mobile-panel-materials .mat-item span {
        font-size: 0.65rem !important;
        text-align: center !important;
        color: var(--text-light) !important;
        line-height: 1.2 !important;
    }

    /* --- Drag handles: smaller on mobile (cabinet is smaller on screen) --- */
    .drag-handle {
        width: 22px !important;
        height: 22px !important;
        border-width: 1.5px !important;
        font-size: 9px !important;
    }
    .drag-handle::before, .drag-handle::after {
        font-size: 9px !important;
    }
    .drag-tooltip { display: none !important; }

    /* --- Plus buttons: hidden on mobile (dim-container is the tap target instead) --- */
    .plus-btn {
        display: none !important;
    }

    /* --- Dim containers: tappable on mobile --- */
    .dim-container {
        cursor: pointer !important;
        touch-action: manipulation !important;
        -webkit-tap-highlight-color: rgba(37,99,235,0.15) !important;
        min-width: 44px !important;
        min-height: 36px !important;
        padding: 4px 8px !important;
        border-radius: 8px !important;
        background: rgba(255,255,255,0.92) !important;
        border: 1.5px solid var(--secondary) !important;
        box-shadow: 0 1px 4px rgba(37,99,235,0.15) !important;
        display: flex !important;
        align-items: center !important;
        gap: 4px !important;
    }
    .dim-container:active {
        background: rgba(59,130,246,0.12) !important;
        transform: scale(0.96) !important;
    }
    .dim-input {
        pointer-events: none !important;
        background: transparent !important;
        border: none !important;
        font-weight: 700 !important;
        color: var(--primary) !important;
        width: 28px !important;
        font-size: 12px !important;
        text-align: center !important;
    }
    .dim-suffix {
        color: #3b82f6 !important;
        font-size: 11px !important;
    }

    /* --- Slider buttons larger on mobile --- */
    .slider-btn {
        width: 44px !important;
        height: 44px !important;
        border-radius: 10px !important;
    }

    /* --- Materials grid: larger touch targets --- */
    .material-btn {
        width: 52px !important;
        height: 52px !important;
    }

    /* --- Quick calc modal: full-screen on mobile --- */
    #quick-calc-modal {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
        z-index: 700 !important;
        align-items: flex-end !important;
    }
    .qc-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        padding: 20px !important;
        max-height: 85dvh;
        overflow-y: auto;
    }

    /* --- Order modal: full-screen on mobile --- */
    #order-modal {
        align-items: flex-end !important;
    }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0 !important;
        max-height: 92dvh !important;
        padding: 20px !important;
    }

    /* --- Dim containers: smaller on mobile to match smaller cabinet --- */
    .dim-container {
        padding: 3px 6px !important;
        font-size: 11px !important;
    }
    .dim-input {
        width: 32px !important;
        font-size: 11px !important;
    }
    .dim-suffix {
        font-size: 10px !important;
    }

    /* --- editor-select: larger on mobile --- */
    .editor-select {
        padding: 12px 35px 12px 12px !important;
        font-size: 1rem !important;
    }

    /* --- Hide desktop-only elements on mobile --- */
    .hide-on-mobile { display: none !important; }

    /* --- Show mobile-only elements --- */
    .show-on-mobile { display: block !important; }

    /* --- Ensure mobile panels are hidden by default (not open) --- */
    .mobile-panel:not(.open) { pointer-events: none; }
    #mobile-cell-sheet:not(.open) { pointer-events: none; }
    #mobile-col-sheet:not(.open) { pointer-events: none; }
    #mobile-cell-right-panel:not(.open) { pointer-events: none; }
    #mobile-cell-left-panel:not(.open) { pointer-events: none; }

    /* --- Mobile panel body scrollbar --- */
    .mobile-panel-body::-webkit-scrollbar { width: 3px; }
    .mobile-panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

    /* --- Columns value display on mobile --- */
    #mobile-val-columns {
        font-size: 1.1rem;
        font-weight: 800;
        color: var(--primary);
        min-width: 28px;
        text-align: center;
    }

    /* --- Mobile handle type select --- */
    #mobile-inp-handle-type {
        width: 100%;
        margin-bottom: 10px;
    }

    /* --- Prevent body scroll when panel open --- */
    body.mobile-panel-open {
        overflow: hidden;
    }

    /* --- Smooth canvas resize --- */
    canvas {
        display: block;
        width: 100% !important;
        height: 100% !important;
    }

    /* --- Mobile view mode buttons (in view panel) --- */
    .mobile-view-mode-btn {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 10px 6px;
        border: 1px solid var(--border);
        border-radius: 10px;
        background: var(--bg-light);
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-dark);
        cursor: pointer;
        font-family: inherit;
        transition: all 0.2s;
        min-height: 60px;
    }
    .mobile-view-mode-btn i { font-size: 1.2rem; color: var(--text-light); }
    .mobile-view-mode-btn.active {
        background: var(--primary);
        color: white;
        border-color: var(--primary);
    }
    .mobile-view-mode-btn.active i { color: white; }
    .mobile-view-btns {
        display: flex;
        gap: 8px;
        margin-bottom: 4px;
    }

    /* --- Mobile label (small label above select) --- */
    .mobile-label {
        display: block;
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-light);
        margin-bottom: 4px;
    }

    /* --- Mobile panel divider --- */
    .mobile-panel-divider {
        height: 1px;
        background: var(--border);
        margin: 12px 0;
    }

    /* --- Mobile sheet handle (drag pill at top of sheets) --- */
    .mobile-sheet-handle {
        width: 40px;
        height: 4px;
        background: var(--border);
        border-radius: 2px;
        margin: 10px auto 0;
        flex-shrink: 0;
    }

    /* --- Mobile stepper value input/span --- */
    .mobile-stepper-val {
        min-width: 36px;
        text-align: center;
        font-size: 1rem;
        font-weight: 700;
        color: var(--primary);
        background: transparent;
        border: none;
        outline: none;
        -moz-appearance: textfield;
        font-family: inherit;
    }
    .mobile-stepper-val::-webkit-outer-spin-button,
    .mobile-stepper-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

    /* --- Mobile stepper button --- */
    .mobile-stepper-btn {
        width: 34px;
        height: 34px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: white;
        font-size: 0.9rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dark);
        transition: all 0.2s;
        flex-shrink: 0;
    }
    .mobile-stepper-btn:hover { border-color: var(--secondary); color: var(--secondary); background: var(--highlight); }
    .mobile-stepper-btn:active { transform: scale(0.92); }

    /* ===== MOBILE CELL SIDE PANELS ===== */
    #mobile-cell-right-panel,
    #mobile-cell-left-panel {
        position: fixed;
        top: 88px;
        bottom: calc(60px + env(safe-area-inset-bottom));
        width: 63px;
        background: white;
        z-index: 490;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 8px 4px 16px;
        gap: 4px;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }
    #mobile-cell-right-panel {
        right: 0;
        border-radius: 16px 0 0 16px;
        transform: translateX(100%);
        border-left: 1px solid var(--border);
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
    }
    #mobile-cell-left-panel {
        left: 0;
        border-radius: 0 16px 16px 0;
        transform: translateX(-100%);
        border-right: 1px solid var(--border);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
    }
    #mobile-cell-right-panel.open {
        transform: translateX(0);
    }
    #mobile-cell-left-panel.open {
        transform: translateX(0);
    }

    /* Panel section label */
    .mcell-panel-label {
        font-size: 0.62rem;
        font-weight: 700;
        color: var(--text-light);
        text-transform: uppercase;
        letter-spacing: 0.4px;
        text-align: center;
        padding: 2px 0;
        width: 100%;
        flex-shrink: 0;
    }

    /* Panel separator line */
    .mcell-panel-sep {
        width: 56px;
        height: 1px;
        background: var(--border);
        margin: 4px 0;
        flex-shrink: 0;
    }

    /* Side panel button ג€” normal size */
    .mcell-side-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        width: 54px;
        min-height: 58px;
        padding: 8px 3px;
        border: 2px solid var(--border);
        border-radius: 10px;
        background: var(--bg-light);
        cursor: pointer;
        font-size: 0.6rem;
        font-weight: 600;
        color: var(--text-dark);
        font-family: inherit;
        transition: all 0.18s;
        flex-shrink: 0;
        text-align: center;
        line-height: 1.2;
    }
    .mcell-side-btn i {
        font-size: 1.1rem;
        color: var(--text-light);
        transition: color 0.18s;
    }
    .mcell-side-btn:active { transform: scale(0.93); }
    .mcell-side-btn.active {
        border-color: var(--accent);
        background: #fffbeb;
        color: var(--primary);
    }
    .mcell-side-btn.active i { color: var(--accent); }

    /* Smaller variant for sub-options */
    .mcell-side-btn-sm {
        min-height: 46px;
        font-size: 0.58rem;
        padding: 6px 3px;
    }
    .mcell-side-btn-sm i { font-size: 0.95rem; }

    /* Category button ג€” wider, fills panel, used in main view */
    .mcell-cat-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        width: calc(100% - 8px);
        min-height: 52px;
        padding: 8px 4px;
        border: 2px solid var(--border);
        border-radius: 10px;
        background: var(--bg-light);
        cursor: pointer;
        font-size: 0.62rem;
        font-weight: 700;
        color: var(--text-dark);
        font-family: inherit;
        transition: all 0.18s;
        flex-shrink: 0;
        text-align: center;
        line-height: 1.2;
    }
    .mcell-cat-btn i {
        font-size: 1.15rem;
        color: var(--text-light);
        transition: color 0.18s;
    }
    .mcell-cat-btn:active { transform: scale(0.93); }
    .mcell-cat-btn.active {
        border-color: var(--accent);
        background: #fffbeb;
        color: var(--primary);
    }
    .mcell-cat-btn.active i { color: var(--accent); }

    /* Back button ג€” small arrow at top of sub-view */
    .mcell-back-btn {
        width: calc(100% - 8px);
        height: 28px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: var(--bg-light);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-light);
        font-size: 0.85rem;
        flex-shrink: 0;
        transition: all 0.15s;
        font-family: inherit;
    }
    .mcell-back-btn:active { transform: scale(0.92); background: var(--highlight); }

    /* Sub-view container */
    #mcp-view-sub {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: 4px;
    }
    #mcp-view-sub.active {
        display: flex;
    }

    /* Mini +/- button for steppers inside side panels */
    .mcell-mini-btn {
        width: 36px;
        height: 32px;
        border-radius: 8px;
        border: 1px solid var(--border);
        background: white;
        font-size: 0.85rem;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-dark);
        flex-shrink: 0;
        transition: all 0.18s;
        font-family: inherit;
    }
    .mcell-mini-btn:active { transform: scale(0.9); background: var(--highlight); }

    /* Count value display */
    .mcell-count-val {
        font-size: 1.15rem;
        font-weight: 900;
        color: var(--primary);
        text-align: center;
        display: block;
        padding: 2px 0;
        min-width: 28px;
    }

    /* Height input inside right panel */
    .mcell-height-input {
        width: 52px;
        border: 1px solid var(--border);
        border-radius: 6px;
        background: var(--bg-light);
        text-align: center;
        font-size: 0.85rem;
        font-weight: 700;
        color: var(--primary);
        padding: 4px 2px;
        -moz-appearance: textfield;
        font-family: inherit;
        flex-shrink: 0;
    }
    .mcell-height-input::-webkit-inner-spin-button,
    .mcell-height-input::-webkit-outer-spin-button { -webkit-appearance: none; }

    /* Scrollbar for side panels */
    #mobile-cell-right-panel::-webkit-scrollbar,
    #mobile-cell-left-panel::-webkit-scrollbar { width: 2px; }
    #mobile-cell-right-panel::-webkit-scrollbar-thumb,
    #mobile-cell-left-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 1px; }

    /* Canvas shrinks when cell side panels are open */
    body.mobile-cell-panels-open #canvas-container {
        left: 63px !important;
        right: 63px !important;
    }
}

/* --- Desktop: hide all mobile-only elements --- */
@media (min-width: 769px) {
    #mobile-bottom-nav,
    #mobile-top-bar,
    #mobile-overlay,
    .mobile-panel,
    #mobile-cell-sheet,
    #mobile-cell-right-panel,
    #mobile-cell-left-panel,
    #mobile-col-bar,
    #mobile-col-sheet {
        display: none !important;
    }
}

/* ============================================================
   MODEL VIEWER MODAL
   ============================================================ */
#model-viewer-modal {
    position: fixed;
    inset: 0;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
}
.mv-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.78);
    backdrop-filter: blur(5px);
    cursor: pointer;
}
.mv-container {
    position: relative;
    width: 90vw;
    height: 85vh;
    background: #0f172a;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 32px 100px rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
}
.mv-close {
    position: absolute;
    top: 14px;
    left: 14px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.mv-close:hover { background: rgba(255, 255, 255, 0.25); }
.mv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.85);
    font-size: 1.1rem;
    gap: 10px;
    font-family: 'Inter', 'Rubik', sans-serif;
    flex-direction: column;
}
.mv-loading .mv-loading-sub {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
}
#mv-element {
    width: 100%;
    height: 100%;
    background: transparent;
}
@media (max-width: 768px) {
    .mv-container { width: 100vw; height: 100dvh; border-radius: 0; }
    .mv-close { top: 10px; left: 10px; }
}

