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

:root {
    --bg-primary: #36393f;
    --bg-secondary: #2f3136;
    --bg-tertiary: #202225;
    --bg-accent: #40444b;
    --text-primary: #dcddde;
    --text-secondary: #8e9297;
    --text-muted: #72767d;
    --accent-color: #5865f2;
    --accent-hover: #4752c4;
    --success: #3ba55c;
    --danger: #ed4245;
    --border-color: #42454a;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

#app {
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* Drop Zone */
.drop-zone {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
    position: relative;
}

.drop-content {
    text-align: center;
    padding: 4rem;
    border: 3px dashed var(--border-color);
    border-radius: 16px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: all 0.3s ease;
    max-width: 500px;
}

.drop-content:hover,
.drop-zone.dragover .drop-content {
    border-color: var(--accent-color);
    background: var(--bg-accent);
    transform: scale(1.02);
}

.drop-icon {
    width: 80px;
    height: 80px;
    color: var(--accent-color);
    margin-bottom: 1.5rem;
}

.drop-content h2 {
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.drop-content p {
    color: var(--text-secondary);
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(32, 34, 37, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.loading-overlay.active {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--bg-accent);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Main Interface */
#main-interface {
    display: flex;
    height: 100vh;
}

/* Sidebar */
#sidebar {
    width: 320px;
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--bg-tertiary);
}

.sidebar-header {
    padding: 1rem;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

#user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

#user-name {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    background: var(--bg-accent);
    border: none;
    padding: 0.5rem;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.icon-btn:hover {
    background: var(--accent-color);
    color: white;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.search-box {
    padding: 0.75rem 1rem;
}

.search-box input,
.messages-search input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    border-radius: 8px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
}

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

.search-box input:focus,
.messages-search input:focus {
    outline: 2px solid var(--accent-color);
}

.conversation-filters {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem 0.75rem;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 0.4rem 0.75rem;
    border: none;
    border-radius: 16px;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.filter-btn.active {
    background: var(--accent-color);
    color: white;
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.conversation-item.active {
    background: var(--bg-accent);
    border-left: 3px solid var(--accent-color);
}

.conversation-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 1rem;
    flex-shrink: 0;
}

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

.conversation-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 0.2rem;
}

.conversation-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    gap: 0.5rem;
}

.conversation-type {
    background: var(--bg-tertiary);
    padding: 0.1rem 0.4rem;
    border-radius: 4px;
}

/* Content Area */
#content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-width: 0;
}

.panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Stats Panel */
#stats-panel {
    padding: 2rem;
    overflow-y: auto;
}

#stats-panel h2 {
    margin-bottom: 1.5rem;
    font-size: 1.5rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
}

.chart-box {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 12px;
}

.chart-box h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--text-secondary);
}

.chart-box canvas {
    max-height: 300px;
}

#top-conversations,
#word-cloud {
    max-height: 300px;
    overflow-y: auto;
}

.top-conv-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border-color);
}

.top-conv-item:last-child {
    border-bottom: none;
}

.top-conv-rank {
    width: 24px;
    height: 24px;
    background: var(--accent-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: bold;
}

.top-conv-name {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.top-conv-count {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.word-item {
    display: inline-block;
    padding: 0.3rem 0.6rem;
    margin: 0.2rem;
    background: var(--bg-accent);
    border-radius: 16px;
    font-size: 0.85rem;
}

/* Messages Panel */
.messages-header {
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.messages-header h2 {
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.messages-search {
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.message {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    border-radius: 8px;
    transition: background 0.2s;
}

.message:hover {
    background: var(--bg-secondary);
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    flex-shrink: 0;
}

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

.message-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.message-author {
    font-weight: 600;
    color: var(--text-primary);
}

.message-timestamp {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.message-text {
    color: var(--text-primary);
    line-height: 1.5;
    word-break: break-word;
}

.message-text a {
    color: #00aff4;
    text-decoration: none;
}

.message-text a:hover {
    text-decoration: underline;
}

.message-attachments {
    margin-top: 0.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.attachment {
    max-width: 400px;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
}

.attachment-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-accent);
    border-radius: 8px;
    color: #00aff4;
    text-decoration: none;
    font-size: 0.9rem;
}

.attachment-link:hover {
    background: var(--bg-tertiary);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 2rem;
}

.empty-state svg {
    width: 80px;
    height: 80px;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-accent);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    #main-interface {
        flex-direction: column;
    }

    #sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
    }

    .charts-container {
        grid-template-columns: 1fr;
    }

    .chart-box {
        min-width: 0;
    }
}

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

/* Highlight for search */
.highlight {
    background: rgba(250, 166, 26, 0.3);
    padding: 0.1rem 0.2rem;
    border-radius: 2px;
}
