/* --- Core Layout --- */
html, body {
    height: 100%;
    margin: 0;
    overflow: hidden; /* Prevents scrolling on the body */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    display: flex;
    flex-direction: column;
    text-align: center;
}

header {
    padding: 10px;
    flex-shrink: 0; /* Prevents header from shrinking */
}

main#image-container {
    flex-grow: 1; /* Makes the main area fill all available space */
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Align editors to the top */
    gap: 20px;
    padding: 20px;
    overflow: hidden; /* Hide any potential overflow */
}

footer#controls-container {
    flex-shrink: 0; /* Prevents footer from shrinking */
    padding: 15px;
    background-color: #ffffff;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.08);
    display: flex;
    justify-content: center;
    gap: 15px;
    z-index: 10;
    /* Added wrap to prevent overflow on small screens */
    flex-wrap: wrap; 
}

/* NEW: Style for the filename input group */
.download-name-group {
    display: flex;
    align-items: center;
    gap: 8px;
    /* Allow it to shrink if needed, but not too much */
    flex-shrink: 1; 
    min-width: 180px; 
}

.download-name-group label {
    font-size: 14px;
    font-weight: bold;
    white-space: nowrap;
}

.download-name-group input[type="text"] {
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 14px;
    flex-grow: 1; /* Allow input to take available space */
    min-width: 0; /* Needed for flex-grow to work properly */
}


/* --- Drag & Drop Overlay Styling --- */
#drag-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 123, 255, 0.85);
    z-index: 9999;
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    pointer-events: none; /* Allows drop event to reach elements below */
}
body.dragging #drag-overlay {
    display: flex; /* Shown when dragging class is on body */
}
.drag-overlay-content {
    color: white;
    font-size: 2.5em;
    font-weight: bold;
    border: 4px dashed white;
    padding: 40px 80px;
    border-radius: 20px;
}


/* --- Image Editor Styling --- */
.image-editor {
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    position: relative;
    width: 45%;
    max-height: 95%; 
    max-width: 600px;
    padding: 15px;
    box-sizing: border-box; 
    transition: border-color 0.3s;
}

.image-editor.cropping {
    border-color: #007bff;
}

.canvas-wrapper {
    flex-grow: 1; 
    background-color: #2c3e50; 
    border-radius: 4px;
    margin-bottom: 15px;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    min-height: 200px; 
    position: relative; /* For cursor styling */
}

.image-editor canvas {
    /* Let JS control the size, but ensure it doesn't overflow its parent visually */
    max-width: 100%;
    max-height: 100%;
    position: absolute; /* Stack canvases */
}

/* Cursors for crop mode */
.canvas-wrapper.cropping-active { cursor: crosshair; }
.canvas-wrapper.cropping-active.cursor-move { cursor: move; }
.canvas-wrapper.cropping-active.cursor-nwse { cursor: nwse-resize; }
.canvas-wrapper.cropping-active.cursor-nesw { cursor: nesw-resize; }
.canvas-wrapper.cropping-active.cursor-ew { cursor: ew-resize; }
.canvas-wrapper.cropping-active.cursor-ns { cursor: ns-resize; }


.delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background-color: rgba(220, 53, 69, 0.8);
    color: white;
    font-weight: bold;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    transition: background-color 0.2s;
}
.delete-btn:hover { background-color: #c82333; }

/* --- Controls Styling --- */
.control-btn { 
    padding: 12px 25px; 
    font-size: 16px; 
    font-weight: bold; 
    color: white; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    transition: background-color 0.2s; 
    flex-shrink: 0; /* Prevent buttons from shrinking */
}
#download-btn { background-color: #007bff; }
#download-btn:hover { background-color: #0056b3; }
#swap-btn { background-color: #ffc107; color: #212529; }
#swap-btn:hover { background-color: #e0a800; }

#clear-all-btn { background-color: #6c757d; }
#clear-all-btn:hover { background-color: #5a6268; }


.editor-controls { 
    width: 100%; 
    max-width: 400px; 
    margin: 0 auto; 
    flex-shrink: 0;
}
.control-group { 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    margin-bottom: 12px; 
    gap: 10px;
}
.control-group label { 
    font-size: 14px;
    margin-right: 10px; 
    white-space: nowrap; 
    flex-shrink: 0;
}
.control-group input[type="range"] { 
    width: 100%; 
}
.control-group button { 
    padding: 8px 12px; 
    background-color: #6c757d; 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 14px;
}
.control-group button:hover { background-color: #5a6268; }

.control-reset-btn {
    padding: 4px 8px !important;
    font-size: 18px !important;
    line-height: 1;
    flex-shrink: 0;
    margin-left: 5px;
}

/* CROP CONTROL STYLES */
button[data-action="crop"] {
    background-color: #17a2b8;
}
button[data-action="crop"]:hover {
    background-color: #138496;
}
.crop-actions {
    display: flex; /* Changed to flex for the inner group */
    flex-direction: column; /* Stack inner groups */
    gap: 12px; /* Space between inner groups */
}
.crop-actions .control-group {
    margin-bottom: 0; /* Reset margin-bottom for inner groups */
}
.crop-actions button {
    padding: 8px 15px;
    font-size: 14px;
    font-weight: bold;
}
.crop-actions .apply-crop-btn {
    background-color: #28a745;
}
.crop-actions .apply-crop-btn:hover {
    background-color: #218838;
}
.crop-actions .cancel-crop-btn {
    background-color: #dc3545;
}
.crop-actions .cancel-crop-btn:hover {
    background-color: #c82333;
}