/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: all 0.2s ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, #7c3aed 100%);
    color: white;
    padding: 2rem;
    text-align: center;
}

.header-content {
    max-width: 800px;
    margin: 0 auto;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.logo-img {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
}

.logo h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
    margin: 0;
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    padding: 1.5rem;
    flex: 1;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* Panel Styles */
.editor-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
    max-height: calc(100vh - 200px);
    padding-right: 0.5rem;
}

.editor-panel::-webkit-scrollbar {
    width: 6px;
}

.editor-panel::-webkit-scrollbar-track {
    background: var(--background);
    border-radius: 3px;
}

.editor-panel::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.editor-panel::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

.preview-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 1.5rem;
    max-height: calc(100vh - 200px);
    overflow: hidden;
}

/* Section Styles */
.section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.section-title .icon {
    font-size: 1.1rem;
}

/* Template Selection */
.template-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.template-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 0.75rem;
    background: var(--surface);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

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

.template-btn.active {
    border-color: var(--primary-color);
    background: rgba(37, 99, 235, 0.05);
}

.template-icon {
    font-size: 1.5rem;
}

.template-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    font-family: inherit;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text-primary);
    transition: var(--transition);
}

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

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

/* Checkbox Styles */
.badge-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-secondary);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.checkbox-label:hover {
    background: var(--surface-hover);
}

.checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--primary-color);
}

/* Custom Badges List */
.custom-badges-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.custom-badge-item {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.5rem;
    background: var(--surface-hover);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
}

.custom-badge-item button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--danger-color);
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
}

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

.btn-primary:hover {
    background: var(--primary-hover);
}

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

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

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    margin-top: 0.5rem;
    background: var(--primary-color);
    color: white;
}

.btn-small:hover {
    background: var(--primary-hover);
}

.btn-icon {
    font-size: 1rem;
}

/* Section Builder */
.section-builder {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.section-builder h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.section-list {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    min-height: 100px;
    padding: 0.5rem;
    background: var(--surface-hover);
    border-radius: var(--radius);
    border: 1px dashed var(--border-color);
}

.section-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.section-item:hover {
    border-color: var(--primary-color);
}

.section-item.dragging {
    opacity: 0.5;
}

.section-item-name {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.section-item-actions {
    display: flex;
    gap: 0.25rem;
}

.section-item-actions button {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    padding: 0.125rem;
    opacity: 0.7;
    transition: var(--transition);
}

.section-item-actions button:hover {
    opacity: 1;
}

/* Section Forms */
#sectionForms {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.section-form {
    padding: 1rem;
    background: var(--surface-hover);
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
}

.section-form h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

/* Preview Panel */
.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.preview-tabs {
    display: flex;
    gap: 0.25rem;
    background: var(--surface-hover);
    padding: 0.25rem;
    border-radius: var(--radius);
}

.preview-tab {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.preview-tab.active {
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.preview-actions {
    display: flex;
    gap: 0.5rem;
}

.preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.preview-view,
.markdown-view {
    display: none;
}

.preview-view.active,
.markdown-view.active {
    display: block;
}

/* Markdown Preview Styles */
.preview-view {
    font-size: 0.9rem;
    line-height: 1.7;
}

.preview-view h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.preview-view h2 {
    font-size: 1.35rem;
    font-weight: 600;
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    padding-bottom: 0.375rem;
    border-bottom: 1px solid var(--border-color);
}

.preview-view h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-top: 1.25rem;
    margin-bottom: 0.5rem;
}

.preview-view p {
    margin-bottom: 1rem;
}

.preview-view ul,
.preview-view ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.preview-view li {
    margin-bottom: 0.25rem;
}

.preview-view code {
    background: var(--surface-hover);
    padding: 0.125rem 0.375rem;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    font-family: 'Consolas', 'Monaco', monospace;
}

.preview-view pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1rem;
}

.preview-view pre code {
    background: transparent;
    padding: 0;
    color: inherit;
}

.preview-view blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 1rem;
    margin: 1rem 0;
    color: var(--text-secondary);
}

.preview-view a {
    color: var(--primary-color);
    text-decoration: none;
}

.preview-view a:hover {
    text-decoration: underline;
}

.preview-view img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
}

.preview-view table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
}

.preview-view th,
.preview-view td {
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    text-align: left;
}

.preview-view th {
    background: var(--surface-hover);
    font-weight: 600;
}

/* Markdown Code View */
.markdown-view pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.markdown-view code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
}

/* Footer */
.footer {
    background: var(--surface);
    border-top: 1px solid var(--border-color);
    padding: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.footer-content {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.footer-content a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.footer-content a:hover {
    text-decoration: underline;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

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

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

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

/* Mobile Responsive */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .editor-panel {
        max-height: none;
        overflow-y: visible;
    }

    .preview-panel {
        position: relative;
        top: 0;
        max-height: 600px;
    }

    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .section-builder {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 1.5rem 1rem;
    }

    .logo h1 {
        font-size: 1.35rem;
    }

    .main-content {
        padding: 1rem;
        gap: 1rem;
    }

    .section {
        padding: 1rem;
    }

    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .badge-options {
        grid-template-columns: 1fr;
    }

    .preview-header {
        flex-direction: column;
        gap: 0.75rem;
    }

    .preview-actions {
        width: 100%;
        justify-content: center;
    }

    .btn {
        padding: 0.5rem 0.75rem;
        font-size: 0.8rem;
    }
}

/* Drag and Drop Styles */
.sortable .section-item {
    cursor: grab;
}

.sortable .section-item:active {
    cursor: grabbing;
}

.drop-zone {
    background: rgba(37, 99, 235, 0.1);
    border-color: var(--primary-color);
}

/* Animation */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.section {
    animation: fadeIn 0.3s ease;
}
