/* Chatbot Widget Styles */

/* Chat button (floating) */
.chatbot-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #0d5a9c 0%, #2e7d32 100%);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(13, 90, 156, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    z-index: 1000;
}

.chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(13, 90, 156, 0.6);
}

.chatbot-button svg {
    width: 30px;
    height: 30px;
    fill: white;
}

.chatbot-button.hidden {
    display: none;
}

/* Chat window */
.chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 550px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    z-index: 999;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.chatbot-window.active {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.chatbot-header {
    background: linear-gradient(135deg, #0d5a9c 0%, #2e7d32 100%);
    color: white;
    padding: 16px 20px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chatbot-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chatbot-header .status {
    font-size: 12px;
    opacity: 0.9;
}

.chatbot-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.chatbot-close:hover {
    opacity: 1;
}

/* Messages container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
}

/* Message */
.message {
    margin-bottom: 16px;
    display: flex;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    justify-content: flex-end;
}

.message.assistant {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #0d5a9c 0%, #2e7d32 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

/* Markdown formatting within message bubbles */
.message-bubble p {
    margin: 0 0 8px 0;
}

.message-bubble p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    font-weight: 600;
    color: inherit;
}

.message-bubble em {
    font-style: italic;
}

.message-bubble ul,
.message-bubble ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-bubble li {
    margin: 4px 0;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
    margin: 8px 0 4px 0;
    font-weight: 600;
}

.message-bubble h1 { font-size: 16px; }
.message-bubble h2 { font-size: 15px; }
.message-bubble h3 { font-size: 14px; }
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 { font-size: 13px; }

.message-bubble code {
    background: #f5f5f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.message-bubble pre {
    background: #f5f5f5;
    padding: 8px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-bubble pre code {
    background: none;
    padding: 0;
}

.message-bubble a {
    color: #0d5a9c;
    text-decoration: underline;
}

.message-bubble a:hover {
    color: #2e7d32;
}

.message-time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.message.assistant .message-time {
    text-align: left;
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-10px);
        opacity: 1;
    }
}

/* Warning message */
.warning-message {
    background: #fff3cd;
    color: #856404;
    padding: 12px 16px;
    margin: 12px 0;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    border-left: 4px solid #ffc107;
}

/* Input area */
.chatbot-input {
    border-top: 1px solid #e9ecef;
    padding: 16px 20px;
    background: white;
    border-radius: 0 0 12px 12px;
}

.input-group {
    display: flex;
    gap: 8px;
}

.chatbot-input input {
    flex: 1;
    border: 1px solid #dee2e6;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input input:focus {
    border-color: #0d5a9c;
}

.chatbot-input input:disabled {
    background: #f8f9fa;
    cursor: not-allowed;
}

.send-button {
    background: linear-gradient(135deg, #0d5a9c 0%, #2e7d32 100%);
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.send-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(13, 90, 156, 0.3);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Rating */
.chatbot-rating {
    padding: 16px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    text-align: center;
}

.chatbot-rating p {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #495057;
}

.rating-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.rating-button {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 24px;
    padding: 8px 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rating-button:hover {
    border-color: #0d5a9c;
    transform: translateY(-2px);
}

.rating-button.positive {
    color: #28a745;
}

.rating-button.negative {
    color: #dc3545;
}

.rating-button.selected {
    border-color: #0d5a9c;
    background: #0d5a9c;
    color: white;
}

/* Message counter */
.message-counter {
    font-size: 12px;
    color: #6c757d;
    text-align: center;
    padding: 8px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

/* RTL Support */
[dir="rtl"] .chatbot-button {
    right: auto;
    left: 20px;
}

[dir="rtl"] .chatbot-window {
    right: auto;
    left: 20px;
}

[dir="rtl"] .message.user {
    justify-content: flex-start;
}

[dir="rtl"] .message.assistant {
    justify-content: flex-end;
}

[dir="rtl"] .message.user .message-bubble {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .message.assistant .message-bubble {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .chatbot-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 100px);
        bottom: 20px;
        right: 20px;
    }

    [dir="rtl"] .chatbot-window {
        right: auto;
        left: 20px;
    }
}

/* Error state */
.error-message {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    margin: 12px 0;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
    border-left: 4px solid #dc3545;
}

/* Agent button in header */
.agent-button {
    background: white;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    font-size: 16px;
    color: #0d5a9c;
}

.agent-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

.agent-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Agent message styling */
.message.agent .message-bubble {
    background: #e8f4f8;
    color: #0d5a9c;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(13, 90, 156, 0.1);
}

.agent-badge {
    display: block;
    font-size: 11px;
    color: #0d5a9c;
    margin-top: 4px;
    font-weight: 600;
}

.agent-badge i {
    margin-right: 4px;
}

/* ======================
   SignalR Real-time Features
   ====================== */

/* Connection indicator on chat button */
.connection-indicator {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid white;
    background: #6c757d;
    transition: background 0.3s ease;
}

.connection-indicator.connected {
    background: #28a745;
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.6);
}

.connection-indicator.connecting {
    background: #ffc107;
    animation: pulse 1.5s infinite;
}

.connection-indicator.reconnecting {
    background: #ff9800;
    animation: pulse 1.5s infinite;
}

.connection-indicator.disconnected {
    background: #dc3545;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

/* Connection status in header */
.status-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.connection-status {
    font-size: 10px;
    opacity: 0.8;
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* Typing indicator container (separate from message typing) */
.typing-indicator-container {
    padding: 8px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
}

.typing-indicator-text {
    font-size: 12px;
    color: #6c757d;
    font-style: italic;
}

/* Read receipts */
.message.read {
    opacity: 1;
}

.message.read .message-bubble::after {
    content: "✓✓";
    font-size: 10px;
    color: #28a745;
    margin-left: 4px;
}

/* Online/Offline status badges */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.status-badge.online {
    background: #d4edda;
    color: #155724;
}

.status-badge.online::before {
    content: "●";
    color: #28a745;
}

.status-badge.offline {
    background: #f8d7da;
    color: #721c24;
}

.status-badge.offline::before {
    content: "●";
    color: #dc3545;
}

/* Queue notification badge */
.queue-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    border: 2px solid white;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Message states */
.message.sending {
    opacity: 0.6;
}

.message.sending .message-bubble::after {
    content: "⏱";
    font-size: 10px;
    opacity: 0.5;
    margin-left: 4px;
}

.message.failed {
    opacity: 0.5;
}

.message.failed .message-bubble {
    border: 1px solid #dc3545;
}

.message.failed .message-bubble::after {
    content: "✗";
    font-size: 10px;
    color: #dc3545;
    margin-left: 4px;
}

/* Reconnection banner */
.reconnection-banner {
    background: #fff3cd;
    color: #856404;
    padding: 8px 12px;
    text-align: center;
    font-size: 12px;
    border-bottom: 1px solid #ffc107;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.reconnection-banner .spinner {
    width: 12px;
    height: 12px;
    border: 2px solid #856404;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* RTL support for SignalR features */
[dir="rtl"] .connection-indicator {
    right: auto;
    left: 4px;
}

[dir="rtl"] .agent-badge i {
    margin-right: 0;
    margin-left: 4px;
}

[dir="rtl"] .message.read .message-bubble::after {
    margin-left: 0;
    margin-right: 4px;
}
