:root {
    --primary-color: #d946ef;
    --primary-gradient: linear-gradient(135deg, #d946ef 0%, #ec4899 100%);
    --bg-color: #f3f4f6;
    --sidebar-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --radius-lg: 12px;
    --radius-md: 8px;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* =========================================
   LEFT PANEL (CANVAS)
   ========================================= */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background-color: #e5e5e5; /* Slightly darker to distinguish canvas */
}

/* Header */
.canvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 20;
    pointer-events: none; /* Let clicks pass through to canvas if needed */
}

.canvas-header > * {
    pointer-events: auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    font-weight: 700;
    color: var(--primary-color);
}

.logo-icon {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo-text {
    color: #333;
}

.canvas-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.text-btn {
    background: transparent;
    border: none;
    color: white;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    text-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: opacity 0.2s;
}

.text-btn:hover {
    opacity: 0.8;
}

.user-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid white;
}

/* Viewport / Image Area */
.viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Initial View */
#initial-view {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    font-size: 1.1rem;
    z-index: 1;
    pointer-events: none;
}

#initial-view p {
    pointer-events: auto;
    cursor: pointer;
    padding: 1rem 2rem;
    background: rgba(255, 255, 255, 0.9);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    transition: all 0.2s;
}

#initial-view p:hover {
    background: rgba(255, 255, 255, 1);
    transform: translateY(-2px);
}

/* =========================================
   COMPARISON SLIDER (FIXED)
   ========================================= */
.comparison-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e5e5e5;
}

.comparison-box {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden; /* Ensures content stays inside */
}

/* Top and Bottom Shader Gradients */
.comparison-box::before,
.comparison-box::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    width: 100%;
    height: 120px; /* Height of the gradient fade */
    z-index: 15; /* Above images but below interactive elements */
    pointer-events: none; /* Allow clicks to pass through */
}

.comparison-box::before {
    top: 0;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.4), transparent);
}

.comparison-box::after {
    bottom: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.4), transparent);
}

/* Ensure labels are not clipped */
.comparison-box .label {
    position: absolute;
    z-index: 25;
}

/* Shared styles for both images */
.comparison-box img {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    user-select: none;
}

/* 1. Background Image: Always fills the container */
#final-image {
    width: 100%; 
    z-index: 1;
}

/* 2. Overlay Wrapper: The "Window" that resizes */
.overlay-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 50%; /* Initial slider position */
    height: 100%;
    overflow: hidden; /* Clips the image inside */
    z-index: 10;
    border-right: 2px solid white;
}

/* 3. Foreground Image: MUST be fixed size to prevent squishing */
#base-image {
    /* CRITICAL FIX: 
       We set this to 100vw (viewport width) so it's always wide enough.
       The 'object-fit: cover' ensures it aligns with the background image visually.
       Ideally, JavaScript should set this to the exact pixel width of .comparison-box,
       but 100vw is a solid CSS-only fallback.
    */
    width: 100vw; 
    max-width: none; /* Allow it to overflow the .overlay-image wrapper */
    z-index: 2;
}

/* Slider Handle */
.slider-handle {
    position: absolute;
    top: 50%;
    left: 50%; /* Initial slider position */
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: col-resize; /* Shows resize cursor */
    z-index: 30; /* Above the shadow gradients (z-index: 15) */
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
    isolation: isolate; /* Creates a new stacking context */
}

/* Ensure slider is hidden when it has the hidden class, even with inline styles */
.slider-handle.hidden {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
}

.label {
    position: absolute;
    padding: 4px 12px;
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(4px);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #333;
    z-index: 25;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1); /* Optional: Adds subtle depth */
}

/* Static badges on viewport borders - Left and Right */
.badge-before-static,
.badge-after-static {
    position: fixed !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    z-index: 1000 !important;
    white-space: nowrap;
    pointer-events: none;
}

.badge-before-static {
    left: 20px !important;
    right: auto !important;
}

.badge-after-static {
    right: 400px !important; 
    left: auto !important;
}

/* Override hidden class for badges when they should be visible */
.badge-before-static:not(.hidden),
.badge-after-static:not(.hidden) {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Floating Controls */
.floating-btn {
    position: absolute;
    bottom: 24px;
    left: 24px;
    background: white;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    transition: transform 0.2s;
    z-index: 20;
    color: var(--text-main);
    font-family: inherit;
}

.floating-btn:hover {
    transform: translateY(-2px);
}

.floating-tools {
    position: absolute;
    bottom: 24px;
    right: 24px;
    display: flex;
    gap: 0.5rem;
    z-index: 20;
}

.tool-btn {
    width: 40px;
    height: 40px;
    background: white;
    border: none;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    color: var(--text-main);
    transition: all 0.2s;
}

.tool-btn:hover {
    transform: translateY(-2px);
}

.tool-btn.active {
    background: var(--primary-color);
    color: white;
}

.tool-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.tool-btn:disabled:hover {
    transform: none;
}

/* Loading Background - Shows old image with transparency */
.loading-background {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 40;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.3;
    pointer-events: none;
}

/* Loading */
#loading-msg {
    position: absolute;
    z-index: 50;
    background: rgba(255,255,255,0.9);
    padding: 2rem;
    border-radius: var(--radius-lg);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.hidden { display: none !important; }

/* =========================================
   RIGHT PANEL (SIDEBAR)
   ========================================= */
.sidebar {
    width: 380px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 30;
}

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

.control-group {
    margin-bottom: 2rem;
}

/* Custom Instructions Typing Bar - Center Position */
.custom-instructions-bar-center {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 30;
    width: 90%;
    max-width: 900px;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.instructions-bar-content {
    background: white;
    padding: 0.75rem;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--border-color);
}

.instructions-label-center {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    gap: 0.5rem;
}

.instructions-input-wrapper-center {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.instructions-input-center {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 32px;
    font-family: inherit;
    font-size: 0.95rem;
    background: white;
    line-height: 1.5;
    height: 48px;
}

.instructions-input-center:focus {
    outline: none;
    box-shadow: 0 2px 6px rgba(217, 70, 239, 0.2);
}

.instructions-input-center::placeholder {
    color: #9ca3af;
}

.apply-instructions-btn-center {
    padding: 0;
    width: 48px;
    height: 48px;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s;
    box-shadow: 0 1px 3px rgba(217, 70, 239, 0.3);
    flex-shrink: 0;
}

.apply-instructions-btn-center:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 2px 6px rgba(217, 70, 239, 0.4);
}

.apply-instructions-btn-center:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
    font-weight: 700;
}

/* Room Chips */
.chips-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 20px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
    font-family: inherit;
}

.chip:hover {
    border-color: #ccc;
}

.chip.active {
    background: #a855f7; /* Purple from screenshot */
    color: white;
    border-color: #a855f7;
}

/* Style Grid */
.style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.style-card {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 4/3;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.style-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.style-card:hover img {
    transform: scale(1.05);
}

.style-card .style-name {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.7), transparent);
    color: white;
    padding: 20px 8px 8px;
    font-size: 0.875rem;
    font-weight: 500;
}

.style-card.active {
    border-color: var(--primary-color);
}

.check-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--primary-color);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

/* Add Custom Style Card */
.style-card.add-new-style {
    border: 2px dashed #ccc;
    background: #fafafa;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.style-card.add-new-style .style-name {
    position: static;
    background: none;
    color: var(--text-muted);
    padding: 0;
    margin-top: 0.5rem;
}

.add-icon {
    font-size: 2rem;
    line-height: 1;
}

/* Pending state for custom styles */
.style-card.pending {
    background: #fafafa;
    border-style: dashed;
    border-color: #ccc;
}

.style-card.pending img {
    display: none;
}

.style-card.pending::before {
    content: '?';
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-muted);
}

/* Advanced Options */
.advanced-options summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    background: #f9fafb;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.advanced-options summary::-webkit-details-marker {
    display: none;
}

.advanced-content {
    padding: 1rem 0;
}

.advanced-content label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-main);
    font-weight: 500;
}

.checkbox-option {
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.checkbox-option label {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    cursor: pointer;
    margin-bottom: 0;
}

.checkbox-option input[type="checkbox"] {
    margin-top: 0.125rem;
    cursor: pointer;
    flex-shrink: 0;
}

.checkbox-option .checkbox-label-content {
    display: flex;
    flex-direction: column;
    flex: 1;
}

.checkbox-option label strong {
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

.checkbox-option .option-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
    line-height: 1.4;
}

.input-with-btn {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.input-with-btn input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
}

.input-with-btn button {
    padding: 0.5rem 1rem;
    background: #333;
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    transition: opacity 0.2s;
}

.input-with-btn button:hover {
    opacity: 0.9;
}

.input-wrapper {
    margin-top: 0.5rem;
}

.input-wrapper textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    resize: vertical;
    min-height: 60px;
}

/* Sidebar Footer */
.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--border-color);
    background: white;
}

.generate-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary-gradient);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: opacity 0.2s;
    font-family: inherit;
}

.generate-btn:hover:not(:disabled) {
    opacity: 0.9;
}

.generate-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.credit-cost {
    text-align: center;
    font-size: 0.75rem;
    color: #f59e0b; /* Amber color */
    margin-top: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

/* Search Panel Overlay */
.search-panel {
    position: absolute;
    bottom: 0;
    right: 380px; /* Width of sidebar */
    width: 300px;
    background: white;
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
    z-index: 25;
    max-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
}

.search-header h4 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-main);
    text-transform: none;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-header h4::before {
    content: '🔍';
    font-size: 1.1rem;
}

.search-header button {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s;
    line-height: 1;
}

.search-header button:hover {
    color: var(--text-main);
    background: rgba(0, 0, 0, 0.1);
    transform: scale(1.1);
}

.search-grid {
    padding: 0.875rem;
    overflow-y: auto;
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

/* Product Cards in Search Results */
.product-card {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    text-decoration: none;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: relative;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    border-color: var(--primary-color);
}

.product-image-container {
    position: relative;
    width: 100%;
    aspect-ratio: 1 / 1;
    overflow: hidden;
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
}

.product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: block;
}

.product-card:hover .product-image {
    transform: scale(1.05);
}

.match-badge {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--primary-color);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
    z-index: 1;
    border: 1px solid rgba(217, 70, 239, 0.1);
}

.product-content {
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 0 0 auto;
    background: white;
}

.product-title {
    margin: 0;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 1.8em;
}

.product-card:hover .product-title {
    color: var(--primary-color);
}

.product-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.product-price {
    color: var(--primary-color);
    font-weight: 700;
    font-size: 0.75rem;
    letter-spacing: -0.01em;
}

.product-source {
    font-size: 0.65rem;
    color: var(--text-muted);
    background: #f9fafb;
    padding: 2px 5px;
    border-radius: 4px;
    width: fit-content;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

.link-indicator {
    position: absolute;
    bottom: 10px;
    right: 10px;
    color: var(--text-muted);
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.product-card:hover .link-indicator {
    opacity: 1;
    transform: translate(2px, -2px);
}

.no-results {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

.no-results p {
    font-size: 0.95rem;
    margin: 0;
}

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

.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

/* For Selection Box Drawing */
#selection-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    cursor: crosshair;
}

#selection-box {
    border: 2px dashed #fff;
    background: rgba(255, 255, 255, 0.2);
    position: absolute;
    display: none;
    pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5); /* Dim background */
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #d1d5db transparent;
}

/* =========================================
   HISTORY MODAL
   ========================================= */
.history-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.history-modal.hidden {
    display: none;
}

.history-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.history-modal:not(.hidden) .history-modal-overlay {
    opacity: 1;
    pointer-events: auto;
}

.history-modal-content {
    position: relative;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    pointer-events: auto;
}

.history-modal:not(.hidden) .history-modal-content {
    transform: scale(1);
    opacity: 1;
}

.history-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
}

.history-header h4 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.history-header h4::before {
    content: '🕐';
    font-size: 1.3rem;
}

.close-btn {
    background: rgba(0, 0, 0, 0.05);
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    line-height: 1;
}

.close-btn:hover {
    color: var(--text-main);
    background: rgba(217, 70, 239, 0.1);
    transform: scale(1.1);
}

.history-grid {
    padding: 1.5rem;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    flex: 1;
}

.history-empty {
    grid-column: 1 / -1;
    text-align: center;
    color: var(--text-muted);
    padding: 3rem 1rem;
    font-size: 0.95rem;
}

.history-item {
    background: white;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 2px solid var(--border-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: relative;
}

.history-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(217, 70, 239, 0.2);
    border-color: var(--primary-color);
}

.history-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(217, 70, 239, 0.1), 0 8px 24px rgba(217, 70, 239, 0.2);
}

.history-item-thumbnail {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    background: #f3f4f6;
}

.history-item-thumbnail img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.history-item:hover .history-item-thumbnail img {
    transform: scale(1.05);
}

.history-item-label {
    padding: 0.75rem;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    background: linear-gradient(135deg, #fafafa 0%, #ffffff 100%);
    border-top: 1px solid var(--border-color);
}

.history-item.active .history-item-label {
    background: var(--primary-gradient);
    color: white;
    border-top-color: transparent;
}

.history-item-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.history-item.active .history-item-badge {
    background: white;
    color: var(--primary-color);
}
