/**
 * Universal Forms CSS v3.0
 * Container-specific styling for universal form components
 * 
 * Features:
 * - Responsive grid systems for each container type
 * - Container-aware field layouts  
 * - Hierarchical event isolation visual feedback
 * - Smooth animations and transitions
 * - Memory-efficient styling with component isolation
 */

/* ===== UNIVERSAL FORM BASE ===== */

.universal-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.universal-form-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.universal-field {
    position: relative;
}

.field-container {
    width: 100%;
}

.field-label-section {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.field-input {
    width: 100%;
}

.required-indicator {
    color: #dc2626;
    font-weight: 600;
}

.field-metadata {
    font-size: 0.75rem;
    color: #6b7280;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* ===== FORM STATE CLASSES ===== */

.form-dirty {
    position: relative;
}

.form-dirty::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #f59e0b;
    border-radius: 0.5rem;
    opacity: 0.3;
    pointer-events: none;
}

.form-success {
    position: relative;
}

.form-success::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #10b981;
    border-radius: 0.5rem;
    opacity: 0.5;
    pointer-events: none;
    animation: successPulse 1s ease-out;
}

@keyframes successPulse {
    0% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 0.5; transform: scale(1); }
}

.form-error {
    position: relative;
}

.form-error::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #dc2626;
    border-radius: 0.5rem;
    opacity: 0.6;
    pointer-events: none;
    animation: errorShake 0.5s ease-out;
}

@keyframes errorShake {
    0%, 20%, 40%, 60%, 80% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
}

.submitting {
    opacity: 0.7;
    pointer-events: none;
    position: relative;
}

.submitting::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid #3b82f6;
    border-top: 2px solid transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== FIELD FOCUS STATES ===== */

.field-focused {
    border-color: #3b82f6 !important;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1) !important;
}

.field-container-focused {
    background-color: rgba(59, 130, 246, 0.02);
    border-radius: 0.375rem;
}

.field-error {
    border-color: #dc2626 !important;
    background-color: #fef2f2 !important;
}

.field-error::placeholder {
    color: #dc2626;
}

/* ===== INLINE COMPACT CONTAINER ===== */

.compact-inline-form {
    min-height: 80px;
    transition: all 0.2s ease-out;
}

.compact-inline-form .form-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.compact-inline-form .compact-field {
    flex: 1;
    min-width: 8rem;
    max-width: 12rem;
}

.compact-inline-form .field-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
    display: block;
}

.compact-inline-form .field-input input,
.compact-inline-form .field-input select,
.compact-inline-form .field-input textarea {
    width: 100%;
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.25rem;
    transition: all 0.15s ease;
}

.compact-inline-form .inline-compact-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.compact-inline-form .action-btn {
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.15s ease;
    border: none;
    cursor: pointer;
}

.compact-inline-form .save-btn {
    color: #059669;
    background: transparent;
}

.compact-inline-form .save-btn:hover {
    color: #047857;
    background-color: #ecfdf5;
}

.compact-inline-form .cancel-btn {
    color: #9ca3af;
    background: transparent;
}

.compact-inline-form .cancel-btn:hover {
    color: #6b7280;
    background-color: #f9fafb;
}

/* ===== INLINE EXPANDED CONTAINER ===== */

.expanded-inline-form {
    min-height: 120px;
    transition: all 0.3s ease-out;
}

.expanded-inline-form .form-fields {
    display: grid;
    gap: 1rem;
    /* Grid columns set dynamically via classes */
}

.expanded-inline-form .expanded-field {
    background: #ffffff;
    padding: 1rem;
    border-radius: 0.5rem;
    border: 1px solid #e5e7eb;
    transition: all 0.2s ease;
}

.expanded-inline-form .expanded-field:hover {
    border-color: #d1d5db;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.expanded-inline-form .field-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

.expanded-inline-form .field-input input,
.expanded-inline-form .field-input select,
.expanded-inline-form .field-input textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.expanded-inline-form .inline-expanded-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.expanded-inline-form .action-btn {
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    border: 1px solid;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.expanded-inline-form .save-btn {
    color: #ffffff;
    background-color: #059669;
    border-color: transparent;
}

.expanded-inline-form .save-btn:hover {
    background-color: #047857;
    box-shadow: 0 2px 4px rgba(5, 150, 105, 0.2);
}

.expanded-inline-form .cancel-btn {
    color: #374151;
    background-color: #e5e7eb;
    border-color: #d1d5db;
}

.expanded-inline-form .cancel-btn:hover {
    background-color: #d1d5db;
}

/* ===== MODAL CONTAINER ===== */

.modal-backdrop {
    backdrop-filter: blur(4px);
    z-index: 9999; /* Ensure modal appears above navigation */
}

.modal-container {
    max-width: 90vw;
    max-height: 90vh;
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-body {
    max-height: 60vh;
    overflow-y: auto;
    scrollbar-width: thin;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.modal-form-content .form-fields {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-form-content .form-field {
    width: 100%;
}

.modal-form-content .field-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
}

.modal-form-content .field-input input,
.modal-form-content .field-input select,
.modal-form-content .field-input textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
}

.modal-slider-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.modal-slider-actions .action-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.modal-slider-actions .save-btn {
    background-color: #3b82f6;
    color: #ffffff;
    border: none;
}

.modal-slider-actions .save-btn:hover {
    background-color: #2563eb;
}

.modal-slider-actions .cancel-btn {
    background-color: #ffffff;
    color: #6b7280;
    border: 1px solid #d1d5db;
}

.modal-slider-actions .cancel-btn:hover {
    background-color: #f9fafb;
}

/* ===== SLIDER CONTAINER ===== */

.slider-backdrop {
    backdrop-filter: blur(2px);
    z-index: 9998; /* Ensure slider appears above navigation */
}

.slider-panel {
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.1);
}

.slider-form-content .form-fields {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.slider-form-content .form-field {
    width: 100%;
    padding: 0;
}

.slider-form-content .field-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.5rem;
}

.slider-form-content .field-input input,
.slider-form-content .field-input select,
.slider-form-content .field-input textarea {
    width: 100%;
    padding: 0.75rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.375rem;
    transition: all 0.15s ease;
}

/* ===== WIDE SLIDER CONTAINER ===== */

.wide-slider-backdrop {
    backdrop-filter: blur(3px);
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 9997; /* Ensure wide slider appears above navigation */
}

.wide-slider-panel {
    box-shadow: -6px 0 20px rgba(0, 0, 0, 0.15);
}

.wide-slider-form-content .form-fields {
    display: grid;
    gap: 1.5rem;
    /* Grid responsive classes applied via template */
}

.wide-slider-form-content .form-field {
    background: #ffffff;
    padding: 1.5rem;
    border-radius: 0.75rem;
    border: 1px solid #e5e7eb;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.wide-slider-form-content .form-field:hover {
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
    transform: translateY(-1px);
}

.wide-slider-form-content .field-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 0.75rem;
}

.wide-slider-form-content .field-input input,
.wide-slider-form-content .field-input select,
.wide-slider-form-content .field-input textarea {
    width: 100%;
    padding: 0.875rem;
    font-size: 0.875rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    transition: all 0.15s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.wide-slider-form-content .field-input input:focus,
.wide-slider-form-content .field-input select:focus,
.wide-slider-form-content .field-input textarea:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Wide slider specific enhancements */
.wide-slider-open body {
    overflow: hidden;
}

.wide-slider-header {
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 100%);
}

.wide-slider-body {
    background: #f8fafc;
}

.form-summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #6b7280;
    font-size: 0.875rem;
}

/* ===== RESPONSIVE DESIGN ===== */

/* Mobile optimizations */
@media (max-width: 640px) {
    .compact-inline-form .form-fields {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .compact-inline-form .compact-field {
        min-width: 100%;
        max-width: 100%;
    }
    
    .expanded-inline-form .form-fields {
        grid-template-columns: 1fr !important;
    }
    
    .modal-container {
        margin: 1rem;
        max-width: calc(100vw - 2rem);
    }
    
    .slider-panel,
    .wide-slider-panel {
        width: 100vw !important;
        max-width: 100vw !important;
    }
    
    .wide-slider-form-content .form-fields {
        grid-template-columns: 1fr !important;
    }
}

/* Tablet optimizations */
@media (min-width: 641px) and (max-width: 1024px) {
    .wide-slider-panel {
        width: 70vw !important;
    }
    
    /* Remove forced 2-column layout on tablets - let Tailwind handle it */
}

/* Desktop optimizations */
@media (min-width: 1025px) {
    .compact-inline-form .compact-field {
        max-width: 10rem;
    }
    
    .wide-slider-form-content .form-fields {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ===== UTILITY CLASSES ===== */

.form-debug {
    background: #dbeafe;
    border: 1px solid #93c5fd;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 1rem;
}

.form-recommendations {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 1rem;
}

.recommendations-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #92400e;
}

.recommendations-list {
    list-style: disc;
    list-style-position: inside;
    color: #78350f;
    font-size: 0.875rem;
}

.debug-badge {
    background: #dbeafe;
    color: #1e40af;
    padding: 0.25rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */

.action-btn:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-field {
        border-width: 2px;
    }
    
    .action-btn {
        border-width: 2px;
    }
    
    .field-focused {
        border-width: 3px !important;
    }
}