/* ===========================
   Reset & Base
   =========================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:          #1a1d23;
    --bg-sidebar:  #111318;
    --bg-card:     #22262e;
    --bg-input:    #2c313b;
    --accent:      #5865f2;
    --accent-dark: #4752c4;
    --text:        #dcddde;
    --text-muted:  #72767d;
    --text-strong: #ffffff;
    --border:      #2e3340;
    --green:       #3ba55c;
    --red:         #ed4245;
    --radius:      8px;
    --sidebar-w:   240px;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===========================
   Auth pages
   =========================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px 36px;
    width: 100%;
    max-width: 400px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 24px;
}

.auth-logo h1 {
    font-size: 1.3rem;
    color: var(--text-strong);
    font-weight: 700;
}

.logo-icon {
    font-size: 1.6rem;
    color: var(--accent);
}

.auth-card h2 {
    font-size: 1.5rem;
    color: var(--text-strong);
    margin-bottom: 20px;
    font-weight: 600;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    font-size: 0.95rem;
    outline: none;
    transition: border-color .15s;
}

.form-group input:focus {
    border-color: var(--accent);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background .15s;
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #fff;
    margin-top: 8px;
}

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

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 16px;
}

.alert-error {
    background: rgba(237, 66, 69, .15);
    border: 1px solid var(--red);
    color: #f88;
}

.auth-footer {
    text-align: center;
    margin-top: 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

/* ===========================
   Chat layout
   =========================== */
.chat-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    color: var(--text-strong);
    font-size: 0.95rem;
}

.sidebar-title { font-size: 0.9rem; }

.sidebar-section {
    padding: 16px 8px 8px;
    flex: 1;
}

.sidebar-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 4px;
}

.btn-new-channel {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 0 4px;
    border-radius: 4px;
    line-height: 1;
    transition: color .12s, background .12s;
}
.btn-new-channel:hover {
    color: var(--text-strong);
    background: var(--bg-card);
}

.new-channel-form {
    padding: 6px 8px 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.new-channel-form input {
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-strong);
    font-size: 0.85rem;
    outline: none;
}
.new-channel-form input:focus { border-color: var(--accent); }
.new-channel-actions {
    display: flex;
    gap: 6px;
}
.btn-confirm {
    flex: 1;
    padding: 5px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background .12s;
}
.btn-confirm:hover { background: var(--accent-dark); }
.btn-cancel {
    padding: 5px 10px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: color .12s;
}
.btn-cancel:hover { color: var(--red); }

.sidebar-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 0 8px;
    margin-bottom: 4px;
}

.channel-item {
    padding: 6px 10px;
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    transition: background .12s, color .12s;
}

.channel-item:hover, .channel-item.active {
    background: var(--bg-card);
    color: var(--text-strong);
}

.sidebar-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: rgba(0,0,0,.15);
}

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

.username-display {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-strong);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-logout {
    color: var(--text-muted);
    font-size: 1.1rem;
    padding: 4px 6px;
    border-radius: 4px;
    transition: color .12s, background .12s;
}

.btn-logout:hover {
    color: var(--red);
    background: rgba(237,66,69,.12);
    text-decoration: none;
}

/* --- Avatar --- */
.avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
    text-transform: uppercase;
    flex-shrink: 0;
}

/* --- Chat main --- */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    height: 52px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg);
}

.channel-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-strong);
}

.online-badge {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

.online-badge.online {
    color: var(--green);
}

/* --- Messages --- */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.message {
    display: flex;
    gap: 14px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: background .1s;
}

.message:hover {
    background: rgba(255,255,255,.03);
}

.message-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    flex-shrink: 0;
    margin-top: 2px;
}

.message-mine .message-avatar {
    background: var(--green);
}

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

.message-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.message-author {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--text-strong);
}

.message-mine .message-author {
    color: #6ae16a;
}

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

.message-text {
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 0.95rem;
}

.empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* --- Input area --- */
.input-area {
    padding: 12px 20px 18px;
    flex-shrink: 0;
}

#chat-form {
    display: flex;
    gap: 10px;
    align-items: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 4px 4px 16px;
    transition: border-color .15s;
}

#chat-form:focus-within {
    border-color: var(--accent);
}

#msg-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-strong);
    font-size: 0.95rem;
    padding: 8px 0;
}

#msg-input::placeholder { color: var(--text-muted); }

.btn-send {
    width: 36px;
    height: 36px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
}

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

/* ===========================
   Responsive
   =========================== */
@media (max-width: 580px) {
    .sidebar { width: 60px; }
    .sidebar-title, .channel-item, .username-display, .sidebar-label { display: none; }
    .sidebar-header { justify-content: center; padding: 14px 8px; }
    .sidebar-footer { justify-content: center; padding: 10px 4px; }
    .btn-logout { display: none; }
}
