/* Form Modals - Unified styling for embedded Lead & Inventory forms */

/* Modal Overlay */
.form-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(30, 41, 59, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    overflow-y: auto;
    padding: 20px;
    justify-content: center;
    align-items: center;
}
.form-modal-overlay.active { display: flex; }

/* Modal Container */
.form-modal {
    background: var(--surface-color, #ffffff);
    border-radius: 16px;
    max-width: 720px;
    width: 100%;
    margin: auto;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    animation: modalSlideIn 0.25s ease-out;
    max-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-20px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Modal Header */
.form-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    background: linear-gradient(to bottom, var(--surface-color, #ffffff), rgba(249, 250, 251, 0.5));
}
.form-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary, #1f2937);
}
.form-modal-close {
    background: var(--surface-color, #f3f4f6);
    border: 1px solid var(--border-color, #e5e7eb);
    font-size: 20px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-secondary, #6b7280);
    line-height: 1;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: all 0.2s;
}
.form-modal-close:hover { 
    background: #fee2e2; 
    border-color: #fecaca;
    color: #dc2626; 
    transform: scale(1.05);
}

/* Modal Body */
.form-modal-body {
    padding: 20px 24px 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Form Styling */
.modal-form h4 {
    margin: 20px 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--primary-color, #2563eb);
}
.modal-form h4:first-child { margin-top: 0; }

.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 140px;
}
.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary, #374151);
}
.col-25 { flex: 0 0 calc(25% - 12px); }
.col-33 { flex: 0 0 calc(33.333% - 11px); }
.col-40 { flex: 0 0 calc(40% - 8px); }
.col-50 { flex: 0 0 calc(50% - 8px); }
.col-60 { flex: 0 0 calc(60% - 8px); }

/* Inputs */
.modal-form input[type="text"],
.modal-form input[type="tel"],
.modal-form input[type="number"],
.modal-form input[type="date"],
.modal-form input[type="time"],
.modal-form input[type="file"],
.modal-form textarea,
.modal-form select {
    padding: 10px 12px;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    font-size: 0.9375rem;
    background: var(--input-bg, #fff);
    color: var(--text-primary, #1f2937);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.modal-form input:focus,
.modal-form textarea:focus,
.modal-form select:focus {
    outline: none;
    border-color: var(--primary-color, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.modal-form textarea { resize: vertical; min-height: 60px; }

/* Required asterisk */
.required-asterisk { color: var(--danger-color, #ef4444); }

/* Check button */
.check-btn {
    font-size: 0.75rem;
    color: var(--primary-color, #2563eb);
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(37, 99, 235, 0.1);
    transition: background 0.15s;
}
.check-btn:hover { background: rgba(37, 99, 235, 0.2); }

/* Field status */
.field-status {
    font-size: 0.8125rem;
    padding: 6px 10px;
    border-radius: 6px;
    margin-top: 4px;
}
.field-status.error { background: rgba(239, 68, 68, 0.1); color: var(--danger-color, #dc2626); }
.field-status.success { background: rgba(34, 197, 94, 0.1); color: var(--success-color, #16a34a); }

/* Custom Dropdown */
.custom-multiselect { position: relative; }
.hidden-validation-input { position: absolute; opacity: 0; pointer-events: none; height: 0; }
.custom-select-toggle {
    padding: 10px 12px;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    background: var(--input-bg, #fff);
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text-secondary, #6b7280);
    transition: border-color 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.custom-select-toggle.active { color: var(--text-primary, #1f2937); }
.custom-select-toggle:hover { border-color: var(--primary-color, #2563eb); }
.custom-select-options {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: 220px;
    overflow-y: auto;
    z-index: 100;
    margin-top: 4px;
}
.custom-select-search { padding: 8px; border-bottom: 1px solid var(--border-color, #e5e7eb); }
.custom-select-search .search-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 6px;
    font-size: 0.875rem;
}
.custom-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--text-primary, #374151);
    transition: background 0.1s;
}
.custom-option:hover { background: var(--hover-bg, #f3f4f6); }
.custom-option.selected { background: rgba(37, 99, 235, 0.08); color: var(--primary-color, #2563eb); }
.custom-option .checkmark { display: none; color: var(--primary-color, #2563eb); }
.custom-option.selected .checkmark { display: inline; }

/* Image Upload */
.image-upload-section {
    margin: 20px 0;
    padding: 16px;
    border: 2px dashed var(--border-color, #d1d5db);
    border-radius: 12px;
    background: var(--hover-bg, #f9fafb);
}
.image-upload-section h4 { margin: 0 0 12px; border: none; padding: 0; }
.upload-area { text-align: center; padding: 8px 0; }
.upload-button {
    padding: 10px 20px;
    background: var(--primary-color, #2563eb);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.upload-button:hover:not(:disabled) { background: var(--primary-hover, #1d4ed8); transform: translateY(-1px); }
.upload-button:disabled { opacity: 0.6; cursor: not-allowed; }
.upload-progress { display: none; margin-top: 12px; }
.progress-bar { height: 6px; background: var(--border-color, #e5e7eb); border-radius: 3px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary-color, #2563eb); width: 0; transition: width 0.3s; }
.progress-text { font-size: 0.8125rem; color: var(--text-secondary, #6b7280); margin-bottom: 6px; }
.image-previews { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.image-preview { position: relative; width: 80px; height: 80px; border-radius: 8px; overflow: hidden; }
.image-preview img { width: 100%; height: 100%; object-fit: cover; }
.image-preview .remove-image {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.compression-info { font-size: 0.8125rem; color: var(--text-secondary, #6b7280); margin-top: 10px; }

/* Status Message */
.status-message {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.9375rem;
    margin: 16px 0;
}
.status-message.success { background: rgba(34, 197, 94, 0.1); color: var(--success-color, #16a34a); border: 1px solid rgba(34, 197, 94, 0.2); }
.status-message.error { background: rgba(239, 68, 68, 0.1); color: var(--danger-color, #dc2626); border: 1px solid rgba(239, 68, 68, 0.2); }
.status-message.info { background: rgba(59, 130, 246, 0.1); color: var(--primary-color, #2563eb); border: 1px solid rgba(59, 130, 246, 0.2); }

/* Form Actions */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #e5e7eb);
}
.btn-submit, .btn-secondary {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-submit {
    background: var(--primary-color, #2563eb);
    color: #fff;
    border: none;
}
.btn-submit:hover:not(:disabled) { background: var(--primary-hover, #1d4ed8); }
.btn-submit:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-secondary {
    background: var(--card-bg, #fff);
    color: var(--text-primary, #374151);
    border: 1px solid var(--border-color, #d1d5db);
}
.btn-secondary:hover { background: var(--hover-bg, #f3f4f6); border-color: var(--text-secondary, #9ca3af); }

/* Bulk Import */
.import-instructions {
    background: var(--hover-bg, #f3f4f6);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 20px;
}
.import-instructions h4 { margin: 0 0 12px; border: none; padding: 0; font-size: 0.9rem; }
.instruction-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 6px 16px;
    font-size: 0.8125rem;
}
.instruction-grid span:nth-child(odd) { color: var(--text-primary, #374151); }
.instruction-grid span:nth-child(even) { color: var(--text-secondary, #6b7280); }

/* Phone Input Integration */
.modal-form .iti { width: 100%; }
.modal-form .iti__selected-dial-code { font-size: 0.875rem; }

/* Responsive - Tablets */
@media (max-width: 768px) {
    .form-modal { max-width: 95%; }
    .col-25 { flex: 0 0 calc(50% - 8px); }
}

/* Responsive - Mobile */
@media (max-width: 640px) {
    .form-modal { margin: 10px; max-width: none; border-radius: 12px; }
    .form-modal-header { padding: 14px 16px; }
    .form-modal-header h3 { font-size: 1.1rem; }
    .form-modal-body { padding: 16px; max-height: calc(100vh - 120px); }
    .form-row { flex-direction: column; gap: 12px; }
    .col-25, .col-33, .col-40, .col-50, .col-60 { flex: 1 1 100%; }
    .form-actions { flex-direction: column; }
    .form-actions button { width: 100%; }
    .image-upload-section { padding: 12px; }
    .image-preview { width: 70px; height: 70px; }
}

/* Responsive - Very Small Screens (320px) */
@media (max-width: 380px) {
    .form-modal-overlay { padding: 8px; }
    .form-modal { margin: 4px; border-radius: 10px; }
    .form-modal-header { padding: 12px 14px; }
    .form-modal-header h3 { font-size: 1rem; }
    .form-modal-body { padding: 12px; max-height: calc(100vh - 100px); }
    .form-group label { font-size: 0.8125rem; }
    .modal-form input, .modal-form textarea, .modal-form select, .custom-select-toggle { 
        padding: 8px 10px; 
        font-size: 0.875rem; 
    }
    .btn-submit, .btn-secondary { padding: 10px 16px; font-size: 0.875rem; }
    .check-btn { font-size: 0.7rem; padding: 2px 6px; }
    .image-preview { width: 60px; height: 60px; }
    .upload-button { padding: 8px 16px; font-size: 0.875rem; }
    .instruction-grid { font-size: 0.75rem; gap: 4px 10px; }
    .status-message { padding: 10px 12px; font-size: 0.875rem; }
}

/* Toast Notification */
.form-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10001;
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 90%;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}
.toast-close {
    margin-left: 12px;
    cursor: pointer;
    opacity: 0.7;
    font-weight: bold;
}
.toast-close:hover { opacity: 1; }
.form-toast.success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.form-toast.error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.form-toast.info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
[data-theme="dark"] .form-toast.success { background: #166534; color: #dcfce7; }
[data-theme="dark"] .form-toast.error { background: #991b1b; color: #fee2e2; }
[data-theme="dark"] .form-toast.info { background: #1e40af; color: #dbeafe; }

/* Dark Mode */
[data-theme="dark"] .form-modal-overlay { background: rgba(0, 0, 0, 0.5); }
[data-theme="dark"] .form-modal { background: var(--card-bg); box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); }
[data-theme="dark"] .form-modal-header { background: linear-gradient(to bottom, var(--card-bg), rgba(30, 41, 59, 0.5)); }
[data-theme="dark"] .form-modal-close { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.1); }
[data-theme="dark"] .form-modal-close:hover { background: rgba(239, 68, 68, 0.2); border-color: rgba(239, 68, 68, 0.3); color: #f87171; }
[data-theme="dark"] .custom-select-options { background: var(--card-bg); }
[data-theme="dark"] .image-upload-section { background: rgba(255, 255, 255, 0.03); }
[data-theme="dark"] .import-instructions { background: rgba(255, 255, 255, 0.05); }
