/* NEW 4-BAR LAYOUT FOR CROP TOOL */

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #0a0a0a;
    color: #fff;
    overflow-x: hidden;
    overflow-y: auto;
    /* Prevent bounce/overscroll on iOS */
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

/* Custom Scrollbar - Desktop with mouse only (not touch devices) */
@media (hover: hover) and (pointer: fine) {
    ::-webkit-scrollbar {
        width: 8px;
        height: 8px;
    }

    ::-webkit-scrollbar-track {
        background: #1a1a1a;
        border-radius: 4px;
    }

    ::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #00ffa3 0%, #00d4aa 100%);
        border-radius: 4px;
        transition: background 0.3s ease;
    }

    ::-webkit-scrollbar-thumb:hover {
        background: linear-gradient(135deg, #00d4aa 0%, #00b894 100%);
    }

    /* Firefox Scrollbar */
    * {
        scrollbar-width: thin;
        scrollbar-color: #00ffa3 #1a1a1a;
    }
}

/* Main Tool Container - Fits viewport, scrollable content below */
.tool-container {
    width: 100vw;
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   1. TOP TOOLBAR - Tool-specific styles only
   (Base toolbar styles are in common.css)
   ============================================ */
.session-btn {
    background: transparent;
    border: none;
    color: #ff8800;
}

.session-btn:hover {
    background: rgba(255, 136, 0, 0.2);
}

.cached-images-btn {
    background: transparent;
    border: none;
    color: #ff8800;
}

.cached-images-btn:hover {
    background: rgba(255, 136, 0, 0.15);
    color: #ff9922;
}

/* Zoom Controls */
.toolbar-divider {
    width: 1px;
    height: 30px;
    background: #444;
    margin: 0 0.5rem;
}

.zoom-btn {
    min-width: 50px;
}

.zoom-btn .btn-text {
    font-size: 1.2rem;
    font-weight: 700;
    margin-top: -0.25rem;
}

.zoom-slider-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    min-width: 150px;
    padding: 0.25rem 0.5rem;
}

.zoom-slider {
    width: 100%;
    height: 4px;
    background: #444;
    border-radius: 2px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #00ffa3 0%, #00d4aa 100%);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 255, 163, 0.3);
    transition: all 0.2s;
}

.zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 10px rgba(0, 255, 163, 0.5);
}

.zoom-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: linear-gradient(135deg, #00ffa3 0%, #00d4aa 100%);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 255, 163, 0.3);
    transition: all 0.2s;
}

.zoom-slider::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 3px 10px rgba(0, 255, 163, 0.5);
}

.zoom-slider:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.zoom-slider:disabled::-webkit-slider-thumb {
    cursor: not-allowed;
}

.zoom-slider:disabled::-moz-range-thumb {
    cursor: not-allowed;
}

.zoom-level-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 50px;
    padding: 0.25rem 0.5rem;
    background: rgba(0, 255, 163, 0.1);
    border: 1px solid rgba(0, 255, 163, 0.3);
    border-radius: 4px;
    color: #00ffa3;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: 'Courier New', monospace;
}

/* ============================================
   2. MAIN AREA (Left Sidebar + Canvas + Right Sidebar)
   ============================================ */
.main-area {
    flex: 1;
    display: grid;
    grid-template-columns: 60px 1fr 60px;
    overflow: hidden;
    position: relative;
    /* Background and transition now in common.css */
}

/* LEFT SIDEBAR (Settings Icons) */
.left-sidebar {
    background: linear-gradient(180deg, #1a1a1a 0%, #2d2d2d 100%);
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: 1rem 0.5rem;
    gap: 0.5rem;
    z-index: 100;
}

/* Hide mobile sidebar on desktop */
.mobile-sidebar {
    display: none;
}

.settings-btn {
    width: 100%;
    min-height: 50px;
    background: transparent;
    border: none;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: all 0.2s;
    color: #888;
    padding: 0.5rem 0.25rem;
}

.settings-btn svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.settings-btn span {
    font-size: 0.625rem;
    font-weight: 500;
    text-align: center;
    word-wrap: break-word;
    line-height: 1.2;
}

.settings-btn:hover,
.settings-btn.active {
    background: rgba(0, 255, 163, 0.08);
    color: #00ffa3;
}

/* Settings Panels (Slide from left sidebar's right edge) */
/* Note: Positioning and animation now handled in common.css */
.settings-panel {
    border-right: 1px solid #333;
    display: flex;
    flex-direction: column;
    /* Background now in common.css */
}

.settings-panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.settings-panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #00ffa3;
}

.close-panel {
    width: 28px;
    height: 28px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 4px;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-panel:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: #ff0000;
    color: #ff0000;
}

.settings-panel-content {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}

/* Aspect Ratio Buttons */
.ratio-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.ratio-btn {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #444;
    border-radius: 6px;
    color: #888;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.ratio-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #666;
}

.ratio-btn.active {
    background: transparent;
    border-color: #00ffa3;
    color: #00ffa3;
}

/* Shape Buttons */
.shape-buttons {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
}

.shape-btn {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #444;
    border-radius: 6px;
    color: #888;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.shape-btn svg {
    width: 24px;
    height: 24px;
    color: inherit;
}

.shape-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #666;
}

.shape-btn.active {
    background: transparent;
    border-color: #00ffa3;
    color: #00ffa3;
}

.shape-info {
    margin-bottom: 1rem;
}

/* Transform Buttons */
.transform-group {
    margin-bottom: 0.5rem;
}

.transform-group-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #888;
    margin-bottom: 0.5rem;
    text-align: left;
}

.straighten-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.straighten-header label {
    font-size: 0.875rem;
    color: #888;
}

.straighten-reset-btn {
    padding: 0.25rem 0.625rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #444;
    border-radius: 4px;
    color: #888;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    height: 24px;
    line-height: 1;
}

.straighten-reset-btn:hover {
    background: rgba(0, 255, 163, 0.1);
    border-color: #00ffa3;
    color: #00ffa3;
}

.straighten-reset-btn:active {
    transform: scale(0.95);
}

.transform-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.transform-btn {
    flex: 1;
    min-width: calc(50% - 0.25rem);
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid #444;
    border-radius: 6px;
    color: #888;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.transform-btn svg {
    width: 24px;
    height: 24px;
    color: inherit;
}

.transform-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #666;
    color: #fff;
}

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

.transform-info {
    margin-bottom: 1rem;
}

/* Desktop: slider and reset button on separate lines */
.slider-reset-container {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.slider-reset-container .btn-secondary {
    width: 100%;
}

/* Input Groups */
.input-group {
    margin-bottom: 1rem;
}

.input-group label {
    display: block;
    font-size: 0.875rem;
    color: #888;
    margin-bottom: 0.5rem;
}

.input-group input[type="number"],
.input-group select {
    width: 100%;
    padding: 0.625rem;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #444;
    border-radius: 6px;
    color: #fff;
    font-size: 0.875rem;
}

.input-group select {
    cursor: pointer;
}

.input-group select option {
    background: #000;
    color: #fff;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    border-bottom: 1px solid rgba(0, 255, 163, 0.1);
}

.input-group select option:hover {
    background: #000;
    color: #00ffa3;
}

.input-group select option:checked {
    background: #000;
    color: #00ffa3;
    font-weight: 600;
}

.input-group input[type="number"]:focus,
.input-group select:focus {
    outline: none;
    border-color: #00ffa3;
}

/* Dimensions Container with Lock Button */
.dimensions-container {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.dimensions-container .input-group {
    flex: 1;
    margin-bottom: 0;
}

.dimension-lock-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    padding: 0;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid #444;
    border-radius: 6px;
    color: #888;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-bottom: 0;
}

.dimension-lock-btn svg {
    width: 20px;
    height: 20px;
}

.dimension-lock-btn:hover {
    background: rgba(0, 255, 163, 0.1);
    border-color: #00ffa3;
    color: #00ffa3;
}

.dimension-lock-btn.locked {
    background: rgba(0, 255, 163, 0.15);
    border-color: #00ffa3;
    color: #00ffa3;
}

.dimension-lock-btn.locked:hover {
    background: rgba(0, 255, 163, 0.25);
}

.slider {
    width: 100%;
    height: 6px;
    background: #333;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: #00ffa3;
    border-radius: 50%;
    cursor: pointer;
}

.slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #00ffa3;
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.btn {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #00ffa3 0%, #00d4aa 50%, #00b894 100%);
    color: #000;
    font-weight: 700;
    box-shadow: 0 4px 15px rgba(0, 255, 163, 0.2);
}

.btn-primary:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 8px 25px rgba(0, 255, 163, 0.4);
}

.btn-outline {
    background: transparent;
    border: 2px solid #00ffa3;
    color: #00ffa3;
}

.btn-outline:hover {
    background: rgba(0, 255, 163, 0.15);
}

.btn-secondary {
    background: linear-gradient(135deg, #444 0%, #555 100%);
    color: #fff;
    border: 1px solid #666;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-secondary:hover {
    background: linear-gradient(135deg, #555 0%, #666 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 255, 163, 0.1);
}

.btn-secondary svg {
    width: 18px;
    height: 18px;
}

/* CENTER CANVAS AREA */
/* Note: grid-column positioning now handled in common.css */
/* Canvas background and layout now defined in common.css with radial dot pattern */

.canvas-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: auto;
}

.canvas-wrapper.zoomed {
    cursor: grab;
    overflow: auto;
    /* Change to flex-start to allow proper scrolling in all directions */
    align-items: flex-start;
    justify-content: flex-start;
    /* Add padding = viewport/2 to allow any canvas point to be centered */
    padding: 50vh 50vw;
}

.canvas-wrapper.zoomed:active {
    cursor: grabbing;
}

.canvas-wrapper.panning {
    cursor: grabbing;
    user-select: none;
}

.canvas-placeholder {
    text-align: center;
    color: #666;
}

.canvas-placeholder svg {
    width: 64px;
    height: 64px;
    margin-bottom: 1rem;
    color: #444;
}

.canvas-placeholder .upload-text {
    font-size: 0.875rem;
    color: #888;
    margin-bottom: 0.25rem;
}

.canvas-placeholder h3 {
    font-size: 1.125rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 0.5rem;
    min-height: 30px;
}

.canvas-placeholder p {
    font-size: 1rem;
    margin-bottom: 1rem;
}

.canvas-placeholder .supported-formats {
    font-size: 0.75rem;
    color: #666;
    margin-bottom: 1.5rem;
}

.canvas-placeholder .btn {
    margin-top: 0.5rem;
    width: auto;
    min-width: 300px;
    min-height: 50px;
    padding: 0.875rem 2rem;
    font-size: 1rem;
}

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

/* Allow canvas to exceed container when zoomed */
.canvas-wrapper.zoomed #canvas {
    max-width: none;
    max-height: none;
}

/* Fit to Screen Button - Positioned at top right of canvas */
.fit-to-screen-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border: 1px solid #444;
    border-radius: 8px;
    color: #888;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.fit-to-screen-btn svg {
    width: 20px;
    height: 20px;
}

.fit-to-screen-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #2d2d2d 0%, #3d3d3d 100%);
    border-color: #00ffa3;
    color: #00ffa3;
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 255, 163, 0.2);
}

.fit-to-screen-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

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

.crop-selection {
    position: absolute;
    border: 2px solid #888;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(0, 0, 0, 0.5);
    pointer-events: all;
    z-index: 2;
}

/* Rule of Thirds Grid Overlay - Hidden by default, shown during interaction */
.rule-of-thirds-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

/* Show grid when crop box is being interacted with */
.crop-selection.interacting .rule-of-thirds-grid {
    opacity: 1;
}

/* Vertical line 1 (left third) */
.rule-of-thirds-grid::before {
    content: '';
    position: absolute;
    top: 0;
    left: 33.333%;
    width: 2px;
    height: 100%;
    background: rgba(136, 136, 136, 0.4);
}

/* Vertical line 2 (right third) */
.rule-of-thirds-grid::after {
    content: '';
    position: absolute;
    top: 0;
    left: 66.666%;
    width: 2px;
    height: 100%;
    background: rgba(136, 136, 136, 0.4);
}

/* Horizontal lines using additional divs */
.rule-of-thirds-h1 {
    position: absolute;
    left: 0;
    top: 33.333%;
    width: 100%;
    height: 2px;
    background: rgba(136, 136, 136, 0.4);
    pointer-events: none;
    z-index: 2;
}

.rule-of-thirds-h2 {
    position: absolute;
    left: 0;
    top: 66.666%;
    width: 100%;
    height: 2px;
    background: rgba(136, 136, 136, 0.4);
    pointer-events: none;
    z-index: 2;
}

/* Professional L-shaped Corner Handles - OUTSIDE the box */
.crop-handle {
    position: absolute;
    width: 20px;
    height: 20px;
    z-index: 3;
    pointer-events: all;
}

.crop-handle::before,
.crop-handle::after {
    content: '';
    position: absolute;
    background: #00ffa3;
}

/* Corner handles - L-shaped brackets positioned OUTSIDE */
.crop-handle.tl { top: -5px; left: -5px; cursor: nwse-resize; }
.crop-handle.tl::before { top: 0; left: 0; width: 20px; height: 3px; }
.crop-handle.tl::after { top: 0; left: 0; width: 3px; height: 20px; }

.crop-handle.tr { top: -5px; right: -5px; cursor: nesw-resize; }
.crop-handle.tr::before { top: 0; right: 0; width: 20px; height: 3px; }
.crop-handle.tr::after { top: 0; right: 0; width: 3px; height: 20px; }

.crop-handle.bl { bottom: -5px; left: -5px; cursor: nesw-resize; }
.crop-handle.bl::before { bottom: 0; left: 0; width: 20px; height: 3px; }
.crop-handle.bl::after { bottom: 0; left: 0; width: 3px; height: 20px; }

.crop-handle.br { bottom: -5px; right: -5px; cursor: nwse-resize; }
.crop-handle.br::before { bottom: 0; right: 0; width: 20px; height: 3px; }
.crop-handle.br::after { bottom: 0; right: 0; width: 3px; height: 20px; }

/* Edge handles - Short thick lines OUTSIDE */
.crop-handle.t { 
    top: -5px; 
    left: 50%; 
    transform: translateX(-50%); 
    cursor: ns-resize;
    width: 30px;
    height: 7px;
}
.crop-handle.t::before { 
    top: 0; 
    left: 50%; 
    transform: translateX(-50%);
    width: 30px; 
    height: 3px; 
}

.crop-handle.b { 
    bottom: -5px; 
    left: 50%; 
    transform: translateX(-50%); 
    cursor: ns-resize;
    width: 30px;
    height: 7px;
}
.crop-handle.b::before { 
    bottom: 0; 
    left: 50%; 
    transform: translateX(-50%);
    width: 30px; 
    height: 3px; 
}

.crop-handle.l { 
    left: -5px; 
    top: 50%; 
    transform: translateY(-50%); 
    cursor: ew-resize;
    width: 7px;
    height: 30px;
}
.crop-handle.l::before { 
    left: 0; 
    top: 50%; 
    transform: translateY(-50%);
    width: 3px; 
    height: 30px; 
}

.crop-handle.r { 
    right: -5px; 
    top: 50%; 
    transform: translateY(-50%); 
    cursor: ew-resize;
    width: 7px;
    height: 30px;
}
.crop-handle.r::before { 
    right: 0; 
    top: 50%; 
    transform: translateY(-50%);
    width: 3px; 
    height: 30px; 
}

/* Shape overlay for crop selection */
.shape-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 3;
}

.crop-selection.shape-circle {
    border-radius: 50%;
}

.crop-selection.shape-rounded {
    border-radius: 20%;
}

/* Hide border and box-shadow for complex shapes (heart, star, triangle, pentagon, hexagon) */
.crop-selection.shape-complex {
    border: none;
    /* Remove box-shadow - will use SVG mask instead */
    box-shadow: none;
}

/* SVG mask overlay for complex shapes */
.shape-mask-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

.shape-mask-overlay svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ============================================
   MODALS & OVERLAYS
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #333;
    border-top-color: #00ffa3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: calc(var(--vh, 1vh) * 100);
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: linear-gradient(135deg, #1a1a1a 0%, #2d2d2d 100%);
    border: 1px solid #333;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    overflow: hidden;
}

.modal-content.modal-preview {
    max-width: 90vw;
    max-height: 90vh;
}

.modal-preview-body {
    max-height: calc(90vh - 80px);
    overflow-y: auto;
}

.preview-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    background: #000;
    border-radius: 8px;
    padding: 1rem;
}

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

.modal-header h4 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    color: #fff;
}

.modal-close {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #444;
    border-radius: 6px;
    color: #888;
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.modal-close:hover {
    background: rgba(255, 0, 0, 0.1);
    border-color: #ff0000;
    color: #ff0000;
}

.modal-body {
    padding: 1.5rem;
}

.modal-body p {
    color: #ccc;
    line-height: 1.6;
    margin-bottom: 1.5rem;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
}

.modal-actions .btn {
    flex: 1;
}

/* Drag and drop for canvas area */
.canvas-area.dragover {
    background: rgba(0, 255, 163, 0.05);
    border: 2px dashed #00ffa3;
}

/* ============================================
   MOBILE RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    /* Hide transform group labels on mobile */
    .transform-group-label {
        display: none;
    }
    
    /* Shape buttons - 4 per row on mobile */
    /* Aspect Ratio panel - compact for 130px panel height */
    #aspectPanel .settings-panel-content {
        padding: 0.4rem 0.5rem;
    }
    
    .ratio-buttons {
        gap: 0.25rem;
    }
    
    .ratio-btn {
        padding: 0.3rem 0.4rem;
        font-size: 0.65rem;
    }
    
    .shape-buttons {
        grid-template-columns: repeat(4, 1fr);
        gap: 0.25rem;
    }
    
    /* Shapes panel - compact for 130px panel height */
    #shapePanel .settings-panel-content {
        padding: 0.4rem 0.5rem;
    }
    
    #shapePanel .shape-info {
        margin-bottom: 0.3rem;
    }
    
    #shapePanel .shape-info p {
        font-size: 0.6rem;
        margin-bottom: 0.3rem;
    }
    
    .shape-btn {
        padding: 0.25rem 0.15rem;
        gap: 0.15rem;
        font-size: 0.55rem;
    }
    
    .shape-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .shape-btn span {
        font-size: 0.5rem;
        line-height: 1;
    }
    
    /* Mobile active state - only icon and text green */
    .mobile-sidebar .settings-btn.active {
        color: #00ffa3 !important;
    }
    
    .mobile-sidebar .settings-btn:hover {
        color: #00ffa3 !important;
    }
    
    /* Mobile layout - prevent URL bar bounce */
    .tool-container {
        display: flex;
        flex-direction: column;
        /* Use dvh (dynamic viewport height) for better mobile browser support */
        height: 100dvh;
        height: calc(var(--vh, 1vh) * 100);
        /* Initially prevent scroll - only allow when SEO content opens */
        overflow: hidden;
        position: fixed;
        width: 100%;
        top: 0;
        left: 0;
    }
    
    /* Allow scroll only when SEO content is visible */
    .tool-container.allow-scroll {
        overflow-y: auto;
        position: relative;
    }
    
    /* Top toolbar stays at top - MOBILE FIX: Ensure touch events reach buttons */
    .top-toolbar {
        order: 1;
        flex-shrink: 0;
        z-index: 500;
        isolation: isolate;
        pointer-events: auto;
        touch-action: manipulation;
        position: relative;
    }
    
    /* Main area in middle */
    .main-area {
        order: 3;
        display: flex;
        flex-direction: column;
        flex: 1;
        overflow: hidden;
        min-height: 300px;
    }
    
    /* When panel opens, it overlays from bottom */
    .main-area.panel-open {
        /* Panel overlays, no padding needed */
    }
    
    /* Canvas takes available space */
    .canvas-area {
        flex: 1;
        min-height: 0; /* Allow flex to shrink */
        grid-column: auto;
        display: flex;
        flex-direction: column;
    }
    
    .main-area.panel-open .canvas-area {
        grid-column: auto;
        /* When panel is open (130px height), reduce canvas area */
        flex: 1;
        min-height: 0;
        max-height: calc(100% - 130px);
    }
    
    .canvas-wrapper {
        flex: 1;
        min-height: 0;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* Mobile Button Size Fix */
    .canvas-placeholder .btn {
        width: auto;
        min-width: 200px;
        min-height: 48px;
        padding: 0.75rem 1.75rem;
        font-size: 0.9375rem;
    }
    
    .canvas-placeholder h3 {
        font-size: 1rem;
    }
    
    .canvas-placeholder svg {
        width: 48px;
        height: 48px;
    }
    
    /* Hide desktop sidebar on mobile */
    .desktop-sidebar {
        display: none !important;
    }
    
    /* Show mobile sidebar on mobile - Settings bar at bottom */
    .mobile-sidebar {
        display: flex;
        order: 4;
        position: relative;
        width: 100%;
        height: 60px;
        flex-direction: row;
        justify-content: center;
        border-right: none;
        border-top: 1px solid #333;
        padding: 0.5rem;
        gap: 0.75rem;
        flex-shrink: 0;
        z-index: 500;
        /* Create new stacking context to ensure buttons are always clickable */
        isolation: isolate;
        /* Ensure touch events are received */
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    .settings-btn {
        width: 38px;
        height: 38px;
        gap: 1px;
    }
    
    .settings-btn svg {
        width: 16px;
        height: 16px;
    }
    
    .settings-btn span {
        font-size: 0.55rem;
    }
    
    /* Settings panels adjust for mobile - slide from bottom */
    .settings-panel {
        top: auto;
        left: 0 !important;
        right: 0;
        bottom: -130px;
        width: 100%;
        height: 130px;
        border-right: none;
        border-top: 1px solid #333;
        border-radius: 12px 12px 0 0;
        overflow-y: auto;
        z-index: 450;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    .settings-panel.active {
        bottom: 0px;
        left: 0 !important;
        z-index: 450;
    }
    
    /* MOBILE FIX: Right sidebar toggle button - ensure touch events reach it */
    /* NOTE: Do NOT override position - common.css sets position: fixed correctly */
    .right-sidebar-toggle {
        z-index: 500;
        isolation: isolate;
        pointer-events: auto;
        touch-action: manipulation;
        /* position: relative removed - it was breaking the fixed positioning from common.css */
    }
    
    /* MOBILE FIX: Right sidebar (tools panel) - ensure touch events reach tool items */
    .right-sidebar {
        z-index: 500;
        isolation: isolate;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    /* MOBILE FIX: Tool items in right sidebar */
    .tool-item {
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    /* MOBILE FIX: Fit to screen button - ensure touch events reach it */
    .fit-to-screen-btn {
        z-index: 500;
        isolation: isolate;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    /* MOBILE FIX: Canvas controls container */
    .canvas-controls {
        z-index: 500;
        isolation: isolate;
        pointer-events: auto;
        touch-action: manipulation;
    }
    
    /* Hide entire panel header on mobile for compact design */
    .settings-panel-header {
        display: none;
    }
    
    /* Compact mobile controls */
    .settings-panel-content {
        padding: 0.5rem 0.6rem;
    }
    
    .input-group {
        margin-bottom: 0.4rem;
    }
    
    .input-group label {
        font-size: 0.65rem;
        margin-bottom: 0.2rem;
    }
    
    .input-group input[type="number"],
    .input-group select {
        padding: 0.35rem 0.4rem;
        font-size: 0.75rem;
        height: 28px;
    }
    
    /* Horizontal scrollable aspect ratio buttons */
    .ratio-buttons {
        display: flex;
        flex-direction: row;
        gap: 0.3rem;
        overflow-x: auto;
        overflow-y: hidden;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        padding-bottom: 0.3rem;
    }
    
    .ratio-buttons::-webkit-scrollbar {
        display: none;
    }
    
    .ratio-btn {
        flex: 0 0 auto;
        min-width: 65px;
        padding: 0.35rem 0.4rem;
        font-size: 0.7rem;
        scroll-snap-align: start;
    }
    
    /* Scroll dots indicator */
    .scroll-dots {
        display: flex;
        justify-content: center;
        gap: 0.3rem;
        margin-top: 0.4rem;
        padding: 0.15rem 0;
    }
    
    .scroll-dot {
        width: 5px;
        height: 5px;
        border-radius: 50%;
        background: #444;
        transition: all 0.3s;
    }
    
    .scroll-dot.active {
        background: #00ffa3;
        transform: scale(1.2);
    }
    
    /* Horizontal scrollable shape buttons */
    .shape-buttons {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.3rem !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        scroll-snap-type: x mandatory !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding-bottom: 0.3rem !important;
        grid-template-columns: none !important;
    }
    
    .shape-buttons::-webkit-scrollbar {
        display: none !important;
    }
    
    .shape-btn {
        flex: 0 0 auto !important;
        min-width: 65px !important;
        scroll-snap-align: start !important;
    }
    
    /* Compact Output Panel - Format + Quality on same line */
    #outputPanel .settings-panel-content {
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }
    
    #outputPanel .format-quality-row {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }
    
    #outputPanel .format-buttons {
        display: flex;
        gap: 0.35rem;
        flex-wrap: nowrap;
    }
    
    #outputPanel .format-btn {
        flex: 0 0 auto;
        padding: 0.4rem 0.6rem;
        background: rgba(255, 255, 255, 0.03);
        border: 1px solid #444;
        border-radius: 6px;
        color: #888;
        font-size: 0.7rem;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s;
        white-space: nowrap;
    }
    
    #outputPanel .format-btn:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: #666;
    }
    
    #outputPanel .format-btn.active {
        background: rgba(0, 255, 163, 0.15);
        border-color: #00ffa3;
        color: #00ffa3;
    }
    
    #outputPanel .quality-slider-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    #outputPanel .quality-slider-container label {
        font-size: 0.65rem;
        margin: 0;
    }
    
    /* Dimension inputs with lock button on mobile - compact for 130px panel */
    #dimensionsPanel .settings-panel-content {
        padding: 0.4rem 0.5rem;
    }
    
    #dimensionsPanel .dimensions-container {
        display: flex;
        gap: 0.25rem;
        margin-bottom: 0.3rem;
    }
    
    #dimensionsPanel .dimensions-container .input-group {
        flex: 1;
        margin-bottom: 0;
    }
    
    #dimensionsPanel .dimensions-container .input-group label {
        font-size: 0.6rem;
        margin-bottom: 0.15rem;
    }
    
    #dimensionsPanel .dimensions-container .input-group input {
        padding: 0.3rem 0.35rem;
        font-size: 0.7rem;
        height: 28px;
    }
    
    #dimensionsPanel .dimension-lock-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
    }
    
    #dimensionsPanel .dimension-lock-btn svg {
        width: 14px;
        height: 14px;
    }
    
    #dimensionsPanel .btn {
        width: 100%;
        padding: 0.35rem 0.4rem;
        font-size: 0.7rem;
    }
    
    .btn {
        padding: 0.65rem 1rem;
        font-size: 0.875rem;
    }
    
    .setting-group label {
        font-size: 0.75rem;
    }
    
    .setting-control input,
    .setting-control select {
        font-size: 0.875rem;
        padding: 0.5rem;
    }
    
    /* Transform Panel Mobile Optimization */
    
    /* Display both transform groups side by side to get all 4 buttons in one line */
    .transform-groups-wrapper {
        display: flex;
        flex-direction: row;
        gap: 0.4rem;
        margin-bottom: 0.75rem;
    }
    
    .transform-groups-wrapper .transform-group {
        flex: 1;
        margin-bottom: 0 !important;
    }
    
    .transform-groups-wrapper .transform-buttons {
        display: flex;
        flex-wrap: nowrap !important;
        gap: 0.4rem;
    }
    
    .transform-groups-wrapper .transform-btn {
        flex: 1 1 auto !important;
        min-width: 0 !important;
        padding: 0.5rem 0.25rem !important;
        font-size: 0.65rem !important;
        gap: 0.25rem !important;
    }
    
    .transform-groups-wrapper .transform-btn svg {
        width: 18px;
        height: 18px;
    }
    
    /* Transform panel - compact for 130px panel height */
    #transformPanel .settings-panel-content {
        padding: 0.4rem 0.5rem;
    }
    
    .transform-groups-wrapper {
        gap: 0.3rem;
        margin-bottom: 0.3rem;
    }
    
    .transform-group {
        gap: 0.25rem;
    }
    
    .transform-group h4 {
        font-size: 0.6rem;
        margin-bottom: 0.2rem;
    }
    
    .transform-buttons {
        gap: 0.25rem;
    }
    
    .transform-btn {
        padding: 0.25rem 0.2rem;
        gap: 0.15rem;
    }
    
    .transform-btn svg {
        width: 14px;
        height: 14px;
    }
    
    .transform-groups-wrapper .transform-btn span {
        font-size: 0.55rem;
    }
    
    /* Straighten label + reset button on same line */
    #transformPanel .straighten-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.2rem;
    }
    
    #transformPanel .straighten-header label {
        font-size: 0.6rem;
        margin: 0;
    }
    
    #transformPanel .straighten-reset-btn {
        font-size: 0.55rem;
        padding: 0.1rem 0.3rem;
        height: auto;
    }
    
    /* Slider + Reset Transform button on same line */
    #transformPanel .slider-reset-container {
        display: flex !important;
        flex-direction: row !important;
        gap: 0.3rem !important;
        align-items: center !important;
        margin-bottom: 0 !important;
    }
    
    #transformPanel .slider-reset-container .slider {
        flex: 1 !important;
        margin: 0 !important;
        height: 4px !important;
    }
    
    #transformPanel .slider-reset-container .btn-secondary {
        flex-shrink: 0 !important;
        padding: 0.3rem 0.4rem !important;
        font-size: 0.55rem !important;
        white-space: nowrap !important;
        width: auto !important;
    }
    
    /* Larger crop handles for mobile touch */
    .crop-handle {
        width: 20px;
        height: 20px;
    }
    
    .crop-handle.tl { top: -10px; left: -10px; }
    .crop-handle.tr { top: -10px; right: -10px; }
    .crop-handle.bl { bottom: -10px; left: -10px; }
    .crop-handle.br { bottom: -10px; right: -10px; }
    .crop-handle.t { top: -10px; }
    .crop-handle.b { bottom: -10px; }
    .crop-handle.l { left: -10px; }
    .crop-handle.r { right: -10px; }
}
