/**
 * Chat Dashboard Styles - 2 Column Layout
 * Matches Email page design patterns
 * VERSION: 2025-12-19
 */

/* ============================================
   PAGE LAYOUT - 2 COLUMNS
   ============================================ */

.chat-page {
    height: calc(100vh - 64px);
    padding: 0;
    overflow: hidden;
    background: #F9FAFB;
}

.chat-layout {
    display: grid;
    grid-template-columns: 384px 4px 1fr;
    height: 100%;
}

/* Resize Handle */
.chat-resize-handle {
    width: 4px;
    background: #E5E7EB;
    cursor: col-resize;
    position: relative;
    transition: background 0.15s ease;
}

.chat-resize-handle:hover,
.chat-resize-handle.dragging {
    background: #155DFC;
}

.chat-resize-handle::before {
    content: '';
    position: absolute;
    left: -4px;
    right: -4px;
    top: 0;
    bottom: 0;
}

/* ============================================
   LEFT PANEL - CONVERSATION LIST
   ============================================ */

.chat-list-panel {
    background: #FFFFFF;
    border-right: 1px solid #E5E7EB;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Search */
.chat-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px;
    border-bottom: 1px solid #E5E7EB;
}

.chat-search img {
    opacity: 0.5;
    flex-shrink: 0;
}

.chat-search-input {
    flex: 1;
    border: 1px solid #D1D5DB;
    border-radius: 10px;
    padding: 8px 16px 8px 8px;
    font-size: 14px;
    color: #111827;
    background: transparent;
}

.chat-search-input:focus {
    outline: none;
    border-color: #155DFC;
}

.chat-search-input::placeholder {
    color: rgba(10, 10, 10, 0.5);
}

/* Filters Section */
.chat-filters-section {
    padding: 16px;
    border-bottom: 1px solid #E5E7EB;
}

.chat-filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.chat-filters-title {
    font-size: 12px;
    font-weight: 500;
    color: #6A7282;
    text-transform: uppercase;
    margin: 0;
}

.chat-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: none;
    border: none;
    border-radius: 6px;
    color: #6A7282;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-settings-btn:hover {
    background: #F3F4F6;
    color: #155DFC;
}

/* Status Filters */
.chat-status-filters {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-status-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.chat-status-btn:hover {
    background: #F3F4F6;
}

.chat-status-btn.active {
    background: #EFF6FF;
}

.chat-status-btn.active .chat-status-label {
    color: #1447E6;
    font-weight: 500;
}

.chat-status-label {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: #364153;
}

.chat-status-count {
    font-size: 12px;
    font-weight: 500;
    color: #364153;
    background: #E5E7EB;
    padding: 2px 8px;
    border-radius: 9999px;
    min-width: 24px;
    text-align: center;
}

.chat-status-btn.active .chat-status-count {
    background: #BEDBFF;
    color: #1447E6;
}

/* Conversation List */
.chat-conversation-list {
    flex: 1;
    overflow-y: auto;
}

/* Loading State */
.chat-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #6A7282;
    gap: 12px;
}

.chat-loading-spinner {
    width: 24px;
    height: 24px;
    border: 3px solid #E5E7EB;
    border-top-color: #155DFC;
    border-radius: 50%;
    animation: chatSpin 0.8s linear infinite;
}

@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.chat-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #6A7282;
    text-align: center;
    gap: 12px;
}

.chat-empty svg {
    color: #D1D5DB;
}

.chat-empty p {
    font-size: 15px;
    font-weight: 500;
    color: #374151;
    margin: 0;
}

.chat-empty span {
    font-size: 13px;
    color: #6A7282;
}

/* Conversation Item */
.chat-conversation-item {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid #E5E7EB;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-conversation-item:hover {
    background: #F9FAFB;
}

.chat-conversation-item.selected {
    background: #EFF6FF;
}

.chat-conversation-item.unread {
    background: #FEFCE8;
}

.chat-conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6A7282;
    flex-shrink: 0;
}

.chat-conversation-avatar.online::after {
    content: '';
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #10B981;
    border: 2px solid #FFFFFF;
    border-radius: 50%;
}

.chat-conversation-content {
    flex: 1;
    min-width: 0;
}

.chat-conversation-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 4px;
}

.chat-conversation-name {
    font-size: 14px;
    font-weight: 600;
    color: #101828;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Customer link in conversation list */
a.chat-customer-link {
    color: #7C3AED;
    text-decoration: none;
    transition: color 0.15s ease;
}

a.chat-customer-link:hover {
    color: #6D28D9;
    text-decoration: underline;
}

/* No avatar layout adjustment */
.chat-conversation-content.chat-no-avatar {
    padding-left: 4px;
}

.chat-conversation-time {
    font-size: 12px;
    color: #6A7282;
    white-space: nowrap;
    flex-shrink: 0;
}

.chat-conversation-preview {
    font-size: 13px;
    color: #6A7282;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-bottom: 8px;
}

.chat-conversation-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.chat-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 8px;
}

.chat-tag-status {
    background: #D1FAE5;
    color: #065F46;
}

.chat-tag-status.handed-off {
    background: #FEF3C7;
    color: #92400E;
}

.chat-tag-status.resolved {
    background: #E5E7EB;
    color: #6B7280;
}

.chat-tag-intent {
    background: #DBEAFE;
    color: #1E40AF;
}

/* Source tags - Onsite (widget) vs Offsite (public chat) */
.chat-tag-source {
    font-size: 10px;
    font-weight: 500;
    padding: 2px 6px;
    border-radius: 4px;
}

.chat-tag-source-onsite {
    background: #ECFDF5;
    color: #047857;
}

.chat-tag-source-offsite {
    background: #EEF2FF;
    color: #4338CA;
}

/* ============================================
   RIGHT PANEL - CONVERSATION DETAIL
   ============================================ */

.chat-detail-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #F9FAFB;
    height: 100%;
}

/* Empty State */
.chat-detail-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    color: #6A7282;
    padding: 40px;
}

.chat-detail-empty svg {
    color: #D1D5DB;
    margin-bottom: 16px;
}

.chat-detail-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 8px 0;
}

.chat-detail-empty p {
    font-size: 14px;
    margin: 0;
}

/* Detail Content */
.chat-detail-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Detail Header */
.chat-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: #FFFFFF;
    border-bottom: 1px solid #E5E7EB;
}

.chat-visitor-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-visitor-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #E5E7EB;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6A7282;
}

.chat-visitor-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-visitor-name {
    font-size: 15px;
    font-weight: 600;
    color: #101828;
}

.chat-visitor-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #6A7282;
}

.chat-visitor-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    background: #D1FAE5;
    color: #065F46;
}

.chat-visitor-status.handed-off {
    background: #FEF3C7;
    color: #92400E;
}

.chat-visitor-status.resolved {
    background: #E5E7EB;
    color: #6B7280;
}

.chat-visitor-status::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
}

/* Detail Actions */
.chat-detail-actions {
    display: flex;
    gap: 8px;
}

.chat-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: #F3F4F6;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #364153;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-action-btn:hover {
    background: #E5E7EB;
}

.chat-action-btn.active {
    background: #155DFC;
    color: #FFFFFF;
}

.chat-action-resolve {
    color: #059669;
}

.chat-action-resolve:hover {
    background: #D1FAE5;
}

/* Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Message Bubble */
.chat-message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
}

.chat-message.inbound {
    align-self: flex-start;
}

.chat-message.outbound {
    align-self: flex-end;
}

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

.chat-message.inbound .chat-message-bubble {
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-bottom-left-radius: 4px;
    color: #364153;
}

.chat-message.outbound .chat-message-bubble {
    background: #155DFC;
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.chat-message.outbound.ai .chat-message-bubble {
    background: linear-gradient(135deg, #6366F1 0%, #8B5CF6 100%);
}

.chat-message-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 11px;
    color: #9CA3AF;
}

.chat-message.outbound .chat-message-meta {
    justify-content: flex-end;
}

.chat-message-sender {
    font-weight: 500;
}

/* Typing Indicator */
.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: #F3F4F6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    max-width: fit-content;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
}

.chat-typing-dots span {
    width: 6px;
    height: 6px;
    background: #9CA3AF;
    border-radius: 50%;
    animation: chatTyping 1.4s infinite;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatTyping {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

.chat-typing-text {
    font-size: 12px;
    color: #6A7282;
}

/* System Message */
.chat-system-message {
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
    color: #6A7282;
    background: #F9FAFB;
    border-radius: 8px;
    align-self: center;
}

/* Input Area */
.chat-input-area {
    border-top: 1px solid #E5E7EB;
    background: #FFFFFF;
}

.chat-takeover-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #FEF3C7;
    font-size: 13px;
    color: #92400E;
}

.chat-input-form {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 16px;
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid #D1D5DB;
    border-radius: 12px;
    padding: 12px 16px;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    max-height: 120px;
    overflow-y: auto;
}

.chat-input:focus {
    outline: none;
    border-color: #155DFC;
    box-shadow: 0 0 0 3px rgba(21, 93, 252, 0.1);
}

.chat-input::placeholder {
    color: #9CA3AF;
}

.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: #155DFC;
    border: none;
    border-radius: 12px;
    color: #FFFFFF;
    cursor: pointer;
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    background: #1447E6;
}

.chat-send-btn:disabled {
    background: #9CA3AF;
    cursor: not-allowed;
}

/* ============================================
   SETTINGS MODAL
   ============================================ */

.chat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: chatFadeIn 0.15s ease;
}

.chat-modal {
    background: #FFFFFF;
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    margin: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    animation: chatModalSlideIn 0.2s ease;
}

.chat-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid #E5E7EB;
}

.chat-modal-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: #101828;
    margin: 0;
}

.chat-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: none;
    border-radius: 8px;
    color: #6A7282;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-modal-close:hover {
    background: #F3F4F6;
    color: #374151;
}

.chat-modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-settings-section {
    margin-bottom: 24px;
}

.chat-settings-section:last-child {
    margin-bottom: 0;
}

.chat-settings-section h3 {
    font-size: 14px;
    font-weight: 600;
    color: #101828;
    margin: 0 0 16px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid #E5E7EB;
}

.chat-settings-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.chat-settings-row:last-child {
    margin-bottom: 0;
}

.chat-settings-row label {
    font-size: 14px;
    color: #374151;
}

.chat-settings-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

.chat-settings-row input[type="text"],
.chat-settings-row input[type="color"],
.chat-settings-row select,
.chat-settings-row textarea {
    padding: 8px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 14px;
    color: #374151;
    min-width: 200px;
}

.chat-settings-row input[type="color"] {
    width: 44px;
    height: 36px;
    padding: 4px;
    cursor: pointer;
}

.chat-settings-row textarea {
    resize: vertical;
    min-height: 60px;
}

.chat-settings-row input:focus,
.chat-settings-row select:focus,
.chat-settings-row textarea:focus {
    outline: none;
    border-color: #155DFC;
}

.chat-settings-slider {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-settings-slider input[type="range"] {
    width: 160px;
    cursor: pointer;
}

.chat-settings-slider span {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    min-width: 40px;
}

.chat-settings-hint {
    font-size: 13px;
    color: #6A7282;
    margin: 0 0 12px 0;
}

/* Embed Code */
.chat-embed-code {
    position: relative;
    background: #1F2937;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
}

.chat-embed-code code {
    display: block;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 12px;
    color: #E5E7EB;
    white-space: pre-wrap;
    word-break: break-all;
}

.chat-copy-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #E5E7EB;
    cursor: pointer;
    transition: background 0.15s ease;
}

.chat-copy-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-copy-btn.copied {
    background: #10B981;
    color: #FFFFFF;
}

/* Modal Footer */
.chat-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px;
    border-top: 1px solid #E5E7EB;
}

.chat-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-btn-secondary {
    background: #F3F4F6;
    border: 1px solid #E5E7EB;
    color: #374151;
}

.chat-btn-secondary:hover {
    background: #E5E7EB;
}

.chat-btn-primary {
    background: #155DFC;
    border: none;
    color: #FFFFFF;
}

.chat-btn-primary:hover {
    background: #1447E6;
}

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

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

/* ============================================
   MOBILE NAVIGATION
   ============================================ */

.chat-mobile-nav {
    display: none;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border-bottom: 1px solid #E5E7EB;
    padding: 12px 16px;
    z-index: 100;
}

.chat-mobile-back {
    display: flex;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 500;
    color: #155DFC;
    cursor: pointer;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

/* Tablet - Narrower left panel */
@media (max-width: 1200px) {
    .chat-layout {
        grid-template-columns: 340px 4px 1fr;
    }
}

/* Tablet Portrait - Stack on selection */
@media (max-width: 1024px) {
    .chat-layout {
        grid-template-columns: 1fr;
    }

    .chat-resize-handle {
        display: none;
    }

    .chat-list-panel {
        max-width: none;
    }

    .chat-list-panel.hidden {
        display: none;
    }

    .chat-detail-panel {
        display: none;
        position: fixed;
        top: 64px;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        padding-top: 60px;
    }

    .chat-detail-panel.active {
        display: flex;
    }

    .chat-mobile-nav {
        display: none;
    }

    .chat-mobile-nav.active {
        display: block;
    }
}

/* Mobile - Full screen panels */
@media (max-width: 768px) {
    .chat-page {
        height: calc(100vh - 56px);
    }

    .chat-filters-section {
        padding: 12px;
    }

    .chat-conversation-item {
        padding: 12px;
    }

    .chat-detail-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 12px;
    }

    .chat-detail-actions {
        width: 100%;
    }

    .chat-action-btn {
        flex: 1;
        justify-content: center;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-message {
        max-width: 85%;
    }

    .chat-input-form {
        padding: 12px;
    }

    .chat-modal {
        margin: 12px;
        max-height: 95vh;
    }

    .chat-settings-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .chat-settings-row input[type="text"],
    .chat-settings-row select,
    .chat-settings-row textarea {
        width: 100%;
        min-width: unset;
    }
}

/* Small Mobile */
@media (max-width: 480px) {
    .chat-status-filters {
        gap: 2px;
    }

    .chat-status-btn {
        padding: 6px 10px;
    }

    .chat-conversation-preview {
        -webkit-line-clamp: 1;
    }

    .chat-conversation-tags {
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .chat-tag {
        flex-shrink: 0;
    }
}

/* ============================================
   TRANSLATION FEATURES
   ============================================ */

/* Language badge in conversation header */
.chat-visitor-language {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #FEF3C7;
    color: #92400E;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    margin-left: 8px;
}

/* Translate button in message bubbles */
.chat-translate-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    margin-top: 8px;
    background: transparent;
    border: 1px solid #E5E7EB;
    border-radius: 4px;
    font-size: 11px;
    color: #6B7280;
    cursor: pointer;
    transition: all 0.15s ease;
}

.chat-translate-btn:hover {
    background: #F3F4F6;
    border-color: #D1D5DB;
    color: #374151;
}

.chat-translate-btn:disabled {
    opacity: 0.6;
    cursor: wait;
}

.chat-translate-btn svg {
    flex-shrink: 0;
}

/* Message content wrapper */
.chat-message-content {
    word-break: break-word;
}

/* Inbound message translate button styling */
.chat-message.inbound .chat-translate-btn {
    background: rgba(255, 255, 255, 0.8);
}

.chat-message.inbound .chat-translate-btn:hover {
    background: rgba(255, 255, 255, 1);
}
