/**
 * Forms Advanced Styles
 * Modern, polished UI for form builder and dynamic forms
 */

/* ============================================
   FORM BUILDER LAYOUT
   ============================================ */

.form-builder-layout {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 1.5rem;
    height: calc(100vh - 200px);
    min-height: 600px;
}

/* Field Library (Left Sidebar) */
.field-library {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow-y: auto;
}

.field-types-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
}

.field-type-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.2s ease;
    -webkit-user-select: none;
    user-select: none;
}

.field-type-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.field-type-item:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.field-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.field-label {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Form Canvas (Center) */
.form-canvas {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.canvas-header {
    padding: 1.5rem;
    border-bottom: 2px solid #f3f4f6;
}

.step-tabs {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.step-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1rem;
    background: #f3f4f6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    font-size: 0.875rem;
    font-weight: 500;
}

.step-tab:hover {
    background: #e5e7eb;
}

.step-tab.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.step-tab-delete {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: all 0.2s ease;
}

.step-tab-delete:hover {
    background: #ef4444;
    color: white;
}

.canvas-body {
    flex: 1;
    padding: 1.5rem;
    overflow-y: auto;
}

.drop-zone {
    min-height: 400px;
    border: 3px dashed #d1d5db;
    border-radius: 12px;
    padding: 2rem;
    transition: all 0.3s ease;
    background: #fafafa;
}

.drop-zone.drag-over {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
    transform: scale(1.02);
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #9ca3af;
    font-size: 1rem;
    text-align: center;
}

/* Field Items */
.field-item {
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    transition: all 0.2s ease;
    cursor: pointer;
}

.field-item:hover {
    border-color: #667eea;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.field-item.selected {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.05) 0%, rgba(118, 75, 162, 0.05) 100%);
}

.field-item-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.field-type-badge {
    padding: 0.25rem 0.625rem;
    background: #667eea;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 6px;
    text-transform: uppercase;
}

.field-item-actions {
    margin-left: auto;
    display: flex;
    gap: 0.5rem;
}

.field-action {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.25rem;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.field-action:hover {
    opacity: 1;
    transform: scale(1.1);
}

.field-drag-handle {
    background: none;
    border: none;
    cursor: grab;
    font-size: 1rem;
    padding: 0.25rem;
    opacity: 0.5;
    color: #6b7280;
}

.field-drag-handle:active {
    cursor: grabbing;
}

.required-badge {
    display: inline-block;
    margin-top: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
}

/* Field Properties (Right Sidebar) */
.field-properties {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    overflow-y: auto;
}

/* ============================================
   FILE UPLOAD WIDGET
   ============================================ */

.file-upload-widget {
    width: 100%;
}

.drop-zone {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 2.5rem;
    text-align: center;
    transition: all 0.3s ease;
    cursor: pointer;
    background: #fafafa;
}

.drop-zone:hover {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.03) 0%, rgba(118, 75, 162, 0.03) 100%);
}

.drop-zone.drag-over {
    border-color: #667eea;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.1) 0%, rgba(118, 75, 162, 0.1) 100%);
    transform: scale(1.02);
}

.file-input-hidden {
    display: none;
}

.drop-zone-content {
    pointer-events: none;
}

.drop-zone-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 1rem;
    color: #9ca3af;
}

.drop-zone-text {
    font-size: 1rem;
    color: #4b5563;
    margin-bottom: 0.5rem;
}

.drop-zone-browse {
    color: #667eea;
    font-weight: 600;
    text-decoration: underline;
}

.drop-zone-hint {
    font-size: 0.875rem;
    color: #9ca3af;
}

/* File List */
.file-list {
    margin-top: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    transition: all 0.2s ease;
}

.file-item:hover {
    border-color: #667eea;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.1);
}

.file-item.uploading {
    border-color: #3b82f6;
}

.file-item.uploaded {
    border-color: #10b981;
}

.file-item.error {
    border-color: #ef4444;
    background: #fef2f2;
}

.file-preview {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

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

.file-icon {
    width: 60px;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    background: #f3f4f6;
    border-radius: 8px;
    flex-shrink: 0;
}

.file-details {
    flex: 1;
    min-width: 0;
}

.file-name {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    color: #6b7280;
}

.file-status-badge {
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
}

.file-status-badge.success {
    background: #d1fae5;
    color: #065f46;
}

.file-status-badge.error {
    background: #fee2e2;
    color: #991b1b;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transition: width 0.3s ease;
}

.file-remove-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: #fee2e2;
    color: #ef4444;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-remove-btn:hover:not(:disabled) {
    background: #ef4444;
    color: white;
}

.file-remove-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-remove-btn svg {
    width: 16px;
    height: 16px;
}

.file-upload-error {
    margin-top: 1rem;
    padding: 1rem;
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    border-radius: 8px;
    color: #991b1b;
    animation: slideIn 0.3s ease;
}

/* ============================================
   FORM VALIDATION STYLES
   ============================================ */

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.2s ease;
    background: white;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-input.error,
.form-select.error,
.form-textarea.error {
    border-color: #ef4444;
    background: #fef2f2;
}

.form-input.valid,
.form-select.valid,
.form-textarea.valid {
    border-color: #10b981;
}

.field-error-message {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: #fee2e2;
    border-left: 4px solid #ef4444;
    border-radius: 6px;
    animation: slideIn 0.3s ease;
}

.field-error-message p {
    margin: 0;
    font-size: 0.875rem;
    color: #991b1b;
}

.field-error-message p + p {
    margin-top: 0.5rem;
}

/* ============================================
   DYNAMIC FORM PREVIEW
   ============================================ */

.form-preview-wrapper {
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.preview-step {
    animation: fadeIn 0.3s ease;
}

.preview-step.hidden {
    display: none;
}

/* ============================================
   BUTTONS
   ============================================ */

.btn {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-secondary {
    background: #f3f4f6;
    color: #374151;
}

.btn-secondary:hover {
    background: #e5e7eb;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.8125rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 1280px) {
    .form-builder-layout {
        grid-template-columns: 240px 1fr 280px;
    }
}

@media (max-width: 1024px) {
    .form-builder-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }
    
    .field-library,
    .field-properties {
        max-height: 300px;
    }
}

@media (max-width: 640px) {
    .form-builder-layout {
        gap: 1rem;
    }
    
    .field-library,
    .canvas-header,
    .canvas-body,
    .field-properties {
        padding: 1rem;
    }
    
    .drop-zone {
        padding: 1.5rem;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.space-y-2 > * + * {
    margin-top: 0.5rem;
}

.space-y-3 > * + * {
    margin-top: 0.75rem;
}

.space-y-4 > * + * {
    margin-top: 1rem;
}

.grid {
    display: grid;
}

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

.gap-2 {
    gap: 0.5rem;
}

.flex {
    display: flex;
}

.items-center {
    align-items: center;
}

.justify-between {
    justify-content: space-between;
}

.text-sm {
    font-size: 0.875rem;
}

.text-xs {
    font-size: 0.75rem;
}

.font-semibold {
    font-weight: 600;
}

.font-medium {
    font-weight: 500;
}

.text-gray-500 {
    color: #6b7280;
}

.text-gray-600 {
    color: #4b5563;
}

.mb-1 {
    margin-bottom: 0.25rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mt-6 {
    margin-top: 1.5rem;
}

.pt-4 {
    padding-top: 1rem;
}

.border-t {
    border-top: 1px solid #e5e7eb;
}

.block {
    display: block;
}

.w-full {
    width: 100%;
}
