/* AI Doc - Personal AI Assistant Styles */

/* Floating Widget Container */
.ai-doc-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    font-family: 'Inter', 'Poppins', sans-serif;
}

/* Main Toggle Button - Doctor Avatar */
.ai-doc-toggle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 3px solid rgba(255, 255, 255, 0.9);
    cursor: pointer;
    box-shadow: 0 6px 25px rgba(102, 126, 234, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
    padding: 0;
}

.ai-doc-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(102, 126, 234, 0.7);
    border-color: #fff;
}

.ai-doc-toggle:active {
    transform: scale(0.95);
}

/* Avatar Images */
.ai-doc-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.ai-doc-speaking-img {
    position: absolute;
    top: 0;
    left: 0;
}

/* Idle pulse animation */
.ai-doc-toggle:not(.speaking):not(.thinking) .ai-doc-avatar-img {
    animation: ai-doc-avatar-pulse 3s ease-in-out infinite;
}

@keyframes ai-doc-avatar-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* Speaking animation - glowing effect */
.ai-doc-toggle.avatar-speaking {
    animation: ai-doc-speaking-glow 0.5s ease-in-out infinite alternate;
    border-color: #00ff88;
}

@keyframes ai-doc-speaking-glow {
    0% { 
        box-shadow: 0 0 20px rgba(0, 255, 136, 0.6), 0 0 40px rgba(102, 126, 234, 0.4);
    }
    100% { 
        box-shadow: 0 0 30px rgba(0, 255, 136, 0.8), 0 0 60px rgba(102, 126, 234, 0.6);
    }
}

/* Thinking animation */
.ai-doc-toggle.thinking {
    animation: ai-doc-thinking-pulse 0.8s ease-in-out infinite;
    border-color: #ffd700;
}

.ai-doc-toggle.thinking .ai-doc-avatar-img {
    animation: ai-doc-thinking 0.8s ease-in-out infinite;
}

@keyframes ai-doc-thinking {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes ai-doc-thinking-pulse {
    0%, 100% { 
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    }
    50% { 
        box-shadow: 0 0 35px rgba(255, 215, 0, 0.7);
    }
}

/* Doctor Icon (fallback) */
.ai-doc-icon {
    font-size: 32px;
    color: white;
    animation: ai-doc-pulse 2s ease-in-out infinite;
}

@keyframes ai-doc-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* Speaking animation (fallback) */
.ai-doc-toggle.speaking .ai-doc-icon {
    animation: ai-doc-speaking 0.3s ease-in-out infinite alternate;
}

@keyframes ai-doc-speaking {
    0% { transform: scale(1) rotate(-2deg); }
    100% { transform: scale(1.1) rotate(2deg); }
}

/* Notification badge */
.ai-doc-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    background: linear-gradient(135deg, #f5576c 0%, #f093fb 100%);
    border-radius: 50%;
    color: white;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: ai-doc-bounce 1s ease infinite;
}

@keyframes ai-doc-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Chat Window */
.ai-doc-chat {
    position: absolute;
    bottom: 95px;
    right: 0;
    width: 380px;
    max-height: 550px;
    background: white;
    border-radius: 20px;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: ai-doc-slide-up 0.3s ease;
}

.ai-doc-chat.active {
    display: flex;
}

@keyframes ai-doc-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header */
.ai-doc-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-doc-header-avatar {
    width: 50px;
    height: 50px;
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.ai-doc-header-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.ai-doc-header-info h4 {
    margin: 0;
    font-size: 18px;
    font-weight: 700;
}

.ai-doc-header-info p {
    margin: 0;
    font-size: 12px;
    opacity: 0.9;
}

.ai-doc-header-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-doc-stop-btn,
.ai-doc-history-btn,
.ai-doc-new-chat-btn,
.ai-doc-close {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-doc-stop-btn {
    background: #e74c3c;
    animation: ai-doc-stop-pulse 1s ease-in-out infinite;
}

@keyframes ai-doc-stop-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.ai-doc-stop-btn:hover {
    background: #c0392b;
}

.ai-doc-mute-btn.muted {
    background: rgba(231, 76, 60, 0.8);
}

.ai-doc-mute-btn.muted:hover {
    background: #e74c3c;
}

.ai-doc-history-btn:hover,
.ai-doc-new-chat-btn:hover,
.ai-doc-mute-btn:hover,
.ai-doc-close:hover {
    background: rgba(255,255,255,0.3);
}

/* History Panel */
.ai-doc-history-panel {
    flex: 1;
    overflow-y: auto;
    background: #f8f9fa;
    max-height: 400px;
}

.ai-doc-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background: white;
    border-bottom: 1px solid #eee;
}

.ai-doc-history-header h5 {
    margin: 0;
    font-size: 14px;
    color: #333;
}

.ai-doc-history-back {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 15px;
    font-size: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.ai-doc-history-back:hover {
    transform: scale(1.05);
}

.ai-doc-history-list {
    padding: 10px;
}

.ai-doc-history-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 10px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    cursor: pointer;
    transition: all 0.2s;
}

.ai-doc-history-item:hover {
    transform: translateX(5px);
    box-shadow: 0 3px 10px rgba(0,0,0,0.1);
}

.ai-doc-history-item-content {
    flex: 1;
    overflow: hidden;
}

.ai-doc-history-title {
    display: block;
    font-weight: 500;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 13px;
}

.ai-doc-history-date {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 3px;
}

.ai-doc-history-delete {
    background: transparent;
    border: none;
    color: #ccc;
    padding: 5px;
    cursor: pointer;
    transition: color 0.2s;
}

.ai-doc-history-delete:hover {
    color: #e74c3c;
}

.ai-doc-history-loading,
.ai-doc-history-empty,
.ai-doc-history-error {
    text-align: center;
    padding: 30px;
    color: #888;
    font-size: 13px;
}

.ai-doc-history-empty {
    color: #667eea;
}

/* Clickable Links in Messages */
.ai-doc-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px dotted #667eea;
    transition: all 0.2s ease;
}

.ai-doc-link:hover {
    color: #764ba2;
    border-bottom-color: #764ba2;
    text-decoration: none;
}

.ai-doc-heading {
    font-weight: 600;
    color: #333;
    margin: 8px 0 4px 0;
    font-size: 14px;
}

h3.ai-doc-heading {
    font-size: 15px;
}

h4.ai-doc-heading {
    font-size: 13px;
}

/* Video Popup Modal */
.ai-doc-video-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-doc-video-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
}

.ai-doc-video-modal-content {
    position: relative;
    width: 80%;
    max-width: 900px;
    height: 60%;
    max-height: 600px;
    min-width: 320px;
    min-height: 240px;
    background: #1a1a2e;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.ai-doc-video-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.ai-doc-video-title {
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.ai-doc-video-modal-actions {
    display: flex;
    gap: 8px;
}

.ai-doc-video-external,
.ai-doc-video-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.ai-doc-video-external:hover,
.ai-doc-video-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-doc-video-container {
    flex: 1;
    padding: 10px;
    background: #0d0d1a;
}

.ai-doc-video-container iframe,
.ai-doc-video-container video {
    width: 100%;
    height: 100%;
    border-radius: 8px;
}

.ai-doc-video-resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: se-resize;
    background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.3) 50%);
    border-radius: 0 0 12px 0;
}

.ai-doc-video-resize-handle:hover {
    background: linear-gradient(135deg, transparent 50%, rgba(255,255,255,0.5) 50%);
}

@media (max-width: 768px) {
    .ai-doc-video-modal-content {
        width: 95%;
        height: 50%;
        max-width: none;
    }
}

/* Chat Messages Area */
.ai-doc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-height: 350px;
    background: #f8f9fa;
}

/* Message Bubbles */
.ai-doc-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    animation: ai-doc-message-appear 0.3s ease;
}

@keyframes ai-doc-message-appear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ai-doc-message.ai {
    background: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.ai-doc-message.user {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

/* Typing indicator */
.ai-doc-typing {
    display: flex;
    gap: 5px;
    padding: 15px 20px;
    background: white;
    border-radius: 18px;
    align-self: flex-start;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}

.ai-doc-typing span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: ai-doc-typing-dot 1.4s ease-in-out infinite;
}

.ai-doc-typing span:nth-child(2) { animation-delay: 0.2s; }
.ai-doc-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ai-doc-typing-dot {
    0%, 100% { transform: translateY(0); opacity: 0.4; }
    50% { transform: translateY(-8px); opacity: 1; }
}

/* Quick Suggestions */
.ai-doc-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    background: white;
    border-top: 1px solid #eee;
}

.ai-doc-suggestion {
    padding: 8px 14px;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    border: 1px solid #dee2e6;
    border-radius: 20px;
    font-size: 12px;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-doc-suggestion:hover {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-2px);
}

/* Input Area */
.ai-doc-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 15px;
    background: white;
    border-top: 1px solid #eee;
    align-items: center;
    flex-wrap: wrap;
}

.ai-doc-input {
    flex: 1;
    padding: 12px 18px;
    border: 2px solid #e9ecef;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.ai-doc-input:focus {
    border-color: #667eea;
}

.ai-doc-send {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.ai-doc-send:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.ai-doc-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Voice Button */
.ai-doc-voice {
    width: 52px;
    height: 52px;
    min-width: 52px;
    min-height: 52px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 22px;
    box-shadow: 0 3px 12px rgba(17, 153, 142, 0.5);
}

.ai-doc-voice:hover,
.ai-doc-voice:active {
    transform: scale(1.15);
    box-shadow: 0 4px 18px rgba(17, 153, 142, 0.6);
}

.ai-doc-voice.listening {
    animation: ai-doc-voice-pulse 1s ease-in-out infinite;
    border-color: #38ef7d;
}

@keyframes ai-doc-voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(17, 153, 142, 0.5); }
    50% { box-shadow: 0 0 0 15px rgba(17, 153, 142, 0); }
}

/* Camera Button */
.ai-doc-camera {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 20px;
    box-shadow: 0 3px 12px rgba(102, 126, 234, 0.4);
}

.ai-doc-camera:hover,
.ai-doc-camera:active {
    transform: scale(1.15);
    box-shadow: 0 4px 18px rgba(102, 126, 234, 0.5);
}

/* Upload Button */
.ai-doc-upload {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 3px 12px rgba(240, 147, 251, 0.4);
    transition: all 0.2s;
}

.ai-doc-upload:hover,
.ai-doc-upload:active {
    transform: scale(1.15);
    box-shadow: 0 4px 18px rgba(240, 147, 251, 0.5);
}

/* Apply to Form Buttons */
.ai-doc-apply-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}

.ai-doc-apply-btn {
    padding: 10px 15px;
    border: none;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
    box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}

.ai-doc-apply-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

.ai-doc-apply-btn i {
    font-size: 14px;
}

/* Welcome message styling */
.ai-doc-welcome {
    text-align: center;
    padding: 20px;
}

.ai-doc-welcome h5 {
    color: #333;
    margin-bottom: 8px;
}

.ai-doc-welcome p {
    color: #666;
    font-size: 13px;
}

/* Quick Action Buttons - Phase 2 */
.ai-doc-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
    margin-top: 5px;
}

.ai-doc-quick-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.ai-doc-quick-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.5);
}

.ai-doc-quick-action i {
    font-size: 11px;
}

/* Navigation Prompt */
.ai-doc-nav-prompt {
    display: flex;
    justify-content: center;
    padding: 15px;
    margin: 10px 0;
}

.ai-doc-nav-prompt-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: white;
    border-radius: 25px;
    font-weight: 500;
    animation: navPulse 1s infinite;
}

.ai-doc-nav-prompt-content i {
    animation: slideRight 0.6s infinite;
}

@keyframes navPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes slideRight {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(5px); }
}

/* Proactive Tips - Phase 3 */
.ai-doc-proactive-tip {
    padding: 8px 0;
    animation: tipSlideIn 0.4s ease;
}

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

.ai-doc-tip-content {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
    color: #7c4a1a;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
}

.ai-doc-tip-content i {
    font-size: 16px;
    color: #e67e22;
}

.ai-doc-tip-action {
    margin-left: auto;
    padding: 5px 12px;
    background: #e67e22;
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.ai-doc-tip-action:hover {
    background: #d35400;
    transform: scale(1.05);
}

/* Download and WhatsApp Action Buttons */
.ai-doc-download-action,
.ai-doc-whatsapp-action {
    padding: 10px 0;
    animation: tipSlideIn 0.4s ease;
}

.ai-doc-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3);
}

.ai-doc-download-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
    color: white;
    text-decoration: none;
}

.ai-doc-download-btn i {
    font-size: 16px;
}

.ai-doc-whatsapp-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: white;
    text-decoration: none;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);
}

.ai-doc-whatsapp-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
    color: white;
    text-decoration: none;
}

.ai-doc-whatsapp-btn i {
    font-size: 18px;
}

/* Streaming cursor animation */
.ai-doc-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #667eea;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: ai-doc-blink 0.7s infinite;
}

@keyframes ai-doc-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Mobile Responsive */
@media (max-width: 480px) {
    .ai-doc-chat {
        width: calc(100vw - 40px);
        right: -10px;
        max-height: 70vh;
    }
    
    .ai-doc-toggle {
        width: 60px;
        height: 60px;
    }
    
    .ai-doc-icon {
        font-size: 28px;
    }
    
    .ai-doc-quick-action {
        font-size: 11px;
        padding: 6px 10px;
    }
}

/* ============================================================
   AI DOC POPUP OVERLAY
   ============================================================ */
.ai-doc-popup-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(10, 10, 30, 0.65);
    z-index: 99999;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}
.ai-doc-popup-overlay.active {
    display: flex;
}

.ai-doc-popup-card {
    width: min(860px, 95vw);
    height: min(640px, 90vh);
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 32px 80px rgba(0,0,0,0.35), 0 4px 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ai-doc-popup-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes ai-doc-popup-in {
    from { opacity: 0; transform: scale(0.88) translateY(30px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ai-doc-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    flex-shrink: 0;
}

.ai-doc-popup-action-btn {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 8px;
    width: 34px; height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.85rem;
    transition: background 0.15s;
}
.ai-doc-popup-action-btn:hover {
    background: rgba(255,255,255,0.32);
}

.ai-doc-popup-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f8f9fd;
}
.ai-doc-popup-body::-webkit-scrollbar { width: 6px; }
.ai-doc-popup-body::-webkit-scrollbar-track { background: transparent; }
.ai-doc-popup-body::-webkit-scrollbar-thumb { background: #c5cae9; border-radius: 3px; }

.ai-doc-popup-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.ai-doc-popup-user-msg {
    display: flex;
    justify-content: flex-end;
}
.ai-doc-popup-user-bubble {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 10px 16px;
    max-width: 75%;
    font-size: 0.93rem;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(102,126,234,0.3);
}

.ai-doc-popup-ai-msg {
    background: white;
    border-radius: 4px 18px 18px 18px;
    padding: 14px 18px;
    max-width: 90%;
    font-size: 0.92rem;
    line-height: 1.65;
    box-shadow: 0 2px 12px rgba(0,0,0,0.07);
    border: 1px solid #e8eaf6;
    color: #2d2d4e;
    align-self: flex-start;
}
.ai-doc-popup-ai-msg p { margin-bottom: 0.5rem; }
.ai-doc-popup-ai-msg p:last-child { margin-bottom: 0; }
.ai-doc-popup-ai-msg strong { color: #1A237E; }
.ai-doc-popup-ai-msg code {
    background: #f0f2ff;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    color: #512da8;
}

.ai-doc-popup-msg-group {
    max-width: 90%;
}

.ai-doc-popup-nav-indicator {
    background: linear-gradient(135deg, #e8eaf6, #c5cae9);
    border: 1px solid #9fa8da;
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 0.85rem;
    color: #283593;
    font-weight: 500;
}

.ai-doc-popup-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid #e8eaf6;
    background: white;
    flex-shrink: 0;
}

.ai-doc-popup-input {
    flex: 1;
    border: 1.5px solid #c5cae9;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 0.93rem;
    outline: none;
    transition: border-color 0.2s;
    background: #f8f9fd;
    color: #2d2d4e;
}
.ai-doc-popup-input:focus {
    border-color: #667eea;
    background: white;
}
.ai-doc-popup-input::placeholder { color: #b0bec5; }

.ai-doc-popup-send-btn {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    border: none;
    border-radius: 50%;
    width: 44px; height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1rem;
    box-shadow: 0 4px 12px rgba(102,126,234,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
}
.ai-doc-popup-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 18px rgba(102,126,234,0.55);
}

/* Mobile */
@media (max-width: 600px) {
    .ai-doc-popup-card {
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
}

/* Popout button in widget header */
.ai-doc-popout-btn {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.25);
    color: white;
    border-radius: 6px;
    width: 30px; height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 0.78rem;
    transition: background 0.15s;
    padding: 0;
}
.ai-doc-popout-btn:hover {
    background: rgba(255,255,255,0.28);
}

/* ==========================================
   QUICK ACTIONS BAR
   ========================================== */
.ai-doc-quick-bar {
    background: linear-gradient(135deg, #1a237e 0%, #283593 100%);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 8px 10px 6px;
    flex-shrink: 0;
}

.ai-doc-quick-bar-title {
    font-size: 0.58rem;
    font-weight: 700;
    color: rgba(255,255,255,0.55);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 5px;
}

.ai-doc-quick-btns {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.ai-doc-quick-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 8px;
    color: white;
    padding: 5px 7px;
    cursor: pointer;
    font-size: 0.58rem;
    min-width: 44px;
    transition: background 0.15s, transform 0.1s;
    white-space: nowrap;
}

.ai-doc-quick-btn:hover {
    background: rgba(255,255,255,0.22);
    transform: translateY(-1px);
}

.ai-doc-quick-btn i {
    font-size: 0.9rem;
    color: #81d4fa;
}

.ai-doc-quick-btn span {
    font-size: 0.55rem;
    color: rgba(255,255,255,0.85);
}

/* ==========================================
   DATA CARDS (patient search, DB query)
   ========================================== */
.ai-doc-data-card {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin: 6px 0;
    overflow: hidden;
    font-size: 0.78rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.ai-doc-data-card-header {
    background: linear-gradient(135deg, #1a237e, #283593);
    color: white;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.ai-doc-data-body {
    padding: 8px 10px;
    max-height: 200px;
    overflow-y: auto;
}

.ai-doc-data-module {
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #f5f5f5;
}

.ai-doc-data-module strong {
    display: block;
    font-size: 0.72rem;
    color: #1a237e;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 3px;
}

.ai-doc-data-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 3px;
}

.ai-doc-field {
    background: #f5f5f5;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.7rem;
    color: #424242;
}

.ai-doc-field em {
    font-style: normal;
    color: #1a237e;
    font-weight: 600;
    margin-right: 2px;
}

.ai-doc-data-empty {
    padding: 12px;
    text-align: center;
    color: #9e9e9e;
    font-style: italic;
    font-size: 0.78rem;
}

.ai-doc-data-action-btn {
    display: block;
    text-align: center;
    background: #e3f2fd;
    color: #1565c0;
    text-decoration: none;
    padding: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    border-top: 1px solid #e0e0e0;
    transition: background 0.15s;
}

.ai-doc-data-action-btn:hover {
    background: #bbdefb;
    color: #0d47a1;
    text-decoration: none;
}

/* Mini table for DB query results */
.ai-doc-table-wrap {
    overflow-x: auto;
    max-height: 180px;
    overflow-y: auto;
}

.ai-doc-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.68rem;
}

.ai-doc-mini-table th {
    background: #e8eaf6;
    color: #1a237e;
    padding: 4px 8px;
    text-align: left;
    font-weight: 700;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

.ai-doc-mini-table td {
    padding: 3px 8px;
    border-bottom: 1px solid #f5f5f5;
    color: #424242;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-doc-mini-table tr:hover td {
    background: #f5f5f5;
}

/* ==========================================
   ACTION CARDS (create/write/search status)
   ========================================== */
.ai-doc-action-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #e8eaf6;
    border-left: 3px solid #3949ab;
    border-radius: 6px;
    padding: 7px 10px;
    margin: 4px 0;
    font-size: 0.75rem;
    color: #1a237e;
    font-weight: 500;
}

.ai-doc-action-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid #3949ab;
    border-top-color: transparent;
    border-radius: 50%;
    animation: ai-doc-spin 0.6s linear infinite;
    margin-left: auto;
}

@keyframes ai-doc-spin {
    to { transform: rotate(360deg); }
}

.ai-doc-action-result {
    display: flex;
    align-items: center;
    gap: 6px;
    background: white;
    border-left: 3px solid #4CAF50;
    border-radius: 6px;
    padding: 6px 10px;
    margin: 3px 0;
    font-size: 0.73rem;
    color: #333;
}

/* ==========================================
   GENERATED DOCUMENTS
   ========================================== */
.ai-doc-generated-doc {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 10px;
    margin: 6px 0;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.ai-doc-doc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #004d40, #00695c);
    color: white;
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
}

.ai-doc-doc-patient {
    font-size: 0.72rem;
    opacity: 0.8;
    flex: 1;
}

.ai-doc-doc-copy, .ai-doc-doc-print {
    background: rgba(255,255,255,0.18);
    border: 1px solid rgba(255,255,255,0.3);
    color: white;
    border-radius: 4px;
    padding: 2px 7px;
    cursor: pointer;
    font-size: 0.68rem;
    transition: background 0.15s;
}

.ai-doc-doc-copy:hover, .ai-doc-doc-print:hover {
    background: rgba(255,255,255,0.3);
}

.ai-doc-doc-content {
    width: 100%;
    min-height: 140px;
    max-height: 250px;
    padding: 10px;
    border: none;
    border-bottom: 1px solid #e0e0e0;
    font-size: 0.72rem;
    font-family: 'Courier New', monospace;
    resize: vertical;
    color: #333;
    background: #fafafa;
    line-height: 1.5;
    box-sizing: border-box;
}

.ai-doc-doc-actions {
    display: flex;
    gap: 6px;
    padding: 6px 10px;
    background: #f5f5f5;
}

.ai-doc-doc-btn {
    background: #1a237e;
    color: white;
    border: none;
    border-radius: 5px;
    padding: 4px 10px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: background 0.15s;
}

.ai-doc-doc-btn:hover {
    background: #283593;
}
