@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --font-family: 'Plus Jakarta Sans', sans-serif;
    
    /* Neumorphic base colors */
    --color-bg: #f8fafc;
    --color-surface: #ffffff; 
    
    --color-text-main: #102747;
    --color-text-muted: #64748b;
    --color-border: #dbe4ef;
    
    --color-btn-disabled-bg: #cbd5e1;
    --color-btn-disabled-text: #ffffff;
    
    --color-btn-active-bg: #1769e0;
    --color-btn-active-text: #ffffff;
    --color-btn-active-hover: #0f55bc;

    --color-success-bg: #dcfce7;
    --color-success-text: #166534;
    --color-success-border: #bbf7d0;
    
    --color-error-bg: #fef2f2;
    --color-error-text: #991b1b;
    --color-error-border: #fecaca;
    
    --color-loading-bg: #e2e8f0;
    --color-loading-text: #334155;
    
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    /* Neumorphic Shadows */
    --shadow-out: 0 12px 30px rgba(16, 39, 71, 0.08);
    --shadow-out-sm: 0 4px 14px rgba(16, 39, 71, 0.08);
    --shadow-in: inset 0 0 0 1px #dbe4ef;
    --shadow-in-deep: inset 0 0 0 2px #9bb9de;
}
}

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

body {
    font-family: var(--font-family);
    background-color: var(--color-bg);
    color: var(--color-text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Navbar */
.navbar {
    background-color: var(--color-surface);
    box-shadow: 0 4px 12px rgba(148, 163, 184, 0.1);
    position: sticky;
    top: 0;
    z-index: 10;
    border: none;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--color-text-main);
}

.nav-links {
    display: flex;
    gap: 1.5rem;
}

.auth-nav {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    min-width: 8rem;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
}

.auth-nav-status {
    white-space: nowrap;
}

.auth-nav-link {
    color: var(--color-btn-active-bg);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
}

.auth-nav-link:hover {
    color: var(--color-btn-active-hover);
    text-decoration: underline;
}

.auth-nav-button {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-out-sm);
    border-radius: var(--radius-md);
    color: var(--color-text-main);
    cursor: pointer;
    font: inherit;
    font-weight: 600;
    padding: 0.375rem 0.75rem;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.auth-nav-button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.auth-nav-button:active:not(:disabled) {
    box-shadow: var(--shadow-in);
    transform: translateY(1px);
}

.auth-nav-button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
    box-shadow: none;
}

.auth-nav-error {
    color: var(--color-error-text);
    font-size: 0.75rem;
}

.nav-link {
    text-decoration: none;
    color: var(--color-text-muted);
    font-weight: 600;
    font-size: 0.9375rem;
    transition: color 0.2s ease;
}

.nav-link:hover {
    color: var(--color-btn-active-bg);
}

.nav-link.active {
    color: var(--color-btn-active-bg);
}

.brand-icon {
    color: var(--color-btn-active-bg);
    filter: drop-shadow(2px 2px 4px rgba(37, 99, 235, 0.3));
}

/* Main Layout */
.app-root {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2.5rem 1.5rem;
}

.page-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.fade-in {
    animation: fadeIn 0.4s ease-out;
}

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

/* Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.page-title {
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    color: var(--color-text-main);
    margin-bottom: 0.25rem;
}

.page-subtitle {
    font-size: 1.125rem;
    color: var(--color-text-muted);
    font-weight: 500;
}

/* 3D Physical Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 0.95rem;
    font-weight: 600;
    border-radius: var(--radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
    text-decoration: none;
    gap: 0.5rem;
}

.btn:disabled {
    cursor: not-allowed;
    background: var(--color-btn-disabled-bg);
    color: var(--color-btn-disabled-text);
    box-shadow: none;
    transform: none;
}

.btn-launch:not(:disabled) {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 6px 6px 12px rgba(37, 99, 235, 0.3), -4px -4px 10px rgba(255, 255, 255, 0.8);
}

.btn-launch:not(:disabled):hover {
    transform: translateY(-1px);
    box-shadow: 8px 8px 16px rgba(37, 99, 235, 0.35), -4px -4px 12px rgba(255, 255, 255, 0.9);
}

.btn-launch:not(:disabled):active {
    box-shadow: inset 4px 4px 10px rgba(0, 0, 0, 0.2); 
    transform: translateY(2px);
}

/* Status Banner */
.status-banner {
    width: 100%;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    transition: all 0.3s ease;
    font-size: 0.9375rem;
    box-shadow: var(--shadow-out-sm);
    border: 1px solid var(--color-border);
}

.status-content {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

.status-loading {
    background-color: var(--color-surface);
    color: var(--color-text-main);
}

.status-success {
    background-color: var(--color-success-bg);
    color: var(--color-success-text);
    box-shadow: 4px 4px 8px #bbf7d0, -4px -4px 8px #ffffff;
}

.status-error {
    background-color: var(--color-error-bg);
    color: var(--color-error-text);
    box-shadow: 4px 4px 8px #fecaca, -4px -4px 8px #ffffff;
}

.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 3px solid currentColor;
    border-right-color: transparent;
    border-radius: var(--radius-full);
    animation: spin 0.75s linear infinite;
}

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

.retry-btn {
    background: var(--color-surface);
    border: none;
    color: inherit;
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
    font-weight: 700;
    border-radius: 8px;
    cursor: pointer;
    box-shadow: var(--shadow-out-sm);
    transition: all 0.2s ease;
    font-family: inherit;
}

.retry-btn:active {
    box-shadow: var(--shadow-in);
    transform: translateY(1px);
}

/* Empty State */
.empty-state-container {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 5rem 2rem;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: var(--shadow-in);
    border: 1px solid var(--color-border);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    max-width: 420px;
}

.empty-icon-wrap {
    width: 4.5rem;
    height: 4.5rem;
    background-color: var(--color-surface);
    box-shadow: var(--shadow-out);
    color: var(--color-btn-active-bg);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.empty-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text-main);
    margin-bottom: 0.5rem;
}

.empty-description {
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

/* Notices */
.hidden {
    display: none !important;
}

.notice-inline {
    background-color: var(--color-surface);
    color: var(--color-text-main);
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-in);
    border-left: 4px solid var(--color-btn-active-bg);
    font-size: 0.9375rem;
    font-weight: 600;
    animation: slideDown 0.3s ease-out;
}

/* Settings & Auth Cards - 3D Neumorphic */
.auth-page {
    display: flex;
    justify-content: center;
    padding: 1rem 0 3rem;
}

.auth-card,
.settings-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-out);
    border: 1px solid var(--color-border);
    max-width: 42rem;
    padding: 2.5rem;
    width: 100%;
    margin-bottom: 1.5rem;
    transition: transform 0.2s ease;
}

.settings-card:hover {
    transform: translateY(-2px);
}

.settings-access-card {
    max-width: 36rem;
}

.settings-eyebrow {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #64748b;
    text-transform: uppercase;
    margin-bottom: 0.5rem;
    display: block;
}

.auth-heading {
    margin: 0 0 1.5rem 0;
    color: #0f172a;
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
}

.clerk-auth-mount {
    min-height: 14rem;
}

.auth-owner-note {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    margin-top: 1rem;
    text-align: center;
}

.settings-layout {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 0;
    width: 100%;
}

.settings-layout > div,
.settings-card,
.settings-form,
.settings-form .form-group,
.settings-form .form-control {
    min-width: 0;
}

.settings-layout > div {
    width: 100%;
    max-width: 100%;
}

.settings-card {
    overflow-wrap: anywhere;
}

.settings-status {
    align-items: center;
    border-radius: var(--radius-md);
    display: flex;
    font-weight: 600;
    font-size: 0.875rem;
    gap: 0.625rem;
    margin: 1.5rem 0;
    padding: 1rem;
    box-shadow: var(--shadow-in);
}

.settings-status-info {
    color: var(--color-text-main);
}

.settings-status-success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
    box-shadow: inset 2px 2px 5px #bbf7d0, inset -2px -2px 5px #ffffff;
}

.settings-status-error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
    box-shadow: inset 2px 2px 5px #fecaca, inset -2px -2px 5px #ffffff;
}

.settings-cta {
    margin-top: 0.5rem;
    text-decoration: none;
}

.settings-source {
    color: var(--color-text-main);
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 1.25rem;
}

.settings-form {
    padding-top: 1.5rem;
}

.settings-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.settings-actions .btn {
    min-width: 7.5rem;
}

.settings-guide {
    background: var(--color-surface);
    box-shadow: var(--shadow-in);
    border-left: 4px solid var(--color-btn-active-bg);
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    font-size: 0.85rem;
    margin-top: 2rem;
    padding: 1.25rem;
}

.settings-guide strong {
    color: var(--color-text-main);
    display: block;
    margin-bottom: 0.375rem;
}

.template-owner-gate {
    color: var(--color-text-muted);
    font-size: 0.75rem;
    line-height: 1.35;
}

.template-owner-gate a {
    color: #6d28d9;
    font-weight: 700;
}

@media (max-width: 720px) {
    .nav-container {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 0.75rem 1rem;
        min-width: 0;
    }

    .nav-brand {
        flex: 1 1 auto;
    }

    .nav-links {
        gap: 0.875rem;
        order: 3;
        width: 100%;
        min-width: 0;
        flex-wrap: wrap;
    }

    .auth-nav {
        min-width: auto;
    }

    .auth-card,
    .settings-card {
        padding: 1.5rem;
    }

    .settings-layout > div[style*="grid"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .settings-actions .btn {
        min-width: 0;
        max-width: 100%;
        white-space: normal;
    }
}

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

/* Templates Grid - 3D Styled */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
}

@media (max-width: 1024px) {
    .templates-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .templates-grid {
        grid-template-columns: 1fr;
    }
}

.template-card {
    background-color: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-out);
    border: 1px solid var(--color-border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.template-card:hover {
    transform: translateY(-4px);
    box-shadow: 10px 10px 20px #cbd5e1, -10px -10px 20px #ffffff;
}

.template-card-title,
.template-header h3 {
    font-weight: 800;
    font-size: 1.25rem;
    color: var(--color-text-main);
    margin-bottom: 0.25rem;
    word-break: break-word;
}

.template-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
}

.template-badge,
.badge {
    background-color: var(--color-surface);
    box-shadow: var(--shadow-out-sm);
    color: var(--color-btn-active-bg);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-full);
    display: inline-block;
}

/* Aligned Framed Image Placeholder & Wrapper */
.template-body,
.template-image-area {
    width: 100%;
    height: 180px;
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--color-surface);
    box-shadow: var(--shadow-in);
}

.template-img,
.template-image {
    width: 100%;
    height: 100%;
    border-radius: var(--radius-md);
    object-fit: cover;
}

.no-img,
.template-image-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 600;
}

.template-stats {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.template-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: auto;
}

.template-generation {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 9rem;
}

.btn-generate,
.btn-generate-image {
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: #ffffff;
    box-shadow: 4px 4px 10px rgba(124, 58, 237, 0.25), -4px -4px 10px rgba(255, 255, 255, 0.8);
    border: none;
    white-space: nowrap;
}

.btn-generate:hover:not(:disabled),
.btn-generate-image:hover:not(:disabled) {
    transform: translateY(-1px);
}

.btn-generate:active:not(:disabled),
.btn-generate-image:active:not(:disabled) {
    box-shadow: inset 3px 3px 8px rgba(0,0,0,0.2);
    transform: translateY(2px);
}

.btn-generate:disabled,
.btn-generate-image:disabled {
    background: #c4b5fd;
    box-shadow: none;
    color: #ffffff;
}

.btn-auth-prompt {
    font-size: 0.8125rem;
    text-decoration: none;
    color: #7c3aed;
    font-weight: 700;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text-main);
    box-shadow: var(--shadow-out-sm);
}

.btn-secondary:active:not(:disabled) {
    box-shadow: var(--shadow-in);
    transform: translateY(1px);
}

.btn-danger {
    background: var(--color-surface);
    color: #ef4444;
    box-shadow: var(--shadow-out-sm);
}

.btn-danger:active:not(:disabled) {
    box-shadow: inset 4px 4px 8px #cbd5e1, inset -4px -4px 8px #ffffff;
    transform: translateY(2px);
}

.btn-outline {
    background-color: transparent;
    box-shadow: var(--shadow-out-sm);
    color: var(--color-text-main);
}

/* Modal - 3D Styled */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 2rem 1rem;
    z-index: 50;
    overflow-y: auto;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--color-surface);
    border-radius: 24px;
    width: 100%;
    max-width: 600px;
    max-height: calc(100vh - 4rem);
    padding: 2.5rem;
    position: relative;
    overflow-y: auto;
    transform: translateY(-20px) scale(0.95);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 12px 12px 24px rgba(148, 163, 184, 0.4), -12px -12px 24px #ffffff;
    border: 1px solid var(--color-border);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 800;
}

.modal-close {
    background: var(--color-surface);
    border: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--color-text-muted);
    box-shadow: var(--shadow-out-sm);
    transition: all 0.2s;
}

.modal-close:active {
    box-shadow: var(--shadow-in);
    transform: translateY(1px);
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-weight: 700;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    color: var(--color-text-main);
}

/* 3D Indented Input Fields */
.form-control {
    width: 100%;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    border: none;
    background: var(--color-surface);
    box-shadow: var(--shadow-in);
    color: var(--color-text-main);
    font-size: 1rem;
    outline: none;
    transition: all 0.2s ease;
    font-family: inherit;
}

.form-control:focus {
    box-shadow: var(--shadow-in-deep);
}

.form-control.error {
    box-shadow: inset 3px 3px 6px #fecaca, inset -3px -3px 6px #ffffff;
}

.form-help {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    margin-top: 0.5rem;
}

.form-error {
    color: #DC2626;
    font-size: 0.8125rem;
    font-weight: 600;
    margin-top: 0.5rem;
    display: none;
}

.form-error.active {
    display: block;
}

.variation-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.variation-item {
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

textarea.form-control {
    resize: vertical;
    min-height: 3rem;
}

.btn-remove {
    background: var(--color-surface);
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    width: 3rem;
    height: 3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: var(--shadow-out-sm);
    transition: all 0.2s;
}

.btn-remove:active {
    box-shadow: var(--shadow-in);
    color: #DC2626;
    transform: translateY(1px);
}

.btn-add-variation {
    background: var(--color-surface);
    border: none;
    box-shadow: var(--shadow-out-sm);
    color: var(--color-btn-active-bg);
    padding: 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    margin-top: 0.5rem;
    transition: all 0.2s;
}

.btn-add-variation:active {
    box-shadow: var(--shadow-in);
    transform: translateY(1px);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2.5rem;
    padding-top: 1.5rem;
}

/* Toast */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.toast {
    background-color: var(--color-surface);
    border-radius: var(--radius-md);
    padding: 1.25rem 1.5rem;
    box-shadow: 8px 8px 16px rgba(148, 163, 184, 0.25), -8px -8px 16px #ffffff;
    display: flex;
    align-items: center;
    gap: 1rem;
    font-weight: 600;
    animation: slideInRight 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    border-left: 6px solid var(--color-success-text);
}

.toast.error {
    border-left-color: #DC2626;
}

@keyframes slideInRight {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOutRight {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(120%); opacity: 0; }
}