/* LiveChat Host Panel - ChatWay Style */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: #f8fafc;
    color: #1f2937;
    line-height: 1.5;
}

/* ==================== LOGIN PAGE ==================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: white;
    padding: 48px 40px;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-logo {
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 28px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 8px;
}

.login-subtitle {
    color: #6b7280;
    margin-bottom: 32px;
}

.login-credit {
    color: #374151;
    font-size: 18px;
    font-weight: 700;
    margin-top: 4px;
    margin-bottom: 26px;
}

.login-credit span {
    color: #ef4444;
}

.form-group {
    text-align: left;
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    font-size: 15px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: #f97316;
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

.error-message {
    background: #fef2f2;
    color: #dc2626;
    padding: 12px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 16px;
    display: none;
}

.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: #f97316;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

.btn-primary:hover {
    background: #ea580c;
    transform: translateY(-1px);
}

/* ==================== DASHBOARD ==================== */
.dashboard {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 64px;
    background: #1f2937;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 16px 0;
}

.sidebar-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 24px;
}

.logo {
    padding: 8px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: #9ca3af;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.2s, color 0.2s;
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.nav-btn.active {
    background: #f97316;
    color: white;
}

.nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: #ef4444;
    color: white;
    font-size: 10px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 0 8px;
}

.host-profile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.host-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #f97316;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.status-select {
    width: 100%;
    padding: 4px;
    border: none;
    background: transparent;
    color: #9ca3af;
    font-size: 11px;
    cursor: pointer;
    text-align: center;
}

.status-select:focus {
    outline: none;
}

.logout-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #9ca3af;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.logout-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Conversation List Panel */
.conv-list-panel {
    width: 320px;
    background: white;
    border-right: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

.conv-list-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.conv-list-header h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 12px;
}

.event-controls {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-bottom: 10px;
}

.event-controls select {
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    background: white;
    cursor: pointer;
}

.new-event-btn {
    border: 1px solid #ea580c;
    border-radius: 6px;
    background: #f97316;
    color: white;
    padding: 8px 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.new-event-btn:hover { background: #ea580c; }
.new-event-btn:disabled { cursor: wait; opacity: .7; }

.conv-filters select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    cursor: pointer;
}

.conv-list {
    flex: 1;
    overflow-y: auto;
}

.conv-item {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    transition: background 0.2s;
}

.conv-item:hover {
    background: #f9fafb;
}

.conv-item.active {
    background: #fff7ed;
    border-left: 3px solid #f97316;
}

.conv-item.unread {
    background: #fffbeb;
}

.conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #e5e7eb;
    color: #6b7280;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.conv-avatar.pending {
    background: #fef3c7;
    color: #d97706;
}

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

.conv-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.conv-name {
    font-weight: 600;
    font-size: 14px;
    color: #1f2937;
}

.conv-time {
    font-size: 12px;
    color: #9ca3af;
}

.conv-preview {
    font-size: 13px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.unread-indicator {
    width: 8px;
    height: 8px;
    background: #f97316;
    border-radius: 50%;
    flex-shrink: 0;
}

.conv-footer {
    margin-top: 6px;
}

.conv-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: capitalize;
}

.status-pending {
    background: #fef3c7;
    color: #d97706;
}

.status-active {
    background: #dcfce7;
    color: #16a34a;
}

.status-closed {
    background: #f3f4f6;
    color: #6b7280;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: #9ca3af;
}

.empty-state p {
    margin-top: 12px;
}

.loading {
    padding: 40px 20px;
    text-align: center;
    color: #9ca3af;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    min-width: 0;
    min-height: 0; /* let the column children (chat-view) constrain & scroll */
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    position: relative;
}

.no-chat-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.no-chat-content {
    text-align: center;
    color: #9ca3af;
}

.no-chat-content h3 {
    margin-top: 16px;
    font-size: 18px;
    color: #6b7280;
}

.no-chat-content p {
    margin-top: 8px;
    font-size: 14px;
}

.chat-view {
    flex: 1;
    min-height: 0; /* allow inner message list to scroll instead of growing */
    display: flex;
    flex-direction: column;
    background: white;
}

.chat-header {
    flex: none; /* never shrink the header */
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: white;
}

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

.chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #f97316;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 18px;
}

.chat-header-text h3 {
    font-size: 16px;
    font-weight: 600;
}

.visitor-status {
    font-size: 13px;
    color: #6b7280;
}

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

.action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 6px;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
}

.action-btn:hover {
    background: #f3f4f6;
    color: #1f2937;
}

.action-btn.is-active {
    background: #fff7ed;
    border-color: #fdba74;
    color: #c2410c;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Messages */
.messages-container {
    flex: 1 1 auto;
    min-height: 0; /* critical: lets this scroll instead of pushing the input off-screen */
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.message {
    display: flex;
    max-width: 70%;
}

.message-visitor {
    align-self: flex-start;
}

.message-host {
    align-self: flex-end;
}

.message-system {
    align-self: center;
    max-width: 100%;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
}

.message-visitor .message-bubble {
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.message-host .message-bubble {
    background: #f97316;
    color: white;
    border-bottom-right-radius: 4px;
}

.message-text {
    word-wrap: break-word;
    white-space: pre-wrap;
    line-height: 1.5;
}

.message-image-wrap {
    max-width: 280px;
}

.message-image {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.12);
}

.message-caption {
    margin-top: 8px;
}

.message-save-btn {
    display: inline-flex;
    margin-top: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #c2410c;
    background: #fff7ed;
    border: 1px solid #fdba74;
    border-radius: 6px;
    padding: 4px 8px;
    text-decoration: none;
}

.message-save-btn:hover {
    background: #ffedd5;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
}

.message-system {
    font-size: 13px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 8px 16px;
    border-radius: 20px;
}

/* Typing Indicator */
.typing-indicator {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 24px 16px;
    font-size: 13px;
    color: #6b7280;
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

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

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.8); }
    40% { transform: scale(1.2); }
}

/* Chat Input */
.chat-input-container {
    flex: none; /* always pinned at the bottom, never pushed off-screen */
    padding: 10px 16px;
    border-top: 1px solid #e5e7eb;
    background: white;
    position: relative; /* anchor for the emoji picker popup */
}

/* Emoji picker popup */
.emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 16px;
    width: 320px;
    max-width: calc(100% - 32px);
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 10px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16);
    z-index: 50;
}

.emoji-item {
    width: 38px;
    height: 38px;
    border: none;
    background: transparent;
    border-radius: 8px;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, transform 0.12s;
}

.emoji-item:hover {
    background: #f3f4f6;
    transform: scale(1.15);
}

.emoji-picker::-webkit-scrollbar { width: 6px; }
.emoji-picker::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: #f3f4f6;
    border-radius: 12px;
    padding: 8px 12px;
}

.attach-btn {
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.attach-btn:hover {
    background: rgba(249, 115, 22, 0.12);
    color: #c2410c;
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.5;
    min-height: 22px;
    max-height: 160px;
    padding: 6px 0;
    overflow-y: auto;
    outline: none;
    min-width: 0;
}

.send-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: #f97316;
    color: white;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.2s;
}

.send-btn:hover {
    background: #ea580c;
    transform: scale(1.05);
}

/* Visitor Panel */
.visitor-panel {
    width: 280px;
    background: white;
    border-left: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
}

.visitor-panel-header {
    padding: 20px;
    border-bottom: 1px solid #e5e7eb;
}

.visitor-panel-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.visitor-panel-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
}

.visitor-info-item {
    margin-bottom: 20px;
}

.visitor-info-item label {
    display: block;
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.visitor-info-item span {
    font-size: 14px;
    color: #1f2937;
    word-break: break-all;
}

.truncate {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    text-transform: capitalize;
}

/* Scrollbars */
.conv-list::-webkit-scrollbar,
.messages-container::-webkit-scrollbar,
.visitor-panel-content::-webkit-scrollbar {
    width: 6px;
}

.conv-list::-webkit-scrollbar-track,
.messages-container::-webkit-scrollbar-track,
.visitor-panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.conv-list::-webkit-scrollbar-thumb,
.messages-container::-webkit-scrollbar-thumb,
.visitor-panel-content::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 1024px) {
    .visitor-panel {
        display: none !important;
    }
}

@media (max-width: 768px) {
    .conv-list-panel {
        width: 280px;
    }
}

@media (max-width: 640px) {
    .dashboard {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 60px;
        flex-direction: row;
        padding: 0 16px;
    }
    
    .sidebar-header {
        flex-direction: row;
    }
    
    .sidebar-footer {
        flex-direction: row;
    }
    
    .host-profile {
        flex-direction: row;
    }
    
    .conv-list-panel {
        width: 100%;
        height: 40%;
    }
    
    .chat-panel {
        height: 60%;
    }
}
