:root {
    --bg-main: #131320;
    --bg-secondary: #1a1a2e;
    --bg-tertiary: #0e0e1a;
    --accent: #8b5cf6;
    --accent-2: #06b6d4;
    --accent-hover: #7c3aed;
    --text-primary: #f4f4f8;
    --text-muted: #9698ab;
    --border-color: #2a2a42;
    --admin-color: #06b6d4;
    --success: #22c55e;
    --danger: #f43f5e;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: transparent;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2a42; border-radius: 10px; }

/* Floating launcher button */
#chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(139, 92, 246, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    z-index: 999998;
}
#chat-btn:hover { transform: scale(1.06); box-shadow: 0 10px 30px rgba(139, 92, 246, 0.6); }
#chat-btn { position: fixed; }
.logo-mark { display: flex; align-items: center; justify-content: center; }

.unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--bg-main);
    animation: popIn 0.2s ease;
}
@keyframes popIn { from { transform: scale(0); } to { transform: scale(1); } }

/* Main chat window */
#chat-window {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    height: 580px;
    max-height: 80vh;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 999999;
    display: none;
}
#chat-window.open { display: flex; }

/* Header */
.chat-header {
    background: var(--bg-tertiary);
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background-image: linear-gradient(135deg, rgba(139,92,246,0.15), rgba(6,182,212,0.08));
}
.header-info { display: flex; align-items: center; gap: 10px; }
.brand-mark {
    width: 32px; height: 32px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: flex; align-items: center; justify-content: center;
    color: white;
    flex-shrink: 0;
}
.header-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-title { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.header-sub { font-size: 11.5px; color: var(--text-muted); display: flex; align-items: center; gap: 5px; }
.status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 6px var(--success);
    display: inline-block;
}
.header-actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
}
.icon-btn:hover { color: white; background: rgba(255,255,255,0.06); }
.icon-btn.muted { color: var(--danger); }
.close-btn { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 15px; transition: color 0.2s; padding: 4px 8px; }
.close-btn:hover { color: white; }

/* Centered informational screens */
.screen-center {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 32px;
    text-align: center;
    gap: 12px;
    background: var(--bg-main);
}
.screen-center h3 { font-size: 16px; }
.screen-center p { color: var(--text-muted); font-size: 13px; line-height: 1.5; }

.primary-btn {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border: none;
    padding: 11px 18px;
    border-radius: 10px;
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 6px;
}
.primary-btn:hover { opacity: 0.9; }

/* Chat area */
#chat-main { flex: 1; flex-direction: column; overflow: hidden; background: var(--bg-main); display: flex; position: relative; }
.chat-body { flex: 1; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

/* Messages */
.msg { display: flex; gap: 10px; max-width: 85%; animation: fadeIn 0.2s ease; }
.msg.no-anim { animation: none; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: translateY(0);} }
.msg-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 11px; flex-shrink: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
}
.msg-content {
    background: var(--bg-secondary);
    padding: 10px 14px;
    border-radius: 4px 14px 14px 14px;
    font-size: 13.5px;
    line-height: 1.45;
    word-break: break-word;
    border: 1px solid var(--border-color);
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .msg-content {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border-radius: 14px 4px 14px 14px;
    border: none;
}
.msg.user .msg-avatar { display: none; }
.msg.system {
    align-self: center;
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
    font-size: 11.5px;
    padding: 6px 12px;
    border-radius: 16px;
    max-width: 100%;
    border: none;
}

.msg-stack { display: flex; flex-direction: column; gap: 2px; }
.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 4px;
}
.msg.user .msg-time { text-align: right; justify-content: flex-end; }
.receipt { display: inline-flex; }
.receipt.seen { color: var(--accent-2); }

.msg-image {
    max-width: 220px;
    border-radius: 12px;
    display: block;
    cursor: pointer;
    border: 1px solid var(--border-color);
}

/* Drag & drop overlay */
.chat-body { position: relative; }
.drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(19, 19, 32, 0.92);
    border: 2px dashed var(--accent);
    border-radius: 12px;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 5;
    pointer-events: none;
}
.chat-body.drag-active .drop-overlay { display: flex; }
.drop-overlay-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--accent-2);
    font-size: 13px;
    font-weight: 600;
}

/* File preview strip */
.file-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}
.file-preview img {
    width: 34px; height: 34px;
    border-radius: 7px;
    object-fit: cover;
    border: 1px solid var(--border-color);
}
.file-preview span {
    font-size: 12px;
    color: var(--text-muted);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-preview button {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    padding: 2px 6px;
}
.file-preview button:hover { color: var(--danger); }

/* Scroll to bottom */
.scroll-bottom-btn {
    position: absolute;
    bottom: 128px;
    right: 24px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
    z-index: 4;
}
.scroll-bottom-btn:hover { background: var(--accent); border-color: var(--accent); }

.status-dot.offline { background: var(--danger); box-shadow: 0 0 6px var(--danger); }
.status-dot.reconnecting { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }

/* Footer / input */
#typing-indicator { font-size: 11px; color: var(--text-muted); padding: 0 18px; height: 16px; font-style: italic; }
.chat-footer {
    padding: 14px 16px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}
.input-row {
    display: flex;
    gap: 6px;
    align-items: center;
    background: var(--bg-main);
    padding: 6px 6px 6px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    transition: border-color 0.2s;
}
.input-row:focus-within { border-color: var(--accent); }
.input-row input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 8px 0;
    font-size: 13.5px;
    outline: none;
    min-width: 0;
}
.input-row button {
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
    flex-shrink: 0;
}
.input-row button:hover { opacity: 0.9; }
.file-label {
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.2s;
    flex-shrink: 0;
}
.file-label:hover { color: white; }

.footer-tools { display: flex; justify-content: space-between; align-items: center; padding: 0 4px; }
.file-name-text { font-size: 11px; color: var(--text-muted); }
.file-error { color: var(--danger); font-size: 11px; }
.powered-by { font-size: 10.5px; color: var(--text-muted); margin-left: auto; opacity: 0.7; }

@media (max-width: 420px) {
    #chat-window { width: 100vw; height: 100vh; max-height: 100vh; bottom: 0; right: 0; border-radius: 0; }
    #chat-btn { bottom: 16px; right: 16px; }
}
