/* ==========================================================================
   Premium Midnight Dark Theme - Chat Centric Overhaul
   ========================================================================== */

   :root {
    /* Colors */
    --bg-base: #0a0a0a;
    --bg-surface: rgba(23, 23, 23, 0.65);
    --bg-surface-solid: #171717;
    --border-light: rgba(255, 255, 255, 0.08);
    --border-focus: rgba(255, 255, 255, 0.2);
    
    --text-primary: #ededed;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    
    --accent: #10a37f;
    --accent-hover: #1ab892;
    --accent-glow: rgba(16, 163, 127, 0.2);
    --accent-dim: rgba(16, 163, 127, 0.1);
    
    /* Layout */
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --radius-pill: 9999px;
    
    --sidebar-width: 260px;
    --drawer-width: 400px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    height: 100vh;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3f3f46; border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: #52525b; }

/* Utilities */
.glass {
    background: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-light);
}

.glass-panel {
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-light);
}

.glass-overlay {
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(8px);
}

.hidden { display: none !important; }

/* ==========================================================================
   Login & Modals
   ========================================================================== */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.overlay:not(.active) {
    display: none;
}

.login-box, .modal-box {
    width: 400px;
    padding: 32px;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

.login-box .logo { justify-content: center; margin-bottom: 8px; }
.login-box .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 16px; font-size: 0.9rem; }

.modern-input {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
}

.modern-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
}

.modern-select {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-light);
    color: var(--text-primary);
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}
.modern-select:focus { border-color: var(--accent); }

.primary-btn {
    background: var(--accent);
    color: white;
    border: none;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.outline-btn {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-primary);
}
.outline-btn:hover { background: rgba(255,255,255,0.05); }

/* ==========================================================================
   App Layout
   ========================================================================== */
.app-wrapper {
    display: flex;
    height: 100vh;
    width: 100vw;
    overflow: hidden; /* Prevent scrollbar when drawer is hidden */
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-light);
    z-index: 10;
}

.sidebar-header { padding: 20px; }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 1.1rem; }
.new-chat-btn-wrapper { padding: 0 20px 20px; }
.new-chat-btn-wrapper button { width: 100%; }

.sidebar-menu {
    flex: 1;
    padding: 0 20px;
    overflow-y: auto;
}
.sidebar-menu h3 { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; margin-bottom: 12px; letter-spacing: 0.05em; }

.history-list { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.history-item {
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
    display: flex;
    align-items: center;
}
.history-item:hover, .history-item.active {
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
}

.delete-session-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    opacity: 0; /* show on hover */
}
.history-item:hover .delete-session-btn {
    opacity: 1;
}
.delete-session-btn:hover {
    color: #ef4444; /* red */
    background: rgba(239, 68, 68, 0.1);
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.upload-btn {
    width: 100%;
    padding: 10px;
    background: transparent;
    border: 1px dashed var(--border-light);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}
.upload-btn:hover { border-color: var(--accent); color: var(--accent); }

.user-profile { display: flex; align-items: center; gap: 12px; font-size: 0.9rem; font-weight: 500; }
.avatar { width: 32px; height: 32px; background: var(--accent-dim); color: var(--accent); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; }

/* ==========================================================================
   Main Chat
   ========================================================================== */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    background: var(--bg-base);
}

.chat-header {
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-light);
}

.chat-header h2 { font-size: 1rem; font-weight: 500; }
.badge { font-size: 0.75rem; color: var(--accent); background: var(--accent-dim); padding: 4px 10px; border-radius: var(--radius-pill); border: 1px solid rgba(16,163,127,0.3); }

.chat-container {
    flex: 1;
    padding: 40px 20% 120px 20%;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

.chat-message {
    display: flex;
    gap: 16px;
    max-width: 100%;
}

.msg-user { flex-direction: row-reverse; }
.msg-avatar { font-size: 1.5rem; flex-shrink: 0; }
.msg-content {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-primary);
    word-break: break-word;
}

.msg-user .msg-content {
    background: rgba(255,255,255,0.05);
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    border-top-right-radius: 4px;
}

/* Actions (Feedback, View Evidence) */
.msg-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
}

.action-btn {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}
.action-btn:hover { background: rgba(255,255,255,0.05); color: var(--text-primary); }
.action-btn.view-data-btn { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }
.action-btn.view-data-btn:hover { background: var(--accent); color: white; }

/* Floating Input */
.floating-input-wrapper {
    position: absolute;
    bottom: 32px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

.input-container {
    pointer-events: auto;
    display: flex;
    align-items: center;
    width: 60%;
    min-width: 400px;
    padding: 8px 12px 8px 24px;
    border-radius: var(--radius-pill);
    box-shadow: 0 10px 40px rgba(0,0,0,0.8);
}

#query-input { flex: 1; background: transparent; border: none; color: var(--text-primary); font-size: 1rem; outline: none; }
.send-button { background: var(--text-primary); color: var(--bg-base); border: none; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; margin-left: 12px; transition: 0.2s; }
.send-button:hover { background: var(--accent); color: white; transform: scale(1.05); }

/* ==========================================================================
   Analysis Drawer (Features 5, 6 - Data Visualization)
   ========================================================================== */
.analysis-drawer {
    width: var(--drawer-width);
    flex-shrink: 0;
    border-left: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    z-index: 20;
    margin-right: 0;
    transform: translateX(0);
    transition: margin-right 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    background: var(--bg-surface-solid);
}

.analysis-drawer.hidden {
    margin-right: calc(-1 * var(--drawer-width));
    transform: translateX(100%);
}

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

.drawer-header h2 { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.icon-btn { background: transparent; border: none; color: var(--text-secondary); cursor: pointer; font-size: 1.2rem; }

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.drawer-section h3 { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.05em; }
.drawer-box { background: rgba(0,0,0,0.3); border: 1px solid var(--border-light); border-radius: var(--radius-md); overflow: hidden; }

#network-container { height: 200px; width: 100%; }

.table-wrapper table { width: 100%; border-collapse: collapse; text-align: left; }
.table-wrapper th { padding: 8px 12px; font-size: 0.7rem; color: var(--text-muted); border-bottom: 1px solid var(--border-light); }
.table-wrapper td { padding: 8px 12px; font-size: 0.8rem; border-bottom: 1px solid var(--border-light); }
.table-wrapper tr:last-child td { border-bottom: none; }

.chunk-list { display: flex; flex-direction: column; gap: 0; }
.chunk-item { padding: 12px; border-bottom: 1px solid var(--border-light); display: flex; gap: 12px; }
.chunk-item:last-child { border-bottom: none; }
.chunk-img { width: 60px; height: 60px; object-fit: cover; border-radius: var(--radius-sm); }
.chunk-text { font-size: 0.75rem; color: var(--text-secondary); flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Typing indicator */
.typing-indicator { display: inline-flex; gap: 4px; padding: 4px; }
.typing-indicator span { width: 6px; height: 6px; background: var(--accent); border-radius: 50%; animation: bounce 1.4s infinite ease-in-out; }
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1); } }

/* --- Multimodal Media Features --- */
.media-preview-container {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 12px;
    padding: 10px;
    margin-bottom: 10px;
    position: absolute;
    bottom: 100%;
    left: 0;
    max-width: 200px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    z-index: 50;
}
.media-preview-container.hidden {
    display: none;
}
#media-preview-content img, #media-preview-content video {
    max-width: 100%;
    border-radius: 8px;
    display: block;
}
#media-preview-content audio {
    width: 100%;
    height: 30px;
}
.remove-media {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #ef4444;
    color: white;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    z-index: 10;
    cursor: pointer;
    border: none;
}
.attach-button {
    color: #94a3b8;
    padding: 8px;
    transition: all 0.2s ease;
    cursor: pointer;
}
.attach-button:hover {
    color: #14b8a6;
    transform: scale(1.1);
}
.chat-media {
    max-width: 100%;
    border-radius: 8px;
    margin-top: 10px;
    display: block;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}
.chat-audio {
    margin-top: 10px;
    width: 100%;
    max-width: 300px;
}
