/* Paint Studio - Main Styles */

/* Override responsive.css mobile rules for paint app inputs */
.paint-app input,
.paint-app button,
.paint-app select {
    width: auto !important;
    max-width: none !important;
    padding: initial !important;
    font-size: inherit !important;
    height: auto !important;
}

.paint-app .toolbar-input {
    width: 50px !important;
    min-width: 50px !important;
    max-width: 50px !important;
    padding: 6px 4px !important;
    font-size: 0.85rem !important;
}

.paint-app .adj-input {
    width: 45px !important;
    min-width: 45px !important;
    max-width: 45px !important;
    padding: 5px 2px !important;
    font-size: 0.8rem !important;
}

.paint-app .adj-slider {
    width: 100% !important;
    height: 4px !important;
    padding: 0 !important;
}

.paint-app .toolbar-slider {
    width: 80px !important;
    height: 6px !important;
    padding: 0 !important;
}

.paint-app .action-btn {
    padding: 6px 10px !important;
    font-size: 0.8rem !important;
    width: auto !important;
}

/* Override main layout for paint app */
.paint-main {
    padding: 0;
    margin: 0;
    height: calc(100vh - var(--header-height) - 60px);
    min-height: 600px;
}

.paint-app {
    display: grid;
    grid-template-columns: 60px 1fr 280px;
    height: 100%;
    background: var(--bg-body);
    gap: 0;
}

/* Modal Styles */
.paint-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.paint-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.paint-modal {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 24px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    transform: scale(0.9) translateY(20px);
    transition: transform 0.3s ease;
}

.paint-modal-overlay.active .paint-modal {
    transform: scale(1) translateY(0);
}

.paint-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}

.paint-modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-heading);
    display: flex;
    align-items: center;
    gap: 10px;
}

.paint-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--input-bg);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-muted);
    transition: all 0.2s;
}

.paint-modal-close:hover {
    background: #ff4444;
    color: white;
}

.paint-modal-body {
    margin-bottom: 20px;
}

.paint-form-group {
    margin-bottom: 16px;
}

.paint-form-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.paint-form-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 1rem;
    transition: all 0.2s;
    box-sizing: border-box;
}

.paint-form-input:focus {
    outline: none;
    border-color: #FF6B6B;
    box-shadow: 0 0 0 3px rgba(255, 107, 107, 0.2);
}

.paint-form-select {
    width: 100%;
    padding: 12px 16px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-size: 1rem;
    cursor: pointer;
}

.paint-modal-footer {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.paint-btn {
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
}

.paint-btn-primary {
    background: var(--primary-gradient);
    color: white;
}

.paint-btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.paint-btn-secondary {
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.paint-btn-secondary:hover {
    background: var(--bg-surface-hover, #3a3a4e);
}

.paint-format-options {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.paint-format-option {
    flex: 1;
    padding: 12px;
    background: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
}

.paint-format-option:hover {
    border-color: var(--text-muted);
}

.paint-format-option.selected {
    border-color: #FF6B6B;
    background: rgba(255, 107, 107, 0.1);
}

.paint-format-option-label {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 4px;
}

.paint-format-option-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Left Toolbar */
.toolbar {
    background: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    gap: 4px;
    align-items: center;
    overflow-y: auto;
    overflow-x: hidden;
    width: 60px;
    min-width: 60px;
    max-width: 60px;
    z-index: 100;
    position: relative;
}

.tool-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    color: var(--text-muted);
    transition: all 0.2s ease;
    position: relative;
}

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

.tool-btn.active {
    background: var(--primary-gradient);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 107, 0.3);
}

.tool-btn[title]::after {
    content: attr(title);
    position: fixed;
    left: 75px;
    background: var(--bg-surface);
    color: var(--text-main);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    z-index: 99999;
    transform: translateY(-50%);
}

.tool-btn:hover[title]::after {
    opacity: 1;
}

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

/* Canvas Area */
.canvas-area {
    display: flex;
    flex-direction: column;
    background: #1a1a2e;
    overflow: hidden;
}

.canvas-toolbar {
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-color);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 50px;
    flex-wrap: wrap;
    overflow-x: auto;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
    flex-shrink: 0;
}

.toolbar-group label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
}

.toolbar-input {
    width: 50px !important;
    min-width: 50px !important;
    max-width: 50px !important;
    padding: 6px 4px !important;
    font-size: 0.85rem !important;
    text-align: center !important;
    box-sizing: border-box !important;
    background: var(--input-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 6px !important;
    color: var(--text-main) !important;
}

.toolbar-slider {
    width: 80px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--input-bg);
    border-radius: 3px;
    cursor: pointer;
}

.toolbar-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary-gradient);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(255, 107, 107, 0.3);
}

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

.toolbar-separator {
    width: 1px;
    height: 32px;
    background: var(--border-color);
    margin: 0 8px;
    flex-shrink: 0;
}

.quick-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

/* Action buttons in toolbar */
.action-btn {
    padding: 6px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 4px;
}

.action-btn:hover {
    background: var(--bg-surface-hover, #3a3a4e);
    border-color: var(--primary-color, #FF6B6B);
}

.action-btn:active {
    transform: scale(0.97);
}

/* Canvas Wrapper */
.canvas-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 20px;
    position: relative;
    background:
        linear-gradient(45deg, #252538 25%, transparent 25%),
        linear-gradient(-45deg, #252538 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #252538 75%),
        linear-gradient(-45deg, transparent 75%, #252538 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    background-color: #1e1e32;
}

#paint-canvas {
    /* Transparency checkerboard pattern */
    background-image:
        linear-gradient(45deg, #ccc 25%, transparent 25%),
        linear-gradient(-45deg, #ccc 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ccc 75%),
        linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
    background-color: #fff;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    cursor: crosshair;
    image-rendering: pixelated;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.canvas-wrapper.drag-over {
    outline: 4px dashed #FF6B6B;
    outline-offset: -4px;
    background-color: rgba(255, 107, 107, 0.1) !important;
}

.canvas-wrapper.drag-over::after {
    content: 'Drop image here';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-gradient);
    color: white;
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 1.25rem;
    font-weight: 600;
    pointer-events: none;
    z-index: 100;
}

/* Right Panel */
.right-panel {
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.panel-section {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.panel-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-heading);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.panel-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border: none;
    background: var(--input-bg);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: var(--text-muted);
    transition: all 0.2s;
    flex-shrink: 0;
}

.panel-btn:hover {
    background: var(--primary-gradient);
    color: white;
}

/* Color Picker Section */
.color-main {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: flex-start;
    flex-wrap: nowrap;
}

.color-preview-box {
    position: relative;
    width: 64px;
    height: 64px;
}

.color-preview {
    width: 100%;
    height: 100%;
    border-radius: 10px;
    border: 2px solid var(--border-color);
    cursor: pointer;
    transition: transform 0.2s;
}

.color-preview:hover {
    transform: scale(1.05);
}

.color-fg {
    position: absolute;
    top: 0;
    left: 0;
    width: 44px;
    height: 44px;
    z-index: 2;
}

.color-bg {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 44px;
    height: 44px;
    z-index: 1;
}

.color-controls {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    overflow: hidden;
}

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

.color-input-row label {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 20px;
}

.color-input-row input[type="text"] {
    flex: 1;
    padding: 6px 8px !important;
    font-size: 0.8rem !important;
    font-family: monospace !important;
}

.swap-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border: 1px solid var(--border-color);
    background: var(--input-bg);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-muted);
}

.swap-btn:hover {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
}

/* Color Palette */
.color-palette {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
}

.palette-color {
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.15s;
}

.palette-color:hover {
    transform: scale(1.15);
    z-index: 1;
}

/* Layers Panel */
.layers-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--input-bg);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.layer-item:hover {
    background: var(--bg-surface-hover);
}

.layer-item.active {
    border-color: #FF6B6B;
    background: var(--bg-surface);
}

.layer-visibility {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.9rem;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.layer-visibility:hover {
    opacity: 1;
}

.layer-visibility.hidden {
    opacity: 0.3;
}

.layer-drag-handle {
    cursor: grab;
    color: var(--text-muted);
    font-size: 0.7rem;
    letter-spacing: -2px;
    padding: 0 4px;
    user-select: none;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.layer-drag-handle:hover {
    opacity: 1;
}

.layer-item.dragging {
    opacity: 0.5;
}

.layer-item.drag-over {
    border-top: 2px solid #FF6B6B;
    margin-top: -2px;
}

.layer-thumb {
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.layer-info {
    flex: 1;
    min-width: 0;
}

.layer-name {
    font-size: 0.85rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.layer-opacity {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.layer-delete {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 0.75rem;
    opacity: 0.4;
    transition: all 0.2s;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.layer-delete:hover {
    opacity: 1;
    background: #ff4444;
    color: white;
}

/* Adjustments Panel */
.adjustments-panel {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.adjustment-row {
    display: grid;
    grid-template-columns: 70px 1fr 45px;
    align-items: center;
    gap: 8px;
}

.adjustment-row label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.adj-slider {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, #4a86e8, #FF6B6B);
    border-radius: 2px;
    cursor: pointer;
}

.adj-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
}

.adj-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.adj-input {
    width: 45px !important;
    min-width: 45px !important;
    max-width: 45px !important;
    padding: 5px 2px !important;
    font-size: 0.8rem !important;
    color: var(--text-main) !important;
    background: var(--input-bg) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: 4px !important;
    text-align: center !important;
    font-family: monospace !important;
    box-sizing: border-box !important;
}

.adj-input:focus {
    outline: none;
    border-color: #FF6B6B;
}

/* Hide number input spinners */
.adj-input::-webkit-outer-spin-button,
.adj-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.adj-input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.adjustment-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.adj-btn {
    flex: 1;
    padding: 10px 14px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--primary-gradient);
    color: white;
    min-height: 38px;
}

.adj-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.adj-btn.secondary {
    background: var(--input-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.adj-btn.secondary:hover {
    background: var(--bg-surface-hover);
}

/* Filters Grid */
.filters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.filter-btn {
    padding: 10px 12px;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-main);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    min-height: 38px;
}

.filter-btn:hover {
    background: var(--primary-gradient);
    color: white;
    border-color: transparent;
}

/* Styles for quick-actions and action-btn are defined earlier in this file */

/* Responsive */
@media (max-width: 1200px) {
    .right-panel {
        width: 260px;
    }

    .paint-app {
        grid-template-columns: 60px 1fr 260px;
    }
}

@media (max-width: 1024px) {
    .paint-app {
        grid-template-columns: 50px 1fr 240px;
    }

    .right-panel {
        width: 240px;
        padding: 12px;
    }

    .panel-section {
        padding: 10px;
    }

    /* Make canvas toolbar wrap */
    #canvas-toolbar {
        flex-wrap: wrap;
        height: auto;
        min-height: 50px;
        padding: 8px 12px;
        gap: 8px;
    }

    .toolbar-separator {
        display: none;
    }
}

@media (max-width: 768px) {
    .paint-app {
        grid-template-columns: 50px 1fr;
    }

    .right-panel {
        display: none;
    }

    /* Make toolbar tools larger for touch */
    .tool-btn {
        width: 40px;
        height: 40px;
    }

    .toolbar {
        width: 50px;
        min-width: 50px;
        max-width: 50px;
    }

    /* Simplify canvas toolbar */
    #canvas-toolbar {
        padding: 6px 10px;
    }

    .action-btn {
        padding: 8px 8px;
        font-size: 0.75rem;
    }

    .quick-actions {
        gap: 2px;
    }
}

@media (max-width: 576px) {

    /* Complete mobile layout redesign */
    .paint-app {
        display: flex;
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        /* Dynamic viewport for mobile browsers */
    }

    /* Move toolbar to bottom */
    .toolbar {
        order: 3;
        width: 100%;
        max-width: 100%;
        min-width: 100%;
        height: auto;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 8px 10px;
        gap: 6px;
        border-right: none;
        border-top: 1px solid var(--border-color);
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .tool-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        font-size: 1.2rem;
        flex-shrink: 0;
    }

    .tool-divider {
        width: 1px;
        height: 30px;
        margin: 0 4px;
    }

    /* Disable tooltip on mobile (use touch) */
    .tool-btn[title]::after {
        display: none;
    }

    /* Canvas area takes remaining space */
    .canvas-wrapper {
        order: 2;
        flex: 1;
        padding: 5px;
        min-height: 0;
    }

    /* Top toolbar becomes minimal */
    #canvas-toolbar {
        order: 1;
        padding: 6px 8px;
        flex-wrap: nowrap;
        overflow-x: auto;
        gap: 4px;
        -webkit-overflow-scrolling: touch;
    }

    /* Hide most toolbar items on mobile */
    .toolbar-group:not(:first-child) {
        display: none;
    }

    .toolbar-separator {
        display: none;
    }

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

    /* Minimal action buttons */
    .action-btn {
        padding: 8px 10px;
        font-size: 0.75rem;
        min-width: 40px;
    }

    /* Hide labels, show icons only */
    .toolbar-group label {
        display: none;
    }

    /* Right panel hidden but accessible via button */
    .right-panel {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        width: 85%;
        max-width: 320px;
        height: 100%;
        z-index: 1000;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    }

    .right-panel.mobile-open {
        display: block;
        transform: translateX(0);
    }

    /* Mobile panel overlay */
    .mobile-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .mobile-overlay.active {
        display: block;
    }

    /* Floating menu button */
    .mobile-menu-btn {
        display: flex !important;
        position: fixed;
        bottom: 80px;
        right: 15px;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: var(--primary-gradient);
        border: none;
        color: white;
        font-size: 1.4rem;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4);
        z-index: 500;
        cursor: pointer;
    }

    /* Undo/Redo floating buttons */
    .mobile-quick-actions {
        display: flex !important;
        position: fixed;
        bottom: 80px;
        left: 15px;
        gap: 8px;
        z-index: 500;
    }

    .mobile-quick-actions button {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--bg-surface);
        border: 1px solid var(--border-color);
        color: var(--text-main);
        font-size: 1.1rem;
        display: flex;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }

    /* Panel close button for mobile */
    .panel-close-btn {
        display: block !important;
        position: absolute;
        top: 10px;
        right: 10px;
        width: 36px;
        height: 36px;
        border-radius: 50%;
        background: var(--input-bg);
        border: none;
        color: var(--text-main);
        font-size: 1.2rem;
        cursor: pointer;
        z-index: 10;
    }
}

/* --- FIX MOBILE (Step 251 - Polished Compact) --- */
@media (max-width: 900px) {

    /* 1. Global: Single Screen Fixed */
    .mobile-quick-actions,
    .mobile-menu-btn,
    body>header {
        display: none !important;
    }

    /* Use > with spaces as standard */
    body>header {
        display: none !important;
    }

    /* Fallback for weird formatting */

    .paint-main {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }

    .paint-app {
        display: flex;
        flex-direction: column;
        height: 100% !important;
    }

    /* 2. Top Toolbar: Sleek Horizontal Scroller */
    .canvas-toolbar {
        order: 1;
        height: 54px !important;
        flex-shrink: 0 !important;
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 0 12px !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        white-space: nowrap !important;
        background: var(--bg-surface) !important;
        border-bottom: 1px solid var(--border-color);
        scrollbar-width: none;
    }

    .canvas-toolbar::-webkit-scrollbar {
        display: none;
    }

    /* Icons Only */
    .action-btn {
        font-size: 0 !important;
        padding: 8px !important;
        width: 36px !important;
        height: 36px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        border-radius: 8px !important;
        min-width: 36px !important;
    }

    .action-btn i {
        font-size: 1.2rem !important;
        margin: 0 !important;
    }

    .toolbar-group {
        margin: 0 !important;
        display: flex !important;
        gap: 8px !important;
        align-items: center !important;
    }

    .toolbar-group span,
    .toolbar-group label {
        display: none !important;
    }

    .toolbar-separator {
        height: 20px;
        margin: 0 4px;
        display: block !important;
        width: 1px;
        background: var(--border-color);
    }

    /* Hide Quick Actions container styles to let buttons flow */
    .quick-actions {
        display: flex !important;
        gap: 8px !important;
    }

    /* 3. Canvas */
    .canvas-area {
        order: 2;
        flex: 1 1 auto !important;
        height: auto !important;
        min-height: 200px !important;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--bg-dark);
    }

    .canvas-wrapper {
        width: 100% !important;
        height: 100% !important;
        flex: 1 !important;
    }

    /* 4. Tools Dock */
    .toolbar {
        order: 3;
        width: 100%;
        height: 64px !important;
        flex-shrink: 0 !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        justify-content: flex-start !important;
        padding: 8px 16px !important;
        gap: 16px !important;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-color);
    }

    .tool-btn {
        width: 44px !important;
        height: 44px !important;
        flex-shrink: 0;
        border-radius: 12px !important;
    }

    /* 5. Right Panel (Compact) */
    .right-panel {
        order: 4;
        display: flex !important;
        flex-direction: column !important;
        position: static !important;
        width: 100% !important;
        height: 35vh !important;
        max-height: 280px !important;
        min-height: 180px !important;
        flex-shrink: 0 !important;
        border-top: 1px solid var(--border-color);
        background: var(--bg-panel);
        overflow-y: auto !important;
        padding: 0 !important;
    }

    .panel-section {
        padding: 12px 16px !important;
    }

    .color-palette {
        gap: 8px !important;
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)) !important;
    }

    .color-swatch {
        width: 36px;
        height: 36px;
        border-radius: 8px;
    }
}

/* Obsolete Fix-217 Block (Disabled) */
@media (max-width: 0px) {

    .mobile-quick-actions,
    .mobile-menu-btn,
    body>header {
        display: none !important;
    }

    .right-panel {
        display: block !important;
        position: static !important;
        width: 100% !important;
        height: auto !important;
        transform: none !important;
        opacity: 1 !important;
    }

    /* Fix top toolbar stacking */
    .canvas-toolbar {
        flex-wrap: wrap !important;
        height: auto !important;
        padding: 12px !important;
    }

    .quick-actions {
        display: contents !important;
    }

    .toolbar-separator {
        display: none !important;
    }

    .action-btn {
        flex: 1 1 30% !important;
        min-width: 80px !important;
        padding: 12px !important;
    }

    .toolbar-group {
        width: 100% !important;
        margin-bottom: 8px !important;
        display: flex !important;
        justify-content: space-between !important;
    }
}

/* Hide mobile elements on desktop */
.mobile-menu-btn,
.mobile-quick-actions,
.mobile-overlay,
.panel-close-btn {
    display: none;
}

/* Touch-friendly adjustments for all mobile */
@media (hover: none) and (pointer: coarse) {

    /* Larger touch targets */
    .filter-btn,
    .adj-btn {
        min-height: 44px;
    }

    .layer-item {
        min-height: 54px;
    }

    .panel-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    /* Better scrolling */
    .layers-list,
    .toolbar {
        -webkit-overflow-scrolling: touch;
    }
}

/* Responsive Layout for Small Screens */
@media (max-width: 900px) {
    .paint-app {
        display: flex;
        flex-direction: column;
        grid-template-columns: none;
        /* override grid */
        height: 100% !important;
    }

    /* Toolbar becomes horizontal top bar */
    .toolbar {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        height: auto;
        min-height: 50px;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        padding: 4px 10px;
        overflow-x: auto;
        gap: 8px;
        flex-shrink: 0;
    }

    .tool-divider {
        width: 1px;
        height: 24px;
        margin: 0 4px;
    }

    .canvas-wrapper {
        flex: 1;
        width: 100%;
        min-height: 0;
        /* allows flex shrink */
    }

    /* Right panel becomes bottom scrollable area */
    .right-panel {
        width: 100%;
        height: 350px;
        /* Fixed height for panel on mobile */
        border-left: none;
        border-top: 1px solid var(--border-color);
        flex-shrink: 0;
    }
}

@media (max-width: 360px) {
    .paint-app .adj-input {
        width: 35px !important;
        min-width: 35px !important;
        font-size: 0.7rem !important;
    }

    .paint-app .toolbar-input {
        width: 40px !important;
        min-width: 40px !important;
    }
}

/* --- Enhanced Mobile Layout (Polished) --- */
@media (max-width: 900px) {

    /* Hide Global Header */
    body>header {
        display: none !important;
    }

    /* Force Full Height */
    .paint-main {
        height: 100vh !important;
        min-height: 0 !important;
    }

    .paint-app {
        height: 100% !important;
    }

    /* File Ops (Top) */
    .canvas-toolbar {
        order: 1;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding: 5px 10px;
        min-height: 48px;
        scrollbar-width: none;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border-color);
        gap: 8px;
    }

    .canvas-toolbar::-webkit-scrollbar {
        display: none;
    }

    .canvas-toolbar .action-btn {
        flex-shrink: 0;
        padding: 6px 10px;
        font-size: 0.75rem;
        border-radius: 6px;
        background: var(--input-bg);
    }

    /* Canvas (Middle) */
    .canvas-area {
        order: 2;
        flex: 1;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .canvas-wrapper {
        flex: 1;
        min-height: 0;
    }

    /* Tools (Bottom Dock) */
    .toolbar {
        order: 3;
        width: 100%;
        min-height: 60px;
        height: auto;
        flex-direction: row;
        border-top: 1px solid var(--border-color);
        border-right: none;
        box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.3);
        z-index: 50;
        padding: 8px 12px;
        gap: 16px;
        justify-content: center;
        background: var(--bg-surface);
        scrollbar-width: none;
    }

    .toolbar::-webkit-scrollbar {
        display: none;
    }

    .tool-btn {
        width: 42px;
        height: 42px;
        border-radius: 10px;
        flex-shrink: 0;
    }

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

    /* Right Panel (Drawer) */
    .right-panel {
        order: 4;
        width: 100%;
        height: 300px;
        border-top: 1px solid var(--border-color);
        border-left: none;
        flex-shrink: 0;
    }
}

/* --- Final Mobile Layout: Vertical Stack --- */
@media (max-width: 900px) {

    /* Hide Global Header */
    body>header {
        display: none !important;
    }

    /* Allow page scrolling */
    .paint-main {
        height: auto !important;
        min-height: 100vh !important;
    }

    .paint-app {
        height: auto !important;
        overflow: visible !important;
        display: flex;
        flex-direction: column;
    }

    /* File Ops (Top) - Wrapped */
    .canvas-toolbar {
        order: 1;
        flex-wrap: wrap;
        height: auto;
        padding: 10px;
        gap: 8px;
        background: var(--bg-surface);
        border-bottom: 1px solid var(--border-color);
        min-height: 50px;
    }

    .canvas-toolbar::-webkit-scrollbar {
        display: none;
    }

    .canvas-toolbar .action-btn {
        flex: 1 1 auto;
        justify-content: center;
        padding: 10px 14px;
        font-size: 0.85rem;
        background: var(--input-bg);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        min-width: 80px;
    }

    /* Canvas (Middle) - Generous Height */
    .canvas-area {
        order: 2;
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .canvas-wrapper {
        width: 100%;
        height: 60vh;
        /* 60% of screen height */
        min-height: 400px;
        border-bottom: 1px solid var(--border-color);
    }

    /* Tools (Below Canvas) - Wrapped */
    .toolbar {
        order: 3;
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        border-top: none;
        border-bottom: 1px solid var(--border-color);
        padding: 20px 16px;
        gap: 16px;
        justify-content: center;
        background: var(--bg-surface);
        box-shadow: none;
        flex-shrink: 0;
    }

    .tool-btn {
        width: 50px;
        height: 50px;
        border-radius: 12px;
        background: var(--input-bg);
        border: 1px solid var(--border-color);
        flex-shrink: 0;
    }

    .tool-btn.active {
        background: var(--primary-gradient);
        border: none;
    }

    .tool-divider {
        display: none;
    }

    /* Right Panel (Bottom) - Full Content */
    .right-panel {
        order: 4;
        width: 100%;
        height: auto !important;
        max-height: none !important;
        border: none;
        padding-bottom: 60px;
        flex-shrink: 0;
        overflow: visible;
    }

    .panel-section {
        padding: 20px;
    }

    .color-palette {
        grid-template-columns: repeat(auto-fit, minmax(36px, 1fr));
        gap: 8px;
    }
}

/* --- FINAL MOBILE FIX (Step 267 - Override All) --- */
@media (max-width: 900px) {

    /* RESET Everything first to kill conflict styles */
    .paint-app,
    .paint-main,
    .right-panel,
    .toolbar,
    .canvas-toolbar,
    .canvas-area,
    .canvas-wrapper {
        min-height: 0 !important;
        max-height: none !important;
        height: auto !important;
        width: auto !important;
        flex: 0 1 auto !important;
        overflow: visible !important;
    }

    /* 1. Global Fixed Layout */
    .paint-main {
        height: 100vh !important;
        height: 100dvh !important;
        overflow: hidden !important;
    }

    .paint-app {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
    }

    /* 2. Top Toolbar (Icons) */
    .canvas-toolbar {
        order: 1 !important;
        height: 52px !important;
        flex: 0 0 52px !important;
        /* Rigid height */
        display: flex !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        align-items: center !important;
        padding: 0 12px !important;
        gap: 8px !important;
        background: var(--bg-surface) !important;
        border-bottom: 1px solid var(--border-color) !important;
    }

    .action-btn {
        font-size: 0 !important;
        width: 36px !important;
        height: 36px !important;
        padding: 0 !important;
        justify-content: center !important;
    }

    .action-btn i {
        font-size: 1.2rem !important;
        margin: 0 !important;
    }

    .toolbar-group span {
        display: none !important;
    }

    /* 3. Canvas (Fills Center) */
    .canvas-area {
        order: 2 !important;
        flex: 1 1 auto !important;
        /* Grows */
        height: auto !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .canvas-wrapper {
        flex: 1 !important;
        width: 100% !important;
        height: 100% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }

    #paint-canvas {
        max-width: 95% !important;
        max-height: 95% !important;
        width: auto !important;
        height: auto !important;
        object-fit: contain !important;
        box-shadow: 0 5px 20px rgba(0, 0, 0, 0.5) !important;
    }

    /* 4. Tools Dock (Above Panel) */
    .toolbar {
        order: 3 !important;
        height: 64px !important;
        flex: 0 0 64px !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        /* CRITICAL */
        overflow-x: auto !important;
        /* CRITICAL */
        justify-content: flex-start !important;
        align-items: center !important;
        padding: 0 16px !important;
        gap: 12px !important;
        background: var(--bg-surface) !important;
        border-top: 1px solid var(--border-color) !important;
        white-space: nowrap !important;
        /* CRITICAL */
    }

    .tool-btn {
        width: 44px !important;
        height: 44px !important;
        flex: 0 0 44px !important;
        /* Rigid size */
        margin: 0 !important;
    }

    /* 5. Right Panel (Bottom Drawer) */
    .right-panel {
        order: 4 !important;
        position: static !important;
        width: 100% !important;
        /* FORCE FULL WIDTH */
        height: 35vh !important;
        flex: 0 0 35vh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto !important;
        background: var(--bg-panel) !important;
        border-top: 1px solid var(--border-color) !important;
        padding: 0 !important;
        /* Reset padding */
        margin: 0 !important;
        /* Reset margin */
        left: auto !important;
        right: auto !important;
        top: auto !important;
        bottom: auto !important;
        transform: none !important;
    }

    .panel-section {
        padding: 12px 16px !important;
        margin: 0 !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .color-palette {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr)) !important;
        gap: 8px !important;
        width: 100% !important;
    }
}

/* --- SCALING FOR SMALL SCREENS (320-576px) --- */
@media (max-width: 576px) {

    /* Scale down Top Toolbar */
    .canvas-toolbar {
        height: 48px !important;
        flex: 0 0 48px !important;
        gap: 6px !important;
    }

    .action-btn {
        width: 32px !important;
        height: 32px !important;
    }

    .action-btn i {
        font-size: 1.1rem !important;
    }

    /* Scale down Bottom Toolbar */
    .toolbar {
        height: 56px !important;
        flex: 0 0 56px !important;
        gap: 10px !important;
        padding: 0 10px !important;
    }

    .tool-btn {
        width: 40px !important;
        height: 40px !important;
        flex: 0 0 40px !important;
    }

    /* Scale down Panel */
    .right-panel {
        height: 35vh !important;
        /* Keep relative height */
    }

    .color-swatch {
        width: 32px !important;
        height: 32px !important;
    }

    .color-palette {
        grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)) !important;
    }
}

/* --- EXTRA POLISH (Step 298 & 309) --- */
@media (max-width: 900px) {

    /* Hide the footer text content on mobile so user sees ONLY the app */
    main+section.container {
        display: none !important;
    }

    /* Ensure body doesn't scroll */
    body,
    html {
        overflow: hidden !important;
        height: 100% !important;
        margin: 0 !important;
    }

    /* Refine Wrapper to prevent scrollbars */
    .canvas-wrapper {
        height: auto !important;
        overflow: hidden !important;
    }

    /* FORCE FULL WIDTH on Panel Sections (Fixes empty black space) */
    .right-panel,
    .panel-section,
    .color-palette,
    .color-main {
        width: 100% !important;
        min-width: 100% !important;
        max-width: none !important;
        box-sizing: border-box !important;
    }

    /* --- APP NAVIGATION RESTORE (Step 360) --- */
    @media (max-width: 900px) {

        /* 1. Show Header (Compact) */
        body>header {
            display: flex !important;
            position: relative !important;
            height: 50px !important;
            min-height: 50px !important;
            overflow: hidden !important;
            z-index: 200 !important;
            padding: 0 10px !important;
            align-items: center !important;
        }

        body>header .container {
            padding: 0 !important;
            margin: 0 !important;
            max-width: none !important;
            width: 100% !important;
            display: flex !important;
            align-items: center !important;
            justify-content: center !important;
        }

        /* Fix Flexbox alignment issues caused by clearfix pseudos */
        body>header .container::before,
        body>header .container::after {
            display: none !important;
        }

        body>header .nav-links {
            display: none !important;
        }

        body>header {
            background: var(--bg-surface) !important;
        }

        body>header .brand {
            font-size: 1.2rem !important;
            margin: 0 !important;
            flex: 0 0 auto !important;
            width: auto !important;
        }

        /* 2. Adjust App Height to fit Header */
        .paint-main {
            height: calc(100vh - 50px) !important;
            height: calc(100dvh - 50px) !important;
        }
    }

    /* Hide stray buttons */
    .panel-close-btn,
    .mobile-menu-btn {
        display: none !important;
    }
}