/**
 * EHR Form Auto-save Styles
 * CSS for auto-save status indicators, recovery prompts, and dialogs
 */

/* =========================
   AUTO-SAVE STATUS INDICATOR
   ========================= */

.ehr-autosave-status {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 13px;
    min-height: 38px;
    transition: all 0.2s ease;
}

.save-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #e2e8f0;
    transition: all 0.3s ease;
    position: relative;
    flex-shrink: 0;
}

.save-indicator.saving {
    background: #f59e0b;
    animation: pulse 1.5s infinite;
}

.save-indicator.saved {
    background: #10b981;
    animation: success-ping 0.5s ease;
}

.save-indicator.restored {
    background: #3b82f6;
    animation: success-ping 0.5s ease;
}

.save-indicator.error {
    background: #ef4444;
    animation: error-shake 0.5s ease;
}

.save-message {
    font-weight: 500;
    color: #64748b;
    opacity: 0;
    transform: translateY(2px);
    transition: all 0.3s ease;
}

.save-indicator.saving ~ .save-message,
.save-indicator.saved ~ .save-message,
.save-indicator.restored ~ .save-message,
.save-indicator.error ~ .save-message {
    opacity: 1;
    transform: translateY(0);
}

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

@keyframes success-ping {
    0% { transform: scale(1); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

@keyframes error-shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

/* =========================
   RECOVERY PROMPT
   ========================= */

.ehr-recovery-prompt {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border: 1px solid #3b82f6;
    border-radius: 12px;
    padding: 16px 20px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
    animation: slideInDown 0.3s ease;
}

.recovery-content {
    display: flex;
    align-items: center;
    gap: 16px;
}

.recovery-icon {
    width: 40px;
    height: 40px;
    background: #3b82f6;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 18px;
    flex-shrink: 0;
}

.recovery-message {
    flex: 1;
}

.recovery-message strong {
    display: block;
    color: #1e40af;
    font-size: 15px;
    margin-bottom: 4px;
}

.recovery-message p {
    color: #1e40af;
    font-size: 14px;
    margin: 0;
    opacity: 0.8;
}

.recovery-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.recovery-actions .btn {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
}

/* =========================
   GLOBAL RECOVERY PROMPT
   ========================= */

.ehr-global-recovery-prompt {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-bottom: 2px solid #f59e0b;
    padding: 12px 20px;
    z-index: 9998;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.2);
    animation: slideInDown 0.3s ease;
}

.global-recovery-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    max-width: 1200px;
    margin: 0 auto;
}

.global-recovery-icon {
    width: 36px;
    height: 36px;
    background: #f59e0b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 16px;
    flex-shrink: 0;
}

.global-recovery-message {
    flex: 1;
    text-align: center;
}

.global-recovery-message strong {
    display: block;
    color: #92400e;
    font-size: 15px;
    margin-bottom: 2px;
}

.global-recovery-message p {
    color: #92400e;
    font-size: 13px;
    margin: 0;
    opacity: 0.8;
}

.global-recovery-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.global-recovery-actions .btn {
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
}

/* =========================
   RECOVERY DIALOG
   ========================= */

.ehr-recovery-dialog-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(6px);
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.ehr-recovery-dialog {
    background: white;
    border-radius: 16px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.4);
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    animation: scaleIn 0.3s ease;
}

.ehr-recovery-dialog h3 {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin: 0 0 8px 0;
    padding: 24px 24px 0;
}

.ehr-recovery-dialog > p {
    color: #64748b;
    font-size: 14px;
    margin: 0 0 20px 0;
    padding: 0 24px;
}

.recovery-form-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 300px;
    overflow-y: auto;
}

.recovery-form-item {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s ease;
}

.recovery-form-item:hover {
    background: #f8fafc;
}

.recovery-form-item:last-child {
    border-bottom: none;
}

.recovery-form-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-title {
    font-weight: 600;
    color: #1e293b;
    font-size: 14px;
}

.form-date {
    font-size: 12px;
    color: #64748b;
}

.form-url {
    font-size: 11px;
    color: #94a3b8;
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recovery-form-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.recovery-form-actions .btn {
    padding: 6px 10px;
    font-size: 12px;
    border-radius: 6px;
    min-width: auto;
}

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

.recovery-dialog-footer .btn {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
}

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

@media (max-width: 768px) {
    .ehr-global-recovery-prompt {
        padding: 16px;
    }
    
    .global-recovery-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    
    .global-recovery-message {
        text-align: center;
    }
    
    .global-recovery-actions {
        justify-content: center;
    }
    
    .ehr-recovery-dialog {
        margin: 20px;
        max-height: calc(100vh - 40px);
    }
    
    .recovery-form-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 20px 16px;
    }
    
    .recovery-form-details {
        width: 100%;
    }
    
    .recovery-form-actions {
        width: 100%;
        justify-content: flex-end;
    }
    
    .recovery-dialog-footer {
        flex-direction: column;
        gap: 8px;
    }
    
    .recovery-dialog-footer .btn {
        width: 100%;
        justify-content: center;
    }
    
    .recovery-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    
    .recovery-message {
        text-align: center;
    }
    
    .recovery-actions {
        justify-content: center;
        width: 100%;
    }
}

@media (max-width: 480px) {
    .ehr-autosave-status {
        padding: 6px 10px;
        font-size: 12px;
        margin-bottom: 12px;
    }
    
    .save-indicator {
        width: 10px;
        height: 10px;
    }
    
    .ehr-global-recovery-prompt {
        padding: 12px;
    }
    
    .global-recovery-icon {
        width: 32px;
        height: 32px;
        font-size: 14px;
    }
    
    .global-recovery-message strong {
        font-size: 14px;
    }
    
    .global-recovery-message p {
        font-size: 12px;
    }
    
    .recovery-icon {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
    
    .recovery-message strong {
        font-size: 14px;
    }
    
    .recovery-message p {
        font-size: 13px;
    }
}

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

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

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

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

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

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .ehr-autosave-status {
        background: #1e293b;
        border-color: #374151;
    }
    
    .save-message {
        color: #9ca3af;
    }
    
    .ehr-recovery-prompt {
        background: linear-gradient(135deg, #1e3a8a, #1e40af);
        border-color: #3b82f6;
    }
    
    .recovery-message strong,
    .recovery-message p {
        color: #dbeafe;
    }
    
    .ehr-global-recovery-prompt {
        background: linear-gradient(135deg, #92400e, #b45309);
        border-color: #f59e0b;
    }
    
    .global-recovery-message strong,
    .global-recovery-message p {
        color: #fef3c7;
    }
    
    .ehr-recovery-dialog {
        background: #1e293b;
    }
    
    .ehr-recovery-dialog h3 {
        color: #e2e8f0;
    }
    
    .ehr-recovery-dialog > p {
        color: #9ca3af;
    }
    
    .recovery-form-item {
        border-color: #374151;
    }
    
    .recovery-form-item:hover {
        background: #0f172a;
    }
    
    .form-title {
        color: #e2e8f0;
    }
    
    .form-date {
        color: #9ca3af;
    }
    
    .form-url {
        color: #6b7280;
    }
    
    .recovery-dialog-footer {
        background: #0f172a;
        border-color: #374151;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .ehr-autosave-status {
        border-width: 2px;
    }
    
    .ehr-recovery-prompt,
    .ehr-global-recovery-prompt {
        border-width: 2px;
    }
    
    .save-indicator {
        border: 1px solid currentColor;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .save-indicator,
    .ehr-recovery-prompt,
    .ehr-global-recovery-prompt,
    .ehr-recovery-dialog {
        animation: none !important;
        transition: none !important;
    }
    
    .save-indicator.saving {
        animation: none;
        background: #f59e0b;
    }
}
