:root {
    --primary-gradient: linear-gradient(135deg, #FF8E53 0%, #FF6B35 100%);
    --bg-color: #f8f8f8;
    --chat-bg: #ffffff;
    --text-main: #333333;
    --text-muted: #888888;
    --user-msg-bg: #FFF5F0;
    /* Light Orange */
    --support-msg-bg: #f5f5f5;
    /* Light Gray */
    --accent-color: #FF6B35;
    --header-height: 70px;
    --footer-min-height: 80px;
    --input-bg: #f5f5f5;
    --border-color: #eee;
    --sidebar-bg: #ffffff;
    --sidebar-hover: #f8f9fa;
    --sidebar-active: #FFF5F0;
    --sidebar-border: #eee;
}

[data-theme="dark"] {
    --bg-color: #111827;
    --chat-bg: #1f2937;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
    --user-msg-bg: #374151;
    /* Dark Gray instead of Blue */
    --support-msg-bg: #4b5563;
    /* Lighter Gray */
    --primary-gradient: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    /* Dark Gray/Black gradient */
    --input-bg: #374151;
    --border-color: #374151;
    --sidebar-bg: #111827;
    --sidebar-hover: #1f2937;
    --sidebar-active: #374151;
    /* Dark Gray active state */
    --sidebar-border: #374151;
    --accent-color: #6b7280;
    /* Gray accent */
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    height: 100vh;
    height: 100dvh;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-main);
    overflow: hidden;
    overscroll-behavior: none;
}

.chat-container {
    width: 100%;
    max-width: 500px;
    height: 100vh;
    height: 100dvh;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    position: relative;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Header Styles */
.chat-header {
    height: var(--header-height);
    background: var(--primary-gradient);
    color: white;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 10;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: inherit;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 5px;
    transition: opacity 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    opacity: 0.8;
}

.avatar-container {
    position: relative;
}

.support-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: white;
    padding: 2px;
}

.online-indicator {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #2ecc71;
    border: 2px solid var(--chat-bg);
    border-radius: 50%;
}

.header-info h1 {
    font-size: 1rem;
    font-weight: 600;
}

.header-info .status {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Message Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--chat-bg);
    /* Use variable */
    overscroll-behavior: contain;
}

.history-separator {
    text-align: center;
    margin: 10px 0;
    position: relative;
}

.history-separator span {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--chat-bg);
    padding: 0 10px;
    position: relative;
    z-index: 1;
}

/* Loader Styles */
.loader-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    width: 100%;
}

.spinner {
    width: 30px;
    height: 30px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--accent-color);
    animation: spin 1s ease-in-out infinite;
}

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

.session-end-notice span {
    color: #ff4d4f;
    font-weight: 700;
    border: 1px solid #ff4d4f;
    border-radius: 20px;
    padding: 5px 15px;
}

#messageInput:disabled {
    cursor: not-allowed;
    color: #ccc;
}

/* Message Bubble Styles */
.message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.4;
    position: relative;
    animation: fadeIn 0.3s ease-out;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    align-self: flex-end;
    background: var(--user-msg-bg);
    color: var(--text-main);
    border-bottom-right-radius: 2px;
}

.message.support {
    align-self: flex-start;
    background: var(--support-msg-bg);
    color: var(--text-main);
    border-bottom-left-radius: 2px;
}

.message-content img {
    max-width: 100%;
    border-radius: 8px;
    margin: 5px 0;
    display: block;
}

.message-content video {
    max-width: 100%;
    border-radius: 8px;
    margin: 5px 0;
    display: block;
}

.message-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 5px;
    display: block;
}

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

/* Emoji Picker */
.emoji-picker {
    position: absolute;
    bottom: 90px;
    left: 20px;
    background: white;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 10px;
    box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.emoji-list {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    font-size: 1.5rem;
}

.emoji-list span {
    cursor: pointer;
    transition: transform 0.1s;
}

.emoji-list span:hover {
    transform: scale(1.2);
}

/* Footer Input Area */
.chat-footer {
    padding: 15px 20px 30px 20px;
    background: var(--chat-bg);
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border-radius: 25px;
    padding: 5px 5px 5px 15px;
    gap: 10px;
    transition: background 0.3s;
}

.input-wrapper:focus-within {
    background: var(--chat-bg);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

.input-actions {
    display: flex;
    gap: 10px;
    color: var(--text-muted);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 0.9rem;
    outline: none;
    color: var(--text-main);
}

.send-btn {
    background: var(--primary-gradient);
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.send-btn:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.send-btn:active {
    transform: scale(0.98);
}

/* Scrollbar Styles */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 10px;
}

/* Preview Overlay */
.preview-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(5px);
}

.preview-content {
    background: white;
    width: 90%;
    max-width: 400px;
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.preview-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.preview-header h3 {
    font-size: 1rem;
}

.close-preview {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: #666;
}

.preview-body {
    padding: 20px;
    background: #f9f9f9;
    display: flex;
    justify-content: center;
    max-height: 400px;
    min-height: 200px;
}

.preview-body img,
.preview-body video {
    max-width: 100%;
    max-height: 350px;
    border-radius: 10px;
    object-fit: contain;
}

.preview-footer {
    padding: 15px 20px;
    display: flex;
    gap: 15px;
    background: white;
}

.cancel-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 12px;
    background: #f5f5f5;
    cursor: pointer;
    font-weight: 500;
}

.confirm-btn {
    flex: 2;
    padding: 12px;
    border: none;
    border-radius: 12px;
    background: var(--primary-gradient);
    color: white;
    cursor: pointer;
    font-weight: 600;
}

/* Admin Specific Layout */
.admin-layout-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: calc(100vh - var(--header-height));
}

.session-sidebar {
    width: 250px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid var(--sidebar-border);
    background: var(--sidebar-bg);
}

.sidebar-header h3 {
    font-size: 0.9rem;
    color: var(--text-main);
}

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

.session-item {
    padding: 15px;
    border-bottom: 1px solid var(--sidebar-border);
    cursor: pointer;
    transition: background 0.2s;
}

.session-item:hover {
    background: var(--sidebar-hover);
}

.session-item.active {
    background: var(--sidebar-active);
    border-left: 4px solid var(--accent-color);
}

.session-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.session-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.unread-badge {
    background: #ff4d4f;
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: bold;
    min-width: 18px;
    text-align: center;
}

.session-info {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 3px;
}

/* Header inside the chat area for the current session */
.active-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--chat-bg);
    border-bottom: 1px solid var(--border-color);
    z-index: 5;
}

.user-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-user-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main);
}

.chat-user-code {
    font-size: 0.75rem;
    color: #FF6B35;
    font-family: monospace;
    background: var(--sidebar-active);
    padding: 2px 8px;
    border-radius: 10px;
    width: fit-content;
}

.close-session-btn {
    background: var(--chat-bg);
    color: #ff4d4f;
    border: 1px solid #ff4d4f;
    padding: 8px 15px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.close-session-btn:hover {
    background: #ff4d4f;
    color: #fff;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.loading-sessions {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 0.8rem;
}

/* Desktop styles - centered modal-like look */
@media (min-width: 600px) {

    /* For index.html (Customer) */
    .chat-container {
        height: 600px;
        border-radius: 20px;
    }
}

/* For admin.html, override the max-width to be wider */
body:has(.admin-layout-wrapper) .chat-container {
    max-width: 100% !important;
    width: 100% !important;
    height: 100vh !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}