/* ============================================
   AI ASSISTANT — RAG-based EMS Chat
   منصة الجنوب — المساعد التشغيلي الذكي
   Right-side slide-out panel
   ============================================ */

/* Container — Fixed bottom-right */
.ai-assistant-container {
    position: fixed;
    bottom: 25px;
    right: 25px;
    z-index: 9999;
    direction: rtl;
}

/* Toggle Button */
.ai-toggle-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #1E3A5F 0%, #2563EB 100%);
    color: white;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(30, 58, 95, 0.4), 0 0 0 4px rgba(37, 99, 235, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.ai-toggle-btn:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 25px rgba(30, 58, 95, 0.5), 0 0 0 6px rgba(37, 99, 235, 0.15);
}

.ai-toggle-btn.active {
    background: linear-gradient(135deg, #EF4444 0%, #DC2626 100%);
    transform: rotate(90deg);
}

/* Notification Badge */
.ai-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #EF4444;
    color: white;
    font-size: 11px;
    font-weight: 700;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: ai-badge-pulse 2s infinite;
}

@keyframes ai-badge-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* Slide-out Panel — RIGHT side */
.ai-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 440px;
    max-width: 100vw;
    height: 100vh;
    background: #FFFFFF;
    box-shadow: -12px 0 48px rgba(15, 23, 42, 0.15);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    direction: rtl;
}

.ai-panel.open {
    transform: translateX(0);
}

/* Panel Header */
.ai-panel-header {
    background: linear-gradient(135deg, #0F172A 0%, #1E3A5F 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.ai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.ai-header-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.ai-status {
    font-size: 12px;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-status-dot {
    width: 8px;
    height: 8px;
    background: #10B981;
    border-radius: 50%;
    animation: ai-status-blink 2s infinite;
}

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

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

.ai-header-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    font-size: 14px;
    text-decoration: none;
}

.ai-header-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Panel Body */
.ai-panel-body {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background: #F8FAFC;
    position: relative;
}

/* Welcome Screen */
.ai-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    text-align: center;
    gap: 16px;
    flex: 1;
}

.ai-welcome-icon {
    width: 80px;
    height: 80px;
    background: linear-gradient(135deg, #1E3A5F, #2563EB);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    color: white;
    box-shadow: 0 8px 24px rgba(37, 99, 235, 0.2);
}

.ai-welcome h3 {
    margin: 0;
    color: #1E293B;
    font-size: 1.1rem;
    font-weight: 700;
}

.ai-welcome p {
    margin: 0;
    color: #64748B;
    font-size: 0.9rem;
    max-width: 320px;
    line-height: 1.6;
}

.ai-suggestions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 300px;
    margin-top: 8px;
}

.ai-suggestion-btn {
    background: white;
    border: 1px solid #E2E8F0;
    border-radius: 12px;
    padding: 12px 16px;
    font-size: 0.9rem;
    color: #1E3A5F;
    cursor: pointer;
    transition: all 0.2s;
    text-align: right;
    font-family: inherit;
}

.ai-suggestion-btn:hover {
    background: #EFF6FF;
    border-color: #3B82F6;
    transform: translateX(-4px);
}

/* Messages Area */
.ai-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 20px;
    flex: 1;
    min-height: 0;
}

/* Message Bubbles */
.ai-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.7;
    word-wrap: break-word;
    animation: ai-message-in 0.3s ease-out;
    position: relative;
}

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

.ai-message.bot {
    background: white;
    color: #1E293B;
    align-self: flex-start;
    border: 1px solid #E2E8F0;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.ai-message.user {
    background: linear-gradient(135deg, #1E3A5F, #2563EB);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
}

.ai-message-content {
    margin-bottom: 4px;
}

.ai-message-time {
    font-size: 11px;
    opacity: 0.5;
    display: block;
    text-align: left;
    margin-top: 4px;
}

.ai-message.user .ai-message-time {
    color: rgba(255,255,255,0.7);
    text-align: right;
}

/* Confidence Badge */
.ai-confidence {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    margin-top: 8px;
}

/* Sources */
.ai-message-sources {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid #E2E8F0;
    flex-wrap: wrap;
}

.ai-sources-label {
    font-size: 11px;
    color: #94A3B8;
    font-weight: 600;
}

.ai-source-tag {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #EFF6FF;
    color: #2563EB;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    transition: transform 0.2s;
}

.ai-source-tag:hover {
    transform: scale(1.15);
    background: #DBEAFE;
}

/* Typing Indicator */
.ai-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.ai-typing-indicator span {
    width: 8px;
    height: 8px;
    background: #CBD5E1;
    border-radius: 50%;
    animation: ai-typing 1.4s infinite ease-in-out both;
}

.ai-typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes ai-typing {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Panel Footer */
.ai-panel-footer {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #E2E8F0;
    flex-shrink: 0;
}

.ai-input-area {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    border-radius: 16px;
    padding: 8px 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.ai-input-area:focus-within {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.ai-input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    color: #1E293B;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 120px;
    padding: 4px 0;
    direction: rtl;
}

.ai-input::placeholder {
    color: #94A3B8;
}

.ai-send-btn {
    background: linear-gradient(135deg, #1E3A5F, #2563EB);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 14px;
}

.ai-send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.ai-send-btn:active {
    transform: scale(0.95);
}

.ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-footer-note {
    font-size: 11px;
    color: #94A3B8;
    text-align: center;
    margin-top: 8px;
}

/* Scrollbar */
.ai-panel-body::-webkit-scrollbar,
.ai-messages::-webkit-scrollbar {
    width: 6px;
}

.ai-panel-body::-webkit-scrollbar-track,
.ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-panel-body::-webkit-scrollbar-thumb,
.ai-messages::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 480px) {
    .ai-panel {
        width: 100vw;
    }
    .ai-assistant-container {
        bottom: 15px;
        right: 15px;
    }
    .ai-toggle-btn {
        width: 52px;
        height: 52px;
        font-size: 20px;
    }
}

/* Sessions Sidebar */
.ai-sessions-sidebar {
    position: absolute;
    top: 0;
    right: 0;
    width: 280px;
    height: 100%;
    background: #F8FAFC;
    border-left: 1px solid #E2E8F0;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 10;
    display: flex;
    flex-direction: column;
}

.ai-sessions-sidebar.open {
    transform: translateX(0);
}

.ai-sessions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #E2E8F0;
    background: white;
}

.ai-sessions-header h5 {
    margin: 0;
    font-size: 0.9rem;
    color: #1E293B;
}

.ai-sessions-header button {
    background: none;
    border: none;
    color: #64748B;
    cursor: pointer;
    font-size: 1rem;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-sessions-header button:hover {
    background: #F1F5F9;
    color: #1E293B;
}

.ai-sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.ai-sessions-empty {
    text-align: center;
    padding: 24px;
    color: #94A3B8;
    font-size: 0.85rem;
}

.ai-session-item {
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s;
    background: white;
    border: 1px solid transparent;
    position: relative;
}

.ai-session-item:hover {
    background: #EFF6FF;
    border-color: #BFDBFE;
}

.ai-session-item.active {
    background: #DBEAFE;
    border-color: #3B82F6;
}

.ai-session-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #1E293B;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 28px;
}

.ai-session-date {
    font-size: 0.75rem;
    color: #94A3B8;
    margin-top: 2px;
}

.ai-session-delete {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #94A3B8;
    cursor: pointer;
    font-size: 0.8rem;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s;
}

.ai-session-item:hover .ai-session-delete {
    opacity: 1;
}

.ai-session-delete:hover {
    color: #EF4444;
    background: #FEE2E2;
}

/* Role Badge */
.ai-role-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    background: #EFF6FF;
    color: #1E3A5F;
    border: 1px solid #BFDBFE;
    margin-top: 8px;
}

/* Dark mode support */
.dark-mode .ai-sessions-sidebar {
    background: #1E293B;
    border-color: #334155;
}

.dark-mode .ai-sessions-header {
    background: #1E293B;
    border-color: #334155;
}

.dark-mode .ai-sessions-header h5 {
    color: #F1F5F9;
}

.dark-mode .ai-session-item {
    background: #334155;
}

.dark-mode .ai-session-item:hover {
    background: #475569;
}

.dark-mode .ai-session-item.active {
    background: #1E3A5F;
    border-color: #3B82F6;
}

.dark-mode .ai-session-title {
    color: #F1F5F9;
}

.dark-mode .ai-role-badge {
    background: #1E3A5F;
    color: #BFDBFE;
    border-color: #3B82F6;
}

.dark-mode .ai-panel {
    background: #1E293B;
}

.dark-mode .ai-panel-body {
    background: #0F172A;
}

.dark-mode .ai-welcome h3 {
    color: #F1F5F9;
}

.dark-mode .ai-welcome p {
    color: #94A3B8;
}

.dark-mode .ai-suggestion-btn {
    background: #334155;
    border-color: #475569;
    color: #F1F5F9;
}

.dark-mode .ai-suggestion-btn:hover {
    background: #475569;
    border-color: #3B82F6;
}

.dark-mode .ai-message.bot {
    background: #334155;
    border-color: #475569;
    color: #F1F5F9;
}

.dark-mode .ai-message-sources {
    border-color: #475569;
}

.dark-mode .ai-source-tag {
    background: #1E293B;
    color: #60A5FA;
}

.dark-mode .ai-input-area {
    background: #334155;
    border-color: #475569;
}

.dark-mode .ai-input {
    color: #F1F5F9;
}

.dark-mode .ai-input::placeholder {
    color: #64748B;
}

.dark-mode .ai-panel-footer {
    background: #1E293B;
    border-color: #334155;
}

.dark-mode .ai-footer-note {
    color: #64748B;
}

/* ============================================
   AI Assistant Button — Topbar Circular Style
   ============================================ */

.ai-topbar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
    animation: ai-pulse 2s infinite;
    position: relative;
    padding: 0;
    margin: 0 4px;
    overflow: hidden;
}

.ai-topbar-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.ai-topbar-btn:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 15px rgba(30, 58, 95, 0.4);
    animation: none;
    border-color: rgba(255, 255, 255, 0.6);
}

.ai-topbar-btn.active {
    animation: none;
    border-color: #EF4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.3);
}

@keyframes ai-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.7);
    }
    70% {
        box-shadow: 0 0 0 12px rgba(37, 99, 235, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
    }
}

/* ============================================
   AI Assistant — Details Toggle & Panel
   ============================================ */

.ai-details-toggle {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.ai-details-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #E2E8F0;
    background: rgba(241, 245, 249, 0.8);
    color: #475569;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-details-btn:hover {
    background: #E2E8F0;
    color: #1E293B;
}

.ai-details-btn i {
    font-size: 0.85rem;
}

.ai-details-panel {
    margin-top: 8px;
    padding: 12px;
    border-radius: 8px;
    background: #F8FAFC;
    border: 1px solid #E2E8F0;
    font-size: 0.85rem;
    line-height: 1.7;
    color: #475569;
    max-height: 300px;
    overflow-y: auto;
}

.ai-details-content {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Dark mode */
.dark-mode .ai-details-btn {
    background: rgba(51, 65, 85, 0.8);
    border-color: #475569;
    color: #CBD5E1;
}

.dark-mode .ai-details-btn:hover {
    background: #475569;
    color: #F1F5F9;
}

.dark-mode .ai-details-panel {
    background: #1E293B;
    border-color: #334155;
    color: #94A3B8;
}

/* Message content formatting */
.ai-message-content strong {
    color: #1E3A5F;
    font-weight: 700;
}

.dark-mode .ai-message-content strong {
    color: #60A5FA;
}
