:root {
    --bg-dark: #0a0a0a;
    --bg-panel: #111111;
    --bg-card: #161616;
    --border: #333333;
    --text-main: #e0e0e0;
    --text-dim: #888888;
    --accent: #d4a373;
    /* Gold/Bronze accent from image */
    --accent-hover: #e9c496;
    --danger: #ff5555;
    --success: #50fa7b;
    --font-main: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius: 8px;
}

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

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

/* Grid Background */
.grid-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    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: 50px 50px;
    z-index: -1;
    pointer-events: none;
}

/* Layout */
.app-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.logo h1 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-main);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 15px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
}

.status-indicator.online {
    background: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.status-indicator.offline {
    background: var(--danger);
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.2s;
    display: flex;
    align-items: center;
}

.btn-icon:hover {
    color: var(--text-main);
}

/* Main Content */
.main-content {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
    /* Important for scrolling */
}

/* Sidebar */
.sidebar {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sidebar-section {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.section-header {
    padding: 12px 15px;
    font-size: 0.9rem;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    cursor: default;
}

.section-content {
    padding: 15px;
}

.user-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 15px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 10px;
}

.id-display {
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px;
    border-radius: 4px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.friends-list {
    list-style: none;
    overflow-y: auto;
    max-height: 400px;
}

.friends-list li {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.friends-list li:hover {
    background: var(--bg-card);
}

.friends-list li.active {
    background: var(--bg-card);
    border-left: 3px solid var(--accent);
}

.friends-list li.unread {
    color: var(--accent);
    font-weight: bold;
}

/* Chat Area */
.chat-area {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-dim);
    font-style: italic;
    font-size: 0.9rem;
}

.chat-interface {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header-bar {
    padding: 15px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#current-chat-name {
    font-family: var(--font-mono);
    font-weight: bold;
}

.typing-indicator {
    font-size: 0.8rem;
    color: var(--accent);
    font-style: italic;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
}

.message.me {
    align-self: flex-end;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-right-radius: 0;
}

.message.them {
    align-self: flex-start;
    background: #222;
    border: 1px solid var(--border);
    border-bottom-left-radius: 0;
}

.message .meta {
    display: block;
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-bottom: 5px;
    font-family: var(--font-mono);
}

/* Input Area */
.input-area {
    padding: 15px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    background: var(--bg-panel);
}

.input-area textarea {
    flex: 1;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 10px;
    border-radius: 4px;
    resize: none;
    height: 50px;
    font-family: var(--font-main);
}

.input-area textarea:focus {
    outline: 1px solid var(--accent);
}

.btn {
    padding: 8px 16px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn.primary {
    background: var(--accent);
    color: #000;
}

.btn.secondary {
    background: transparent;
    border: 1px solid var(--text-dim);
    color: var(--text-dim);
}

.btn-icon-large {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-dim);
}

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

.btn-icon-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
}

.btn-icon-box:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Inputs */
input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    font-family: var(--font-main);
}

input:focus {
    outline: 1px solid var(--accent);
}

.input-group {
    margin-bottom: 10px;
}

.input-row {
    display: flex;
    gap: 10px;
}

.actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

/* Drop Zone */
.drop-zone {
    border: 2px dashed var(--border);
    padding: 20px;
    text-align: center;
    margin-bottom: 15px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color 0.2s;
}

.drop-zone:hover {
    border-color: var(--accent);
}

.drop-text {
    color: var(--text-dim);
    font-size: 0.9rem;
}

/* File Previews */
.file-preview img {
    max-width: 100%;
    border-radius: 4px;
    margin-top: 5px;
    border: 1px solid var(--border);
}

.file-preview iframe {
    width: 100%;
    height: 300px;
    border: 1px solid var(--border);
    background: #fff;
    margin-top: 5px;
}

.file-download {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    margin-top: 5px;
    border-radius: 4px;
    font-size: 0.9rem;
}

.file-download a {
    color: var(--accent);
    text-decoration: none;
}

.hidden {
    display: none !important;
}

.flex-grow {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.error-msg {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 5px;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .app-wrapper {
        padding: 10px;
        height: 100vh;
        overflow: hidden;
    }

    .app-header {
        padding: 10px 15px;
        margin-bottom: 10px;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .main-content {
        grid-template-columns: 1fr;
        gap: 0;
        position: relative;
        overflow: hidden;
    }

    /* Mobile View Logic:
       By default, show Sidebar.
       When chat is active, Sidebar gets .hidden-mobile and Chat gets .active-mobile
    */

    .sidebar {
        width: 100%;
        height: 100%;
        overflow-y: auto;
        display: flex;
    }

    .sidebar.hidden-mobile {
        display: none;
    }

    .chat-area {
        display: none;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        z-index: 10;
        border: none;
        border-radius: 0;
    }

    .chat-area.active-mobile {
        display: flex;
    }

    /* Back Button for Mobile */
    .mobile-back-btn {
        display: block !important;
        margin-right: 10px;
        background: none;
        border: none;
        color: var(--text-main);
        font-size: 1.2rem;
        cursor: pointer;
        padding: 5px;
    }

    .chat-header-bar {
        padding: 10px;
    }

    .input-area {
        padding: 10px;
    }

    .btn {
        padding: 10px 16px;
        /* Larger touch target */
    }
}

/* Hide mobile back button on desktop */
.mobile-back-btn {
    display: none;
}