:root {
    --bg-dark: #0a0a0c;
    --panel-bg: rgba(24, 24, 28, 0.7);
    --panel-border: rgba(255, 255, 255, 0.08);
    --accent: #6366f1; /* Indigo */
    --accent-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --danger: #ef4444;
    --success: #10b981;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* subtle gradient background */
    background: radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.1), transparent 25%),
                radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.05), transparent 25%),
                var(--bg-dark);
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
}

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

/* SIDEBAR */
.sidebar {
    width: 340px;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 20px;
    border-right: 1px solid var(--panel-border);
    z-index: 10;
}

.result-info {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 12px;
    background: linear-gradient(transparent, rgba(0,0,0,0.8));
    z-index: 20;
    pointer-events: none;
}

.result-domain {
    font-size: 0.8rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #a5b4fc, #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stats-badge {
    background: rgba(255, 255, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
}

.product-info .subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.product-info h3 {
    font-size: 1.1rem;
    line-height: 1.4;
    font-weight: 500;
}

.image-container {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--panel-border);
}

.image-wrapper {
    width: 100%;
    height: 260px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    transition: opacity 0.3s ease;
}

.image-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.4);
    font-size: 2rem;
    color: var(--accent);
}

.spin {
    animation: spin 1s linear infinite;
}

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

.image-label {
    position: absolute;
    bottom: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.7rem;
    color: #a5b4fc;
    display: flex;
    align-items: center;
    gap: 4px;
    backdrop-filter: blur(4px);
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.nav-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.nav-buttons .btn {
    flex: 1;
    min-width: 40px;
    justify-content: center;
    font-size: 1.2rem;
    padding: 8px;
}

.custom-search {
    margin-top: auto;
}

.label {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.search-box {
    display: flex;
    gap: 8px;
}

.search-box input {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--panel-border);
    color: white;
    padding: 10px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.search-box input:focus {
    outline: none;
    border-color: var(--accent);
}

.selected-preview-box {
    margin-top: 10px;
    padding: 12px;
    border-radius: 12px;
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.2);
    text-align: center;
}

.selected-preview-box img {
    max-width: 100%;
    height: 120px;
    object-fit: contain;
    border-radius: 6px;
    margin-top: 8px;
}

/* BUTTONS */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 8px;
    border: none;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn:active {
    transform: scale(0.96);
}

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

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    border: 1px solid var(--panel-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* MAIN CONTENT */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px;
    border-bottom: 1px solid var(--panel-border);
    z-index: 5;
}

.header-title h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.status-text {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.grid-container {
    flex: 1;
    padding: 32px;
    overflow-y: auto;
    /* Masonry style layout using flex wrap or css grid */
    --grid-item-width: 220px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--grid-item-width), 1fr));
    gap: 20px;
    align-content: start;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: transparent; 
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2); 
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3); 
}

/* RESULT CARDS */
.result-card {
    background: var(--panel-bg);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    /* Enforce perfect square */
    aspect-ratio: 1 / 1;
    display: block;
}

.result-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
    border-color: rgba(255,255,255,0.2);
}

.result-card img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
    transition: filter 0.3s ease;
    z-index: 1;
}

.result-card:hover img {
    filter: brightness(0.8);
}

.result-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 30;
    background: rgba(0,0,0,0.4);
}

.result-card:hover .result-overlay {
    opacity: 1;
}

.result-overlay .btn-use {
    background: var(--success);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 20px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
    transform: translateY(10px);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.result-card:hover .result-overlay .btn-use {
    transform: translateY(0);
}

.result-info {
    padding: 12px;
    background: rgba(0,0,0,0.5);
}

.result-domain {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* TOAST */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 24px;
    border-radius: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--success);
    font-weight: 500;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* LIGHTBOXES */
.fullscreen-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
}
.fullscreen-lightbox.active {
    display: flex;
}
.fullscreen-lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
}

.lightbox {
    position: absolute; /* Over the right panel only */
    inset: 0;
    background: rgba(10, 10, 12, 0.95); /* darker to hide background */
    backdrop-filter: blur(8px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
}
.lightbox.active {
    display: flex;
}
.lightbox-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 80%;
}
.lightbox-content img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    background: #000;
}
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 101;
}
.lightbox-close:hover {
    background: rgba(255,255,255,0.2);
}
.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 2rem;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    z-index: 101;
}
.lightbox-nav:hover {
    background: rgba(255,255,255,0.2);
}
.lightbox-nav.left { left: 20px; }
.lightbox-nav.right { right: 20px; }

/* Pointer on original image */
#originalImageWrapper {
    cursor: zoom-in;
}

#selectedImage {
    cursor: zoom-in;
}

.product-filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-select {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--panel-border);
    color: white;
    padding: 8px;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.85rem;
    width: 100%;
}

.filter-select option {
    background: var(--bg-dark);
}

/* Editor Panel */
.editor-panel {
    width: 90vw;
    height: 90vh;
    display: flex;
    flex-direction: column;
    border-radius: 12px;
    overflow: hidden;
}

.editor-header {
    padding: 15px 24px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.editor-workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.editor-canvas-container {
    flex: 1;
    background-color: #eee;
    background-image:
      linear-gradient(45deg, #ccc 25%, transparent 25%),
      linear-gradient(-45deg, #ccc 25%, transparent 25%),
      linear-gradient(45deg, transparent 75%, #ccc 75%),
      linear-gradient(-45deg, transparent 75%, #ccc 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    position: relative;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

#editCanvas {
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    cursor: crosshair;
    display: block;
}

.editor-sidebar {
    width: 300px;
    background: rgba(0,0,0,0.2);
    border-left: 1px solid var(--panel-border);
    padding: 20px;
    overflow-y: auto;
}

.editor-result-img {
    width: 100%;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.2s;
}

.editor-result-img:hover {
    border-color: var(--accent);
}

