/* Custom theming and specific styles for Imaginus */
:root {
    touch-action: pan-x pan-y;
    height: 100%;
}

html {
    height: 100%;
    min-height: 100vh;
    background: #0f0f14;
}
  
/* Dark theme enhancements */
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: radial-gradient(1200px 800px at 20% 10%, #2a2a72 0%, transparent 60%),
                radial-gradient(1200px 800px at 80% 20%, #009ffd 0%, transparent 60%),
                #0f0f14 !important;
    background-attachment: fixed;
    background-position: center top;
    background-size: cover;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    animation: backgroundColorMove 12s ease-in-out infinite;
    overflow-x: hidden;
}

@keyframes backgroundColorMove {
    0% {
        background: radial-gradient(1200px 800px at 20% 10%, #2a2a72 0%, transparent 60%),
                    radial-gradient(1200px 800px at 80% 20%, #009ffd 0%, transparent 60%),
                    #0f0f14 !important;
    }
    20% {
        background: radial-gradient(1200px 800px at 30% 20%, #3b3b92 0%, transparent 65%),
                    radial-gradient(1200px 800px at 70% 30%, #00afff 0%, transparent 55%),
                    #0f0f14 !important;
    }
    40% {
        background: radial-gradient(1200px 800px at 80% 30%, #4c4ca2 0%, transparent 70%),
                    radial-gradient(1200px 800px at 20% 40%, #1a8cff 0%, transparent 50%),
                    #0f0f14 !important;
    }
    60% {
        background: radial-gradient(1200px 800px at 70% 20%, #1a1a5a 0%, transparent 75%),
                    radial-gradient(1200px 800px at 30% 10%, #0056ff 0%, transparent 45%),
                    #0f0f14 !important;
    }
    80% {
        background: radial-gradient(1200px 800px at 40% 50%, #5c5cb2 0%, transparent 55%),
                    radial-gradient(1200px 800px at 60% 60%, #00d4ff 0%, transparent 65%),
                    #0f0f14 !important;
    }
    100% {
        background: radial-gradient(1200px 800px at 20% 10%, #2a2a72 0%, transparent 60%),
                    radial-gradient(1200px 800px at 80% 20%, #009ffd 0%, transparent 60%),
                    #0f0f14 !important;
    }
}

/* Navbar blurry/glassy effect */
.navbar {
    display: none;
    background: rgba(15, 15, 20, 0.1) !important;
    backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
}

/* Custom card styling for upload area */
.upload-area {
    border: 2px dashed rgba(255, 255, 255, 0.3) !important;
    transition: all 0.25s ease;
    backdrop-filter: blur(10px);
    background: rgba(255, 255, 255, 0.05) !important;
}

.upload-area:hover {
    border-color: rgba(255, 255, 255, 0.5) !important;
    background: rgba(255, 255, 255, 0.1) !important;
    transform: translateY(-2px);
}

.upload-area.drag-over {
    border-color: #0d6efd !important;
    background: rgba(13, 110, 253, 0.1) !important;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

/* Enhanced Image Preview Section */
.image-preview-container {
    width: 100%;
    min-height: 80vh; /* Increased height for better centering */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center; /* Center the content vertically */
    padding: 20px;
    margin: 0 auto; /* Center horizontally */
    max-width: 1400px; /* Limit max width for better centering */
    position: relative;
}

.preview-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
}

.preview-frame {
    position: relative;
    width: 100%;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    padding: 0;
    padding-bottom: 100px; /* Space for the input section */
    backdrop-filter: blur(8px);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Clip zoomed content to frame bounds */
}

/* In-image toolbar (bottom-right vertical, blurred) */
.preview-toolbar {
    position: absolute;
    right: 12px;
    bottom: 120px; /* stay above input section */
    z-index: 11; /* above overlay */
    display: none;
}

.preview-toolbar .toolbar-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: rgba(15, 15, 20, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    padding: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.preview-toolbar .btn-toolbar {
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border-color: rgba(255, 255, 255, 0.35) !important;
    background: rgba(255, 255, 255, 0.04) !important;
}

.preview-toolbar .btn-toolbar i {
    font-size: 18px;
}

/* Rate Limit Badge in Toolbar */
.rate-limit-badge {
    padding: 6px 6px;
    background: rgba(76, 175, 80, 0.15);
    border: 1px solid rgba(76, 175, 80, 0.3);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: #4caf50;
    cursor: help;
    transition: all 0.2s ease;
}

.rate-limit-badge.warning {
    background: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.3);
    color: #ffc107;
}

.rate-limit-badge.limited {
    background: rgba(244, 67, 54, 0.15);
    border-color: rgba(244, 67, 54, 0.3);
    color: #f44336;
}

.rate-limit-badge:hover {
    transform: scale(1.05);
}

@media (max-width: 768px) {
    .preview-toolbar {
        right: 10px;
        bottom: 110px;
    }
    .preview-toolbar .btn-toolbar {
        width: 36px;
        height: 36px;
    }
}

.image-actions-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #0f0f1499;
    backdrop-filter: blur(30px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 1px 1px 0 0;
    padding: 16px;
    z-index: 10;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* Equally spaced action buttons below the image */
.image-actions-header .action-buttons {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 12px;
    width: 100%;
}

.image-actions-header .action-buttons .action-btn {
    width: 100%;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 4px;
}

.image-actions-header .action-buttons .btn-label {
    font-size: 10px;
    font-weight: 500;
    text-align: left;
    line-height: 1;
    color: rgba(255, 255, 255, 0.8);
}


.image-info h6 {
    font-weight: 600;
    color: #e6e6f0;
}

.image-info small {
    color: rgba(255, 255, 255, 0.6);
}

.action-buttons .btn {
    transition: transform 0.2s ease;
    font-weight: 500;
}

.action-buttons .btn:hover {
    transform: translateY(-1px);
}

/* Preview Input Section - Fixed position within preview frame */
.preview-input-section {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: #0f0f1499;
    backdrop-filter: blur(30px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 0 0 1px 1px;
    padding: 16px;
    z-index: 10;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}

/* Rate Limit Status Section - External to image card */
.rate-limit-section {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-bottom: 10px;
    padding: 0;
}

/* Rate Limit Status Display */
.rate-limit-status {
    position: relative;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 10px 16px;
    z-index: 9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rate-limit-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
}

.rate-limit-text {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    background: rgba(76, 175, 80, 0.15);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #4caf50;
}

.rate-limit-text i {
    font-size: 14px;
}

/* Rate limit status color states */
.rate-limit-status.available .rate-limit-text {
    background: rgba(76, 175, 80, 0.15);
    border-color: rgba(76, 175, 80, 0.3);
    color: #4caf50;
}

.rate-limit-status.warning .rate-limit-text {
    background: rgba(255, 193, 7, 0.15);
    border-color: rgba(255, 193, 7, 0.3);
    color: #ffc107;
}

.rate-limit-status.limited .rate-limit-text {
    background: rgba(244, 67, 54, 0.15);
    border-color: rgba(244, 67, 54, 0.3);
    color: #f44336;
}

.preview-input-section .form-control {
    background: rgba(255, 255, 255, 0.05) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 8px;
    padding: 10px 16px;
    font-size: 16px;
    color: #fff !important;
    transition: all 0.2s ease;
}

.preview-input-section .form-control:focus {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.4) !important;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
    color: #fff !important;
}

.preview-input-section .form-control::placeholder {
    color: rgba(255, 255, 255, 0.6) !important;
}

.preview-input-section .btn-primary {
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 600;
    font-size: 16px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-image {
    margin-top: 80px;
    margin-bottom: 63px;
    max-width: 100%;
    max-height: 75vh;
    width: auto;
    height: auto;
    object-fit: contain;
    display: block;
    border-radius: 0px;
}

/* Image container */
.preview-wrapper {
    overflow: hidden; /* Constrain zoomed image within bounds */
    position: relative;
    width: 100%;
    height: 100%;
}

/* remove floating toolbar styles (no longer used) */

/* Custom button styling */
.btn-primary {
    background: transparent !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: #fff !important;
    border-radius: 6px;
    padding: 8px 12px;
    font-weight: 500;
    font-size: 14px;
    transition: all 0.2s ease;
}

.btn-primary:hover {
    background: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.5) !important;
    color: #fff !important;
}

.btn-primary:disabled {
    opacity: 0.5;
    background: transparent !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: rgba(255, 255, 255, 0.5) !important;
    cursor: not-allowed;
}

.btn-outline-light:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Download button with green border */
#downloadBtn {
    border-color: #28a745 !important;
    color: #28a745 !important;
}

#downloadBtn:hover {
    background-color: rgba(40, 167, 69, 0.1) !important;
    border-color: #218838 !important;
    color: #218838 !important;
}

#downloadBtn:disabled {
    border-color: rgba(40, 167, 69, 0.3) !important;
    color: rgba(40, 167, 69, 0.5) !important;
}

/* Form controls dark theme */
.form-control.bg-dark {
    background-color: rgba(255, 255, 255, 0.1) !important;
    border-color: rgba(255, 255, 255, 0.2) !important;
    color: #fff !important;
}

.form-control.bg-dark:focus {
    background-color: rgba(255, 255, 255, 0.15) !important;
    border-color: #0d6efd !important;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
    color: #fff !important;
}

.form-control.bg-dark::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

/* Footer blurry/glassy effect */
#footerInput {
    background: rgba(15, 15, 20, 0.1) !important;
    backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
    box-shadow: 0 -2px 20px rgba(0, 0, 0, 0.1);
}

/* Custom spinner styling */
.spinner-border {
    width: 1rem;
    height: 1rem;
}

/* Center the loading state inside the send button */
.btn-loading {
    display: none; /* hidden by default; JS toggles this while generating */
    align-items: center;
    justify-content: center;
}

#generateBtn { position: relative; }
#generateBtn .btn-text { display: inline-flex; align-items: center; justify-content: center; width: 100%; }
#generateBtn .btn-loading { 
    position: absolute; 
    inset: 0; 
    background: transparent !important;
    border: 1px solid rgba(255, 255, 255, 0.3) !important;
    color: #fff !important;
    border-radius: 6px;
    padding: 8px 12px;
}

/* Alert styling for dark theme */
.alert-danger {
    background-color: rgba(220, 53, 69, 0.15);
    border-color: rgba(220, 53, 69, 0.3);
    color: #f8d7da;
}

/* Upload icon styling */
.upload-icon {
    opacity: 0.8;
}

/* Responsive design */
@media (max-width: 768px) {
    .upload-area {
        min-width: 250px !important;
        max-width: 90% !important;
    }

    .image-preview-container {
        min-height: 85vh; /* Better centering on mobile */
        padding: 10px;
        justify-content: center; /* Keep centered on mobile too */
    }

    /* Add padding to container to prevent mobile footer overlap */
    .container-fluid {
        padding-bottom: 80px;
    }

    .preview-image {
        margin-top: 53px;
        max-height: none;
    }

    .preview-wrapper {
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 70vh; /* Ensure enough height for centering */
    }

    .preview-frame {
        padding: 2px;
        border-radius: 12px;
        margin: 0 auto; /* Center horizontally */
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        width: 100%;
        max-width: 600px; /* Limit width on mobile for better appearance */
    }

    .preview-toolbar {
        right: 8px;
        bottom: 100px; /* Position above input section for mobile */
    }

    .preview-toolbar .toolbar-group {
        padding: 6px;
        gap: 6px;
    }

    .preview-toolbar .btn-toolbar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
}

/* Center mode for initial upload state */
body.center-mode .upload-section {
    min-height: calc(100vh - 60px) !important; /* subtract navbar height to prevent scroll */
    align-items: center !important; /* center vertically */
    padding-top: 0; /* no extra top space */
    transform: translateY(-3vh); /* nudge slightly upward */
}

/* Hide upload section completely when not in edit mode */
.upload-section.hidden {
    display: none !important;
    min-height: 0 !important;
    height: 0 !important;
}

/* Remove min-height when upload section is hidden via inline style */
.upload-section[style*="display: none"] {
    min-height: 0 !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* When image is loaded, adjust layout */
body.has-image .upload-section {
    min-height: auto !important;
}

body.has-image .history-section .card {
    margin-top: 40px;
}

/* Loading overlay styles */
.loading-overlay {
    position: absolute;
    top: 80px; /* Start below image-actions-header */
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 15, 20, 0.3);
    backdrop-filter: blur(8px);
    border-radius: 0 0 8px 8px; /* Only round bottom corners */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9; /* Lower than image-actions-header */
}

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

.loading-content .spinner-border {
    width: 3rem;
    height: 3rem;
}


/* Custom transitions */
.card, .btn, .form-control {
    transition: all 0.2s ease;
}

/* Drag and drop visual feedback */
.upload-area.drag-over .upload-icon {
    transform: scale(1.1);
    transition: transform 0.2s ease;
}

/* Tooltip color tweak for dark theme */
.tooltip-inner {
    background-color: rgba(15, 15, 20, 0.95);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip.bs-tooltip-auto .tooltip-arrow::before,
.tooltip.bs-tooltip-top .tooltip-arrow::before,
.tooltip.bs-tooltip-bottom .tooltip-arrow::before,
.tooltip.bs-tooltip-start .tooltip-arrow::before,
.tooltip.bs-tooltip-end .tooltip-arrow::before {
    border-top-color: rgba(15, 15, 20, 0.95);
    border-bottom-color: rgba(15, 15, 20, 0.95);
    border-left-color: rgba(15, 15, 20, 0.95);
    border-right-color: rgba(15, 15, 20, 0.95);
}

/* History Section Styles */
.history-section {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 15px;
}

.history-section .card {
    background: linear-gradient(135deg, rgba(15, 15, 20, 0.3) 0%, rgba(42, 42, 114, 0.1) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    margin-bottom: 15px;
    margin-top: -50px;
}

.history-section .card-header {
    background: linear-gradient(135deg, rgba(15, 15, 20, 0.4) 0%, rgba(0, 159, 253, 0.1) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px 20px;
}

.history-section .card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff !important;
    margin: 0;
}

.history-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 20px;
    padding: 20px;
    min-height: 200px;
    /* Removed max-height limit to show all history items */
}

.empty-history-message {
    grid-column: 1 / -1; /* Span all columns */
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 300px;
}

/* Custom scrollbar for history section */
.history-grid::-webkit-scrollbar {
    width: 8px;
}

.history-grid::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.history-grid::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 4px;
}

.history-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.5);
}

.history-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
}

.history-item:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
}

.history-image {
    width: 100%;
    height: 180px;
    object-fit: cover;
    display: block;
}

.history-content {
    padding: 12px;
}

.history-prompt {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    margin: 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-timestamp {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 8px;
}

.history-item.selected {
    border-color: #0d6efd;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.3);
}

/* History delete button styles */
.history-delete-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    opacity: 0;
    transition: all 0.2s ease;
    background: rgba(220, 53, 69, 0.9) !important;
    border-color: rgba(220, 53, 69, 0.5) !important;
    color: #fff !important;
    z-index: 10;
}

.history-item:hover .history-delete-btn {
    opacity: 1;
}

.history-delete-btn:hover {
    background: rgba(220, 53, 69, 1) !important;
    border-color: rgba(220, 53, 69, 0.8) !important;
    transform: scale(1.1);
}

/* Feedback Section */
.feedback-section {
    margin-top: 20px;
    padding: 20px 0;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.feedback-section .btn {
    transition: all 0.2s ease;
}

.feedback-section .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 255, 255, 0.1);
}

/* PWA Specific Styles */
/* Install button in navbar */
#pwa-install-btn {
    animation: pulseInstall 2s infinite;
}

@keyframes pulseInstall {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1);
    }
}

/* PWA installed state */
.pwa-installed .navbar::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, #2a2a72, #009ffd, #2a2a72);
    z-index: 1;
}

/* Hide install button when PWA is installed */
.pwa-installed #pwa-install-btn {
    display: none !important;
}

/* iPhone Install Modal Styles */
.modal-content {
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

/* iPhone install button - only show on iOS devices */
#pwa-install-btn {
    display: none;
}

/* Show install button only on iPhone */
@media screen and (max-width: 768px) {
    /* This will be controlled by JavaScript for iPhone detection */
}

/* Offline notification styles */
#offline-notification {
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 193, 7, 0.3);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
}

/* Update notification styles */
.alert-info {
    background-color: rgba(13, 202, 240, 0.15);
    border-color: rgba(13, 202, 240, 0.3);
    color: #b6effb;
}

/* Standalone mode adjustments */
@media all and (display-mode: standalone) {
    /* Hide browser-specific elements when in standalone mode */
    .pwa-only-hide {
        display: none !important;
    }

    /* Adjust navbar for standalone mode */
    .navbar {
        padding-top: env(safe-area-inset-top, 0);
        background: linear-gradient(135deg, rgba(15, 15, 20, 0.95) 0%, rgba(42, 42, 114, 0.3) 100%);
    }

    /* Add safe area padding for iPhone X+ devices */
    body {
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    /* Adjust footer for safe areas */
    #footerInput {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
        padding-left: env(safe-area-inset-left, 16px);
        padding-right: env(safe-area-inset-right, 16px);
    }
}

/* iOS Safari standalone mode specific styles */
@media all and (-webkit-min-device-pixel-ratio: 2) and (display-mode: standalone) {
    .navbar {
        background: linear-gradient(135deg, rgba(15, 15, 20, 0.98) 0%, rgba(42, 42, 114, 0.4) 100%);
        backdrop-filter: blur(20px);
    }
}

/* Responsive history grid */
@media (max-width: 768px) {
    .history-section {
        padding: 0 10px;
    }

    .history-section .card-header {
        padding: 12px 16px;
    }

    .history-section .card-title {
        font-size: 1.1rem;
    }

    .history-grid {
        grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
        gap: 15px;
        padding: 15px;
        /* Removed max-height limit for mobile too */
    }

    .history-image {
        height: 150px;
    }

    .history-content {
        padding: 10px;
    }

    .history-delete-btn {
        opacity: 0.7; /* More visible on mobile */
    }

    .feedback-section {
        margin-top: 15px;
        padding: 15px 0;
    }

    /* Fix mobile layout: ensure action buttons appear above input section */
    .image-actions-header {
        padding: 12px;
    }

    /* Adjust loading overlay for mobile to avoid blurring image-actions-header */
    .loading-overlay {
        top: 60px; /* Account for smaller mobile header */
    }

    .preview-input-section {
        padding: 12px;
        border-radius: 0 0 1px 1px;
    }

    .preview-input-section .form-control {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 8px 12px;
    }

    .preview-input-section .btn-primary {
        padding: 8px 12px;
        font-size: 14px;
    }
}

@media (max-width: 576px) {
    .history-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        padding: 12px;
        /* Removed max-height limit for small screens too */
    }


    .dot {
        font-size: 14px;
    }

    .feedback-section {
        padding: 12px 0;
    }

    /* Additional mobile fixes for very small screens */
    .image-actions-header {
        padding: 10px;
    }

    /* Adjust loading overlay for very small screens */
    .loading-overlay {
        top: 50px; /* Account for smallest mobile header */
    }

    .image-actions-header .action-buttons .btn {
        padding: 6px;
        font-size: 14px;
    }

    .preview-input-section {
        padding: 10px;
    }

    .preview-input-section .form-control {
        font-size: 16px;
        padding: 6px 10px;
    }

    .preview-input-section .btn-primary {
        padding: 6px 10px;
        font-size: 13px;
    }

    /* Zoom toolbar for very small screens */
    .preview-toolbar {
        right: 8px;
        bottom: 90px; /* Position above input section for small mobile */
    }

    .preview-toolbar .btn-toolbar {
        width: 32px;
        height: 32px;
    }

    .preview-toolbar .btn-toolbar i {
        font-size: 14px;
    }
}

/* Install Widget Styles */
.install-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    max-width: 280px;
}

.install-widget.show {
    opacity: 1;
    transform: translateY(0);
}

.install-widget-content {
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-widget i.bi-download {
    color: #2a2a72;
    font-size: 20px;
}

.install-widget-text {
    flex: 1;
    min-width: 0;
}

.install-widget-text strong {
    display: block;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 2px;
}

.install-widget-text small {
    color: rgba(255, 255, 255, 0.7);
    font-size: 12px;
}

.install-widget-btn {
    background: #ffffff;
    border: none;
    border-radius: 8px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.install-widget-btn:hover {
    background: #3a3a82;
    transform: scale(1.05);
}

.install-widget-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s ease;
    font-size: 14px;
}

.install-widget-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

/* Mobile Footer Navigation */
.mobile-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(33, 37, 41, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1000;
    display: none; /* Hidden by default, shown only on mobile */
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
}

.footer-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
    list-style: none;
    margin: 0;
    padding: 0;
    max-width: 500px;
    margin: 0 auto;
}

.footer-nav .nav-item {
    flex: 1;
    text-align: center;
}

.footer-nav .nav-link {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 4px;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.6);
    transition: all 0.2s ease;
    border-radius: 8px;
}

.footer-nav .nav-link:hover,
.footer-nav .nav-item.active .nav-link {
    color: #ffffff;
}

.footer-nav .nav-link i {
    font-size: 20px;
    margin-bottom: 2px;
}

.footer-nav .nav-link span {
    font-size: 11px;
    font-weight: 500;
    line-height: 1;
}

/* Mobile responsive for install widget */
@media (max-width: 768px) {
    /* Show mobile footer only on mobile devices */
    .mobile-footer {
        padding-bottom:30px;
        display: block;
        transition: transform 0.3s ease;
    }
    
    /* Hide footer when input is focused */
    .mobile-footer.input-focused {
        transform: translateY(100%);
        visibility: hidden;
    }
    
    /* Add bottom padding to body to prevent content overlap */
    body {
        padding-bottom: 80px;
    }
    
    /* Adjust install widget positioning to avoid footer */
    .install-widget {
        bottom: 90px;
        right: 15px;
        max-width: 250px;
    }

    .install-widget-content {
        margin-bottom: 30px;
        padding: 10px 14px;
        gap: 10px;
    }

    .install-widget-text strong {
        font-size: 13px;
    }

    .install-widget-text small {
        font-size: 11px;
    }
}

/* Contact Section */
.contact-section {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.contact-section .card {
    margin-bottom: 20px;
    background: linear-gradient(135deg, rgba(15, 15, 20, 0.3) 0%, rgba(42, 42, 114, 0.1) 100%);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.contact-section .card-header {
    background: linear-gradient(135deg, rgba(15, 15, 20, 0.4) 0%, rgba(0, 159, 253, 0.1) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 16px 20px;
}

.contact-section .card-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: #ffffff !important;
    margin: 0;
}

.contact-section .form-control {
    margin-bottom: 10px;
}

.contact-section .form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

.contact-section .form-label {
    color: #ffffff !important;
}

/* Remove extra spacing when sections are displayed alone (without image) */
body:not(.has-image) .history-section,
body:not(.has-image) .contact-section {
    padding-top: 20px;
}

body:not(.has-image) .history-section .card,
body:not(.has-image) .contact-section .card {
    margin-top: 0;
}

@media (max-width: 768px) {
    .contact-section {
        padding: 10px;
    }
    
    .contact-section .card-header {
        padding: 12px 16px;
    }
    
    .contact-section .card-title {
        font-size: 1.1rem;
    }
    
    /* Mobile specific spacing adjustments */
    body:not(.has-image) .history-section,
    body:not(.has-image) .contact-section {
        padding-top: 10px;
    }
}