/**
 * Chatbot Widget Stylesheet
 * 
 * Brand Colors:
 * - Primary Green: #648b19
 * - Secondary Dark Blue: #313e47
 * - White: #ffffff
 * - Light Gray: #f5f5f5
 * - Border Gray: #e0e0e0
 * 
 * Font: Avenir, Arial, sans-serif
 */

/* ============================================
   Container and Positioning
   ============================================ */

.chatbot-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1001;
    font-family: Avenir, Arial, sans-serif;
}

/* ============================================
   Minimized Button
   ============================================ */

.chatbot-button {
    width: 60px;
    height: 60px;
    background-color: #648b19;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    -webkit-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    -moz-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    -ms-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -ms-transition: all 0.3s ease;
}

.chatbot-button:hover {
    background-color: #75a01d;
    transform: scale(1.05);
    -webkit-transform: scale(1.05);
    -moz-transform: scale(1.05);
    -ms-transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    -moz-box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
    -ms-box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chatbot-button-icon {
    width: 30px;
    height: 30px;
    color: #ffffff;
    font-size: 24px;
    line-height: 30px;
    text-align: center;
}

.chatbot-button-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #e74c3c;
    color: #ffffff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 12px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Expanded Chat Window
   ============================================ */

.chatbot-window {
    width: 380px;
    height: 550px;
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    -webkit-box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    -moz-box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    -ms-box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    -webkit-animation: slideUp 0.3s ease;
    -moz-animation: slideUp 0.3s ease;
    -ms-animation: slideUp 0.3s ease;
}

/* ============================================
   Chat Header
   ============================================ */

.chatbot-header {
    background-color: #313e47;
    color: #ffffff;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.chatbot-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chatbot-logo {
    width: 32px;
    height: 32px;
    object-fit: contain;
    background-color: #ffffff;
    border-radius: 4px;
    padding: 3px;
    flex-shrink: 0;
}

.chatbot-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chatbot-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 400;
    opacity: 0.9;
}

.chatbot-status-dot {
    width: 8px;
    height: 8px;
    background-color: #4caf50;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
    -webkit-animation: pulse 2s ease-in-out infinite;
    -moz-animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.1);
    }
}

@-webkit-keyframes pulse {
    0%, 100% {
        opacity: 1;
        -webkit-transform: scale(1);
    }
    50% {
        opacity: 0.6;
        -webkit-transform: scale(1.1);
    }
}

@-moz-keyframes pulse {
    0%, 100% {
        opacity: 1;
        -moz-transform: scale(1);
    }
    50% {
        opacity: 0.6;
        -moz-transform: scale(1.1);
    }
}

.chatbot-subtitle {
    font-size: 12px;
    opacity: 0.8;
    margin: 5px 0 0 0;
}

.chatbot-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background-color 0.2s ease;
    -webkit-transition: background-color 0.2s ease;
    -moz-transition: background-color 0.2s ease;
    -ms-transition: background-color 0.2s ease;
}

.chatbot-close:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Messages Container
   ============================================ */

/* Disclaimer Banner */
.chatbot-disclaimer {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border-left: 4px solid #ffc107;
    padding: 12px 15px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 0 0 15px 0;
    border-radius: 8px;
    animation: slideDown 0.4s ease;
    -webkit-animation: slideDown 0.4s ease;
    -moz-animation: slideDown 0.4s ease;
    max-width: 100%;
}

[dir="rtl"] .chatbot-disclaimer {
    border-left: none;
    border-right: 4px solid #ffc107;
}

.chatbot-disclaimer-icon {
    color: #856404;
    flex-shrink: 0;
    margin-top: 2px;
}

.chatbot-disclaimer-text {
    color: #856404;
    font-size: 12px;
    line-height: 1.5;
    font-weight: 500;
}

.chatbot-disclaimer-text strong {
    font-weight: 700;
    color: #664d03;
}

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

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

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

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    background-color: #f5f5f5;
    display: flex;
    flex-direction: column;
    gap: 15px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.chatbot-messages::-webkit-scrollbar {
    width: 6px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: #e0e0e0;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: #648b19;
    border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
    background: #75a01d;
}

/* ============================================
   Message Bubbles
   ============================================ */

.chatbot-message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: fadeIn 0.3s ease;
    -webkit-animation: fadeIn 0.3s ease;
    -moz-animation: fadeIn 0.3s ease;
    -ms-animation: fadeIn 0.3s ease;
}

.chatbot-message-user {
    align-self: flex-end;
}

.chatbot-message-bot {
    align-self: flex-start;
}

.chatbot-message-content {
    padding: 12px 15px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.4;
    font-size: 14px;
}

.chatbot-message-user .chatbot-message-content {
    background-color: #ffffff;
    color: #333333;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -ms-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chatbot-message-bot .chatbot-message-content {
    background-color: #313e47;
    color: #ffffff;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -webkit-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -moz-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    -ms-box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.chatbot-message-link {
    color: #648b19;
    text-decoration: underline;
    cursor: pointer;
}

.chatbot-message-bot .chatbot-message-link {
    color: #75a01d;
}

.chatbot-timestamp {
    font-size: 11px;
    color: #999999;
    margin-top: 5px;
    padding: 0 5px;
}

.chatbot-message-user .chatbot-timestamp {
    text-align: right;
}

.chatbot-message-bot .chatbot-timestamp {
    text-align: left;
}

/* ============================================
   Input Area
   ============================================ */

.chatbot-input-area {
    display: flex;
    padding: 15px 20px;
    background-color: #ffffff;
    border-top: 1px solid #e0e0e0;
    gap: 10px;
    align-items: center;
}

.chatbot-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 10px 15px;
    font-size: 14px;
    font-family: Avenir, Arial, sans-serif;
    color: #333333;
    background-color: #ffffff;
    outline: none;
    transition: border-color 0.2s ease;
    -webkit-transition: border-color 0.2s ease;
    -moz-transition: border-color 0.2s ease;
    -ms-transition: border-color 0.2s ease;
}

.chatbot-input:focus {
    border-color: #648b19;
}

.chatbot-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.6;
}

.chatbot-input::placeholder {
    color: #999999;
}

.chatbot-send-button {
    background-color: #648b19;
    color: #ffffff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    -webkit-transition: background-color 0.2s ease, transform 0.1s ease;
    -moz-transition: background-color 0.2s ease, transform 0.1s ease;
    -ms-transition: background-color 0.2s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.chatbot-send-button:hover {
    background-color: #75a01d;
}

.chatbot-send-button:active {
    transform: scale(0.95);
    -webkit-transform: scale(0.95);
    -moz-transform: scale(0.95);
    -ms-transform: scale(0.95);
}

.chatbot-send-button:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
    opacity: 0.7;
}

.chatbot-send-button:disabled:hover {
    background-color: #cccccc;
    transform: none;
    -webkit-transform: none;
    -moz-transform: none;
    -ms-transform: none;
}

/* ============================================
   Animations
   ============================================ */

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

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

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

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

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

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

/* Spinner animation for send button */
.chatbot-spinner {
    animation: spin 0.8s linear infinite;
    -webkit-animation: spin 0.8s linear infinite;
    -moz-animation: spin 0.8s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@-webkit-keyframes spin {
    from {
        -webkit-transform: rotate(0deg);
    }
    to {
        -webkit-transform: rotate(360deg);
    }
}

@-moz-keyframes spin {
    from {
        -moz-transform: rotate(0deg);
    }
    to {
        -moz-transform: rotate(360deg);
    }
}

/* ============================================
   Responsive Design - Tablet (768px - 1024px)
   ============================================ */

@media (max-width: 1024px) and (min-width: 768px) {
    .chatbot-window {
        width: 360px;
        height: 500px;
    }
    
    .chatbot-button {
        width: 56px;
        height: 56px;
    }
    
    .chatbot-button-icon {
        width: 28px;
        height: 28px;
        font-size: 22px;
    }
}

/* ============================================
   Responsive Design - Mobile (< 768px)
   ============================================ */

@media (max-width: 767px) {
    .chatbot-container {
        position: fixed;
        bottom: 20px;
        right: 100px;
        left: auto;
        /* ADD THESE: */
        max-width: calc(100vw - 30px);  /* never wider than viewport */
        box-sizing: border-box;
    }

    .chatbot-window {
        position: fixed;
        bottom: 90px;
        right: 10px;
        left: 10px;
        width: auto;                         /* don't set a fixed width */
        max-width: calc(100vw - 20px);       /* hard cap */
        height: 420px;
        max-height: calc(100vh - 120px);
        box-sizing: border-box;
    }
    
    .chatbot-button {
        width: 56px;
        height: 56px;
    }
    
    .chatbot-button-icon {
        width: 28px;
        height: 28px;
        font-size: 22px;
    }
    
    .chatbot-header {
        padding: 15px;
    }
    
    .chatbot-title {
        font-size: 16px;
    }
    
    .chatbot-subtitle {
        font-size: 11px;
    }
    
    .chatbot-messages {
        padding: 15px;
        gap: 12px;
    }
    
    .chatbot-message-content {
        font-size: 13px;
        padding: 10px 12px;
    }
    
    .chatbot-input-area {
        padding: 12px 15px;
    }
    
    .chatbot-input {
        font-size: 13px;
        padding: 9px 12px;
    }
    
    .chatbot-send-button {
        width: 38px;
        height: 38px;
        font-size: 16px;
    }
}

@media (max-width: 480px) {
 .chatbot-container {
        position: fixed;
        bottom: 15px;
        right: 50px;
        left: auto;
        max-width: calc(100vw - 20px);
        box-sizing: border-box;
    }

    .chatbot-window {
        position: fixed;
        bottom: 85px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: calc(100vw - 16px);
        height: 380px;
        max-height: calc(100vh - 110px);
        box-sizing: border-box;
    }
    
    .chatbot-button {
        width: 52px;
        height: 52px;
    }
    
    .chatbot-button-icon {
        width: 26px;
        height: 26px;
        font-size: 20px;
    }
}

/* ============================================
   RTL Support for Arabic Pages
   ============================================ */

[dir="rtl"] .chatbot-container {
    right: auto;
    left: 20px;
}

[dir="rtl"] .chatbot-header {
    direction: rtl;
}

[dir="rtl"] .chatbot-header-content {
    flex-direction: row-reverse;
}

[dir="rtl"] .chatbot-message-user {
    align-self: flex-start;
}

[dir="rtl"] .chatbot-message-bot {
    align-self: flex-end;
}

[dir="rtl"] .chatbot-message-user .chatbot-message-content {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 4px;
}

[dir="rtl"] .chatbot-message-bot .chatbot-message-content {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 4px;
}

[dir="rtl"] .chatbot-message-user .chatbot-timestamp {
    text-align: left;
}

[dir="rtl"] .chatbot-message-bot .chatbot-timestamp {
    text-align: right;
}

[dir="rtl"] .chatbot-input-area {
    direction: rtl;
}

[dir="rtl"] .chatbot-button-badge {
    right: auto;
    left: -5px;
}

[dir="rtl"] .chatbot-messages::-webkit-scrollbar {
    left: 0;
    right: auto;
}

@media (max-width: 767px) {
    [dir="rtl"] .chatbot-container {
        left: 15px;
        right: auto;
    }
}

@media (max-width: 480px) {
    [dir="rtl"] .chatbot-container {
        left: 10px;
        right: auto;
    }
}

/* ============================================
   Accessibility - Focus Indicators
   ============================================ */

.chatbot-button:focus,
.chatbot-close:focus,
.chatbot-send-button:focus,
.chatbot-input:focus {
    outline: 2px solid #648b19;
    outline-offset: 2px;
}

/* ============================================
   Utility Classes
   ============================================ */

.chatbot-hidden {
    display: none !important;
}

.chatbot-visible {
    display: block !important;
}

.chatbot-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 15px;
}

.chatbot-typing-dot {
    width: 8px;
    height: 8px;
    background-color: #999999;
    border-radius: 50%;
    animation: typingAnimation 1.4s infinite;
    -webkit-animation: typingAnimation 1.4s infinite;
    -moz-animation: typingAnimation 1.4s infinite;
}

.chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
    -webkit-animation-delay: 0.2s;
    -moz-animation-delay: 0.2s;
}

.chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
    -webkit-animation-delay: 0.4s;
    -moz-animation-delay: 0.4s;
}

@keyframes typingAnimation {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

@-webkit-keyframes typingAnimation {
    0%, 60%, 100% {
        opacity: 0.3;
        -webkit-transform: translateY(0);
    }
    30% {
        opacity: 1;
        -webkit-transform: translateY(-10px);
    }
}

@-moz-keyframes typingAnimation {
    0%, 60%, 100% {
        opacity: 0.3;
        -moz-transform: translateY(0);
    }
    30% {
        opacity: 1;
        -moz-transform: translateY(-10px);
    }
}

/* ============================================
   Markdown Content Styling
   ============================================ */

/* Paragraphs in bot messages */
.chatbot-message-content p {
    margin: 0.5em 0;
}

.chatbot-message-content p:first-child {
    margin-top: 0;
}

.chatbot-message-content p:last-child {
    margin-bottom: 0;
}

/* Bold text */
.chatbot-message-content strong {
    font-weight: 600;
}

/* Lists */
.chatbot-message-content ul,
.chatbot-message-content ol {
    margin: 0.5em 0;
    padding-left: 1.5em;
}

[dir="rtl"] .chatbot-message-content ul,
[dir="rtl"] .chatbot-message-content ol {
    padding-left: 0;
    padding-right: 1.5em;
}

.chatbot-message-content li {
    margin: 0.3em 0;
}

/* Headings */
.chatbot-message-content h1,
.chatbot-message-content h2,
.chatbot-message-content h3,
.chatbot-message-content h4 {
    margin: 0.8em 0 0.4em 0;
    font-weight: 600;
}

.chatbot-message-content h1:first-child,
.chatbot-message-content h2:first-child,
.chatbot-message-content h3:first-child,
.chatbot-message-content h4:first-child {
    margin-top: 0;
}

/* Code blocks */
.chatbot-message-content code {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.chatbot-message-user .chatbot-message-content code {
    background-color: rgba(0, 0, 0, 0.05);
}

.chatbot-message-content pre {
    background-color: rgba(255, 255, 255, 0.1);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 0.5em 0;
}

.chatbot-message-user .chatbot-message-content pre {
    background-color: rgba(0, 0, 0, 0.05);
}

.chatbot-message-content pre code {
    background-color: transparent;
    padding: 0;
}

/* Links */
.chatbot-message-content a {
    color: #75a01d;
    text-decoration: underline;
}

.chatbot-message-user .chatbot-message-content a {
    color: #648b19;
}

/* ============================================
   LaTeX/KaTeX Styling
   ============================================ */

/* Display math (block) */
.chatbot-message-content .katex-display {
    margin: 1em 0;
    overflow-x: auto;
    overflow-y: hidden;
}

/* Inline math */
.chatbot-message-content .katex {
    font-size: 1.05em;
}

/* Error handling for LaTeX */
.chatbot-message-content .katex-error {
    color: #ff6b6b;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
    background-color: rgba(255, 107, 107, 0.1);
    padding: 2px 6px;
    border-radius: 3px;
}

/* Ensure KaTeX formulas are readable on dark background */
.chatbot-message-bot .katex {
    color: #ffffff;
}

/* Scrollbar for long formulas */
.chatbot-message-content .katex-display::-webkit-scrollbar {
    height: 4px;
}

.chatbot-message-content .katex-display::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.chatbot-message-content .katex-display::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.chatbot-message-user .chatbot-message-content .katex-display::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.chatbot-message-user .chatbot-message-content .katex-display::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
}
