/* ============================================
   Client Chat Portal - Main Stylesheet
   ============================================ */

/* CSS Custom Properties */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #3b82f6;
    --color-navy: #1e3a5f;
    --color-success: #22c55e;
    --color-warning: #eab308;
    --color-danger: #ef4444;
    --color-info: #06b6d4;
    --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --shadow-xl: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    --radius-sm: 0.5rem;
    --radius-md: 0.75rem;
    --radius-lg: 1rem;
    --radius-xl: 1.25rem;
    --radius-full: 9999px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: #1f2937;
    background: linear-gradient(135deg, #eff6ff 0%, #e0e7ff 50%, #f0f9ff 100%);
    min-height: 100vh;
}

html.dark body,
body.dark {
    background: linear-gradient(135deg, #111827 0%, #1e1b4b 50%, #0f172a 100%) !important;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: var(--radius-full);
}

.dark ::-webkit-scrollbar-thumb {
    background: #4b5563;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.dark ::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

/* Dark mode sidebar overlay */
.dark #sidebarOverlay {
    background: rgba(0, 0, 0, 0.7);
}

/* Focus Visible */
*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: 4px;
}

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

.message-wrapper {
    display: flex;
    gap: 0.625rem;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease-out;
}

.message-wrapper.client {
    flex-direction: row-reverse;
    margin-left: auto;
}

.message-wrapper.bot,
.message-wrapper.agent,
.message-wrapper.system {
    margin-right: auto;
}

.message-wrapper.system {
    max-width: 100%;
    justify-content: center;
}

/* Message Avatar */
.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 600;
    font-size: 0.875rem;
    margin-top: 2px;
}

.message-avatar.bot-avatar {
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    color: white;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}

.message-avatar.client-avatar {
    background: linear-gradient(135deg, #8b5cf6, #6d28d9);
    color: white;
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3);
}

.message-avatar.agent-avatar {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.3);
}

/* Message Bubble */
.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-xl);
    position: relative;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.5;
    font-size: 0.9375rem;
}

.message-bubble.bot-bubble {
    background: white;
    color: #1f2937;
    border: 1px solid #e5e7eb;
    border-bottom-left-radius: 0.375rem;
    box-shadow: var(--shadow-sm);
}

.dark .message-bubble.bot-bubble {
    background: #1f2937;
    color: #f3f4f6;
    border-color: #374151;
}

.message-bubble.client-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border-bottom-right-radius: 0.375rem;
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.25);
}

.message-bubble.agent-bubble {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
    border-bottom-left-radius: 0.375rem;
    box-shadow: 0 2px 12px rgba(34, 197, 94, 0.25);
}

.message-bubble.system-bubble {
    background: #f0f9ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
    font-size: 0.8125rem;
    text-align: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-full);
}

.dark .message-bubble.system-bubble {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #1e40af;
}

/* Message Meta */
.message-meta {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.25rem;
    font-size: 0.6875rem;
    color: #9ca3af;
}

.message-wrapper.client .message-meta {
    justify-content: flex-end;
}

.message-status {
    display: flex;
    align-items: center;
}

.message-status svg {
    width: 14px;
    height: 14px;
}

/* ============================================
   FAQ Section
   ============================================ */

.faq-section {
    animation: fadeInUp 0.4s ease-out;
}

.faq-heading {
    font-size: 0.8125rem;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
    text-align: center;
}

.dark .faq-heading {
    color: #9ca3af;
}

.faq-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.5rem;
}

.faq-card {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-normal);
    text-align: left;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dark .faq-card {
    background: #1f2937;
    border-color: #374151;
    color: #e5e7eb;
}

.faq-card:hover {
    border-color: var(--color-primary);
    background: #eff6ff;
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.15);
    transform: translateY(-1px);
}

.dark .faq-card:hover {
    background: #1e3a5f;
    border-color: #60a5fa;
}

.faq-card:active {
    transform: translateY(0);
}

.faq-card-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #eff6ff;
    color: var(--color-primary);
}

.dark .faq-card-icon {
    background: #1e3a5f;
    color: #60a5fa;
}

.faq-card-icon svg {
    width: 18px;
    height: 18px;
}

/* Horizontal scroll for mobile FAQ */
@media (max-width: 640px) {
    .faq-grid {
        display: flex;
        overflow-x: auto;
        gap: 0.625rem;
        padding-bottom: 0.5rem;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
    }

    .faq-card {
        flex-shrink: 0;
        width: auto;
        min-width: 160px;
        scroll-snap-align: start;
    }
}

/* ============================================
   Typing Indicator
   ============================================ */

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0.75rem 1rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: #94a3b8;
    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); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

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

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

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

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

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

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

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toastSlideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(34, 197, 94, 0); }
}

.animate-pulse-glow {
    animation: pulseGlow 2s ease-in-out infinite;
}

/* ============================================
   Toast Notifications
   ============================================ */

.toast {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    border-left: 4px solid var(--color-primary);
    min-width: 280px;
    max-width: 400px;
    animation: toastSlideIn 0.3s ease-out;
    pointer-events: auto;
    font-size: 0.875rem;
}

.toast.success { border-left-color: var(--color-success); }
.toast.warning { border-left-color: var(--color-warning); }
.toast.error { border-left-color: var(--color-danger); }
.toast.info { border-left-color: var(--color-info); }

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.toast-message {
    flex: 1;
    color: #374151;
    font-weight: 500;
}

.toast-close {
    flex-shrink: 0;
    cursor: pointer;
    color: #9ca3af;
    transition: color var(--transition-fast);
    background: none;
    border: none;
    padding: 0;
}

.toast-close:hover {
    color: #374151;
}

.toast.removing {
    animation: toastSlideOut 0.3s ease-in forwards;
}

.dark .toast {
    background: #1f2937;
    border-color: #374151;
}

.dark .toast-message {
    color: #e5e7eb;
}

/* ============================================
   Attachment Styles
   ============================================ */

.attachment-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-md);
}

.dark .attachment-preview {
    background: #374151;
    border-color: #4b5563;
}

.attachment-thumb {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    border: 1px solid #e2e8f0;
}

.attachment-file-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    background: #eff6ff;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-primary);
}

.dark .attachment-file-icon {
    background: #1e3a5f;
}

.attachment-info {
    flex: 1;
    min-width: 0;
}

.attachment-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #374151;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dark .attachment-name {
    color: #e5e7eb;
}

.attachment-size {
    font-size: 0.6875rem;
    color: #9ca3af;
}

.attachment-remove {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fee2e2;
    color: #ef4444;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: none;
    padding: 0;
}

.attachment-remove:hover {
    background: #fecaca;
}

/* Chat message attachments */
.chat-attachment {
    margin-top: 0.5rem;
    border-radius: var(--radius-md);
    overflow: hidden;
}

.chat-attachment img {
    max-width: 240px;
    max-height: 180px;
    object-fit: cover;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform var(--transition-normal);
}

.chat-attachment img:hover {
    transform: scale(1.02);
}

.chat-file-attachment {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.625rem;
    background: rgba(255,255,255,0.15);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chat-file-attachment:hover {
    background: rgba(255,255,255,0.25);
}

.message-bubble.bot-bubble .chat-file-attachment {
    background: #f1f5f9;
}

.dark .message-bubble.bot-bubble .chat-file-attachment {
    background: #374151;
}

/* ============================================
   Agent Status
   ============================================ */

.agent-status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: #ecfdf5;
    border-bottom: 1px solid #d1fae5;
    font-size: 0.8125rem;
    color: #065f46;
    font-weight: 500;
}

.dark .agent-status-bar {
    background: #064e3b;
    border-color: #065f46;
    color: #6ee7b7;
}

.agent-status-bar.connecting {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}

.dark .agent-status-bar.connecting {
    background: #78350f;
    border-color: #92400e;
    color: #fcd34d;
}

/* ============================================
   Empty & Error States
   ============================================ */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
}

.empty-state-icon.info {
    background: #eff6ff;
    color: var(--color-primary);
}

.empty-state-icon.warning {
    background: #fef3c7;
    color: #d97706;
}

.empty-state-icon.error {
    background: #fef2f2;
    color: #dc2626;
}

.empty-state-title {
    font-size: 1rem;
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.25rem;
}

.dark .empty-state-title {
    color: #f3f4f6;
}

.empty-state-desc {
    font-size: 0.8125rem;
    color: #6b7280;
    margin-bottom: 1rem;
    max-width: 280px;
}

.dark .empty-state-desc {
    color: #9ca3af;
}

.empty-state-btn {
    padding: 0.5rem 1.25rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.empty-state-btn:hover {
    background: var(--color-primary-dark);
}

/* ============================================
   Offline Banner
   ============================================ */

.offline-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.8125rem;
    font-weight: 500;
    text-align: center;
}

.dark .offline-banner {
    background: #78350f;
    color: #fcd34d;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Desktop */
@media (min-width: 1024px) {
    #chatPortal {
        height: 90vh;
    }
}

/* Tablet */
@media (max-width: 1023px) {
    #sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        bottom: 0;
        z-index: 40;
        transition: left var(--transition-normal);
    }

    #sidebar.open {
        left: 0;
    }

    #sidebarOverlay.visible {
        display: block;
    }
}

/* Mobile */
@media (max-width: 640px) {
    body {
        padding: 0;
    }

    #chatPortal {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
        max-width: 100%;
    }

    .message-wrapper {
        max-width: 92%;
    }

    #chatMessages {
        padding: 0.75rem;
    }

    .faq-heading {
        padding: 0 0.25rem;
    }
}

/* ============================================
   High Contrast / Accessibility
   ============================================ */

@media (prefers-contrast: high) {
    .message-bubble.bot-bubble {
        border-width: 2px;
    }

    .faq-card {
        border-width: 2px;
    }
}

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

/* ============================================
   Print
   ============================================ */

@media print {
    #chatPortal {
        box-shadow: none;
        border: 1px solid #d1d5db;
    }

    #chatInputArea,
    #floatingChatBtn,
    #toastContainer,
    .faq-section {
        display: none !important;
    }
}
