/**
 * Coderz AI Course Advisor - Chatbot Styles
 * مستشار كودرز الذكي - ستايلز
 */

:root {
    /* Coderz Brand Colors */
    --chatbot-primary: #157EEE;
    --chatbot-primary-dark: #0D5BB8;
    --chatbot-primary-light: #4A9DF4;
    --chatbot-secondary: #36454F;
    --chatbot-success: #28C76F;
    --chatbot-danger: #EA5455;
    --chatbot-warning: #FF9F43;
    --chatbot-bg: #ffffff;
    --chatbot-bg-dark: #1E282E;
    --chatbot-text: #2C3E50;
    --chatbot-text-light: #5D6D7E;
    --chatbot-border: #E2E8F0;
    --chatbot-shadow: 0 25px 50px -12px rgba(21, 126, 238, 0.25);
    --chatbot-radius: 20px;
    --chatbot-radius-sm: 12px;
    --chatbot-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==================== Chatbot Container ==================== */
.coderz-chatbot {
    position: fixed;
    bottom: 20px;
    left: 20px;
    z-index: 9999;
    font-family: 'Tajawal', 'Segoe UI', sans-serif;
}

/* ==================== Floating Button ==================== */
.chatbot-button {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    box-shadow: 0 8px 32px rgba(21, 126, 238, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
    overflow: visible;
}

.chatbot-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(21, 126, 238, 0.5);
}

.chatbot-button svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: var(--chatbot-transition);
}

.chatbot-button .chatbot-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.chatbot-button.open .chatbot-icon-open {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.chatbot-button.open .chatbot-icon-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Pulse Animation */
.chatbot-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--chatbot-primary);
    animation: pulse 2s ease-out infinite;
    z-index: -1;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.5;
    }

    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

.chatbot-button.open .chatbot-pulse {
    animation: none;
    opacity: 0;
}

/* Badge */
.chatbot-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    width: 24px;
    height: 24px;
    background: var(--chatbot-danger);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    animation: bounceIn 0.3s ease;
}

@keyframes bounceIn {
    0% {
        transform: scale(0);
    }

    50% {
        transform: scale(1.2);
    }

    100% {
        transform: scale(1);
    }
}

/* ==================== Chat Window ==================== */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    left: 0;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: var(--chatbot-transition);
}

.chatbot-window.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ==================== Header ==================== */
.chatbot-header {
    background: linear-gradient(135deg, var(--chatbot-bg-dark) 0%, #312e81 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chatbot-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-avatar {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
}

.chatbot-avatar svg {
    width: 26px;
    height: 26px;
    fill: white;
}

.chatbot-header-text h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.channel-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    opacity: 0.9;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--chatbot-secondary);
}

.status-dot.online {
    background: var(--chatbot-secondary);
}

.status-dot.agent {
    background: var(--chatbot-warning);
}

.status-dot.offline {
    background: var(--chatbot-text-light);
}

.chatbot-header-actions {
    display: flex;
    gap: 8px;
}

.chatbot-header-actions button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
}

.chatbot-header-actions button:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chatbot-header-actions svg {
    width: 18px;
    height: 18px;
    fill: white;
}

.chatbot-mute.muted svg {
    opacity: 0.5;
}

/* ==================== Messages Container ==================== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* ==================== Messages ==================== */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: messageIn 0.3s ease;
}

@keyframes messageIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message */
.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.user-message .message-content {
    background: linear-gradient(135deg, var(--chatbot-primary) 0%, var(--chatbot-primary-dark) 100%);
    color: white;
    border-radius: 18px 18px 4px 18px;
    padding: 12px 16px;
}

.user-message .message-time {
    text-align: left;
    color: rgba(255, 255, 255, 0.7);
}

/* Bot Message */
.bot-message {
    align-self: flex-start;
}

.bot-message .message-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: var(--chatbot-primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bot-message .message-avatar svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.bot-message .message-content {
    background: white;
    border-radius: 18px 18px 18px 4px;
    padding: 12px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.message-text {
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-text strong {
    font-weight: 600;
}

.message-text del {
    opacity: 0.6;
}

.message-time {
    font-size: 11px;
    color: var(--chatbot-text-light);
    margin-top: 6px;
    text-align: right;
}

/* Message Links */
.message-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.message-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--chatbot-primary);
    color: white;
    text-decoration: none;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    transition: var(--chatbot-transition);
}

.message-link:hover {
    background: var(--chatbot-primary-dark);
    transform: translateY(-2px);
}

/* System Message */
.system-message {
    align-self: center;
    max-width: 100%;
}

.system-message-content {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(21, 126, 238, 0.1);
    color: var(--chatbot-primary);
    border-radius: 20px;
    font-size: 13px;
}

/* Human Support Notice */
.human-support-notice {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-radius: 16px;
    margin: 10px 0;
}

.human-support-notice .notice-icon {
    width: 40px;
    height: 40px;
    background: #f59e0b;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.human-support-notice .notice-icon svg {
    width: 22px;
    height: 22px;
    fill: white;
}

.human-support-notice .notice-text {
    color: #92400e;
}

.human-support-notice .notice-text strong {
    display: block;
    font-size: 14px;
}

.human-support-notice .notice-text p {
    margin: 4px 0 0;
    font-size: 12px;
    opacity: 0.8;
}

/* ==================== Course Card ==================== */
.course-card {
    margin-top: 12px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--chatbot-border);
}

.course-card-image {
    width: 100%;
    height: 120px;
    object-fit: cover;
}

.course-card-content {
    padding: 12px;
}

.course-card-content h4 {
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--chatbot-text);
}

.course-card-meta {
    display: flex;
    gap: 12px;
    font-size: 12px;
    color: var(--chatbot-text-light);
    margin-bottom: 8px;
}

.course-card-meta i {
    margin-left: 4px;
}

.course-card-price {
    margin-bottom: 10px;
}

.course-card-price .original-price {
    text-decoration: line-through;
    color: var(--chatbot-text-light);
    font-size: 12px;
    margin-left: 8px;
}

.course-card-price .discount-price,
.course-card-price .price {
    font-size: 16px;
    font-weight: 700;
    color: var(--chatbot-primary);
}

.course-card-btn {
    display: block;
    text-align: center;
    padding: 10px;
    background: var(--chatbot-primary);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--chatbot-transition);
}

.course-card-btn:hover {
    background: var(--chatbot-primary-dark);
}

/* ==================== Typing Indicator ==================== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    width: fit-content;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chatbot-primary-light);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-8px);
    }
}

/* ==================== Quick Replies ==================== */
.chatbot-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 20px;
    background: #f8fafc;
    border-top: 1px solid var(--chatbot-border);
    max-height: 0;
    overflow: hidden;
    transition: var(--chatbot-transition);
}

.chatbot-quick-replies.visible {
    max-height: 200px;
    padding: 12px 20px;
}

.quick-reply-btn {
    padding: 8px 16px;
    background: white;
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    color: var(--chatbot-text);
    font-size: 13px;
    cursor: pointer;
    transition: var(--chatbot-transition);
    white-space: nowrap;
}

.quick-reply-btn:hover {
    background: var(--chatbot-primary);
    border-color: var(--chatbot-primary);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(21, 126, 238, 0.3);
}

/* ==================== Input Area ==================== */
.chatbot-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid var(--chatbot-border);
    flex-shrink: 0;
}

.chatbot-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid var(--chatbot-border);
    border-radius: 24px;
    padding: 8px 8px 8px 16px;
    transition: var(--chatbot-transition);
}

.chatbot-input-wrapper:focus-within {
    border-color: var(--chatbot-primary);
    box-shadow: 0 0 0 3px rgba(21, 126, 238, 0.1);
}

.chatbot-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    max-height: 100px;
    min-height: 24px;
    color: var(--chatbot-text);
}

.chatbot-input:focus {
    outline: none;
}

.chatbot-input::placeholder {
    color: var(--chatbot-text-light);
}

/* Input Buttons */
.chatbot-voice,
.chatbot-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
}

.chatbot-voice {
    background: transparent;
    color: var(--chatbot-text-light);
    position: relative;
}

.chatbot-voice:hover {
    color: var(--chatbot-primary);
    background: rgba(21, 126, 238, 0.1);
}

.chatbot-voice svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Voice Waves Animation */
.voice-waves {
    position: absolute;
    display: none;
    gap: 2px;
}

.voice-waves span {
    width: 3px;
    height: 12px;
    background: var(--chatbot-danger);
    border-radius: 2px;
    animation: voiceWave 0.5s ease-in-out infinite alternate;
}

.voice-waves span:nth-child(2) {
    animation-delay: 0.1s;
    height: 18px;
}

.voice-waves span:nth-child(3) {
    animation-delay: 0.2s;
}

@keyframes voiceWave {
    from {
        transform: scaleY(0.5);
    }

    to {
        transform: scaleY(1);
    }
}

.chatbot-voice.listening svg {
    display: none;
}

.chatbot-voice.listening .voice-waves {
    display: flex;
}

.chatbot-voice.listening {
    background: rgba(239, 68, 68, 0.1);
}

.chatbot-voice.hidden {
    display: none;
}

.chatbot-send {
    background: var(--chatbot-primary);
    color: white;
}

.chatbot-send:hover {
    background: var(--chatbot-primary-dark);
    transform: scale(1.05);
}

.chatbot-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
    transform: rotate(180deg);
    /* RTL flip */
}

/* Footer */
.chatbot-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 12px;
    padding-top: 8px;
}

.human-support-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: transparent;
    border: 1px solid var(--chatbot-border);
    border-radius: 16px;
    color: var(--chatbot-text-light);
    font-size: 12px;
    cursor: pointer;
    transition: var(--chatbot-transition);
}

.human-support-btn:hover {
    background: var(--chatbot-warning);
    border-color: var(--chatbot-warning);
    color: white;
}

.human-support-btn svg {
    fill: currentColor;
}

.powered-by {
    font-size: 11px;
    color: var(--chatbot-text-light);
    opacity: 0.6;
}

/* ==================== Responsive ==================== */
@media (max-width: 480px) {
    .coderz-chatbot {
        bottom: 15px;
        left: 15px;
        right: 15px;
    }

    .chatbot-button {
        width: 56px;
        height: 56px;
    }

    .chatbot-window {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        height: calc(100vh - 80px);
        max-height: none;
        border-radius: var(--chatbot-radius) var(--chatbot-radius) 0 0;
    }

    .chatbot-window.open {
        bottom: 0;
    }

    .chatbot-button.open {
        position: fixed;
        bottom: calc(100vh - 70px);
        z-index: 10000;
    }
}

/* ==================== RTL Support ==================== */
[dir="rtl"] .chatbot-send svg {
    transform: rotate(0deg);
}

[dir="rtl"] .user-message .message-content {
    border-radius: 18px 18px 18px 4px;
}

[dir="rtl"] .bot-message .message-content {
    border-radius: 18px 18px 4px 18px;
}

[dir="rtl"] .message-time {
    text-align: left;
}

[dir="rtl"] .user-message .message-time {
    text-align: right;
}

/* ==================== Dark Mode (Optional) ==================== */
@media (prefers-color-scheme: dark) {
    .chatbot-window {
        --chatbot-bg: #1f2937;
        --chatbot-text: #f9fafb;
        --chatbot-text-light: #9ca3af;
        --chatbot-border: #374151;
    }

    .chatbot-messages {
        background: linear-gradient(180deg, #111827 0%, #1f2937 100%);
    }

    .bot-message .message-content,
    .chatbot-input-wrapper,
    .quick-reply-btn,
    .typing-indicator {
        background: #374151;
        color: #f9fafb;
    }

    .quick-reply-btn {
        border-color: #4b5563;
    }

    .chatbot-input-area {
        background: #1f2937;
    }

    .chatbot-quick-replies {
        background: #111827;
    }
}

/* ==================== Animations ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Smooth scroll behavior */
.chatbot-messages {
    scroll-behavior: smooth;
}

/* Focus visible for accessibility */
.chatbot-button:focus-visible,
.quick-reply-btn:focus-visible,
.chatbot-send:focus-visible,
.chatbot-voice:focus-visible {
    outline: 2px solid var(--chatbot-primary);
    outline-offset: 2px;
}

/* Print styles - hide chatbot */
@media print {
    .coderz-chatbot {
        display: none !important;
    }
}