/**
 * Enhanced EHR Form Handler Styles
 * Modern, clean styling for EHR form operations
 * Includes operation loader, toasts, confirmation dialogs, and form states
 */

/* =========================
   TOAST NOTIFICATIONS
   ========================= */

.ehr-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    pointer-events: none;
}

.toast-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.ehr-toast {
    min-width: 320px;
    max-width: 480px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    pointer-events: auto;
    opacity: 0;
    transform: translateX(100%) scale(0.95);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    position: relative;
}

.ehr-toast.show {
    opacity: 1;
    transform: translateX(0) scale(1);
}

.ehr-toast.hiding {
    opacity: 0;
    transform: translateX(100%) scale(0.95);
}

.toast-content {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    position: relative;
    z-index: 2;
}

.toast-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    color: white;
}

.toast-message {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
    color: #1f2937;
    font-weight: 500;
}

.toast-close {
    width: 28px;
    height: 28px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    color: #6b7280;
}

.toast-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: #374151;
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: rgba(0, 0, 0, 0.05);
    overflow: hidden;
}

.toast-progress .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.4));
    animation: toast-progress linear forwards;
    transform-origin: left;
}

@keyframes toast-progress {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* Toast Type Styles */
.toast-success {
    border-left: 4px solid #10b981;
}

.toast-success .toast-icon {
    background: linear-gradient(135deg, #10b981, #059669);
}

.toast-error {
    border-left: 4px solid #ef4444;
}

.toast-error .toast-icon {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.toast-warning {
    border-left: 4px solid #f59e0b;
}

.toast-warning .toast-icon {
    background: linear-gradient(135deg, #f59e0b, #d97706);
}

.toast-info {
    border-left: 4px solid #3b82f6;
}

.toast-info .toast-icon {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

/* =========================
   OPERATION LOADER
   ========================= */

.ehr-operation-loader {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.ehr-operation-loader.show {
    opacity: 1;
    visibility: visible;
}

.ehr-operation-loader.hiding {
    opacity: 0;
}

.ehr-operation-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ehr-operation-content {
    background: white;
    border-radius: 24px;
    padding: 48px 40px 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 400px;
    width: 90%;
    position: relative;
    transform: scale(0.8);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ehr-operation-loader.show .ehr-operation-content {
    transform: scale(1);
}

.ehr-operation-spinner {
    position: relative;
    width: 60px;
    height: 60px;
    margin: 0 auto 24px;
}

.spinner-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: spin 2s linear infinite;
}

.spinner-ring:nth-child(1) {
    border-top-color: #3b82f6;
    animation-delay: 0s;
}

.spinner-ring:nth-child(2) {
    border-top-color: #8b5cf6;
    animation-delay: 0.1s;
    width: 75%;
    height: 75%;
    top: 12.5%;
    left: 12.5%;
}

.spinner-ring:nth-child(3) {
    border-top-color: #06b6d4;
    animation-delay: 0.2s;
    width: 50%;
    height: 50%;
    top: 25%;
    left: 25%;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.ehr-operation-message {
    font-size: 18px;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 20px;
    line-height: 1.4;
}

.ehr-operation-progress {
    width: 100%;
    height: 6px;
    background: #f1f5f9;
    border-radius: 3px;
    overflow: hidden;
    position: relative;
}

.ehr-operation-progress .progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #06b6d4);
    background-size: 200% 100%;
    animation: progress-flow 2s ease-in-out infinite;
    border-radius: 3px;
}

@keyframes progress-flow {
    0%, 100% { background-position: 200% 0; }
    50% { background-position: -200% 0; }
}

/* Operation States */
.operation-success .spinner-ring {
    border-top-color: #10b981;
    animation-duration: 0.5s;
}

.operation-success .ehr-operation-message {
    color: #065f46;
}

.operation-success .progress-bar {
    background: linear-gradient(90deg, #10b981, #059669);
}

.operation-error .spinner-ring {
    border-top-color: #ef4444;
    animation: shake 0.5s ease-in-out infinite;
}

.operation-error .ehr-operation-message {
    color: #991b1b;
}

.operation-error .progress-bar {
    background: linear-gradient(90deg, #ef4444, #dc2626);
}

@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-5deg); }
    75% { transform: rotate(5deg); }
}

/* Content States */
.state-success .ehr-operation-content {
    border-top: 4px solid #10b981;
}

.state-error .ehr-operation-content {
    border-top: 4px solid #ef4444;
}

/* =========================
   CONFIRMATION DIALOG
   ========================= */

.ehr-confirm-dialog {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.ehr-confirm-dialog.show {
    opacity: 1;
    visibility: visible;
}

.ehr-confirm-dialog.hiding {
    opacity: 0;
}

.ehr-confirm-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.ehr-confirm-content {
    background: white;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
    max-width: 480px;
    width: 100%;
    transform: scale(0.9) translateY(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.ehr-confirm-dialog.show .ehr-confirm-content {
    transform: scale(1) translateY(0);
}

.confirm-header {
    padding: 32px 32px 16px;
    text-align: center;
    border-bottom: 1px solid #f1f5f9;
}

.confirm-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
    font-size: 24px;
    color: #64748b;
}

.confirm-title {
    font-size: 20px;
    font-weight: 700;
    color: #1e293b;
    margin: 0;
    line-height: 1.3;
}

.confirm-body {
    padding: 24px 32px;
    text-align: center;
}

.confirm-message {
    font-size: 15px;
    color: #64748b;
    line-height: 1.5;
    margin: 0;
}

.confirm-footer {
    padding: 24px 32px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    background: #fafbfc;
    border-top: 1px solid #f1f5f9;
}

.confirm-footer .btn {
    min-width: 100px;
    font-weight: 600;
    font-size: 14px;
    padding: 12px 20px;
    border-radius: 8px;
    transition: all 0.2s ease;
    border: none;
    cursor: pointer;
}

.confirm-footer .btn-secondary {
    background: #f8fafc;
    color: #64748b;
    border: 1px solid #e2e8f0;
}

.confirm-footer .btn-secondary:hover {
    background: #f1f5f9;
    color: #475569;
    border-color: #cbd5e1;
}

.confirm-footer .btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.confirm-footer .btn-danger:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.confirm-footer .btn-success {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
}

.confirm-footer .btn-success:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.confirm-footer .btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
}

.confirm-footer .btn-warning:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.confirm-footer .btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
}

.confirm-footer .btn-primary:hover {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* =========================
   FORM ENHANCEMENTS
   ========================= */

form[data-ehr-form] {
    position: relative;
}

/* Enhanced form field validation states */
form[data-ehr-form] .form-control.is-invalid,
form[data-ehr-form] .form-select.is-invalid {
    border-color: #ef4444;
    box-shadow: 0 0 0 0.2rem rgba(239, 68, 68, 0.15);
    background-image: none;
}

form[data-ehr-form] .form-control.is-invalid:focus,
form[data-ehr-form] .form-select.is-invalid:focus {
    border-color: #ef4444;
    box-shadow: 0 0 0 0.25rem rgba(239, 68, 68, 0.25);
}

form[data-ehr-form] .invalid-feedback {
    display: block;
    color: #ef4444;
    font-size: 13px;
    font-weight: 500;
    margin-top: 6px;
    padding: 4px 8px;
    background: rgba(239, 68, 68, 0.05);
    border-radius: 6px;
    border-left: 3px solid #ef4444;
}

/* Form submission loading state */
form[data-ehr-form].submitting {
    pointer-events: none;
    opacity: 0.7;
}

form[data-ehr-form].submitting .btn[type="submit"] {
    position: relative;
    color: transparent;
}

form[data-ehr-form].submitting .btn[type="submit"]::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

[data-ehr-action] {
    position: relative;
    overflow: hidden;
    transition: all 0.2s ease;
}

[data-ehr-action]:hover {
    transform: translateY(-1px);
}

[data-ehr-action]:active {
    transform: translateY(0);
}

[data-ehr-action="delete"]:hover {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: transparent;
    color: white;
}

[data-ehr-action="status-change"]:hover {
    transform: translateY(-1px);
}

/* =========================
   ACCESSIBILITY ENHANCEMENTS
   ========================= */

/* Focus management for dialogs */
.ehr-confirm-dialog [data-action="confirm"]:focus {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .ehr-toast,
    .ehr-operation-loader,
    .ehr-confirm-dialog,
    .spinner-ring,
    .progress-bar,
    [data-ehr-action] {
        animation: none !important;
        transition: none !important;
    }
    
    .ehr-operation-content,
    .ehr-confirm-content {
        transform: none !important;
    }
}

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

@media (max-width: 768px) {
    .ehr-toast-container {
        left: 20px;
        right: 20px;
        top: 20px;
    }
    
    .toast-stack {
        align-items: stretch;
    }
    
    .ehr-toast {
        min-width: auto;
        max-width: none;
    }
    
    .ehr-operation-content {
        padding: 32px 24px 24px;
        margin: 20px;
    }
    
    .ehr-operation-message {
        font-size: 16px;
    }
    
    .ehr-confirm-overlay {
        padding: 16px;
    }
    
    .confirm-header {
        padding: 24px 24px 16px;
    }
    
    .confirm-body {
        padding: 16px 24px;
    }
    
    .confirm-footer {
        padding: 20px 24px;
        flex-direction: column-reverse;
    }
    
    .confirm-footer .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .ehr-operation-content {
        padding: 24px 16px 16px;
    }
    
    .ehr-operation-spinner {
        width: 48px;
        height: 48px;
        margin-bottom: 16px;
    }
    
    .confirm-icon {
        width: 48px;
        height: 48px;
        font-size: 20px;
        margin-bottom: 12px;
    }
    
    .confirm-title {
        font-size: 18px;
    }
    
    .confirm-message {
        font-size: 14px;
    }
}

/* =========================
   THEME VARIATIONS
   ========================= */

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .ehr-toast {
        background: #1e293b;
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .toast-message {
        color: #e2e8f0;
    }
    
    .toast-close {
        background: rgba(255, 255, 255, 0.05);
        color: #9ca3af;
    }
    
    .toast-close:hover {
        background: rgba(255, 255, 255, 0.1);
        color: #d1d5db;
    }
    
    .ehr-operation-content {
        background: #1e293b;
    }
    
    .ehr-operation-message {
        color: #e2e8f0;
    }
    
    .ehr-operation-progress {
        background: #374151;
    }
    
    .ehr-confirm-content {
        background: #1e293b;
    }
    
    .confirm-header {
        border-color: #374151;
    }
    
    .confirm-title {
        color: #e2e8f0;
    }
    
    .confirm-message {
        color: #9ca3af;
    }
    
    .confirm-footer {
        background: #0f172a;
        border-color: #374151;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .ehr-toast {
        border-width: 2px;
        border-color: currentColor;
    }
    
    .ehr-operation-content,
    .ehr-confirm-content {
        border: 2px solid currentColor;
    }
    
    .confirm-footer .btn {
        border: 2px solid currentColor;
    }
}

/* =========================
   ANIMATION UTILITIES
   ========================= */

.fade-in {
    animation: fadeIn 0.3s ease forwards;
}

.fade-out {
    animation: fadeOut 0.3s ease forwards;
}

.slide-in-right {
    animation: slideInRight 0.3s ease forwards;
}

.slide-out-right {
    animation: slideOutRight 0.3s ease forwards;
}

.scale-in {
    animation: scaleIn 0.3s ease forwards;
}

.scale-out {
    animation: scaleOut 0.3s ease forwards;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

@keyframes slideOutRight {
    from { transform: translateX(0); }
    to { transform: translateX(100%); }
}

@keyframes scaleIn {
    from { transform: scale(0.8); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes scaleOut {
    from { transform: scale(1); opacity: 1; }
    to { transform: scale(0.8); opacity: 0; }
}
