/**
 * Patient Form Modal Styles
 *
 * ARCHITECTURE: Modern modal with form sections and responsive layout
 * WHY: Consistent with somaNotes design system, accessible and user-friendly
 * TRADEOFF: CSS vars for theming vs hardcoded values - chose vars for dark mode support
 */

/* ===== Modal Overlay ===== */
.patient-form-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 20px;
}

/* ===== Modal Container ===== */
.patient-form-modal {
    background: var(--bg-primary, #ffffff);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    position: relative;
    animation: modalSlideIn 0.3s ease-out;
}

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

/* ===== Modal Header ===== */
.patient-form-header {
    padding: 24px 28px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.patient-form-header .modal-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    margin: 0;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary, #6b7280);
    font-size: 24px;
    padding: 4px;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close-btn:hover {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-primary, #111827);
}

/* ===== Modal Body ===== */
.patient-form-body {
    padding: 28px;
    overflow-y: auto;
    flex: 1;
}

/* Custom scrollbar */
.patient-form-body::-webkit-scrollbar {
    width: 8px;
}

.patient-form-body::-webkit-scrollbar-track {
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 4px;
}

.patient-form-body::-webkit-scrollbar-thumb {
    background: var(--border-color, #d1d5db);
    border-radius: 4px;
}

.patient-form-body::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary, #9ca3af);
}

/* ===== Form Sections ===== */
.form-section {
    margin-bottom: 32px;
}

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

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    margin: 0 0 16px 0;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--primary-color, #3b82f6);
}

/* ===== Form Rows & Groups ===== */
.form-row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

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

.form-group {
    flex: 1;
    min-width: 0; /* Allow flex items to shrink below content size */
}

.form-group.full-width {
    flex: 1 1 100%;
}

.form-group.required label::after {
    content: ' *';
    color: var(--error-color, #ef4444);
}

/* ===== Form Labels ===== */
.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #374151);
    margin-bottom: 6px;
}

/* ===== Form Inputs ===== */
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="tel"],
.form-group input[type="date"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary, #111827);
    background: var(--bg-primary, #ffffff);
    border: 1px solid var(--border-color, #d1d5db);
    border-radius: 6px;
    transition: all 0.2s;
    box-sizing: border-box;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color, #3b82f6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-group input:disabled {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-secondary, #6b7280);
    cursor: not-allowed;
}

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

/* ===== Field Hints & Errors ===== */
.field-hint {
    display: block;
    font-size: 12px;
    color: var(--text-secondary, #6b7280);
    margin-top: 4px;
}

.field-error {
    display: none;
    font-size: 12px;
    color: var(--error-color, #ef4444);
    margin-top: 4px;
}

.field-error:not(:empty) {
    display: block;
}

/* Highlight invalid fields */
.form-group input.invalid,
.form-group select.invalid,
.form-group textarea.invalid {
    border-color: var(--error-color, #ef4444);
}

/* ===== Modal Footer ===== */
.patient-form-footer {
    padding: 20px 28px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.patient-form-footer .btn {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
}

.btn-primary {
    background: var(--primary-color, #3b82f6);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark, #2563eb);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:disabled {
    background: var(--bg-secondary, #e5e7eb);
    color: var(--text-secondary, #9ca3af);
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--bg-secondary, #f3f4f6);
    color: var(--text-primary, #374151);
    border: 1px solid var(--border-color, #d1d5db);
}

.btn-secondary:hover {
    background: var(--bg-tertiary, #e5e7eb);
    border-color: var(--text-secondary, #9ca3af);
}

/* ===== Loading Overlay ===== */
.modal-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border-radius: 12px;
    z-index: 10;
}

.modal-loading i {
    font-size: 48px;
    color: var(--primary-color, #3b82f6);
}

.modal-loading span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #374151);
}

.spinning {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ===== Responsive Design ===== */
@media (max-width: 768px) {
    .patient-form-modal {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .patient-form-modal-overlay {
        padding: 0;
    }

    .form-row {
        flex-direction: column;
        gap: 16px;
    }

    .patient-form-header {
        padding: 20px;
    }

    .patient-form-body {
        padding: 20px;
    }

    .patient-form-footer {
        padding: 16px 20px;
    }
}

/* ===== Dark Mode Support ===== */
@media (prefers-color-scheme: dark) {
    .patient-form-modal {
        --bg-primary: #1f2937;
        --bg-secondary: #374151;
        --bg-tertiary: #4b5563;
        --text-primary: #f9fafb;
        --text-secondary: #d1d5db;
        --border-color: #4b5563;
    }

    .modal-loading {
        background: rgba(31, 41, 55, 0.95);
    }

    .form-group input[type="date"]::-webkit-calendar-picker-indicator {
        filter: invert(1);
    }
}

/* ===== Accessibility ===== */
@media (prefers-reduced-motion: reduce) {
    .patient-form-modal,
    .spinning {
        animation: none !important;
    }

    .btn-primary:hover {
        transform: none;
    }
}

/* Focus visible for keyboard navigation */
.form-group input:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible,
.btn:focus-visible,
.modal-close-btn:focus-visible {
    outline: 2px solid var(--primary-color, #3b82f6);
    outline-offset: 2px;
}
