.main-layout {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 40px;
    width: 100%;
    max-width: 1200px;
    flex-wrap: wrap;
    position: relative;
}

.surgical-table-container {
    background-color: rgba(0, 0, 0, 0);
    border-radius: 20px;
    padding: 0px;
    color: white;
    width: 600px;
    position: relative;
    z-index: 1;
}

/* Desktop layout (default) - side by side */
@media (min-width: 1025px) {
    .main-layout {
        flex-wrap: nowrap;
        align-items: center;
    }
    
    .surgical-table-container {
        position: fixed;
        top: calc(50dvh - 35%);
        right: calc(50dvw - 550px);
        z-index: -10;
    }
}

/* Tablet layout */
@media (max-width: 1024px) and (min-width: 769px) {
    body {
        display: block; /* Allow scrolling on tablet too */
        min-height: auto;
        padding: 15px;
    }
    
    .main-layout {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 15px;
        padding: 15px;
        min-height: auto;
        position: relative;
    }
    
    .surgical-table-container {
        position: fixed;
        top: 15px;
        right: 15px;
        width: 30vw;
        max-width: 30vw;
        min-width: 150px;
        height: 30vw;
        min-height: 150px;
        z-index: 1000;
        background-color: rgba(36, 36, 36, 0.5);
        order: unset;
        margin: 0;
        border-radius: 40px;
        overflow: hidden;
        padding: 0;
    }

    #surgicalTableCanvas {
        width: 90% !important;
        height: 90% !important;
        position:relative;
        left:5%;
        top:5%;
    }
    
    .device {
        order: 1; /* Comes before surgical table */
        margin-right: 0 !important;
        width: 320px !important; /* Keep original device width */
        max-width: 320px !important;
        margin: 0; /* Remove auto centering */
        align-self: flex-start; /* Align to top */
    }
    
    .canvas-container {
        height: 100%;
        width: 100%;
    }
}

/* Mobile layout */
@media (max-width: 768px) {
    body {
        display: block; /* Change from flex to block for scrolling */
        min-height: auto;
        padding: 10px;
    }
    
    .main-layout {
        flex-direction: row;
        align-items: flex-start;
        justify-content: space-between;
        gap: 10px;
        padding: 10px;
        min-height: auto;
        position: relative;
    }
    
    .surgical-table-container {
        position: fixed;
        top: 10px;
        right: 10px;
        width: 25vw;
        max-width: 25vw;
        min-width: 100px;
        height: 25vw;
        min-height: 100px;
        z-index: 1000;
        background-color: rgba(36, 36, 36, 0.5); /* red overlay for debugging */
        order: unset;
        margin: 0;
        border-radius: 40px;
        overflow: hidden;
        padding: 0;
    }

    #surgicalTableCanvas {
        width: 90% !important;
        height: 90% !important;
        position:relative;
        left:5%;
        top:5%;
    }
    
    .device {
        order: 1; /* Comes before surgical table */
        margin-right: 0 !important;
        width: 320px !important; /* Keep original device width */
        max-width: 320px !important;
        margin: 0; /* Remove auto centering */
        align-self: flex-start; /* Align to top */
    }
    
    .canvas-container {
        height: 100%;
        width: 100%;
    }
    
}

.canvas-container {
    width: 100%;
    height: 600px;
    background: transparent;
    border-radius: 10px;
    overflow: hidden;
    /* filter: blur(2.5px); */
    filter: blur(0px); 
}

.controls-container {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 10px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.control-group label {
    font-size: 14px;
    color: #ccc;
    display: flex;
    justify-content: space-between;
}

.control-group input[type="range"] {
    width: 100%;
    height: 6px;
    background: #444;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.control-group input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #00a2ff;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s;
}

.control-group input[type="range"]::-webkit-slider-thumb:hover {
    background: #33b5ff;
}

.version-display {
    display: none !important;
}

/* Leg Articulation Mode Toggle */
.mode-toggle-container {
    margin-top: 15px;
    text-align: center;
    padding: 0 10px;
    position: relative;
    z-index: 1001; /* Ensure button is above surgical table (z-index: 1000) */
}

.mode-toggle-btn {
    background: #4a5568;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 10px 20px;
    font-size: 14px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    font-family: inherit;
    position: relative;
    z-index: 11;
}

.mode-toggle-btn:hover {
    background: #2d3748;
    transform: translateY(-1px);
}

.mode-toggle-btn:active {
    transform: translateY(1px);
}

.mode-toggle-btn.single-mode {
    background: #2b6cb0;
}

.mode-toggle-btn.single-mode:hover {
    background: #2c5282;
}

.mode-icon {
    font-size: 16px;
    font-weight: bold;
}

/* Disabled state for L/R buttons in single mode */
.side-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Desktop layout */
@media (min-width: 1025px) {
    /* Reposition reset button to right side column */
    .reset-btn {
        position: fixed;
        top: 20px;
        right: 20px;
        left: auto;
        width: 80px;
        height: 40px;
        background-color: #ff4444;
        color: white;
        border-radius: 5px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
        z-index: 1002;
        user-select: none;
        transition: background-color 0.2s;
    }
    
    .reset-btn:hover {
        background-color: #ff6666;
    }
    
    .reset-btn:active {
        transform: translateY(2px);
    }
    
    /* Reposition mode toggle below reset button in right column */
    .mode-toggle-container {
        position: fixed;
        top: 80px; /* Below reset button (20px top + 40px height + 20px gap) */
        right: 20px;
        z-index: 1001; /* Above surgical table */
        margin-top: 0;
        width: 200px;
    }
    
    /* Reposition debug nav (pages menu) below mode toggle in right column */
    .external-nav {
        position: fixed !important;
        top: 140px; /* Below mode toggle (80px top + ~40px height + 20px gap) */
        right: 20px;
        bottom: auto !important;
        width: auto;
        margin-top: 0;
        z-index: 1001; /* Above surgical table */
    }
    
    /* Ensure surgical table remains in its original position */
    .surgical-table-container {
        position: fixed;
        top: calc(50dvh - 35%);
        right: calc(50dvw - 550px);
        z-index: -10;
    }
}

/* Tablet layout - vertical column positioning */
@media (max-width: 1024px) and (min-width: 769px) {
    /* Reposition reset button to right side, below surgical table */
    .reset-btn {
        position: fixed;
        top: calc(30vw + 25px); /* Below surgical table (15px top + 30vw height + 10px gap) */
        right: 15px;
        left: auto;
        width: 80px;
        height: 40px;
        background-color: #ff4444;
        color: white;
        border-radius: 5px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 14px;
        font-weight: bold;
        cursor: pointer;
        z-index: 1002;
        user-select: none;
        transition: background-color 0.2s;
    }
    
    .reset-btn:hover {
        background-color: #ff6666;
    }
    
    .reset-btn:active {
        transform: translateY(2px);
    }
    
    /* Reposition mode toggle below reset button */
    .mode-toggle-container {
        position: fixed;
        top: calc(30vw + 85px); /* Below reset button (30vw + 25px top + 40px height + 20px gap) */
        right: 15px;
        z-index: 1001; /* Above surgical table */
        margin-top: 0;
        width: 200px;
        order: unset; /* Remove flex order */
    }
    
    /* Reposition debug nav (pages menu) below mode toggle */
    .external-nav {
        position: fixed !important;
        top: calc(30vw + 145px); /* Below mode toggle (30vw + 85px top + ~40px height + 20px gap) */
        right: 15px;
        bottom: auto !important;
        width: auto;
        margin-top: 0;
        z-index: 1001; /* Above surgical table */
    }
}

/* Mobile adjustments */
@media (max-width: 768px) {
    /* Reposition reset button to right side, below surgical table */
    .reset-btn {
        position: fixed;
        top: calc(25vw + 20px); /* Below surgical table (10px top + 25vw height + 10px gap) */
        right: 10px;
        left: auto;
        width: 60px;
        height: 30px;
        background-color: #ff4444;
        color: white;
        border-radius: 5px;
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 12px;
        font-weight: bold;
        cursor: pointer;
        z-index: 1002; /* Above surgical table */
        user-select: none;
        transition: background-color 0.2s;
    }
    
    .reset-btn:hover {
        background-color: #ff6666;
    }
    
    .reset-btn:active {
        transform: translateY(2px);
    }
    
    /* Reposition mode toggle below reset button */
    .mode-toggle-container {
        position: fixed;
        top: calc(25vw + 60px); /* Below reset button (25vw + 20px top + 30px height + 10px gap) */
        right: 10px;
        width: auto;
        z-index: 1001; /* Above mobile surgical table */
        margin-top: 0;
        padding: 0;
    }
    
    .mode-toggle-btn {
        padding: 6px 12px;
        font-size: 11px;
        border-radius: 15px;
    }
    
    .mode-icon {
        font-size: 12px;
    }
    
    /* Reposition debug nav (pages menu) below mode toggle */
    .external-nav {
        position: fixed !important;
        top: calc(25vw + 110px); /* Below mode toggle (25vw + 60px top + ~40px height + 10px gap) */
        right: 10px;
        bottom: auto !important;
        width: auto;
        margin-top: 0;
        z-index: 1001; /* Above surgical table */
    }
}
