/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    min-height: 100vh;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

/* Header */
.header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

.header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
}

.header h1 i {
    font-size: 2rem;
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Upload Section */
.upload-section {
    background: white;
    border-radius: 16px;
    padding: 40px;
    margin-bottom: 30px;
}

.upload-area {
    border: 3px dashed #ddd;
    border-radius: 12px;
    padding: 60px 20px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.upload-area:hover, .upload-area.drag-over {
    border-color: #667eea;
    background: #f8f9ff;
}

.upload-content {
    pointer-events: none;
}

.upload-icon {
    font-size: 4rem;
    color: #667eea;
    margin-bottom: 20px;
}

.upload-content h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    color: #333;
}

.browse-btn {
    background: #667eea;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    pointer-events: all;
    transition: background 0.3s ease;
}

.browse-btn:hover {
    background: #5a67d8;
}

.file-info {
    color: #666;
    font-size: 0.9rem;
    margin-top: 15px;
}

/* Editor Section */
.editor-section {
    background: white;
    border-radius: 16px;
    overflow: hidden;
}

.editor-toolbar {
    background: #f8f9fa;
    padding: 15px 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
}

.toolbar-group {
    display: flex;
    gap: 10px;
    align-items: center;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid #ddd;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.tool-btn:hover {
    background: #f8f9fa;
    border-color: #667eea;
}

.tool-btn.primary {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

.tool-btn.primary:hover {
    background: #5a67d8;
}

.aspect-ratio-label {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.aspect-ratio-label select {
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
}

.dimension-label {
    font-size: 0.9rem;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dimension-label input {
    width: 80px;
    padding: 6px 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    text-align: center;
}

/* Editor Workspace */
.editor-workspace {
    display: flex;
    min-height: 600px;
}

.canvas-container {
    flex: 1;
    position: relative;
    background: #f8f9fa;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 600px;
}

#imageCanvas {
    max-width: 100%;
    max-height: 100%;
    cursor: move;
    transition: transform 0.3s ease;
}

.crop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.crop-selection {
    position: absolute;
    border: 3px solid #667eea;
    background: rgba(102, 126, 234, 0.15);
    cursor: move;
    pointer-events: all;
    min-width: 20px;
    min-height: 20px;
}

.crop-selection::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: 
        linear-gradient(to right, rgba(255, 255, 255, 0.3) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255, 255, 255, 0.3) 1px, transparent 1px);
    background-size: 33.33% 33.33%;
    pointer-events: none;
}

.crop-selection::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.crop-handles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background: #667eea;
    border: 3px solid white;
    border-radius: 50%;
    cursor: pointer;
    transform: translate(-50%, -50%);
    transition: all 0.2s ease;
}

.handle.nw { top: 0; left: 0; cursor: nw-resize; }
.handle.ne { top: 0; right: 0; cursor: ne-resize; }
.handle.sw { bottom: 0; left: 0; cursor: sw-resize; }
.handle.se { bottom: 0; right: 0; cursor: se-resize; }
.handle.n { top: 0; left: 50%; cursor: n-resize; }
.handle.s { bottom: 0; left: 50%; cursor: s-resize; }
.handle.w { top: 50%; left: 0; cursor: w-resize; }
.handle.e { top: 50%; right: 0; cursor: e-resize; }

/* Preview Panel */
.preview-panel {
    width: 300px;
    background: white;
    border-left: 1px solid #e9ecef;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.preview-panel h3 {
    margin-bottom: 15px;
    color: #333;
    font-size: 1.1rem;
}

.preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8f9fa;
    border-radius: 8px;
    min-height: 200px;
    margin-bottom: 15px;
}

#previewCanvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 4px;
}

.crop-info {
    text-align: center;
    font-size: 0.9rem;
    color: #666;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    color: white;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #333;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    background: white;
    padding: 15px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1001;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.toast.error {
    border-left: 4px solid #e53e3e;
    color: #e53e3e;
}

.toast.success {
    border-left: 4px solid #38a169;
    color: #38a169;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    margin-left: auto;
    opacity: 0.7;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1002;
}

.modal-content {
    background: white;
    border-radius: 12px;
    width: 90%;
    max-width: 500px;
    overflow: hidden;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    opacity: 0.7;
}

.modal-close:hover {
    opacity: 1;
}

.modal-body {
    padding: 20px;
}

.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: 15px;
}

kbd {
    background: #f1f3f4;
    border: 1px solid #dadce0;
    border-radius: 4px;
    padding: 4px 8px;
    font-family: monospace;
    font-size: 0.85rem;
    min-width: 30px;
    text-align: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 10px;
    }
    
    .header h1 {
        font-size: 2rem;
    }
    
    .upload-section {
        padding: 20px;
    }
    
    .upload-area {
        padding: 40px 20px;
    }
    
    .editor-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    
    .toolbar-group {
        justify-content: center;
        flex-wrap: wrap;
    }
    
    .editor-workspace {
        flex-direction: column;
    }
    
    .preview-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e9ecef;
    }
    
    .canvas-container {
        min-height: 400px;
    }
    
    .toast {
        left: 10px;
        right: 10px;
        max-width: none;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.8rem;
        flex-direction: column;
        gap: 10px;
    }
    
    .tool-btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
    
    .upload-content h3 {
        font-size: 1.2rem;
    }
    
    .upload-icon {
        font-size: 3rem;
    }
}

/* Touch Support */
@media (hover: none) and (pointer: coarse) {
    .handle {
        width: 20px;
        height: 20px;
    }
    
    .crop-selection {
        border-width: 3px;
    }
    
    .tool-btn {
        padding: 12px 16px;
        font-size: 1rem;
    }
}

/* High DPI Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .crop-selection {
        border-width: 1px;
    }
}

/* Focus and Accessibility */
.tool-btn:focus,
.browse-btn:focus,
.handle:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.upload-area:focus-within {
    border-color: #667eea;
    background: #f8f9ff;
}

/* Animation for smooth interactions */
.crop-selection {
    transition: none;
}

.canvas-container.zooming #imageCanvas {
    transition: none;
}

.handle:hover {
    transform: translate(-50%, -50%) scale(1.3);
    background: #5a67d8;
}

.handle:active {
    transform: translate(-50%, -50%) scale(1.1);
    background: #4c51bf;
}
