/* Custom styles with improved color scheme */
body {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    min-height: 100vh;
}

/* Header styling */
header h1 {
    background: linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-weight: 700;
    text-shadow: none;
}

header p {
    color: #6c757d !important;
    font-weight: 500;
}

/* Cards styling */
.card {
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 12px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(10px);
}

.card-header {
    background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
    border-bottom: 1px solid rgba(0,0,0,0.08);
    border-radius: 12px 12px 0 0 !important;
}

/* Fixed height layout for three-column design */
.main-row {
    height: 70vh; /* Fixed height based on viewport */
    min-height: 600px; /* Minimum height for small screens */
    max-height: 800px; /* Maximum height to prevent excessive growth */
}

.main-row > .col-lg-5,
.main-row > .col-lg-2 {
    display: flex;
    height: 100%;
}

.main-row > .col-lg-5 > .card,
.main-row > .col-lg-2 > .card {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden; /* Prevent card from growing beyond container */
}

/* Make card bodies fill remaining space with scrolling */
.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Prevent overflow from breaking layout */
}

/* Controls column specific styling */
.controls-column .card-body {
    overflow-y: auto; /* Allow scrolling in controls */
    padding-bottom: 80px; /* Space for convert button */
}

/* Convert button container - always visible at bottom */
.convert-button-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 15px;
    background: linear-gradient(to top, rgba(255,255,255,1) 70%, rgba(255,255,255,0) 100%);
    border-top: 1px solid rgba(0,0,0,0.05);
}

/* Controls column positioning */
.controls-column .card {
    position: relative;
}

/* HTML Editor styling with fixed height and scrolling */
#htmlEditor {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    line-height: 1.4;
    flex: 1;
    resize: none;
    overflow-y: auto;
    min-height: 0; /* Allow flex shrinking */
}

#htmlEditor:focus {
    box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
}

/* Preview container - FIXED HEIGHT WITH SCROLLBARS */
#previewContainer {
    flex: 1;
    overflow: auto !important;
    position: relative;
    min-height: 0; /* Allow flex shrinking */
    background: #f8f9fa;
}

#previewContent {
    /* Allow content to expand naturally without breaking */
    min-width: max-content;
    white-space: normal;
    /* Don't force word wrapping - let content be its natural width */
    word-wrap: normal;
    overflow-wrap: normal;
}

/* Custom button hover effects */
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.25);
}

.btn-success:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(25, 135, 84, 0.25);
    background: linear-gradient(135deg, #198754 0%, #20c997 100%);
}

/* Enhanced convert button styling */
#convertButton {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
    border: none;
    font-weight: 600;
    transition: all 0.3s ease;
}

#convertButton:hover {
    background: linear-gradient(135deg, #218838 0%, #1abc9c 100%);
}

/* Quality value styling */
#qualityValue {
    font-weight: 600;
    color: #6610f2;
}

/* Watermark styling */
#watermarkOpacityValue {
    font-weight: 600;
    color: #20c997;
}

#watermarkOptions {
    background: rgba(248, 249, 250, 0.5);
    padding: 8px;
    border-radius: 6px;
    border: 1px solid rgba(0,0,0,0.08);
    margin-top: 6px;
}

#watermarkOptions .form-text {
    font-size: 10px;
    margin-top: 2px;
}

#watermarkOptions .form-label {
    margin-bottom: 2px;
}

#watermarkOptions .form-control,
#watermarkOptions .form-range {
    font-size: 12px;
}

#watermarkUrl {
    transition: border-color 0.3s ease;
}

#watermarkUrl:focus {
    border-color: #20c997;
    box-shadow: 0 0 0 0.2rem rgba(32, 201, 151, 0.25);
}

/* Image output styling */
#imageOutput img {
    max-width: 100%;
    max-height: 500px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

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

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

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

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Specific scrollbar styling for preview container */
#previewContainer::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

#previewContainer::-webkit-scrollbar-track {
    background: #e9ecef;
    border-radius: 5px;
}

#previewContainer::-webkit-scrollbar-thumb {
    background: #6c757d;
    border-radius: 5px;
}

#previewContainer::-webkit-scrollbar-thumb:hover {
    background: #495057;
}

#previewContainer::-webkit-scrollbar-corner {
    background: #e9ecef;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .main-row {
        height: auto !important; /* Allow natural height on mobile */
        min-height: auto !important;
        max-height: none !important;
    }
    
    .main-row > .col-lg-5,
    .main-row > .col-lg-2 {
        height: auto !important;
        margin-bottom: 1rem;
    }
    
    .main-row > .col-lg-5 > .card,
    .main-row > .col-lg-2 > .card {
        height: auto !important;
        min-height: 300px;
    }
    
    .controls-column .card-body {
        overflow-y: visible !important;
        padding-bottom: 15px !important;
    }
    
    .convert-button-container {
        position: relative !important;
        background: none !important;
        border-top: none !important;
        padding: 10px 15px !important;
        margin-top: 10px;
    }
    
    #previewContainer {
        min-height: 300px;
        max-height: 400px;
    }
    
    #htmlEditor {
        min-height: 300px;
        max-height: 400px;
    }
}