:root {
    --bg-primary: #0a0f1c;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2236;
    --bg-hover: #1e293b;
    --bg-active: #253349;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #266efb;
    --accent-hover: #3b82f6;
    --accent-glow: rgba(38, 110, 251, 0.15);
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --msg-customer: #1e293b;
    --msg-operator: #266efb;
    --radius: 12px;
    --radius-lg: 16px;
    --sidebar-width: 360px;
    --header-height: 64px;

    /* Channel colors */
    --channel-website: #22c55e;
    --channel-vk: #0077FF;
    --channel-max: #8b5cf6;
    --channel-telegram: #229ED9;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'Onest', -apple-system, BlinkMacSystemFont, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Safe area for iOS */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

#app {
    display: flex;
    height: 100%;
    width: 100%;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    height: var(--header-height);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-img {
    height: 28px;
    width: auto;
    display: block;
}

/* Health status indicator */
.health-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    cursor: help;
    transition: background 0.3s;
    position: relative;
}

.health-dot.ok {
    background: var(--success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
    animation: health-pulse 2s infinite;
}

.health-dot.error {
    background: var(--danger);
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

@keyframes health-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.stats {
    display: flex;
    gap: 6px;
}

.stat-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.stat-unread {
    background: var(--danger);
    color: #fff;
    display: none;
}

.stat-unread.visible {
    display: inline-flex;
}

.header-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: all 0.2s;
}

.header-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.header-icon-btn.active {
    background: var(--accent-glow);
    color: var(--accent);
}

.header-icon-btn.logout-btn:hover {
    background: rgba(239, 68, 68, 0.12);
    color: var(--danger);
}

/* Channel Filters */
.channel-filters {
    padding: 12px 16px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.filter-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-light);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.filter-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.filter-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Search */
.search-box {
    padding: 12px 16px;
    position: relative;
    flex-shrink: 0;
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 38px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.search-box input:focus {
    border-color: var(--accent);
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
}

/* Conversations List */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.conversations-list::-webkit-scrollbar {
    width: 4px;
}

.conversations-list::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.conv-item {
    padding: 14px 20px;
    display: flex;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    position: relative;
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--bg-active);
    border-left: 3px solid var(--accent);
    padding-left: 17px;
}

.conv-item.unread {
    background: var(--accent-glow);
}

.conv-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}

.conv-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.conv-channel-badge {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    border: 2px solid var(--bg-secondary);
    color: #fff;
    font-weight: 700;
}

.conv-channel-badge.website { background: var(--channel-website); }
.conv-channel-badge.vk { background: var(--channel-vk); }
.conv-channel-badge.max { background: var(--channel-max); }
.conv-channel-badge.telegram { background: var(--channel-telegram); }

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

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

.conv-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.conv-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-preview .preview-sender {
    color: var(--accent);
    font-weight: 500;
}

.conv-unread-badge {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

.conv-item.unread .conv-unread-badge {
    display: flex;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.empty-state span {
    font-size: 13px;
}

/* === Main Chat Area === */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.chat-empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.4;
}

.chat-empty h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

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

.chat-active {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Chat Header */
.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: background 0.2s;
}

.back-btn:hover {
    background: var(--bg-hover);
}

.chat-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.chat-header-info h3 {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-info span {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-header-channel {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.chat-header-channel.website { background: rgba(34,197,94,0.15); color: var(--channel-website); }
.chat-header-channel.vk { background: rgba(0,119,255,0.15); color: var(--channel-vk); }
.chat-header-channel.max { background: rgba(139,92,246,0.15); color: var(--channel-max); }
.chat-header-channel.telegram { background: rgba(34,158,217,0.15); color: var(--channel-telegram); }

.chat-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(239, 68, 68, 0.15);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-tertiary) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 2px;
}

.msg {
    max-width: 70%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    animation: msg-in 0.2s ease-out;
    position: relative;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-customer {
    align-self: flex-start;
    background: var(--msg-customer);
    border-radius: 4px 16px 16px 16px;
    color: var(--text-primary);
}

.msg-operator {
    align-self: flex-end;
    background: var(--msg-operator);
    border-radius: 16px 4px 16px 16px;
    color: #fff;
}

.msg-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}

.msg-customer .msg-time {
    text-align: left;
}

.msg-attachment {
    margin-top: 6px;
}

.msg-attachment img {
    max-width: 240px;
    max-height: 200px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.msg-attachment img:hover {
    opacity: 0.85;
}

.msg-attachment a {
    color: inherit;
    text-decoration: underline;
    opacity: 0.85;
    font-size: 13px;
}

/* Date separator */
.date-separator {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 12px 0;
}

.date-separator span {
    background: var(--bg-primary);
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
}

/* Typing */
.typing-indicator {
    padding: 8px 20px;
    display: none;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    font-size: 13px;
}

.typing-indicator.visible {
    display: flex;
}

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

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-dot 1.4s infinite;
}

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

@keyframes typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Input Area */
.chat-input-area {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
    flex-shrink: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

.templates-bar {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    scrollbar-width: none;
}

.templates-bar::-webkit-scrollbar { display: none; }

.templates-list {
    display: flex;
    gap: 6px;
}

.template-chip {
    padding: 6px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    color: var(--text-secondary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.template-chip:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

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

.input-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}

.input-btn:hover {
    background: var(--bg-hover);
}

.input-btn.active {
    background: var(--accent-glow);
}

.input-btn.active svg path {
    fill: var(--accent);
}

.chat-input-row textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.chat-input-row textarea:focus {
    border-color: var(--accent);
}

.chat-input-row textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    opacity: 0.5;
}

.send-btn:hover {
    background: var(--accent-hover);
}

.send-btn.active {
    opacity: 1;
    box-shadow: 0 2px 12px rgba(38, 110, 251, 0.4);
}

/* === Responsive / Mobile === */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        z-index: 10;
    }

    .chat-area, .analytics-area {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        z-index: 20;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .chat-area.visible, .analytics-area.visible {
        transform: translateX(0);
    }

    .back-btn {
        display: flex;
    }

    #app {
        position: relative;
        overflow: hidden;
    }

    .msg {
        max-width: 85%;
    }

    /* Analytics mobile adjustments */
    .analytics-header {
        padding: 16px;
    }

    .analytics-header h2 {
        font-size: 18px;
        margin-bottom: 12px;
    }

    .analytics-content {
        padding: 16px;
    }

    .analytics-tabs {
        gap: 8px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .analytics-tabs::-webkit-scrollbar {
        display: none;
    }

    .analytics-tab {
        font-size: 13px;
        white-space: nowrap;
    }

    .analytics-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .toolbar-group {
        flex-wrap: wrap;
        gap: 8px;
    }

    .error-card {
        flex-direction: column;
        gap: 10px;
    }

    .timeline-item {
        gap: 10px;
    }

    .tl-time {
        width: 50px;
        font-size: 11px;
    }
}

/* === Notifications pulse === */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(38, 110, 251, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(38, 110, 251, 0); }
    100% { box-shadow: 0 0 0 0 rgba(38, 110, 251, 0); }
}

.conv-item.new-message {
    animation: pulse 0.6s ease-out;
}

/* === Main Tabs === */
.main-tabs-container {
    padding: 12px 16px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.main-tabs {
    display: flex;
    gap: 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    padding: 4px;
}

.main-tab {
    flex: 1;
    padding: 8px 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.main-tab.active {
    background: var(--bg-secondary);
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* === Analytics Area === */
.analytics-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
}

.analytics-header {
    padding: 24px 32px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.analytics-header h2 {
    font-size: 24px;
    margin-bottom: 20px;
    color: #fff;
}

.analytics-tabs {
    display: flex;
    gap: 16px;
    border-bottom: 1px solid var(--border);
}

.analytics-tab {
    background: none;
    border: none;
    padding: 12px 0;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    position: relative;
    outline: none;
}

.analytics-tab.active {
    color: var(--accent);
}

.analytics-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent);
    border-radius: 3px 3px 0 0;
}

.analytics-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px 32px;
}

.analytics-view {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.analytics-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-info {
    font-size: 14px;
    color: var(--text-muted);
}

/* Base UI components used in analytics */
.btn {
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.btn-outline:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
}

/* Timeline */
.timeline-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 20px;
}

.timeline-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 14px;
}

.timeline-item {
    display: flex;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid var(--border-light);
}

.timeline-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.tl-time {
    font-size: 13px;
    color: var(--text-muted);
    width: 60px;
    flex-shrink: 0;
}

.tl-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

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

.tl-event-name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}

.tl-event-data {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: inherit;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid var(--border-light);
}

/* Errors List */
.error-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--danger);
    padding: 20px;
    margin-bottom: 16px;
    display: flex;
    gap: 16px;
}

.error-card.resolved {
    border-color: var(--success);
    opacity: 0.8;
}

.error-card.level-warn {
    border-color: var(--warning);
}

.err-icon {
    font-size: 24px;
    flex-shrink: 0;
}

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

.err-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 8px;
}

.err-title {
    font-weight: 600;
    font-size: 15px;
    color: var(--danger);
    word-break: break-all;
}

.resolved .err-title { color: var(--success); }
.level-warn .err-title { color: var(--warning); }

.err-meta {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}

.err-stack {
    font-size: 11px;
    color: var(--text-secondary);
    font-family: monospace;
    white-space: pre-wrap;
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: 8px;
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 12px;
    border: 1px solid var(--border-light);
}

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

/* === Login Screen === */
.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 99999;
}

.login-card {
    width: 100%;
    max-width: 380px;
    padding: 48px 36px 40px;
    background: var(--bg-secondary);
    border-radius: 20px;
    border: 1px solid var(--border-light);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
    text-align: center;
}

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.login-logo-img {
    height: 40px;
    width: auto;
    display: block;
}

.login-subtitle {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-input-group input {
    width: 100%;
    padding: 14px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input-group input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-input-group input::placeholder {
    color: var(--text-muted);
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.login-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(38, 110, 251, 0.35);
}

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

.login-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.login-error {
    font-size: 13px;
    color: var(--danger);
    min-height: 20px;
}

@media (max-width: 480px) {
    .login-card {
        margin: 20px;
        padding: 36px 24px 32px;
    }
}

/* === Lightbox Overlay === */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
    transition: background 0.2s;
    line-height: 1;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: 8px;
    cursor: default;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
    background-color: #fff;
}

.lightbox-pdf {
    width: 90vw;
    height: 90vh;
    border-radius: 8px;
    pointer-events: auto;
    background-color: #fff;
    border: none;
}

@media (max-width: 768px) {
    .lightbox-img {
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
    }

    .lightbox-close {
        top: max(12px, env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
    }
}

/* Attachment protection */
.msg-attachment img {
    -webkit-user-select: none;
    user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}

/* === Visitor Intelligence === */

/* Header name row: name + tag inline */
.chat-header-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-name {
    cursor: pointer;
    transition: opacity 0.2s;
}
.chat-header-name:hover {
    opacity: 0.8;
}

/* New / Returning tag badge */
.visitor-tag {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.visitor-tag.new {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}
.visitor-tag.returning {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* Visitor Info Popup */
.visitor-info-popup {
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-light);
    padding: 16px 20px;
    animation: slideDown 0.2s ease-out;
    overflow: hidden;
}

@keyframes slideDown {
    from { max-height: 0; opacity: 0; padding: 0 20px; }
    to { max-height: 500px; opacity: 1; }
}

.visitor-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.visitor-info-close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s;
}
.visitor-info-close-btn:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.visitor-info-body {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 16px;
}

.vi-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-primary);
    padding: 4px 0;
}

.vi-row .vi-icon {
    flex-shrink: 0;
    width: 18px;
    text-align: center;
}

.vi-row .vi-label {
    color: var(--text-secondary);
    font-size: 11px;
    margin-right: 4px;
}

.vi-row .vi-value {
    color: var(--text-primary);
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Editable name row */
.vi-name-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--border-light);
}

.vi-name-input {
    flex: 1;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    padding: 6px 10px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    font-weight: 500;
    transition: border-color 0.2s;
}
.vi-name-input:focus {
    outline: none;
    border-color: var(--accent);
}

.vi-name-save {
    padding: 6px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
    white-space: nowrap;
}
.vi-name-save:hover {
    opacity: 0.9;
}

/* Full-width rows */
.vi-row.full-width {
    grid-column: 1 / -1;
}

/* Conversation list subtitle */
.conv-subtitle {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .visitor-info-body {
        grid-template-columns: 1fr;
    }
}
