/* ============================================================
   WORLD CAPITAL — CHAT CSS  (light theme)
============================================================ */

:root {
    --chat-bg:        #ffffff;
    --chat-surface:   #f8fafc;
    --chat-surface2:  #e8f0fe;
    --chat-border:    #cbd5e1;
    --chat-accent:    #2563eb;
    --chat-accent-bg: rgba(37,99,235,.08);
    --chat-text:      #1e293b;
    --chat-muted:     #94a3b8;
    --chat-system:    #059669;
    --chat-me-bg:     #2563eb;
    --chat-other-bg:  #f1f5f9;
    --chat-header:    #1e293b;
    --chat-sidebar:   #f1f5f9;
    --chat-radius:    14px;
    --chat-shadow:    0 20px 60px rgba(0,0,0,.15), 0 0 0 1px rgba(0,0,0,.06);
}

/* ── MODAL ─────────────────────────────────────────────── */
.chat-modal {
    position: fixed;
    top: 80px;
    right: 30px;
    width: 640px;
    height: 480px;
    min-width: 380px;
    min-height: 340px;
    max-width: 95vw;
    max-height: 85vh;
    resize: both;
    overflow: hidden;
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    border: 1px solid var(--chat-border);
    box-shadow: var(--chat-shadow);
    z-index: 8000;
    display: none;
    font-family: 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
}

.chat-modal.fullscreen {
    top: 60px !important;
    left: 0 !important;
    right: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 150px) !important;
    border-radius: 0;
    resize: none;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* ── HEADER ────────────────────────────────────────────── */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    height: 48px;
    background: var(--chat-header);
    border-bottom: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.chat-header-left,
.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header span {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    letter-spacing: .05em;
    text-transform: uppercase;
}

.chat-header button {
    background: transparent;
    border: none;
    color: rgba(255,255,255,.5);
    font-size: 15px;
    cursor: pointer;
    padding: 5px 7px;
    border-radius: 6px;
    transition: color .15s, background .15s;
    line-height: 1;
}

.chat-header button:hover {
    color: #fff;
    background: rgba(255,255,255,.1);
}

/* ── SETTINGS MENU ─────────────────────────────────────── */
.chat-settings-menu {
    position: absolute;
    top: 52px;
    right: 12px;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 6px;
    display: none;
    box-shadow: 0 8px 32px rgba(0,0,0,.12);
    z-index: 9000;
    min-width: 180px;
}

.chat-settings-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--chat-text);
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 7px;
    font-size: 13px;
    transition: background .12s;
}

.chat-settings-menu button:hover { background: var(--chat-surface2); }

/* ── BODY ──────────────────────────────────────────────── */
.chat-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── SIDEBAR ───────────────────────────────────────────── */
.chat-sidebar {
    width: 210px;
    min-width: 150px;
    background: #eef2f7;
    border-right: 2px solid #cbd5e1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

#chatSearch {
    padding: 10px 12px;
    background: #fff;
    border: none;
    border-bottom: 1px solid var(--chat-border);
    color: var(--chat-text);
    font-size: 12px;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    transition: background .15s;
}

#chatSearch:focus { background: #f0f7ff; }
#chatSearch::placeholder { color: var(--chat-muted); }

#chatUserList {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--chat-border) transparent;
}

/* ── USER ITEMS ────────────────────────────────────────── */
.chat-user-item {
    padding: 10px 12px;
    border-bottom: 1px solid #dde3ec;
    cursor: pointer;
    transition: background .12s;
    position: relative;
    border-left: 3px solid transparent;
}

.chat-user-item:hover { background: #f0f7ff; }

.chat-user-item.active {
    background: #eff6ff !important;
    border-left-color: var(--chat-accent) !important;
}

.chat-user-item.active .chat-user-name { color: var(--chat-accent); }

.chat-user-item.system-conv .chat-user-name { color: var(--chat-system); }

.chat-user-item.active.system-conv {
    background: #ecfdf5 !important;
    border-left-color: var(--chat-system) !important;
}

.chat-user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 24px;
}

.chat-user-preview {
    font-size: 11px;
    color: var(--chat-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-right: 24px;
}

.chat-unread {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-empty {
    padding: 20px 12px;
    text-align: center;
    color: var(--chat-muted);
    font-size: 12px;
    line-height: 1.6;
}

/* ── MESSAGE AREA ──────────────────────────────────────── */
.chat-messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
    overflow: hidden;
}

#chatMessages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--chat-border) transparent;
}

/* ── DATE SEPARATOR ────────────────────────────────────── */
.chat-date-separator {
    text-align: center;
    margin: 12px 0;
    font-size: 11px;
    color: var(--chat-muted);
    font-weight: 600;
    letter-spacing: .06em;
    position: relative;
}

.chat-date-separator::before,
.chat-date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: var(--chat-border);
}

.chat-date-separator::before { left: 0; }
.chat-date-separator::after  { right: 0; }

/* ── BUBBLES ───────────────────────────────────────────── */
.chat-message-wrapper {
    display: flex;
    margin-bottom: 4px;
}

.chat-message-wrapper.me    { justify-content: flex-end; }
.chat-message-wrapper.other { justify-content: flex-start; }

.chat-message {
    max-width: 72%;
    padding: 9px 14px;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.chat-message.me {
    background: var(--chat-me-bg);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message.other {
    background: var(--chat-other-bg);
    color: var(--chat-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--chat-border);
}

.chat-text { word-break: break-word; }

.chat-time {
    font-size: 9px;
    opacity: 0.5;
    margin-top: 3px;
    display: block;
    text-align: right;
}

.chat-message.other .chat-time { text-align: left; }

.chat-message.emoji-only {
    font-size: 36px;
    line-height: 1.2;
    padding: 4px 8px;
    background: transparent !important;
    border: none !important;
}

/* ── SYSTEM MESSAGE ────────────────────────────────────── */
.chat-system-message {
    margin: 8px 0;
    padding: 12px 16px;
    background: #f0fdf4;
    border-radius: 12px;
    border: 1px solid #bbf7d0;
    border-left: 3px solid var(--chat-system);
    font-size: 13px;
    line-height: 1.6;
}

.chat-system-sender {
    font-size: 10px;
    font-weight: 800;
    color: var(--chat-system);
    text-transform: uppercase;
    letter-spacing: .1em;
    margin-bottom: 6px;
}

.chat-system-message .chat-system-text { color: #374151; }
.chat-system-message strong { color: #111827; font-weight: 700; }

.chat-system-message a {
    display: inline-block;
    margin-top: 8px;
    margin-right: 6px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    border: 1px solid;
    transition: background .15s;
}

.chat-system-message a[href*="accept"] {
    color: #15803d; border-color: #86efac; background: #f0fdf4;
}
.chat-system-message a[href*="accept"]:hover { background: #dcfce7; }

.chat-system-message a[href*="refuse"] {
    color: #dc2626; border-color: #fca5a5; background: #fef2f2;
}
.chat-system-message a[href*="refuse"]:hover { background: #fee2e2; }

.chat-system-message .chat-time {
    font-size: 10px; color: var(--chat-muted);
    text-align: right; margin-top: 8px; display: block;
}

.chat-notice {
    text-align: center; padding: 10px 16px;
    font-size: 12px; color: var(--chat-muted); font-style: italic;
}

/* ── INPUT ─────────────────────────────────────────────── */
.chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    background: #f8fafc;
    border-top: 2px solid #cbd5e1;
    flex-shrink: 0;
}

.chat-input textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 8px 12px;
    background: var(--chat-surface2);
    color: var(--chat-text);
    font-size: 13px;
    outline: none;
    height: 36px;
    line-height: 1.4;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}

.chat-input textarea:focus {
    border-color: var(--chat-accent);
    box-shadow: 0 0 0 3px var(--chat-accent-bg);
    background: #fff;
}

.chat-input textarea::placeholder { color: var(--chat-muted); }

.chat-input button#sendChatMessage {
    padding: 8px 16px;
    border: none;
    border-radius: 10px;
    background: var(--chat-accent);
    color: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
    transition: background .15s, transform .1s;
}

.chat-input button#sendChatMessage:hover:not(:disabled) {
    background: #1d4ed8;
    transform: translateY(-1px);
}

.chat-input button#sendChatMessage:disabled { opacity: .35; cursor: not-allowed; }

.chat-input button#emojiToggle {
    background: transparent; border: none;
    font-size: 18px; cursor: pointer;
    padding: 4px; border-radius: 6px;
    transition: transform .15s; line-height: 1;
}

.chat-input button#emojiToggle:hover { transform: scale(1.2); }
.chat-input.chat-disabled { opacity: .5; pointer-events: none; }

/* ── EMOJI PANEL ───────────────────────────────────────── */
.emoji-panel {
    position: absolute;
    bottom: 62px;
    left: 215px;
    width: 260px;
    max-height: 180px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: 10px;
    padding: 8px;
    display: none;
    box-shadow: 0 8px 32px rgba(0,0,0,.12);
    z-index: 100;
}

.emoji-item {
    font-size: 20px; padding: 5px; cursor: pointer;
    display: inline-block; border-radius: 6px;
    transition: transform .1s, background .1s;
}

.emoji-item:hover { transform: scale(1.25); background: var(--chat-surface2); }

/* ── BADGE ─────────────────────────────────────────────── */
.chat-badge {
    display: inline-flex; align-items: center; justify-content: center;
    background: #ef4444; color: #fff; font-size: 10px; font-weight: 700;
    min-width: 18px; height: 18px; padding: 0 4px;
    border-radius: 50%; margin-left: 4px; line-height: 1; vertical-align: middle;
}

.chat-badge.blink { animation: badgeBlink .5s alternate 4; }

@keyframes badgeBlink {
    from { transform: scale(1); background: #ef4444; }
    to   { transform: scale(1.4); background: #f87171; }
}