/* CORE: Variables, Reset, Typography */
:root {
    --bg-void: #000000;
    --bg-deep: #050505;
    --bg-glass: rgba(10, 10, 12, 0.6);
    --bg-glass-heavy: rgba(5, 5, 8, 0.95);
    
    --neon-gold: #ffb700;
    --neon-gold-dim: rgba(255, 183, 0, 0.15);
    --neon-cyan: #06b6d4;
    --neon-cyan-dim: rgba(6, 182, 212, 0.15);
    --neon-emerald: #10b981;
    --neon-fire: #ef4444;

    --text-primary: #f4f4f5;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;

    --sidebar-w: 320px;
    --header-h: 64px;
    
    --font-stack: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

*, *::before, *::after {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* CUSTOM SCROLLBARS */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--neon-cyan); }

html, body {
    height: 100%; width: 100%; margin: 0; padding: 0;
    overflow: hidden; /* Prevent body scroll */
    background: var(--bg-void);
    color: var(--text-primary);
    font-family: var(--font-stack);
    font-size: 14px;
    line-height: 1.5;
}

/* GLOBAL LINKS - NO BLUE */
a { color: inherit; text-decoration: none; }

/* BACKGROUND FX */
body::before {
    content: ""; position: absolute; inset: 0;
    background: radial-gradient(circle at 50% -20%, #1a1a20 0%, #000 70%);
    z-index: -1; pointer-events: none;
}
body::after {
    content: ""; position: absolute; inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 40px 40px;
    opacity: 0.2; z-index: -1; pointer-events: none;
    mask-image: radial-gradient(circle, black 40%, transparent 100%);
}

#root { width: 100%; height: 100%; display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* LAYOUT GRID */
.app-container {
    display: flex; /* Flexbox Layout */
    height: 100%; width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

/* SIDEBAR CONTAINER */
.sidebar-container {
    width: var(--sidebar-w);
    flex-shrink: 0;
    height: 100%;
    position: relative;
}

/* CHAT VIEW - FIXED SCROLLING */
.chat-view {
    flex: 1;
    display: flex; flex-direction: column;
    height: 100%;
    min-width: 0; /* Critical for flex child scrolling */
    background: rgba(0,0,0,0.2);
    position: relative;
}

.chat-header {
    height: var(--header-h);
    padding: 0 24px;
    display: flex; align-items: center; justify-content: space-between;
    background: rgba(10, 10, 12, 0.8);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    z-index: 10;
}

/* SCROLL AREA */
.messages-scroll-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex; flex-direction: column; gap: 4px;
    scroll-behavior: smooth;
    mask-image: linear-gradient(to bottom, transparent 0%, black 20px);
}

/* DATE DIVIDERS */
.date-divider {
    text-align: center; margin: 20px 0; position: sticky; top: 0; z-index: 5;
}
.date-divider span {
    background: rgba(255,255,255,0.1); padding: 4px 12px;
    border-radius: 20px; font-size: 0.75rem; color: var(--text-secondary);
    backdrop-filter: blur(4px);
}

/* MESSAGE ROWS */
.message-row {
    display: flex; gap: 12px; margin-bottom: 2px;
    opacity: 0; animation: fadeIn 0.2s forwards;
}
@keyframes fadeIn { to { opacity: 1; } }

.message-row.sent { flex-direction: row-reverse; }
.message-row.group-start { margin-top: 12px; }

/* BUBBLES */
.message-bubble {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    position: relative;
    word-break: break-word;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}

/* RECEIVED STYLE */
.message-row.received .message-bubble {
    background: linear-gradient(145deg, #1e1e24, #121215);
    border: 1px solid rgba(255,255,255,0.08);
    color: #e4e4e7;
    border-bottom-left-radius: 4px;
}
/* SENT STYLE */
.message-row.sent .message-bubble {
    background: linear-gradient(145deg, #27272a, #18181b);
    border: 1px solid var(--neon-gold-dim);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 15px rgba(0,0,0,0.3);
}

/* GROUPING CORNERS */
.message-row.received.group-middle .message-bubble { border-radius: 4px 18px 18px 4px; }
.message-row.received.group-end .message-bubble { border-radius: 4px 18px 18px 18px; }

.message-row.sent.group-middle .message-bubble { border-radius: 18px 4px 4px 18px; }
.message-row.sent.group-end .message-bubble { border-radius: 18px 4px 18px 18px; }

/* CONTENT STYLING */
.message-content { white-space: pre-wrap; }

/* Fix Links */
.message-content a { color: var(--neon-cyan); text-decoration: none; border-bottom: 1px dotted var(--neon-cyan); }
.message-content a:hover { color: #fff; border-bottom-style: solid; }

/* Fix Markdown/Code */
.message-content code {
    background: rgba(0,0,0,0.3); padding: 2px 6px; border-radius: 4px;
    color: var(--neon-emerald); font-family: var(--font-mono); font-size: 0.9em;
}
.message-content pre {
    background: #08080a; padding: 12px; border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1); overflow-x: auto;
    margin: 8px 0;
}
.message-content pre code { background: none; color: var(--text-secondary); padding: 0; }

/* REply Meta Fix */
.reply-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    border-left: 2px solid var(--text-muted);
    padding-left: 10px; margin: 5px 0 15px 0;
    opacity: 0.7;
    max-height: 60px; overflow: hidden;
    position: relative;
    background: rgba(255,255,255,0.02);
}
.reply-meta:hover { max-height: none; opacity: 1; background: rgba(255,255,255,0.05); }

/* COMPOSER */
.chat-composer {
    padding: 16px 24px;
    background: rgba(10, 10, 12, 0.9);
    border-top: 1px solid rgba(255,255,255,0.06);
    display: flex; gap: 12px; align-items: flex-end;
    backdrop-filter: blur(20px);
}

.composer-input {
    flex: 1; background: #08080a; color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 12px 16px; border-radius: 20px;
    font-family: inherit; font-size: 0.95rem; line-height: 1.5;
    resize: none; min-height: 46px; max-height: 150px;
    transition: 0.2s;
}
.composer-input:focus { outline: none; border-color: var(--neon-gold); box-shadow: 0 0 15px var(--neon-gold-dim); }

.avatar-circle {
    width: 32px; height: 32px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 0.8rem;
    flex-shrink: 0;
}
.avatar-placeholder { width: 32px; flex-shrink: 0; }

/* MODALS */
.overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(10px);
    z-index: 9999; display: flex; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s;
}
.overlay.visible { opacity: 1; pointer-events: auto; }
.modal-card {
    background: #0e0e11; border: 1px solid rgba(255,255,255,0.1); 
    border-radius: 20px; padding: 24px; width: 100%; max-width: 480px; 
    box-shadow: 0 20px 50px #000;
}
.btn-primary { 
    width: 100%; padding: 14px; background: var(--neon-gold); color: #000;
    border: none; font-weight: 800; cursor: pointer; border-radius: 12px; 
    text-transform: uppercase; letter-spacing: 1px;
}
.styled-input { 
    width: 100%; padding: 12px; background: rgba(255,255,255,0.05); 
    border: 1px solid rgba(255,255,255,0.1); color: #fff; border-radius: 8px; margin-bottom: 12px;
}