.builder-section {
    padding: 3rem 0;
}

.builder-intro {
    text-align: center;
    max-width: 800px;
    margin: 0 auto 3rem;
}

.builder-intro h1 {
    margin-bottom: 1rem;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.builder-intro p {
    font-size: 1.125rem;
    color: var(--text-light);
}

.builder-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 3rem;
}

.form-section {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-md);
}

.form-section h2 {
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--border-color);
}

.section-group {
    margin-bottom: 2rem;
}

.section-group h3 {
    font-size: 1.125rem;
    color: var(--primary-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.preview-section {
    position: sticky;
    top: 100px;
    height: fit-content;
}

.preview-controls {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.preview-a4 {
    width: 210mm;
    height: 297mm;
    background: #fff center/cover no-repeat;
    position: relative;
    overflow: hidden;
    margin-inline: auto;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-md);
    transform-origin: top center;
}

.preview-overlay {
    position: absolute;
    inset: 18mm;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow-y: auto;
}

.preview-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.preview-photo {
    width: 120px;
    height: 150px;
    margin: 0 auto 1rem;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--border-color);
}

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

.preview-name {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 0.25rem;
}

.preview-section-block {
    background: rgba(255, 255, 255, 0.9);
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 0.75rem;
}

.preview-section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.25rem;
}

.preview-field {
    position: relative;
    line-height: 1.4;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.preview-label {
    font-weight: 600;
    color: var(--text-color);
    display: inline;
}

.preview-value {
    color: var(--text-light);
    display: inline;
}

.template-gallery {
    margin: 3rem 0;
}

.template-gallery h2 {
    text-align: center;
    margin-bottom: 2rem;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}

.template-item {
    position: relative;
    aspect-ratio: 210 / 297;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    border: 3px solid transparent;
    transition: all 0.3s ease;
}

.template-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.template-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 4px rgba(217, 70, 239, 0.2);
}

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

.file-upload {
    position: relative;
}

.file-upload input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.file-upload-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
}

.file-upload-label:hover {
    border-color: var(--primary-color);
    background: rgba(217, 70, 239, 0.05);
}

.file-preview {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-light);
}

@media (max-width: 1024px) {
    .builder-container {
        grid-template-columns: 1fr;
    }
    
    .preview-section {
        position: static;
    }
    
    .preview-a4 {
        transform: scale(0.7);
        margin-bottom: -100px;
    }
}

@media (max-width: 768px) {
    .preview-a4 {
        transform: scale(0.5);
        margin-bottom: -150px;
    }
    
    .template-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
}

@media (max-width: 480px) {
    .preview-a4 {
        transform: scale(0.35);
        margin-bottom: -200px;
    }
}

[dir="rtl"] .preview-field {
    text-align: right;
}

[dir="rtl"] .preview-header {
    direction: rtl;
}
