/* CSS Custom Properties for consistency */
:root {
    --primary-blue: #3498db;
    --primary-blue-hover: #2980b9;
    --dark-gray: #2c3e50;
    --medium-gray: #34495e;
    --medium-gray-hover: #4a5f7a;
    --light-gray: #6c757d;
    --light-gray-hover: #5a6268;
    --success-green: #27ae60;
    --success-green-hover: #229954;
    --danger-red: #e74c3c;
    --danger-red-hover: #c0392b;
    --purple: #9b59b6;
    --purple-hover: #8e44ad;
    --border-light: #e9ecef;
    --background-light: #f8f9fa;
    --text-dark: #2c3e50;
    --text-muted: #6c757d;
    
    /* Consistent sizing */
    --border-radius: 6px;
    --border-radius-small: 4px;
    --button-padding: 8px 12px;
    --button-height: 36px;
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Sketch app specific body styles - don't interfere with navbar */
.sketch-page {
    background: #f0f0f0;
    min-height: 100vh;
}

/* Sketch app container - positioned below navbar */
.sketch-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px); /* Account for navbar */
    width: 100%;
    margin-top: 10px;
}

/* Main sketch app area */
.sketch-app {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.toolbar {
    background: var(--dark-gray);
    color: white;
    padding: 12px 16px;
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    z-index: 10;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.tool-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 0;
}

.tool-group label {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.9);
    margin-right: 4px;
}

.tool {
    background: var(--medium-gray);
    border: none;
    color: white;
    padding: var(--button-padding);
    cursor: pointer;
    border-radius: var(--border-radius-small);
    font-size: 14px;
    font-weight: 500;
    height: var(--button-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    min-width: 44px;
    font-family: inherit;
    /* Flat design - no shadows or raised appearance */
}

.tool:hover {
    background: var(--medium-gray-hover);
    /* Flat design - no transform or shadow */
}

.tool.active {
    background: var(--primary-blue);
    /* Flat design - no shadow */
}

.tool.active:hover {
    background: var(--primary-blue-hover);
}

.tool:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#colorPicker {
    width: 40px;
    height: var(--button-height);
    border: 2px solid #fff;
    border-radius: var(--border-radius-small);
    cursor: pointer;
    transition: var(--transition);
    /* Flat design - no shadow */
}

#colorPicker:hover {
    border-color: var(--border-light);
    /* Flat design - no transform or shadow */
}

#brushSize {
    width: 100px;
    height: 20px;
}

#sizeDisplay {
    min-width: 30px;
    text-align: center;
    font-weight: 500;
    color: var(--text-dark);
    padding: 4px 8px;
    background: var(--background-light);
    border-radius: var(--border-radius-small);
    border: 1px solid var(--border-light);
    font-size: 13px;
}

.file-label {
    background: #34495e;
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
    font-size: 14px;
    display: inline-block;
}

.file-label:hover {
    background: #4a5f7a;
}

#layerSelect {
    padding: 5px;
    border-radius: 4px;
    background: #34495e;
    color: white;
    border: 1px solid #4a5f7a;
    font-size: 14px;
    cursor: pointer;
}

#layerVisible {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.canvas-container {
    flex: 1;
    display: flex;
    position: relative;
    background: #ddd;
    overflow: hidden;
}

#canvasWrapper {
    position: relative;
    flex: 1;
    background: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    margin: 12px;
    margin-right: 250px; /* Space for layer panel */
    min-height: 400px;
    border-radius: var(--border-radius-small);
    border: 1px solid var(--border-light);
}

.drawing-canvas {
    cursor: crosshair;
    display: block;
}

.layer-panel {
    position: absolute;
    right: 12px;
    top: 12px;
    width: 220px;
    background: white;
    border-radius: var(--border-radius);
    padding: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: calc(100% - 24px);
    overflow-y: auto;
    z-index: 100;
    border: 1px solid var(--border-light);
}

.layer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-light);
}

.layer-header h3 {
    margin: 0;
    color: var(--text-dark);
    font-size: 16px;
    font-weight: 600;
}

.layer-control-btn {
    background: var(--primary-blue);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition);
    font-family: inherit;
    /* Flat design - no shadow */
}

.layer-control-btn:hover {
    background: var(--primary-blue-hover);
    /* Flat design - no transform or shadow */
}

.layer-control-btn.delete {
    background: var(--danger-red);
    font-size: 16px;
    width: 24px;
    height: 24px;
    /* Flat design - no shadow */
}

.layer-control-btn.delete:hover {
    background: var(--danger-red-hover);
    /* Flat design - no shadow */
}

#layerList {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.layer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    margin-bottom: 4px;
}

.layer-item:hover {
    background: #f8f9fa;
    border-color: #e9ecef;
}

.layer-item.active {
    background: #e3f2fd;
    border-color: #3498db;
    color: #2c3e50;
}

.layer-item .visibility-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--border-radius-small);
    transition: var(--transition);
    opacity: 0.7;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layer-item .visibility-btn:hover {
    background: var(--border-light);
    opacity: 1;
    /* Flat design - no transform */
}

.layer-item .visibility-btn.visible {
    opacity: 1;
}

.layer-item .visibility-btn.hidden {
    opacity: 0.3;
}

.layer-item .layer-name {
    flex: 1;
    font-size: 14px;
    user-select: none;
    padding: 2px 4px;
    border-radius: 3px;
}

.layer-item.active .layer-name {
    font-weight: 600;
}

.layer-item .delete-layer {
    opacity: 0;
    transition: opacity 0.2s;
}

.layer-item:hover .delete-layer {
    opacity: 1;
}

button {
    font-family: inherit;
}

#undoBtn, #redoBtn {
    font-size: 20px;
    padding: 5px 10px;
}

#addLayer, #deleteLayer {
    padding: 5px 10px;
    font-weight: bold;
}

/* Colored toolbar buttons with consistent flat design - UPDATED */
#imageBtn {
    background: var(--purple);
    /* FLAT DESIGN - NO SHADOWS */
}

#imageBtn:hover {
    background: var(--purple-hover);
    /* FLAT DESIGN - NO TRANSFORMS */
}

#clearBtn {
    background: var(--danger-red);
    /* FLAT DESIGN - NO SHADOWS */
}

#clearBtn:hover {
    background: var(--danger-red-hover);
    /* FLAT DESIGN - NO TRANSFORMS */
}

#downloadBtn {
    background: var(--success-green);
    /* FLAT DESIGN - NO SHADOWS */
}

#downloadBtn:hover {
    background: var(--success-green-hover);
    /* FLAT DESIGN - NO TRANSFORMS */
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: white;
    border-radius: var(--border-radius);
    max-width: 600px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
    animation: slideUp 0.3s;
    border: 1px solid var(--border-light);
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: #2c3e50;
    font-size: 1.5rem;
}

.modal-close {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: #6c757d;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.2s;
}

.modal-close:hover {
    background: #f0f0f0;
}

.modal-body {
    padding: 20px;
}

.import-section {
    margin-bottom: 25px;
}

.file-drop-zone {
    border: 2px dashed #cbd5e0;
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: #f8f9fa;
}

.file-drop-zone:hover {
    border-color: #3498db;
    background: #e3f2fd;
}

.file-drop-zone.dragover {
    border-color: #3498db;
    background: #e3f2fd;
    transform: scale(1.02);
}

.drop-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.file-drop-zone p {
    margin: 10px 0;
    color: #2c3e50;
    font-weight: 500;
}

.file-drop-zone small {
    color: #6c757d;
}

.image-preview {
    margin-top: 15px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 10px;
    background: #f8f9fa;
}

.image-preview img {
    max-width: 100%;
    max-height: 200px;
    display: block;
    margin: 0 auto;
    border-radius: 4px;
}

.scaling-section {
    margin-bottom: 25px;
}

.scaling-section h3,
.layer-section h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 1.1rem;
}

.scaling-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 10px;
}

.scale-option {
    cursor: pointer;
}

.scale-option input[type="radio"] {
    display: none;
}

.scale-card {
    border: 2px solid var(--border-light);
    border-radius: var(--border-radius);
    padding: 15px 10px;
    text-align: center;
    transition: var(--transition);
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.scale-option input[type="radio"]:checked + .scale-card {
    border-color: var(--primary-blue);
    background: #e3f2fd;
    box-shadow: 0 4px 8px rgba(52, 152, 219, 0.15);
}

.scale-card:hover {
    border-color: var(--primary-blue);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(52, 152, 219, 0.15);
}

.scale-icon {
    font-size: 24px;
    margin-bottom: 8px;
}

.scale-label {
    display: block;
    font-weight: 600;
    color: #2c3e50;
    margin-bottom: 4px;
    font-size: 0.9rem;
}

.scale-card small {
    color: #6c757d;
    font-size: 0.75rem;
    display: block;
}

.layer-section {
    margin-bottom: 20px;
}

.layer-options {
    display: flex;
    gap: 20px;
}

.layer-option {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px 15px;
    border: 2px solid #e9ecef;
    border-radius: 6px;
    transition: all 0.2s;
}

.layer-option:hover {
    border-color: #3498db;
}

.layer-option input[type="radio"] {
    margin-right: 8px;
}

.layer-option input[type="radio"]:checked + span {
    font-weight: 600;
    color: #3498db;
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #e9ecef;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    font-size: 14px;
    min-height: var(--button-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    /* Flat design - no shadow */
}

.btn-primary {
    background: var(--primary-blue);
    color: white;
    /* Flat design - no shadow */
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-blue-hover);
    /* Flat design - no transform or shadow */
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    /* Flat design - no shadow */
}

.btn-secondary {
    background: var(--light-gray);
    color: white;
    /* Flat design - no shadow */
}

.btn-secondary:hover {
    background: var(--light-gray-hover);
    /* Flat design - no transform or shadow */
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Touch-friendly adjustments for mobile */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 5px;
    background: #4a5f7a;
    outline: none;
    border-radius: 3px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 15px;
    height: 15px;
    background: #3498db;
    cursor: pointer;
    border-radius: 50%;
}

input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: #3498db;
    cursor: pointer;
    border-radius: 50%;
}

/* Prevent user selection on UI elements */
.toolbar, .layer-panel {
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    :root {
        --button-height: 44px; /* Larger touch targets on mobile */
    }
    
    .sketch-container {
        height: calc(100vh - 60px); /* Smaller navbar on mobile */
    }
    
    .toolbar {
        padding: 10px;
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .tool-group {
        gap: 8px;
        flex-wrap: wrap;
    }
    
    .tool {
        min-width: 44px;
        min-height: 44px;
        padding: 10px 12px;
    }
    
    #canvasWrapper {
        margin: 8px;
        margin-right: 12px; /* Less space for layer panel on mobile */
        border-radius: var(--border-radius-small);
    }
    
    .layer-panel {
        width: 200px;
        right: 8px;
        top: 8px;
        padding: 12px;
        font-size: 14px;
    }
    
    .layer-control-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }
    
    .layer-control-btn.delete {
        width: 28px;
        height: 28px;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px;
    }
    
    .scaling-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .btn {
        min-height: 44px;
        padding: 12px 16px;
    }
}