/* CSS Reset & Variable Definitions */
:root {
    --bg-main: #080b11;
    --bg-card: rgba(17, 22, 34, 0.75);
    --bg-card-solid: #111622;
    --bg-input: #1a2030;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-color-active: rgba(139, 92, 246, 0.4);
    
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    
    --color-accent: #8b5cf6;
    --color-accent-hover: #a78bfa;
    --color-success: #10b981;
    --color-success-hover: #34d399;
    --color-danger: #ef4444;
    
    --gradient-primary: linear-gradient(135deg, #8b5cf6 0%, #3b82f6 100%);
    --gradient-glow: linear-gradient(135deg, rgba(139, 92, 246, 0.15) 0%, rgba(59, 130, 246, 0.15) 100%);
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --shadow-lg: 0 12px 48px 0 rgba(0, 0, 0, 0.5);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-full: 9999px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(139, 92, 246, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(59, 130, 246, 0.08) 0px, transparent 50%);
    background-attachment: fixed;
}

/* App Layout */
.app-container {
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    height: 100vh;
    gap: 16px;
}

/* Header Styling */
.app-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--color-accent);
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.4));
}

.logo-area h1 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(120deg, #ffffff 60%, #cbd5e1 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 8px;
}

.badge {
    font-size: 10px;
    font-weight: 700;
    background: var(--gradient-primary);
    padding: 2px 6px;
    border-radius: var(--radius-full);
    color: white;
    letter-spacing: 0.5px;
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.3);
    -webkit-text-fill-color: initial;
}

.subtitle {
    font-size: 13px;
    color: var(--text-secondary);
}

/* Workspace Area */
.workspace {
    flex: 1;
    display: flex;
    min-height: 0; /* Important for scrollable children */
}

/* Upload Zone styling */
.upload-zone {
    flex: 1;
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-lg);
    background-color: var(--bg-card);
    backdrop-filter: blur(16px);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    cursor: pointer;
    transition: var(--transition-normal);
    box-shadow: var(--shadow-md);
    overflow: hidden;
}

.upload-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-glow);
    opacity: 0;
    transition: var(--transition-normal);
    z-index: 0;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--color-accent);
    box-shadow: 0 0 24px rgba(139, 92, 246, 0.15);
}

.upload-zone:hover::before, .upload-zone.dragover::before {
    opacity: 1;
}

.file-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    z-index: 1;
    pointer-events: none;
    text-align: center;
    padding: 32px;
}

.upload-icon-wrapper {
    width: 72px;
    height: 72px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-secondary);
    transition: var(--transition-normal);
}

.upload-zone:hover .upload-icon-wrapper, .upload-zone.dragover .upload-icon-wrapper {
    color: var(--color-accent);
    background: rgba(139, 92, 246, 0.1);
    border-color: var(--color-accent-hover);
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(139, 92, 246, 0.1);
}

.upload-icon {
    width: 32px;
    height: 32px;
}

.upload-content h2 {
    font-size: 18px;
    font-weight: 500;
    color: var(--text-primary);
}

.upload-content h2 span {
    color: var(--color-accent);
    font-weight: 600;
}

.upload-tip {
    font-size: 13px;
    color: var(--text-muted);
}

/* Editor Interface */
.editor-container {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 20px;
    animation: fadeIn var(--transition-normal);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.hidden {
    display: none !important;
}

/* Canvas Workspace */
.canvas-workspace {
    flex: 1;
    background-color: rgba(5, 7, 12, 0.4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden;
    padding: 24px;
}

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

#editor-canvas {
    max-width: 100%;
    max-height: 100%;
    box-shadow: var(--shadow-lg);
    border-radius: var(--radius-sm);
    display: block;
    cursor: default;
    background-size: 20px 20px;
    background-image: 
        linear-gradient(to right, rgba(255,255,255,0.02) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.02) 1px, transparent 1px);
}

.canvas-overlay-tip {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(8px);
    padding: 8px 16px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
    border-left: 3px solid var(--color-success);
}

/* Sidebar Container */
.sidebar {
    width: 380px;
    background-color: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    min-height: 0;
}

/* Panel Sections */
.panel-section {
    padding: 18px;
    border-bottom: 1px solid var(--border-color);
}

.panel-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-icon {
    width: 16px;
    height: 16px;
    color: var(--color-accent);
}

/* Preset Buttons */
.preset-grids {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.btn {
    border: 1px solid var(--border-color);
    background-color: var(--bg-input);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-family: inherit;
    font-weight: 500;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    gap: 3px;
}

.btn:hover {
    border-color: rgba(255,255,255,0.2);
    background-color: rgba(255, 255, 255, 0.03);
}

.btn-preset.active {
    background: var(--gradient-glow);
    border-color: var(--color-accent);
    box-shadow: 0 0 12px rgba(139, 92, 246, 0.15);
}

.btn-preset.active .preset-name {
    color: var(--color-accent-hover);
}

.btn-preset .preset-name {
    font-size: 13px;
    font-weight: 600;
}

.btn-preset .preset-desc {
    font-size: 10px;
    color: var(--text-muted);
}

/* Custom Grid Form */
.custom-grid-form {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 12px;
    padding: 12px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    animation: slideDown var(--transition-fast);
}

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

.input-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.input-group label {
    font-size: 11px;
    color: var(--text-secondary);
}

.input-group input, .input-group select {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 10px;
    font-family: inherit;
    font-size: 12px;
    outline: none;
    transition: var(--transition-fast);
}

.input-group input:focus, .input-group select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.15);
}

#btn-apply-custom {
    grid-column: span 2;
    margin-top: 4px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 11px;
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-full {
    width: 100%;
}

.grid-actions {
    margin-top: 8px;
}

/* Export Settings Layout */
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.label-row span {
    font-size: 11px;
    color: var(--color-accent-hover);
    font-weight: 600;
}

/* Custom styled range input */
input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    outline: none;
    border: 1px solid var(--border-color);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-accent);
    cursor: pointer;
    box-shadow: 0 0 6px rgba(139, 92, 246, 0.5);
    transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    background: var(--color-accent-hover);
}

/* Previews Grid Section */
.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

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

.previews-container {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    padding: 4px;
    min-height: 0;
    max-height: 250px;
}

/* Scrollbar styles */
.previews-container::-webkit-scrollbar {
    width: 4px;
}

.previews-container::-webkit-scrollbar-track {
    background: transparent;
}

.previews-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
}

.previews-container::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

.preview-card {
    position: relative;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
    aspect-ratio: 1 / 1;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    justify-content: center;
    align-items: center;
    transition: var(--transition-normal);
}

.preview-card:hover {
    border-color: var(--color-accent);
    transform: scale(1.02);
    box-shadow: var(--shadow-sm);
}

.preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-badge {
    position: absolute;
    top: 4px;
    left: 4px;
    background: rgba(0, 0, 0, 0.6);
    color: var(--text-primary);
    font-size: 9px;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.preview-download-btn {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(139, 92, 246, 0.85);
    color: white;
    width: 20px;
    height: 20px;
    border-radius: 4px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: var(--transition-fast);
    backdrop-filter: blur(4px);
}

.preview-download-btn svg {
    width: 12px;
    height: 12px;
}

.preview-card:hover .preview-download-btn {
    opacity: 1;
}

.preview-download-btn:hover {
    background: var(--color-accent);
    transform: scale(1.1);
}

/* Sidebar Footer & Main Buttons */
.sidebar-footer {
    padding: 16px;
    display: flex;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    background-color: rgba(5, 7, 12, 0.2);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    border: none;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(139, 92, 246, 0.35);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.5);
    background: linear-gradient(135deg, #9a75f8 0%, #4f8ff7 100%);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-icon {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.btn-icon svg {
    width: 16px;
    height: 16px;
}

#btn-export-zip {
    flex: 1;
}

/* Toasts notification system */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 9999;
}

.toast {
    background: rgba(17, 24, 39, 0.9);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    padding: 12px 20px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    color: var(--text-primary);
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: toastIn var(--transition-normal) forwards;
    border-left: 4px solid var(--color-accent);
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.toast.toast-success {
    border-left-color: var(--color-success);
}

.toast.toast-error {
    border-left-color: var(--color-danger);
}

.toast.toast-fade-out {
    animation: toastOut var(--transition-normal) forwards;
}

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

.action-buttons-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.btn-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3) !important;
    color: white !important;
    border: none !important;
}

.btn-success:hover {
    background: linear-gradient(135deg, #34d399 0%, #10b981 100%) !important;
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.45) !important;
    transform: translateY(-1px);
}

/* Modal Overlay Lightbox */
.modal {
    position: fixed;
    inset: 0;
    background-color: rgba(5, 7, 12, 0.9);
    backdrop-filter: blur(12px);
    z-index: 10000;
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-normal);
}

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

.modal-close {
    position: absolute;
    top: 24px;
    right: 24px;
    color: var(--text-secondary);
    font-size: 32px;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    transition: var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--text-secondary);
    transform: rotate(90deg);
}

.modal-content-wrapper {
    max-width: 90%;
    max-height: 85%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    transform: scale(0.92);
    transition: transform var(--transition-normal);
}

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

.modal-img {
    max-width: 100%;
    max-height: 70vh;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    object-fit: contain;
    background-color: #0d111a;
    background-size: 20px 20px;
    background-image: 
        linear-gradient(to right, rgba(255,255,255,0.02) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.02) 1px, transparent 1px);
}

.modal-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#modal-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

#modal-dim {
    font-size: 12px;
    color: var(--text-muted);
}

.modal-actions {
    margin-top: 4px;
}
