/* History page styles */
.history-container {
    padding: var(--spacing-md);
    height: 100%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* History filters in sidebar */
.history-filters-container {
    margin-top: var(--spacing-md);
    padding: 0 var(--spacing-sm);
    border-bottom: 0.0625rem solid var(--border-color); /* 1px */
    padding-bottom: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.history-filters-container h3 {
    font-size: var(--font-size-md);
    font-weight: 500;
    margin-bottom: var(--spacing-md);
    color: var(--text-color);
    padding-left: var(--spacing-xs);
}

.history-filters {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xs);
}

.filter-option {
    position: relative;
}

.filter-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.filter-option label {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: background-color 0.2s;
    color: var(--text-color);
}

.filter-option label:hover {
    background-color: var(--hover-color);
}

.filter-option input[type="radio"]:checked + label {
    background-color: var(--active-color);
    font-weight: 500;
    box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1); /* 0 1px 3px */
}

.filter-option label span {
    font-size: 1.25rem; /* 20px */
    color: var(--text-secondary);
}

.filter-option input[type="radio"]:checked + label span {
    color: var(--primary-color);
}

/* History items grid - Responsive grid with flexible sizing */
.history-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(16rem, 100%), 1fr)); /* 256px min for better proportions */
    gap: var(--spacing-sm);
    padding-bottom: var(--spacing-md);
    margin-top: var(--spacing-sm);
    align-items: start; /* Align items to top for consistent layout */
    /* Ensure minimum viable grid on all screens */
    min-height: 0;
}

.history-item {
    background-color: var(--card-color);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 0.0625rem solid var(--border-color); /* 1px */
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    position: relative;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 16rem; /* 256px - Ensure consistent minimum height */
    max-height: 24rem; /* 384px - Prevent excessively tall containers */
}

.history-item:hover {
    transform: translateY(-0.1875rem); /* -3px */
    box-shadow: 0 0.3125rem 0.9375rem rgba(0, 0, 0, 0.2); /* 0 5px 15px */
}

.history-item-images {
    display: flex;
    height: clamp(8rem, 12vw, 12rem); /* Fluid height: 128px-192px range */
    border-bottom: 0.0625rem solid var(--border-color); /* 1px */
    position: relative;
}

.history-item-image {
    flex: 1;
    overflow: hidden;
    position: relative;
    background-color: rgba(0, 0, 0, 0.1);
    z-index: 1;
}

.history-item-image:first-child {
    border-right: 0.0625rem solid var(--border-color); /* 1px */
}

.history-item-image img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
}

.history-item-info {
    padding: var(--spacing-sm);
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    justify-content: space-between;
    min-height: 0; /* Allow flex items to shrink */
    gap: var(--spacing-xs); /* Add consistent gap between elements */
}

.history-item-title {
    margin: 0 0 var(--spacing-xs) 0;
    font-size: var(--font-size-md);
    font-weight: 500;
    color: var(--text-color);
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical;
}

.history-item-date {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
    margin: 0;
    line-height: 1.2;
    margin-top: auto; /* Push to bottom of container */
    margin-bottom: var(--spacing-xs); /* Space before buttons */
}

.history-item-badge {
    position: absolute;
    top: var(--spacing-xs);
    right: var(--spacing-xs);
    background-color: var(--card-color);
    color: var(--text-color);
    padding: 0.1875rem 0.5rem; /* 3px 8px */
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    opacity: 0.9;
    box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.2); /* 0 2px 4px */
    z-index: 15;
    pointer-events: none;
}



.history-item-actions {
    display: flex;
    justify-content: space-between;
    gap: var(--spacing-sm); /* Increased from xs to sm for better spacing */
    margin-top: var(--spacing-sm);
    z-index: 5;
    flex-wrap: wrap; /* Allow wrapping on very small screens */
}

.history-item-action {
    background-color: var(--card-color);
    border: 0.0625rem solid var(--border-color); /* 1px */
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.625rem 0.75rem; /* 10px 12px - Increased for better touch targets */
    border-radius: 0.5rem; /* 8px */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex: 1;
    min-height: 2.5rem; /* 40px - Ensure adequate touch target height */
    box-shadow: 0 0.0625rem 0.1875rem rgba(0, 0, 0, 0.1); /* 0 1px 3px */
    gap: 0.375rem; /* 6px - Slightly larger gap */
    text-align: center;
    white-space: nowrap; /* Prevent text wrapping within buttons */
}

.history-item-action:hover {
    background-color: var(--hover-color);
    color: var(--text-color);
    transform: translateY(-0.125rem); /* -2px */
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2); /* 0 4px 8px - Enhanced shadow */
    border-color: var(--primary-color); /* Subtle border highlight */
}

/* Improve focus states for accessibility */
.history-item-action:focus {
    outline: 0.125rem solid var(--primary-color);
    outline-offset: 0.125rem;
    background-color: var(--hover-color);
    color: var(--text-color);
}

/* Active state for better feedback */
.history-item-action:active {
    transform: translateY(0);
    box-shadow: 0 0.0625rem 0.125rem rgba(0, 0, 0, 0.1); /* 0 1px 2px */
}

.history-item-action .material-symbols-rounded {
    font-size: 1.125rem; /* 18px */
}

.history-item-action .action-label {
    font-size: 0.8125rem; /* 13px - Larger for better readability */
    font-weight: 500;
    line-height: 1.2;
}

/* Improved responsive breakpoints for better UX */

/* Medium screens - slightly smaller text but still visible */
@media (max-width: 42em) { /* 672px */
    .history-item-action .action-label {
        font-size: 0.75rem; /* 12px - Smaller text on medium screens */
    }
    
    .history-item-action {
        padding: 0.5rem 0.625rem; /* Slightly reduce padding */
        min-height: 2.25rem; /* 36px */
    }
}

/* Small screens - hide labels only on very small screens */
@media (max-width: 30em) { /* 480px */
    .history-item-action .action-label {
        display: none;
    }
    
    /* Adjust button sizing when text is hidden */
    .history-item-action {
        padding: 0.625rem; /* Square padding when no text */
        min-height: 2.75rem; /* 44px - Larger touch target with no text */
        min-width: 2.75rem; /* Square buttons */
    }
    
    .history-item-action .material-symbols-rounded {
        font-size: 1.25rem; /* 20px - Larger icons when no text */
    }
}

/* Very small mobile screens */
@media (max-width: 24em) { /* 384px */
    /* Improve grid on very small screens */
    .history-items {
        grid-template-columns: repeat(auto-fill, minmax(min(11rem, 100%), 1fr)); /* Even smaller minimum on tiny screens */
        gap: var(--spacing-xs); /* Tighter gap on mobile */
    }

    /* Reduce image height on mobile */
    .history-item-images {
        height: clamp(5rem, 8vw, 7rem); /* Even smaller height range on tiny screens */
    }
    
    /* Stack buttons vertically on very small screens */
    .history-item-actions {
        flex-direction: column;
        gap: var(--spacing-xs);
    }
    
    .history-item-action {
        min-height: 2.5rem; /* 40px */
        min-width: auto; /* Full width when stacked */
    }

    /* Stack modal actions vertically on very small screens */
    .detail-actions {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    /* Make buttons full width on mobile */
    .detail-actions .primary-button,
    .detail-actions .secondary-button,
    .detail-actions .danger-button {
        width: 100%;
        justify-content: center;
    }

    /* Improve modal sizing on mobile */
    .modal-content {
        margin: 1% auto;
        width: 98%;
    }

    /* Reduce preset option width on mobile */
    .detail-preset-option-name {
        width: 4rem; /* 64px - smaller on tiny screens */
        flex-shrink: 0;
    }
}

/* Specific colors for different actions */
.history-item-action[data-action="download"]:hover {
    color: #3498db; /* Blue for download */
}

.history-item-action[data-action="regenerate"]:hover {
    color: #2ecc71; /* Green for regenerate */
}

.history-item-action[data-action="delete"]:hover {
    color: #e74c3c; /* Red for delete */
}

.no-history, .no-filtered-items {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    text-align: center;
    height: 100%;
    min-height: 18.75rem; /* 300px */
}

.no-history span, .no-filtered-items span {
    font-size: clamp(2rem, 4vw, 3rem); /* Fluid 32px-48px */
    margin-bottom: var(--spacing-md);
    opacity: 0.5;
    color: var(--text-secondary);
}

.no-history p, .no-filtered-items p {
    margin-bottom: var(--spacing-lg);
    color: var(--text-secondary);
    font-size: var(--font-size-md); /* Use fluid typography */
}

.primary-button {
    background-color: var(--active-color);
    color: var(--text-color);
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: background-color 0.2s;
    font-size: 0.875rem; /* 14px */
    font-weight: 500;
    z-index: 10;
}

.primary-button:hover {
    background-color: var(--hover-color);
}

.primary-button span {
    font-size: 1.125rem; /* 18px */
    margin-right: 0.25rem; /* 4px */
}

.danger-button {
    background-color: #5e2626;
    color: var(--text-color);
    border: none;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: background-color 0.2s;
}

.danger-button:hover {
    background-color: #7e3232;
}

/* Modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    overflow: auto;
}

.modal-content {
    background-color: var(--card-color);
    margin: 3% auto;
    width: 95%;
    max-width: min(62.5rem, 95vw); /* 1000px max, but responsive */
    border-radius: var(--border-radius-md);
    box-shadow: 0 0.3125rem 1.25rem rgba(0, 0, 0, 0.3); /* 0 5px 20px */
    animation: modalFadeIn 0.3s;
    overflow: hidden;
    position: relative;
}

/* Confirmation dialog styles */
.confirm-dialog-content {
    max-width: min(22.5rem, 90vw); /* 360px max, but responsive */
    z-index: 1000; /* Ensure it's above other elements */
    position: relative;
    border-radius: var(--border-radius-md);
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.5); /* 0 8px 24px */
    animation: modalFadeIn 0.25s ease-out;
}

#confirm-dialog {
    z-index: 1001; /* Higher than other modals */
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
}

/* Modal body styling moved to unified section below */

.confirm-icon {
    margin-bottom: var(--spacing-md);
    display: flex;
    justify-content: center;
    align-items: center;
}

.confirm-icon span {
    font-size: clamp(2.5rem, 5vw, 3rem); /* Fluid 40px-48px */
    color: #e74c3c; /* Red color for delete icon */
    background-color: rgba(231, 76, 60, 0.1); /* Light red background */
    border-radius: 50%;
    padding: 1rem; /* 16px */
    display: flex;
    justify-content: center;
    align-items: center;
}

#confirm-message {
    font-size: var(--font-size-md);
    margin-bottom: var(--spacing-lg);
    color: var(--text-color);
    line-height: 1.5;
}

.confirm-actions {
    display: flex;
    justify-content: center;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
}

/* Danger button styling */
.danger-button {
    background-color: #e74c3c; /* Brighter red for better visibility */
    color: white;
    border: none;
    padding: var(--spacing-sm) var(--spacing-lg);
    border-radius: 1.5rem; /* 24px - More rounded corners */
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.875rem; /* 14px */
    min-width: 10rem; /* 160px */
    justify-content: center;
    height: 2.75rem; /* 44px */
}

.danger-button:hover {
    background-color: #c0392b; /* Darker red on hover */
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
}

.danger-button:active {
    transform: translateY(0);
    box-shadow: none;
}

/* Secondary button styling */
.secondary-button {
    background-color: var(--card-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: 18px; /* Rounded corners like generate button */
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: all 0.2s;
    font-weight: 500;
    font-size: 13px;
    min-width: 100px;
    justify-content: center;
}

.secondary-button:hover {
    background-color: var(--hover-color);
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.secondary-button:active {
    transform: translateY(0);
    box-shadow: none;
}

.secondary-button span, .danger-button span {
    font-size: 1rem; /* 16px */
}

@keyframes modalFadeIn {
    from {opacity: 0; transform: translateY(-20px);}
    to {opacity: 1; transform: translateY(0);}
}



.modal-header {
    padding: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--card-color);
    border-top-left-radius: var(--border-radius-md);
    border-top-right-radius: var(--border-radius-md);
    position: relative;
}

.modal-header h3 {
    margin: 0;
    font-weight: 500;
    color: var(--text-color);
    font-size: 0.9375rem; /* 15px */
}

#history-detail-modal .modal-header .close-modal {
    position: absolute;
    top: 0.75rem; /* 12px */
    right: 0.75rem; /* 12px */
    font-size: 1.25rem; /* 20px */
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    padding: 0.375rem; /* 6px */
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.05);
    width: 2rem; /* 32px */
    height: 2rem; /* 32px */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border: 0.0625rem solid rgba(255, 255, 255, 0.1); /* 1px */
    margin: 0;
}

#history-detail-modal .modal-header .close-modal:hover {
    color: var(--text-color);
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* Modal body styles for different contexts */
.modal-content > .modal-body {
    padding: 0;
}

.confirm-dialog-content > .modal-body {
    padding: var(--spacing-md) var(--spacing-lg);
    text-align: center;
}

/* Specific styling for confirmation dialog close button */
#confirm-dialog .modal-header .close-modal {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    line-height: 1;
    padding: 6px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.05);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#confirm-dialog .modal-header .close-modal:hover {
    color: var(--text-color);
    background-color: rgba(255, 255, 255, 0.1);
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.2);
}

/* Detail tabs */
.detail-tabs {
    display: flex;
    background-color: var(--background-color);
    border-bottom: 1px solid var(--border-color);
}

.detail-tab {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    color: var(--text-secondary);
    transition: background-color 0.2s, color 0.2s;
    border-bottom: 0.125rem solid transparent; /* 2px */
}

.detail-tab:hover {
    background-color: var(--hover-color);
    color: var(--text-color);
}

.detail-tab.active {
    color: var(--text-color);
    border-bottom: 0.125rem solid var(--primary-color); /* 2px */
    background-color: var(--card-color);
}

.detail-tab span {
    font-size: 1.125rem; /* 18px */
}

/* Detail views */
.detail-view-container {
    position: relative;
    min-height: clamp(20rem, 30vh, 30rem); /* Responsive height 320px-480px */
}

.detail-view {
    display: none;
    padding: var(--spacing-md);
}

.detail-view.active {
    display: block;
}

.detail-image-container {
    width: 100%;
}

.detail-image {
    height: clamp(18rem, 25vh, 25rem); /* Responsive height 288px-400px */
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.detail-image img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    width: auto;
    height: auto;
}

/* Compare view */
.detail-compare-container {
    display: flex;
    gap: var(--spacing-md);
}

.detail-compare-image {
    flex: 1;
    min-width: 0;
}

.detail-compare-label {
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    color: var(--text-color);
    text-align: center;
    padding: var(--spacing-xs);
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    letter-spacing: 0.5px;
}

/* Detail info */
.detail-info {
    padding: var(--spacing-md);
    background-color: var(--background-color);
    border-top: 1px solid var(--border-color);
}

.detail-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.detail-info-header h4 {
    margin: 0;
    font-weight: 500;
    color: var(--text-color);
}

.detail-date {
    font-size: var(--font-size-xs);
    color: var(--text-secondary);
}

.detail-presets {
    background-color: var(--card-color);
    border-radius: var(--border-radius-sm);
    padding: var(--spacing-md);
    margin-bottom: var(--spacing-md);
    max-height: 12.5rem; /* 200px */
    overflow-y: auto;
}

.detail-preset {
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 0.0625rem solid var(--border-color); /* 1px */
}

.detail-preset:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.detail-preset-name {
    font-weight: 500;
    margin-bottom: var(--spacing-xs);
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
}

.detail-preset-name span {
    font-size: 1.125rem; /* 18px */
}

.detail-preset-option {
    display: flex;
    margin-bottom: 0.125rem; /* 2px */
}

.detail-preset-option-name {
    width: 7.5rem; /* 120px */
    color: var(--text-secondary);
}

.detail-preset-option-value {
    color: var(--text-color);
}

.detail-actions {
    display: flex;
    gap: var(--spacing-md);
    margin-top: var(--spacing-lg);
    justify-content: flex-end;
}

/* Button styles */
.secondary-button {
    background-color: var(--card-color);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    transition: background-color 0.2s;
}

.secondary-button:hover {
    background-color: var(--hover-color);
}






