/* CSS Variables */
:root {
    --primary-color: #2563eb;
    --bg-color: #f8f9fa;
    --text-color: #1e293b;
    --border-color: #dee2e6;
    --input-bg: #ffffff;
    --toolbar-bg: #ffffff;
    --canvas-shadow: 0 20px 40px -10px rgb(0 0 0 / 0.3), 0 10px 20px -5px rgb(0 0 0 / 0.2);
}

* {
    box-sizing: border-box;
}

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

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

::-webkit-scrollbar-thumb {
    background: rgba(100, 116, 139, 0.3);
    border-radius: 10px;
    border: 3px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(100, 116, 139, 0.5);
}

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(100, 116, 139, 0.3) transparent;
}

/* Base Styles */
body {
    font-family: 'Work Sans', 'Inter', system-ui, sans-serif;
    color: var(--text-color);
    margin: 0;
    line-height: 1.5;
    min-height: 100vh;
    background: var(--bg-color);
    overflow-x: hidden;
}

/* Toolbar */
.toolbar {
    grid-area: toolbar;
    background: var(--toolbar-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 16px 24px;
    position: sticky;
    top: 0;
    z-index: 100;
}

.toolbar h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: var(--text-color);

    .titlespan {
        font-weight: 300;
    }
}

/* Layout Grid */
.app {
    display: grid;
    grid-template-columns: 320px 1fr 320px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "toolbar toolbar toolbar"
        "editor preview templates"
        "actions actions actions";
    height: 100vh;
    overflow: hidden;
}

@media (max-width: 1200px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr auto auto;
        grid-template-areas:
            "toolbar"
            "editor"
            "preview"
            "templates"
            "actions";
        height: auto;
        overflow: visible;
    }
}

/* Editor Panel */
.editor {
    grid-area: editor;
    background: white;
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    overflow-y: auto;
}

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

.input-group label {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-color);
}

.help-text {
    font-size: 12px;
    color: #64748b;
    margin-top: -4px;
}

.hidden {
    display: none !important;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 44px;
}

textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

textarea:placeholder-shown:not(:focus) {
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        border-color: var(--border-color);
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
    50% {
        border-color: var(--primary-color);
        box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    }
}

/* Buttons */
.control-btn {
    padding: 10px 16px;
    border: 1px solid var(--border-color);
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.control-btn:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
}

.control-btn i {
    font-size: 16px;
}

.image-upload-btn {
    width: 100%;
    justify-content: center;
}

.image-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.control-group {
    display: flex;
    gap: 6px;
}

.control-group .control-btn {
    flex: 1;
    justify-content: center;
    padding: 8px;
}

.remove-btn {
    background: #fef2f2;
    border-color: #fecaca;
    color: #dc2626;
}

.remove-btn:hover {
    background: #fee2e2;
    border-color: #dc2626;
}

/* Preview Area */
.preview {
    grid-area: preview;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
    overflow: auto;
    background: var(--bg-color);
}

.canvas-container {
    position: relative;
    background: white;
    border-radius: 8px;
    padding: 20px;
    max-width: 800px;
    box-shadow: var(--canvas-shadow);
}

#canvas {
    display: block;
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

/* Flash Effect */
.flash-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: 12px;
    opacity: 0;
    background: linear-gradient(45deg, #ffffff, transparent);
    background: white;
}

.flash-overlay.flash {
    animation: flash 0.5s linear;
}

@keyframes flash {
    0% {
        opacity: 0;
    }
    40% {
        opacity: 1;
    }
    60% {
        opacity: 1;
    }
    100% {
        opacity: 0;
    }
}

/* Template Selector */
.template-selector {
    grid-area: templates;
    background: white;
    border-left: 1px solid var(--border-color);
    padding: 16px;
    overflow-y: auto;
}

.theme-section {
    margin-bottom: 24px;
}

.theme-section:last-child {
    margin-bottom: 0;
}

.theme-section h3 {
    margin: 0 0 12px 0;
    font-size: 13px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.templates-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;


}

.template-btn {
    padding: 0;
    border: 2px solid var(--border-color);
    background: white;
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
    transition: all 0.15s;
    display: block;
}

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

.template-btn.active {
    border-color: var(--primary-color);
    background: #eff6ff;
}

.template-btn img {
    width: 100%;
    height: auto;
    display: block;
    aspect-ratio: 1;
    object-fit: cover;
    image-rendering: crisp-edges;
}

/* Actions */
.actions {
    grid-area: actions;
    background: white;
    border-top: 1px solid var(--border-color);
    padding: 16px 24px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.action-buttons {
    display: flex;
    gap: 12px;
}

.download-btn,
.clear-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.15s;
}

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

.download-btn:hover {
    background: #1d4ed8;
}

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

.clear-btn:hover {
    background: #f8f9fa;
    border-color: #adb5bd;
}

/* Responsive */
@media (max-width: 1200px) {
    .toolbar {
        padding: 12px 16px;
    }

    .toolbar h1 {
        font-size: 18px;
    }

    .editor,
    .template-selector {
        border: none;
        border-bottom: 1px solid var(--border-color);
    }

    .preview {
        padding: 20px;
    }

    .canvas-container {
        max-width: 100%;
        padding:10px;
    }
}

@media (max-width: 640px) {
    .action-buttons {
        width: 100%;
    }

    .download-btn,
    .clear-btn {
        flex: 1;
    }
}
