/* CSS Variables */
:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --accent-primary: #e94560;
    --accent-secondary: #0f3460;
    --border-color: #333;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    --radius: 8px;
    --radius-lg: 16px;
}

/* Reset */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
}

/* Screens */
.screen {
    height: 100%;
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
}

.hidden {
    display: none !important;
}

/* Login Screen */
#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.login-container {
    text-align: center;
    padding: 2rem;
}

.login-container h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    color: var(--accent-primary);
}

.login-container p {
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
}

.btn-primary:hover {
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--accent-secondary);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Screen Layout */
#main-screen {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Header */
#header {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    gap: 1rem;
}

#header h1 {
    flex: 1;
    font-size: 1.25rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

/* Sidebar */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 280px;
    height: 100%;
    background: var(--bg-secondary);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

#sidebar.open {
    transform: translateX(0);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 500;
}

#channel-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
}

#channel-list li {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

#channel-list li:hover {
    background: rgba(255, 255, 255, 0.05);
}

#channel-list li.active {
    background: var(--bg-tertiary);
    border-left: 3px solid var(--accent-primary);
}

#channel-list .channel-name {
    font-weight: 500;
}

#channel-list .channel-desc {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Overlay for sidebar */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

/* Messages Area */
#messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

#messages {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1rem;
    max-width: 100%;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.message-id {
    font-family: monospace;
    font-size: 0.875rem;
    color: var(--accent-primary);
    background: var(--bg-tertiary);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
}

.message-time {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-left: auto;
}

.message-content {
    white-space: pre-wrap;
    word-break: break-word;
}

.message-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.tag {
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
}

#load-more {
    padding: 1rem;
    text-align: center;
}

/* Compose Area */
#compose-area {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
}

#tag-input-container {
    margin-bottom: 0.5rem;
}

#tag-input {
    width: 100%;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    color: var(--text-primary);
    font-size: 0.875rem;
}

#tag-input::placeholder {
    color: var(--text-secondary);
}

#message-input-container {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

#message-input {
    flex: 1;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    resize: none;
    max-height: 200px;
    line-height: 1.4;
}

#message-input::placeholder {
    color: var(--text-secondary);
}

#send-btn {
    color: var(--accent-primary);
}

/* User Menu */
#user-menu {
    position: absolute;
    top: 60px;
    right: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 200px;
    z-index: 50;
}

#user-info {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

#user-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.dropdown-item {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1rem;
}

.dropdown-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

/* Modals */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 1rem;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    width: 100%;
    max-width: 400px;
}

.modal-content h2 {
    margin-bottom: 1rem;
}

.modal-content input {
    width: 100%;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius);
    padding: 0.75rem;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.modal-content input::placeholder {
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--bg-tertiary);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* Responsive */
@media (min-width: 768px) {
    #sidebar {
        position: relative;
        transform: none;
        width: 280px;
        flex-shrink: 0;
    }

    #main-screen {
        flex-direction: row;
    }

    #main-screen > div:not(#sidebar) {
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    #menu-btn {
        display: none;
    }
}

/* Focus styles */
input:focus, textarea:focus, button:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-secondary);
}
