:root {
    --primary: #2563eb;
    --bg-sidebar: #ffffff;
    --bg-app: #f3f4f6;
    --border: #e5e7eb;
    --text: #1f2937;
    --text-muted: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

[data-theme="dark"] {
    --primary: #3b82f6;
    --bg-sidebar: #1f2937;
    --bg-app: #111827;
    --border: #374151;
    --text: #f9fafb;
    --text-muted: #9ca3af;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    background: var(--bg-app);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* --- NEW STYLES FOR VIRAL & MONETIZATION (Added by Upgrade) --- */

/* 1. Safety Banner Style */
.safety-banner {
    background-color: #fff3cd;
    color: #856404;
    padding: 8px;
    text-align: center;
    font-size: 13px;
    border-bottom: 1px solid #ffeeba;
    font-family: inherit;
    flex-shrink: 0;
    z-index: 20;
}

/* Enhanced Button Styles */
.primary-btn {
    background: linear-gradient(to bottom, #2563eb, #1d4ed8);
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 14px;
}

.primary-btn:active {
    transform: translateY(1px);
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.2);
}

/* 2. Ad Box Style */
.ad-box {
    margin: 10px 0 20px 0;
    padding: 15px;
    background: var(--bg-app);
    border: 1px dashed var(--border);
    text-align: center;
    border-radius: 8px;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.ad-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* 3. WhatsApp/Viral Share Button */
.whatsapp-btn {
    background-color: #25D366 !important; /* WhatsApp Green */
    color: white !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
}
.whatsapp-btn:hover {
    background-color: #128C7E !important;
}

/* 4. Automatic Watermark on Cards (REMOVED CSS WATERMARK TO PREVENT DUPLICATION) */
/* The watermark is now injected via app.js only, to ensure it appears exactly once and in the correct position. */
/* .template-wrapper::after { ... } */

/* --- END NEW STYLES --- */


.app-container {
    display: flex;
    height: 100%;
    overflow: hidden; /* Prevent double scrollbars on the main container */
}

.sidebar {
    width: 360px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 10;
    flex-shrink: 0;
    height: 100%;
    box-shadow: 2px 0 10px rgba(0,0,0,0.05); /* Modern shadow */
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sidebar-header > div:first-child {
    flex: 1;
}

.sidebar-header h1 {
    margin: 0;
    font-size: 22px; /* Slightly larger */
    font-weight: 800;
    letter-spacing: -0.5px;
}

.sidebar-header p {
    margin: 5px 0 0;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.controls {
    flex: 1;
    overflow-y: auto;
    padding: 24px; /* More breathing room */
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-top: 5px;
    padding-bottom: 5px;
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.5px;
}

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

label {
    font-size: 13px;
    font-weight: 500;
}

input, select, textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px; /* Softer corners */
    font-size: 14px;
    width: 100%;
    font-family: inherit;
    background: var(--bg-input, #f9fafb);
    color: var(--text);
    transition: all 0.2s ease;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--bg-input-focus, #fff);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1); /* Focus ring */
}

textarea { resize: vertical; }

/* Color input styling */
input[type="color"] {
    padding: 4px 8px;
    height: 42px;
    cursor: pointer;
    -webkit-appearance: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-sidebar);
}

input[type="color"]::-webkit-color-swatch-wrapper {
    padding: 0;
}

input[type="color"]::-webkit-color-swatch {
    border: none;
    border-radius: 4px;
}

input[type="color"]::-moz-color-swatch {
    border: none;
    border-radius: 4px;
}

input[type="color"]:focus {
    outline: none;
    border-color: var(--primary);
}

.dual-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.actions {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column; /* Changed to column for better mobile layout with share btn */
    gap: 10px;
}

.secondary-btn {
    width: 100%;
    padding: 12px;
    background: var(--bg-btn-secondary, white);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.secondary-btn:hover {
    background: var(--bg-btn-secondary-hover, #f9fafb);
}

.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

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

.mobile-toggle {
    display: none;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50px;
    padding: 12px 20px;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    cursor: pointer;
    align-items: center;
    gap: 8px;
}

.mobile-only {
    display: none;
}

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 8px;
    line-height: 1;
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
        height: calc(100vh - 40px); /* Adjust for banner */
    }

    .mobile-toggle {
        display: flex;
    }

    .mobile-only {
        display: block;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
    }

    .sidebar.open {
        transform: translateY(0);
    }

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

    .sidebar-header h1 {
        font-size: 18px;
    }

    .sidebar-header p {
        font-size: 12px;
    }

    .preview-area {
        width: 100%;
        height: 100%;
        padding: 20px;
    }
}

.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* justify-content: center;  Removed to allow scrolling from top */
    padding: 40px;
    background: #e5e5e5;
    overflow-y: auto; /* Enable scrolling for main area */
    position: relative;
}

.canvas-wrapper {
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); /* Deeper shadow */
    background: white;
    transform-origin: top center; /* Change origin for better scrolling behavior */
    width: 1080px;
    height: 1080px;
    margin-bottom: 40px; /* Space for zoom controls and article */
    flex-shrink: 0;
}

#renderTarget {
    width: 100%;
    height: 100%;
    background: white;
}

.zoom-controls {
    position: fixed; /* Fixed so it stays visible while scrolling */
    bottom: 20px;
    left: 50%;
    transform: translateX(180px); /* Offset by sidebar width/2 approx */
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 12px;
    pointer-events: none;
    z-index: 50;
    backdrop-filter: blur(4px);
}

@media (max-width: 768px) {
    .zoom-controls {
        transform: translateX(-50%);
        left: 50%;
        bottom: 80px; /* Above mobile toggle */
    }
}

.help-text {
    font-size: 12px;
    color: var(--text-muted);
    margin: 4px 0 0;
}

#dynamicContent > div {
    margin-bottom: 10px;
}

/* Choices.js overrides */
.choices {
    position: relative !important;
}

.choices__inner {
    background-color: var(--bg-sidebar) !important;
    border: 1px solid var(--border) !important;
    border-radius: 6px;
    min-height: 42px;
    padding: 4px 8px;
    color: var(--text) !important;
}

.choices__list--dropdown {
    z-index: 100;
    background-color: var(--bg-sidebar) !important;
    border: 1px solid var(--border) !important;
}

.choices__list--dropdown .choices__list {
    max-height: 300px;
    overflow-y: auto;
}

.choices__item {
    font-size: 14px;
    color: var(--text) !important;
}

.choices__item--selectable.is-highlighted {
    background-color: var(--bg-btn-secondary-hover, #f3f4f6) !important;
}

.choices[data-type*="select-one"] .choices__input {
    background-color: var(--bg-input, #f3f4f6) !important;
    border-radius: 4px;
    color: var(--text) !important;
}

.choices__placeholder {
    color: var(--text-muted) !important;
}

.choices[data-type*="select-one"]::after {
    border-color: var(--text-muted) transparent transparent transparent !important;
}

.text-btn {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.text-btn:hover {
    color: #1d4ed8;
}

.image-controls {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

/* Dark mode button styles */
[data-theme="dark"] {
    --bg-input: #374151;
    --bg-input-focus: #4b5563;
    --bg-btn-secondary: #374151;
    --bg-btn-secondary-hover: #4b5563;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.theme-toggle:hover {
    background: var(--bg-btn-secondary-hover, #f9fafb);
}

.theme-toggle svg {
    width: 18px;
    height: 18px;
}

.theme-toggle .sun-icon {
    display: none;
}

.theme-toggle .moon-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .sun-icon {
    display: block;
}

[data-theme="dark"] .theme-toggle .moon-icon {
    display: none;
}

.footer-credit {
    padding: 12px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    text-align: center;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.footer-credit a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.footer-credit a:hover {
    color: var(--primary);
}

.footer-credit a .external-link-icon {
    flex-shrink: 0;
    opacity: 0.7;
}

.footer-credit a:hover .external-link-icon {
    opacity: 1;
}

.footer-credit span {
    color: var(--text-muted);
    opacity: 0.7;
}

.footer-credit .separator {
    opacity: 0.4;
}

/* --- SEO ARTICLE SECTION STYLES (High Contrast & Solid Design) --- */
.seo-article-section {
    max-width: 900px;
    width: 100%;
    margin: 40px auto 80px;
    padding: 60px;
    background: #ffffff; /* Solid White for max contrast */
    box-shadow: 0 10px 40px -10px rgba(0,0,0,0.08); /* Soft but deep shadow */
    border: 1px solid var(--border);
    border-radius: 24px;
    color: #1f2937; /* Force dark gray text */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.8;
}

[data-theme="dark"] .seo-article-section {
    background: #1f2937; /* Solid Dark */
    border: 1px solid #374151;
    color: #f3f4f6; /* High contrast light text */
}

.seo-article-section h2 {
    font-size: 36px;
    font-weight: 800;
    margin-bottom: 30px;
    color: #111827; /* Solid Black */
    letter-spacing: -0.5px;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 15px;
    display: inline-block;
}

[data-theme="dark"] .seo-article-section h2 {
    color: #ffffff;
}

.seo-article-section h3 {
    font-size: 22px;
    font-weight: 700;
    margin-top: 40px;
    margin-bottom: 15px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 10px;
}

.seo-article-section h3::before {
    content: '';
    width: 6px;
    height: 24px;
    background: var(--primary);
    border-radius: 4px;
    display: block;
}

.seo-article-section p {
    margin-bottom: 25px;
    font-size: 18px; /* Larger font for readability */
    color: #374151;
    font-weight: 400;
}

[data-theme="dark"] .seo-article-section p {
    color: #d1d5db;
}

.seo-article-section ul, .seo-article-section ol {
    margin-bottom: 30px;
    padding: 30px 40px;
    background: #f9fafb; /* Solid light gray */
    border-radius: 16px;
    border: 1px solid #e5e7eb;
}

[data-theme="dark"] .seo-article-section ul,
[data-theme="dark"] .seo-article-section ol {
    background: #111827;
    border-color: #374151;
}

.seo-article-section li {
    margin-bottom: 15px;
    color: #374151;
    font-weight: 500;
    font-size: 17px;
}

[data-theme="dark"] .seo-article-section li {
    color: #e5e7eb;
}

.seo-article-section li strong {
    color: var(--primary);
}

@media (max-width: 768px) {
    .seo-article-section {
        padding: 30px 20px;
        margin-bottom: 100px;
    }
    .seo-article-section h2 {
        font-size: 26px;
    }
}

/* --- Toast Notification (Micro-UX) --- */
.toast {
    visibility: hidden;
    min-width: 250px;
    /* Center horizontally regardless of width */
    transform: translateX(-50%);
    background-color: #333;
    color: #fff;
    text-align: center;
    border-radius: 8px;
    padding: 12px 16px;
    position: fixed;
    z-index: 10000;
    left: 50%;
    bottom: 30px;
    font-size: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    transition: opacity 0.3s, bottom 0.3s;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.toast.show {
    visibility: visible;
    opacity: 1;
    bottom: 50px;
}

.toast.success {
    background-color: #10B981; /* Green */
    color: white;
}

.toast.error {
    background-color: #EF4444; /* Red */
    color: white;
}
