/* ************************ SEAMLESS TILEMAP EDITOR ************************ */
/* Main application stylesheet - Core UI framework and layout system */
/* This file contains the foundational styles for the Pixel £D Studio application */

:root {
    /* COLOR SYSTEM - Professional Dark Theme */
    --bg-darkest: #0f0f1b;
    /* Deep background */
    --bg-dark: #1a1a2e;
    /* Primary surface */
    --bg-medium: #16213e;
    /* Secondary surface */
    --bg-light: #1e293b;
    /* Tertiary surface */

    /* ACCENT COLORS - Cyberpunk/Terminal Inspired */
    --accent-primary: #00ff41;
    /* Terminal Green */
    --accent-secondary: #ff006e;
    /* Neon Pink */
    --accent-tertiary: #00d9ff;
    /* Cyan */

    /* TEXT & BORDERS */
    --text-primary: #e0e7ff;
    /* Primary text */
    --text-secondary: #94a3b8;
    /* Secondary text */
    --border-color: #2d3748;
    /* Border color */

    /* LAYOUT DIMENSIONS */
    --header-height: 48px;
    --icon-rail-width: 48px;
    --tools-width: 320px;
    --side-panel-width: 280px;
    --border-glow: rgba(0, 255, 65, 0.3);

    --tile-dim: 32;
    /* The number of logical pixels across the tile */
    --pixel-size: 16px;
    /* The size of one logical pixel on screen */


    --header-height: 50px;
    --tools-width: 60px;
    --right-panel-width: 280px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-darkest);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    user-select: none;
}

/* =============================================
   HEADER STYLES
   ============================================= */
header {
    height: var(--header-height);
    background: var(--bg-dark);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    z-index: 10;
    position: relative;
}

.logo-area { display: flex; align-items: baseline; gap: 8px; }

.logo-area h1 {
    font-family: 'Press Start 2P', 'Inter', sans-serif;
    font-size: 16px;
    font-weight: normal;
    color: transparent;
    background-image: linear-gradient(90deg, var(--accent-primary), var(--accent-tertiary), var(--accent-primary));
    background-size: 200%;
    background-position: 0% 50%;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: animate-background 2s infinite alternate linear;
}

/* Masked text background animation */
@keyframes animate-background {
    0% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}

/* Subtle logo glow animation */
@keyframes subtleGlow {
    0% {
        text-shadow: 0 0 8px var(--border-glow);
        color: var(--accent-primary);
    }
    50% {
        text-shadow: 0 0 12px rgba(0, 255, 65, 0.4);
        color: rgba(0, 255, 65, 0.9);
    }
    100% {
        text-shadow: 0 0 15px var(--border-glow);
        color: var(--accent-primary);
    }
}

.badge {
    font-size: 10px;
    background: var(--accent-secondary);
    color: #fff;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
}

.header-controls { display: flex; align-items: center; gap: 8px; }


/* =============================================
   BUTTON STYLES
   ============================================= */
.btn {
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn:hover {
    background: var(--bg-medium);
    border-color: var(--text-secondary);
}

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

.btn.primary {
    background: var(--accent-primary);
    color: #000;
    border: none;
    font-weight: 600;
}

.btn.primary:hover {
    opacity: 0.9;
}

/* AI Sparkle Button */
.btn.ai-magic {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    border: none;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.btn.ai-magic:hover {
    filter: brightness(1.1);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.4);
}

/* =============================================
   MAIN LAYOUT STRUCTURE
   ============================================= */
.workspace {
    display: flex;
    flex: 1;
    height: calc(100vh - var(--header-height));
}

/* =============================================
   LEFT TOOLBAR
   ============================================= */
.tools-panel {
    width: var(--tools-width);
    background: var(--bg-dark);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 10px 0;
    gap: 8px;
    overflow-y: auto;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    position: relative;
}

.tool-btn:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.tool-btn.active {
    background: rgba(0, 217, 255, 0.1);
    color: var(--accent-tertiary);
    border-color: rgba(0, 217, 255, 0.3);
}

/* Tool Button Variants */
.tool-btn.ai-tool {
    color: #a855f7;
}

.tool-btn.ai-tool:hover {
    background: rgba(168, 85, 247, 0.1);
    color: #d8b4fe;
}

.tool-btn.materials-tool {
    color: #ff6b9d;
}

.tool-btn.materials-tool:hover {
    background: rgba(255, 107, 157, 0.1);
    color: #ff8fab;
}

/* Disabled state for tool buttons */
.tool-btn.disabled,
.tool-btn.disabled:hover {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    background: transparent !important;
    color: var(--text-secondary) !important;
    border-color: transparent !important;
}

.tool-divider {
    width: 30px;
    height: 1px;
    background: var(--border-color);
    margin: 4px 0;
}

/* =============================================
   MAIN CANVAS AREA
   ============================================= */
.canvas-area {
    flex: 1;
    position: relative;
    background: #000;
    overflow: hidden;
}

/* Canvas Container */
#canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

#gl-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* Overlay Controls */
.overlay-controls {
    position: absolute;
    top: 10px;
    left: 10px;
    display: flex;
    gap: 5px;
    background: rgba(15, 15, 27, 0.8);
    padding: 5px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    z-index: 1000;
}

/* Transform Space Toggle */
.transform-space-toggle {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.7rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    margin-left: 8px;
}

.transform-space-toggle:hover {
    background: var(--bg-light);
    border-color: var(--text-secondary);
}

.transform-space-toggle .Checkbox {
    width: 14px;
    height: 14px;
    cursor: pointer;
    accent-color: var(--accent-primary);
}

.transform-space-toggle .toggle-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    user-select: none;
}

.transform-space-toggle .Checkbox:checked + .toggle-label {
    color: var(--accent-primary);
    font-weight: 600;
}

/* Zoom Control */
.zoom-control {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(15, 15, 27, 0.8);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    z-index: 1000;
}

.zoom-slider {
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-medium);
    outline: none;
    -webkit-appearance: none;
}

.zoom-slider::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
    -webkit-appearance: none;
}

.zoom-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-primary);
    cursor: pointer;
}

/* =============================================
   RIGHT PANEL SYSTEM
   ============================================= */
.right-panel {
    width: var(--right-panel-width);
    background: var(--bg-dark);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: hidden;
    height: calc(100vh - var(--header-height));
}

/* Layers Container */
.layers-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    max-height: 40%;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-medium);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

/* Panel Controls */
.panel-controls {
    display: flex;
    gap: 6px;
    margin-left: auto;
}

.minimize-panel-btn,
.maximize-panel-btn {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.7rem;
    transition: all 0.2s;
    padding: 2px;
    border-radius: 4px;
}

.minimize-panel-btn:hover,
.maximize-panel-btn:hover {
    color: var(--text-primary);
    background: var(--bg-light);
}

.panel-minimized {
    height: auto !important;
    overflow: hidden;
}

.panel-maximized {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    left: 0;
    width: calc(100% - var(--tools-width)) !important;
    z-index: 1000;
    border-left: none;
    border-right: 1px solid var(--border-color);
}

/* Panel Header */
.panel-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-dark);
    flex-shrink: 0;
    font-size: 0.8rem;
}

.folder-controls {
    display: flex;
    gap: 4px;
    margin-left: auto;
    margin-right: 10px;
}

.folder-btn {
    width: 24px;
    height: 24px;
    padding: 2px;
    font-size: 0.7rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.folder-btn:hover {
    background: var(--bg-medium);
    border-color: var(--text-secondary);
}

.folder-btn i {
    font-size: 0.8rem;
}

.panel-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-content {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
}

/* =============================================
   LAYERS SYSTEM
   ============================================= */
.layers-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px;
    max-height: 40%;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-medium);
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 0.7rem;
    position: relative;
}

/* Drag and Drop Styles */
.drag-handle {
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: grab;
    padding: 0 4px;
}

.drag-handle:active {
    cursor: grabbing;
}

.layer-item.dragging {
    opacity: 0.5;
    background: var(--bg-medium);
    border: 1px dashed var(--accent-primary);
}

.folder-header.drag-over,
.layer-item.drag-over,
.layers-container.drag-over {
    background: var(--bg-medium);
    border-color: var(--accent-primary);
}

.folder-header {
    position: relative;
}

/* Folder Styles */
.folder-item {
    margin-bottom: 4px;
    border-radius: 4px;
    overflow: hidden;
}

.folder-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg-medium);
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.7rem;
}

.folder-header:hover {
    background: var(--bg-light);
}

.folder-icon {
    color: #a855f7;
    font-size: 0.8rem;
}

.folder-name {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 2px;
}

.folder-name:focus {
    background: var(--bg-dark);
    border-color: var(--border-color);
    outline: none;
}

.folder-actions {
    display: flex;
    gap: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.folder-item:hover .folder-actions {
    opacity: 1;
}

.folder-btn {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.7rem;
    padding: 2px;
    background: transparent;
    border: none;
}

.folder-btn:hover {
    color: var(--text-primary);
}

.folder-toggle-btn {
    color: var(--text-secondary);
}

.folder-delete-btn:hover {
    color: var(--accent-secondary);
}

.folder-contents {
    padding-left: 12px;
    margin-top: 2px;
}

/* Folder selection dropdown */
.folder-select-dropdown {
    position: absolute;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 0;
    z-index: 1000;
    min-width: 150px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    font-size: 0.7rem;
}

.dropdown-header {
    padding: 4px 8px;
    color: var(--text-secondary);
    font-size: 0.7rem;
    border-bottom: 1px solid var(--border-color);
}

.dropdown-item {
    padding: 4px 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.dropdown-item:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

.new-folder-item {
    color: var(--accent-primary);
    font-weight: 600;
}

.layer-item:hover {
    border-color: var(--text-secondary);
}

.layer-item.selected {
    border-color: var(--accent-tertiary);
    background: rgba(0, 217, 255, 0.05);
    box-shadow: 0 0 8px rgba(0, 217, 255, 0.1);
}

.layer-icon {
    color: var(--accent-tertiary);
    font-size: 0.8rem;
    width: 20px;
    text-align: center;
}

.layer-name {
    flex: 1;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: 0.7rem;
    padding: 1px 3px;
    border-radius: 2px;
}

.layer-name:focus {
    background: var(--bg-dark);
    border-color: var(--border-color);
    outline: none;
}

.layer-actions {
    display: flex;
    gap: 6px;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.layer-item:hover .layer-actions {
    opacity: 1;
}

.layer-btn {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.8rem;
    padding: 2px;
}

.layer-btn:hover {
    color: var(--text-primary);
}

.layer-btn.delete:hover {
    color: var(--accent-secondary);
}

/* =============================================
   PROPERTY GROUPS & INPUT STYLES
   ============================================= */
.property-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.property-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-group {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px 6px;
}

.input-group span {
    font-size: 0.65rem;
    color: var(--text-secondary);
    width: 15px;
}

input[type="number"],
input[type="text"] {
    background: transparent;
    border: none;
    color: var(--text-primary);
    width: 100%;
    padding: 3px;
    font-size: 0.75rem;
    font-family: inherit;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
}

input[type="color"] {
    width: 100%;
    height: 30px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    padding: 0;
}

/* Material Info Buttons */
.material-info-btn {
    color: var(--text-secondary);
    font-size: 0.7rem;
    cursor: help;
    transition: all 0.2s;
    margin-left: 4px;
}

.material-info-btn:hover {
    color: var(--accent-primary);
    transform: scale(1.1);
}

.empty-state {
    padding: 15px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-style: italic;
}

/* =============================================
   MATERIALS & SCENE SECTIONS
   ============================================= */
.materials-section {
    display: none;
    flex: 1;
    overflow-y: auto;
    flex-direction: column;
}

.scene-section {
    display: none;
    flex: 1;
    overflow-y: auto;
    flex-direction: column;
}

.scene-section .panel-header {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-dark);
}

.scene-section .panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    margin-top: 0;
    /* Ensure no gap between header and content */
}

.materials-section .panel-header {
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--bg-dark);
}

.materials-section .panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    margin-top: 0;
    /* Ensure no gap between header and content */
}

/* =============================================
   CAMERA & EXPORT CONTROLS
   ============================================= */
/* Camera Border Preview */
#camera-border-preview {
    width: 100%;
    height: 200px;
    background: rgba(0, 217, 255, 0.1);
    border: 1px dashed var(--accent-tertiary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 10px;
    transition: all 0.2s ease;
    cursor: move;
    position: relative;
    user-select: none;
}

/* Draggable Camera Border */
#camera-border-preview.dragging {
    opacity: 0.8;
    cursor: grabbing;
}

/* Camera Border Drag Handle */
.camera-border-drag-handle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 24px;
    height: 24px;
    background: var(--bg-medium);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: move;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    z-index: 10;
}

/* Fixed Position Camera Border */
#camera-border-preview.fixed {
    position: fixed;
    z-index: 10000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border-width: 2px;
}

/* Export Button Styling */
#btn-export-png {
    width: 100%;
    margin-top: 10px;
    padding: 8px 12px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

/* Canvas Size Inputs */
#export-width,
#export-height {
    width: 100%;
    padding: 4px 8px;
    font-size: 0.75rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
}

/* Camera Border Toggle */
#show-camera-border {
    width: 18px;
    height: 18px;
    accent-color: var(--accent-primary);
    cursor: pointer;
    margin-right: 6px;
}

/* =============================================
   MATERIALS SYSTEM
   ============================================= */
/* Material Item for Materials Section */
.material-item-full {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.material-item-full:hover {
    background: var(--bg-medium);
    border-color: var(--accent-primary);
}

.material-preview-full {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.material-info-full {
    flex: 1;
}

.material-name-full {
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.material-properties-full {
    display: flex;
    gap: 12px;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.material-actions-full {
    display: flex;
    gap: 6px;
}

.material-actions-full button {
    width: 28px;
    height: 28px;
    padding: 4px;
    font-size: 0.8rem;
}

/* Materials Selector in Properties Panel */
.material-selector {
    width: 100%;
    padding: 6px;
    font-size: 0.7rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    margin-bottom: 8px;
}

/* Materials Selector - Custom Dropdown Implementation */
.material-dropdown-wrapper {
    position: relative;
    width: 100%;
    margin-bottom: 8px;
}

.material-selector {
    width: 100%;
    padding: 8px 12px;
    font-size: 0.7rem;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s;
    min-height: 36px;
    box-sizing: border-box;
}

.material-selector:hover {
    background: var(--bg-medium);
    border-color: var(--text-secondary);
}

.material-selector .selected-material-text {
    flex-grow: 1;
    color: var(--text-primary);
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.material-selector .dropdown-arrow {
    flex-shrink: 0;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.material-dropdown-wrapper.open .dropdown-arrow {
    transform: rotate(180deg);
}

.material-dropdown-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
}

.material-dropdown-list.show {
    display: block;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.material-dropdown-item {
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.7rem;
    color: var(--text-primary);
    min-height: 32px;
    border-left: 3px solid transparent;
}

.material-dropdown-item:hover {
    background: var(--bg-medium);
    border-left-color: var(--accent-primary);
}

.material-dropdown-item.selected {
    background: var(--bg-medium);
    border-left-color: var(--accent-primary);
}

.material-dropdown-item .material-color-swatch {
    width: 16px;
    height: 16px;
    border-radius: 2px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.material-dropdown-item .material-option-text {
    flex-grow: 1;
    color: var(--text-primary);
    font-size: 0.7rem;
}

/* Scrollbar styling for dropdown */
.material-dropdown-list::-webkit-scrollbar {
    width: 6px;
}

.material-dropdown-list::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 3px;
}

.material-dropdown-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.material-dropdown-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Materials Panel Styles */
.material-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.material-item:hover {
    background: var(--bg-medium);
    border-color: var(--accent-primary);
}

.material-item.selected {
    border-color: var(--accent-primary);
    background: rgba(0, 217, 255, 0.05);
}

.material-preview {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    flex-shrink: 0;
}

.material-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.material-name {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-size: 0.7rem;
    padding: 2px 4px;
    border-radius: 2px;
    width: 120px;
}

.material-name:focus {
    background: var(--bg-dark);
    border-color: var(--border-color);
    outline: none;
}

.material-properties {
    display: flex;
    gap: 8px;
    font-size: 0.6rem;
    color: var(--text-secondary);
}

.material-actions {
    display: flex;
    gap: 4px;
}

.material-actions button {
    width: 24px;
    height: 24px;
    padding: 2px;
    font-size: 0.7rem;
}

/* =============================================
   MATERIAL EDIT DIALOG
   ============================================= */
.material-edit-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    z-index: 10000;
    width: 300px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.dialog-header h3 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.close-dialog-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

.close-dialog-btn:hover {
    color: var(--text-primary);
    background: var(--bg-light);
}

.form-group {
    margin-bottom: 10px;
}

.form-group label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-group input[type="color"] {
    width: 100%;
    height: 30px;
}

.form-group input[type="range"] {
    width: 100%;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

/* =============================================
   PANEL TOGGLE & UI ELEMENTS
   ============================================= */
/* FLOATING TOGGLE BUTTON FOR PANEL */
#panel-toggle {
    position: absolute;
    right: 280px;
    /* Aligned with open panel */
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-right: none;
    padding: 10px 4px;
    border-radius: 8px 0 0 8px;
    cursor: pointer;
    z-index: 100;
    color: var(--accent-tertiary);
    transition: right 0.3s cubic-bezier(0.4, 0.0, 0.2, 1);
}

#panel-toggle:hover {
    background: var(--bg-medium);
}

#panel-toggle.panel-hidden {
    right: 0px;
}

#right-panel.hidden {
    display: none;
}

/* Tooltip */
[data-tooltip]:hover::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 10px;
    background: var(--bg-medium);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 100;
    pointer-events: none;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s;
    position: relative;
    flex-shrink: 0;
}

/* Make submenus float OVER the canvas, not inside the toolbar */
.tool-submenu {
    display: none;
    position: fixed !important;
    /* Changed from absolute to fixed */
    left: 68px !important;
    /* Just right of the 60px toolbar + 8px gap */
    top: var(--submenu-top, 100px);
    /* Will be set dynamically via JS */
    background: var(--bg-dark);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
    flex-direction: column;
    gap: 6px;
    z-index: 1000;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    min-width: 48px;
    backdrop-filter: blur(10px);
}

/* Optional: Add a little pointer arrow */
.tool-submenu::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 16px;
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid var(--border-color);
}

/* Make submenu buttons slightly larger and nicer */
.tool-submenu .tool-btn {
    width: 44px;
    height: 44px;
    font-size: 1.2rem;
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(45, 55, 72, 0.8);
}

.tool-submenu .tool-btn:hover {
    background: var(--accent-primary);
    color: #000;
    transform: scale(1.05);
}