/**
 * ChatbotAssistant CSS Styles
 *
 * @category  A75
 * @package   A75_ChatbotAssistant
 * @author    MyCompany
 * @copyright Copyright (c) 2025 MyCompany
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
 */

/* CSS Variables for theming */
:root {
    --chatbot-primary-color: #007bff;
    --chatbot-secondary-color: #6c757d;
    --chatbot-background: #ffffff;
    --chatbot-border: #e9ecef;
    --chatbot-text: #212529;
    --chatbot-text-light: #6c757d;
    --chatbot-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --chatbot-radius: 12px;
    --chatbot-transition: all 0.3s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --chatbot-primary-color: #4da3ff;
        --chatbot-secondary-color: #73809c;
        --chatbot-background: #0f1115;
        --chatbot-border: #2d3442;
        --chatbot-text: #f5f7fb;
        --chatbot-text-light: #c3c9d4;
        --chatbot-shadow: 0 8px 20px rgba(0, 0, 0, 0.5);
    }
    
    .chatbot-window {
        background: var(--chatbot-background);
        border: 1px solid var(--chatbot-border);
    }
    
    .chatbot-header {
        box-shadow: 0 1px 0 var(--chatbot-border);
    }
    
    .chatbot-avatar {
        background: rgba(255, 255, 255, 0.08);
    }
    
    .chatbot-action-btn {
        color: var(--chatbot-text);
    }
    
    .chatbot-consent {
        background: rgba(255, 255, 255, 0.04);
        border-bottom: 1px solid var(--chatbot-border);
    }
    
    .chatbot-messages {
        background: var(--chatbot-background);
    }
    
    .chatbot-messages::-webkit-scrollbar-track {
        background: rgba(255, 255, 255, 0.04);
    }
    
    .chatbot-messages::-webkit-scrollbar-thumb {
        background: rgba(255, 255, 255, 0.2);
    }
    
    .message-text {
        background: rgba(255, 255, 255, 0.06);
        border: 1px solid var(--chatbot-border);
        color: var(--chatbot-text);
    }
    
    .typing-indicator {
        background: rgba(255, 255, 255, 0.06);
    }
    
    .chatbot-input {
        background: var(--chatbot-background);
        color: var(--chatbot-text);
    }
    
    .input-container {
        background-color: var(--chatbot-background);
        border-color: var(--chatbot-border);
    }
}

/* Screen reader only content */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* Main chatbot container */
.chatbot-container {
    position: fixed;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}

/* Position classes */
.chatbot-position-bottom_right {
    bottom: 20px;
    right: 20px;
}

.chatbot-position-bottom_left {
    bottom: 20px;
    left: 20px;
}

.chatbot-position-top_right {
    top: 20px;
    right: 20px;
}

.chatbot-position-top_left {
    top: 20px;
    left: 20px;
}

/* Chatbot toggle button */
.chatbot-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    background: var(--chatbot-primary-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: var(--chatbot-shadow);
    transition: var(--chatbot-transition);
    color: white;
}

.chatbot-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.chatbot-toggle:focus {
    outline: 2px solid var(--chatbot-primary-color);
    outline-offset: 2px;
}

.chatbot-toggle .chatbot-icon {
    transition: var(--chatbot-transition);
}

.chatbot-toggle:hover .chatbot-icon {
    transform: scale(1.1);
}

/* Notification badge */
.chatbot-notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    animation: pulse 2s infinite;
}

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

/* Chatbot window */
.chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: var(--chatbot-background);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

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

/* Header */
.chatbot-header {
    background: var(--chatbot-primary-color);
    color: white;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.chatbot-avatar {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chatbot-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

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

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #28a745;
}

.status-indicator.offline {
    background: #dc3545;
}

.chatbot-action-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 8px;
    border-radius: 4px;
    transition: var(--chatbot-transition);
}

.chatbot-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

.chatbot-action-btn:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
}

/* Privacy consent */
.chatbot-consent {
    padding: 20px;
    background: #f8f9fa;
    border-bottom: 1px solid var(--chatbot-border);
}

.chatbot-consent h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    font-weight: 600;
    color: var(--chatbot-text);
}

.chatbot-consent p {
    margin: 0 0 16px 0;
    font-size: 12px;
    color: var(--chatbot-text-light);
    line-height: 1.5;
}

.consent-actions {
    display: flex;
    gap: 8px;
}

.consent-actions button {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: var(--chatbot-transition);
}

.btn-primary {
    background: var(--chatbot-primary-color);
    color: white;
}

.btn-primary:hover {
    background: #0056b3;
}

.btn-secondary {
    background: var(--chatbot-secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: #545b62;
}

/* Messages container */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

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

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

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

/* Message styles */
.message {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: fadeIn 0.3s ease-out;
}

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

.message.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-message .message-avatar {
    background: var(--chatbot-primary-color);
    color: white;
}

.user-message .message-avatar {
    background: var(--chatbot-secondary-color);
    color: white;
}

.message-content {
    flex: 1;
}

.message-text {
    background: #f8f9fa;
    padding: 10px 12px;
    border-radius: 12px;
    color: var(--chatbot-text);
    word-wrap: break-word;
}

.user-message .message-text {
    background: var(--chatbot-primary-color);
    color: white;
}

.message-time {
    font-size: 11px;
    color: var(--chatbot-text-light);
    margin-top: 4px;
    text-align: right;
}

.user-message .message-time {
    text-align: left;
}

/* Typing indicator */
.chatbot-typing {
    padding: 0 16px;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 12px;
    width: fit-content;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chatbot-text-light);
    animation: typing 1.4s infinite ease-in-out;
}

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

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Input area */
.chatbot-input-area {
    border-top: 1px solid var(--chatbot-border);
    padding: 16px;
}

.input-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: flex-end;
}

.chatbot-input {
    flex: 1;
    border: 1px solid var(--chatbot-border);
    border-radius: 20px;
    padding: 10px 16px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    transition: var(--chatbot-transition);
}

.chatbot-input:focus {
    outline: none;
    border-color: var(--chatbot-primary-color);
    box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--chatbot-primary-color);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--chatbot-transition);
}

.chatbot-send-btn:disabled {
    background: var(--chatbot-secondary-color);
    cursor: not-allowed;
    opacity: 0.6;
}

.chatbot-send-btn:not(:disabled):hover {
    background: #0056b3;
    transform: scale(1.05);
}

.chatbot-send-btn:focus {
    outline: 2px solid var(--chatbot-primary-color);
    outline-offset: 2px;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    font-size: 12px;
    color: var(--chatbot-text-light);
}

.character-count {
    font-size: 11px;
}

.chat-history-link {
    color: var(--chatbot-primary-color);
    text-decoration: none;
    font-size: 11px;
}

.chat-history-link:hover {
    text-decoration: underline;
}

/* Enhanced Mobile responsive */
@media (max-width: 768px) {
    .chatbot-container {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    .chatbot-toggle {
        position: fixed;
        bottom: 20px;
        right: 20px;
        z-index: 10000;
        width: 56px;
        height: 56px;
        /* Improve touch target */
        min-width: 56px;
        min-height: 56px;
    }

    .chatbot-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        animation: slideInFromBottom 0.3s ease-out;
    }

    @keyframes slideInFromBottom {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .message {
        max-width: 90%;
    }

    .chatbot-messages {
        padding: 12px;
        gap: 12px;
    }

    .chatbot-input-area {
        padding: 12px;
    }

    .chatbot-input {
        font-size: 16px; /* Prevent zoom on iOS */
        padding: 12px 16px;
        border-radius: 24px;
    }

    .chatbot-send-btn {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }

    .message-text {
        font-size: 14px;
        line-height: 1.5;
        padding: 12px 16px;
        border-radius: 16px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
        min-width: 32px;
        min-height: 32px;
    }

    .chatbot-action-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 12px;
    }

    /* Improve input container layout */
    .input-container {
        display: flex;
        align-items: flex-end;
        gap: 12px;
        background-color: var(--chatbot-background);
        border: 1px solid var(--chatbot-border);
        border-radius: 24px;
        padding: 8px 12px;
        transition: var(--chatbot-transition);
    }

    .input-container:focus-within {
        border-color: var(--chatbot-primary-color);
        box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
    }

    .chatbot-input {
        border: none;
        background: transparent;
        padding: 8px 0;
    }
}

/* Tablet responsive improvements */
@media (min-width: 769px) and (max-width: 1024px) {
    .chatbot-window {
        width: 380px;
        height: 550px;
    }

    .chatbot-toggle {
        width: 64px;
        height: 64px;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .chatbot-header {
        padding: 12px;
    }

    .chatbot-title {
        font-size: 14px;
    }

    .chatbot-status {
        font-size: 11px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
    }

    .message-text {
        padding: 10px 14px;
        font-size: 13px;
        border-radius: 14px;
    }

    .chatbot-input {
        padding: 8px 0;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .chatbot-send-btn {
        width: 40px;
        height: 40px;
        min-width: 40px;
        min-height: 40px;
    }

    .chatbot-toggle {
        width: 52px;
        height: 52px;
        min-width: 52px;
        min-height: 52px;
    }

    .chatbot-messages {
        padding: 8px;
        gap: 10px;
    }

    .message {
        max-width: 95%;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .chatbot-toggle {
        border: 2px solid;
    }
    
    .message-text {
        border: 1px solid;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --chatbot-background: #2d3748;
        --chatbot-border: #4a5568;
        --chatbot-text: #e2e8f0;
        --chatbot-text-light: #a0aec0;
    }

    .message-text {
        background: #4a5568;
        color: var(--chatbot-text);
    }

    .chatbot-input {
        background: #4a5568;
        color: var(--chatbot-text);
        border-color: var(--chatbot-border);
    }

    .chatbot-consent {
        background: #4a5568;
    }

    .typing-indicator {
        background: #4a5568;
    }
}

/* Processing feedback */
.processing-feedback {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    margin: 8px 16px;
    background: rgba(0, 123, 255, 0.1);
    border: 1px solid rgba(0, 123, 255, 0.2);
    border-radius: 8px;
    opacity: 0.8;
    animation: feedbackPulse 2s infinite;
    transition: all 0.3s ease;
}

.processing-feedback .feedback-icon {
    margin-right: 10px;
    color: var(--chatbot-primary-color);
    flex-shrink: 0;
}

.processing-feedback .feedback-text {
    font-size: 13px;
    color: #555;
    font-style: italic;
    line-height: 1.4;
}

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

.feedback-fade-in {
    animation: feedbackFadeIn 0.4s ease-in;
}

.feedback-fade-out {
    animation: feedbackFadeOut 0.4s ease-out;
}

@keyframes feedbackFadeIn {
    from { 
        opacity: 0; 
        transform: translateY(-15px) scale(0.95); 
    }
    to { 
        opacity: 0.8; 
        transform: translateY(0) scale(1); 
    }
}

@keyframes feedbackFadeOut {
    from { 
        opacity: 0.8; 
        transform: translateY(0) scale(1); 
    }
    to { 
        opacity: 0; 
        transform: translateY(-15px) scale(0.95); 
    }
}

/* Dark mode support for processing feedback */
@media (prefers-color-scheme: dark) {
    .processing-feedback {
        background: rgba(0, 123, 255, 0.15);
        border-color: rgba(0, 123, 255, 0.3);
    }
    
    .processing-feedback .feedback-text {
        color: #cbd5e0;
    }
}

/* High contrast mode for processing feedback */
@media (prefers-contrast: high) {
    .processing-feedback {
        border-width: 2px;
        background: rgba(0, 123, 255, 0.2);
    }
    
    .processing-feedback .feedback-text {
        color: #000;
        font-weight: 500;
    }
}

/* Mobile responsive for processing feedback */
@media (max-width: 768px) {
    .processing-feedback {
        margin: 8px 12px;
        padding: 10px 14px;
    }
    
    .processing-feedback .feedback-text {
        font-size: 12px;
    }
}

/* Table Scroll Wrapper for Widget */
.message-text .table-scroll-wrapper {
    position: relative;
    overflow-x: auto;
    overflow-y: visible;
    margin: 0.5rem 0;
    border: 1px solid var(--chatbot-border);
    border-radius: 6px;
    background-color: var(--chatbot-background);
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}

.message-text .table-scroll-wrapper::-webkit-scrollbar {
    height: 8px;
}

.message-text .table-scroll-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.message-text .table-scroll-wrapper::-webkit-scrollbar-thumb {
    background: var(--chatbot-primary-color);
    border-radius: 4px;
    min-width: 20px;
}

.message-text .table-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: #0056b3;
}

/* Table styles in widget */
.message-text table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.8rem;
    min-width: 250px;
    background-color: transparent;
}

.message-text table th,
.message-text table td {
    padding: 0.375rem 0.5rem;
    text-align: left;
    border: 1px solid var(--chatbot-border);
    vertical-align: top;
    word-wrap: break-word;
    max-width: 150px;
}

.message-text table th {
    background-color: rgba(0, 0, 0, 0.05);
    font-weight: 600;
    white-space: nowrap;
    font-size: 0.75rem;
}

.message-text table tbody tr:nth-child(even) {
    background-color: rgba(0, 0, 0, 0.02);
}

.message-text table tbody tr:hover {
    background-color: rgba(0, 123, 255, 0.05);
}

/* User message table styles */
.user-message .message-text table th {
    background-color: rgba(255, 255, 255, 0.2);
    color: rgba(255, 255, 255, 0.9);
    border-color: rgba(255, 255, 255, 0.3);
}

.user-message .message-text table td {
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
}

.user-message .message-text table tbody tr:nth-child(even) {
    background-color: rgba(255, 255, 255, 0.1);
}

.user-message .message-text table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.15);
}

.user-message .message-text .table-scroll-wrapper {
    border-color: rgba(255, 255, 255, 0.3);
}

/* Mobile table improvements for widget */
@media (max-width: 768px) {
    .message-text table {
        font-size: 0.75rem;
        min-width: 220px;
    }
    
    .message-text table th,
    .message-text table td {
        padding: 0.25rem 0.375rem;
        max-width: 120px;
    }
    
    .message-text table th {
        font-size: 0.7rem;
    }
    
    .message-text .table-scroll-wrapper::-webkit-scrollbar {
        height: 6px;
    }
}

/* Small mobile devices table styles */
@media (max-width: 480px) {
    .message-text table {
        font-size: 0.7rem;
        min-width: 200px;
    }
    
    .message-text table th,
    .message-text table td {
        padding: 0.2rem 0.3rem;
        max-width: 100px;
    }
}

/* Scroll indicators for widget tables */
.message-text .table-scroll-wrapper::before,
.message-text .table-scroll-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 15px;
    pointer-events: none;
    z-index: 2;
    transition: opacity 0.3s ease;
}

.message-text .table-scroll-wrapper::before {
    left: 0;
    background: linear-gradient(to right, var(--chatbot-background), transparent);
    opacity: 0;
}

.message-text .table-scroll-wrapper::after {
    right: 0;
    background: linear-gradient(to left, var(--chatbot-background), transparent);
    opacity: 1;
}

.message-text .table-scroll-wrapper.scrolled-left::before {
    opacity: 1;
}

.message-text .table-scroll-wrapper.scrolled-right::after {
    opacity: 0;
}

.message-text .table-scroll-wrapper.fully-scrolled::after {
    opacity: 0;
}

/* Scroll hint for widget tables */
.message-text .table-scroll-wrapper.has-scroll-hint::after {
    content: '→';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--chatbot-primary-color);
    font-weight: bold;
    font-size: 1em;
    animation: scrollHint 2s ease-in-out infinite;
    pointer-events: none;
    z-index: 3;
}

@keyframes scrollHint {
    0%, 100% { opacity: 0.5; transform: translateY(-50%) translateX(0); }
    50% { opacity: 1; transform: translateY(-50%) translateX(3px); }
}

/* Dark mode table support */
@media (prefers-color-scheme: dark) {
    .message-text table th {
        background-color: rgba(255, 255, 255, 0.1);
    }
    
    .message-text table tbody tr:nth-child(even) {
        background-color: rgba(255, 255, 255, 0.02);
    }
    
    .message-text table tbody tr:hover {
        background-color: rgba(0, 123, 255, 0.1);
    }
    
    .message-text .table-scroll-wrapper::before {
        background: linear-gradient(to right, #2d3748, transparent);
    }
    
    .message-text .table-scroll-wrapper::after {
        background: linear-gradient(to left, #2d3748, transparent);
    }
}

/* NoScript fallback */
.chatbot-noscript {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border-radius: 8px;
    border: 1px solid #f5c6cb;
    max-width: 300px;
    font-size: 12px;
    z-index: 9999;
}
