/* ==========================================================================
   Chat — elegant UI
   ========================================================================== */

:root {
    --bg:            #0b0d13;
    --bg-2:          #11141d;
    --panel:         #151925;
    --panel-2:       #1b2030;
    --border:        #232a3b;
    --border-soft:   #1c2231;
    --text:          #e8eaf0;
    --text-dim:      #9aa3b8;
    --text-faint:    #6b7488;
    --accent:        #6366f1;
    --accent-2:      #8b5cf6;
    --accent-soft:   rgba(99, 102, 241, 0.16);
    --green:         #34d399;
    --danger:        #f87171;
    --bubble-me:     linear-gradient(135deg, #6366f1, #8b5cf6);
    --bubble-them:   #1e2434;
    --radius:        16px;
    --shadow:        0 24px 60px rgba(0, 0, 0, 0.45);
    --font:          'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: var(--font);
    background:
        radial-gradient(1000px 600px at 12% -10%, rgba(99, 102, 241, 0.14), transparent 60%),
        radial-gradient(900px 500px at 100% 110%, rgba(139, 92, 246, 0.12), transparent 55%),
        var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- Auth page */

.auth-body {
    display: grid;
    place-items: center;
    padding: 24px;
    min-height: 100vh;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: linear-gradient(180deg, rgba(23, 27, 40, 0.92), rgba(18, 21, 31, 0.92));
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 30px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.brand-mark {
    width: 46px; height: 46px;
    display: grid; place-items: center;
    font-size: 22px;
    border-radius: 14px;
    background: var(--accent-soft);
    border: 1px solid rgba(99, 102, 241, 0.35);
}

.brand-mark.small { width: 36px; height: 36px; font-size: 18px; border-radius: 11px; }

.brand-title { margin: 0; font-size: 1.3rem; letter-spacing: -0.02em; }
.brand-sub   { margin: 2px 0 0; font-size: 0.82rem; color: var(--text-dim); }

.tabs {
    display: flex;
    background: var(--panel-2);
    border: 1px solid var(--border-soft);
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
    margin-bottom: 18px;
}

.tab {
    flex: 1;
    padding: 9px 10px;
    border: 0;
    background: transparent;
    color: var(--text-dim);
    font: inherit;
    font-weight: 600;
    font-size: 0.88rem;
    border-radius: 9px;
    cursor: pointer;
    transition: background .18s, color .18s;
}
.tab.active { background: var(--accent-soft); color: #c7c9ff; }
.tab:hover:not(.active) { color: var(--text); }

.auth-form { display: none; flex-direction: column; gap: 14px; }
.auth-form.active { display: flex; animation: fade .25s ease; }

.field { display: flex; flex-direction: column; gap: 7px; font-size: 0.84rem; color: var(--text-dim); }

.field input {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 12px 14px;
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    transition: border-color .18s, box-shadow .18s;
}
.field input::placeholder { color: var(--text-faint); }
.field input:focus {
    outline: none;
    border-color: rgba(99, 102, 241, 0.7);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.18);
}

.btn-primary {
    margin-top: 4px;
    padding: 12px 16px;
    border: 0;
    border-radius: 11px;
    background: var(--bubble-me);
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: transform .12s, filter .18s, box-shadow .18s;
    box-shadow: 0 10px 26px rgba(99, 102, 241, 0.32);
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }

.hint { margin: 2px 0 0; font-size: 0.78rem; color: var(--text-faint); line-height: 1.5; }

.alert {
    padding: 11px 14px;
    border-radius: 11px;
    font-size: 0.85rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert.error { background: rgba(248, 113, 113, 0.1); border-color: rgba(248, 113, 113, 0.35); color: #fca5a5; }
.alert.ok    { background: rgba(52, 211, 153, 0.1); border-color: rgba(52, 211, 153, 0.35); color: #6ee7b7; }

/* ------------------------------------------------------------- Chat layout */

.app {
    display: grid;
    grid-template-columns: 280px 1fr;
    height: 100vh;
    height: 100dvh;
}

.sidebar {
    background: linear-gradient(180deg, rgba(21, 25, 37, 0.9), rgba(16, 19, 28, 0.9));
    border-right: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    gap: 18px;
}

.sidebar-head { display: flex; align-items: center; gap: 11px; }
.sidebar-title { font-weight: 700; letter-spacing: -0.01em; }

.sidebar-section-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    color: var(--text-faint);
    font-weight: 600;
    padding-left: 6px;
}

.online-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1; }

.online-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 11px;
    font-size: 0.9rem;
    transition: background .15s;
}
.online-item:hover { background: var(--panel-2); }
.online-empty { color: var(--text-faint); font-size: 0.82rem; padding: 8px 10px; }

.avatar {
    width: 30px; height: 30px;
    flex: 0 0 30px;
    border-radius: 50%;
    display: grid; place-items: center;
    font-size: 0.78rem;
    font-weight: 700;
    color: #fff;
    position: relative;
    text-transform: uppercase;
}
.avatar .dot {
    position: absolute;
    right: -1px; bottom: -1px;
    width: 9px; height: 9px;
    border-radius: 50%;
    background: var(--green);
    border: 2px solid var(--panel);
}

.sidebar-foot {
    border-top: 1px solid var(--border-soft);
    padding-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logout {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: color .15s, border-color .15s;
    white-space: nowrap;
}
.logout:hover { color: var(--danger); border-color: rgba(248, 113, 113, 0.4); }

/* ------------------------------------------------------------------ Chat */

.chat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background:
        radial-gradient(700px 400px at 80% -5%, rgba(139, 92, 246, 0.08), transparent 60%),
        var(--bg-2);
}

.chat-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-soft);
    background: rgba(11, 13, 19, 0.55);
    backdrop-filter: blur(10px);
}
.chat-head-left { display: flex; align-items: center; gap: 12px; }
.status-dot {
    width: 10px; height: 10px; border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}
.chat-title { font-weight: 700; letter-spacing: -0.01em; }
.chat-sub   { font-size: 0.78rem; color: var(--text-dim); margin-top: 1px; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scroll-behavior: smooth;
}

.day-divider {
    align-self: center;
    font-size: 0.72rem;
    color: var(--text-faint);
    background: var(--panel);
    border: 1px solid var(--border-soft);
    padding: 4px 12px;
    border-radius: 999px;
    margin: 14px 0 10px;
}

.msg {
    display: flex;
    gap: 10px;
    max-width: min(680px, 82%);
    margin-top: 10px;
    animation: rise .22s ease both;
}
.msg.grouped { margin-top: 2px; }

.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .msg-col { align-items: flex-end; }

.msg-col { display: flex; flex-direction: column; gap: 3px; min-width: 0; }

.msg-author {
    font-size: 0.74rem;
    color: var(--text-dim);
    font-weight: 600;
    padding: 0 4px;
}

.bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.93rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.msg.them .bubble {
    background: var(--bubble-them);
    border: 1px solid var(--border-soft);
    border-top-left-radius: 5px;
}
.msg.me .bubble {
    background: var(--bubble-me);
    color: #fff;
    border-top-right-radius: 5px;
    box-shadow: 0 8px 22px rgba(99, 102, 241, 0.25);
}
.msg.grouped .bubble { border-radius: 16px; }
.msg.them.grouped .bubble { border-top-left-radius: 6px; }
.msg.me.grouped   .bubble { border-top-right-radius: 6px; }

.msg-time {
    font-size: 0.68rem;
    color: var(--text-faint);
    padding: 0 4px;
    opacity: 0;
    transition: opacity .18s;
}
.msg:hover .msg-time { opacity: 1; }

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-faint);
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}
.empty-state .big { font-size: 2rem; }

/* ------------------------------------------------------------- Composer */

.composer {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 20px calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-soft);
    background: rgba(11, 13, 19, 0.6);
    backdrop-filter: blur(10px);
}

.composer textarea {
    flex: 1;
    resize: none;
    max-height: 160px;
    min-height: 46px;
    padding: 13px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    font: inherit;
    font-size: 0.95rem;
    line-height: 1.4;
    transition: border-color .18s, box-shadow .18s;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer textarea:focus {
    outline: none;
    border-color: rgba(99, 102, 241, 0.7);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.16);
}

.send {
    flex: 0 0 auto;
    width: 46px; height: 46px;
    border: 0;
    border-radius: 14px;
    background: var(--bubble-me);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 10px 24px rgba(99, 102, 241, 0.32);
    transition: transform .12s, filter .18s;
}
.send:hover { filter: brightness(1.1); }
.send:active { transform: translateY(1px) scale(0.97); }
.send:disabled { opacity: .5; cursor: default; }

/* --------------------------------------------------------------- Motion */

@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ Responsive */

@media (max-width: 760px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 30;
        top: 0; bottom: 0; left: 0;
        width: 260px;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow);
    }
    .sidebar.open { transform: none; }
    .messages { padding: 16px; }
    .msg { max-width: 88%; }
    .chat-head { padding: 14px 16px; }
    .menu-btn { display: grid !important; }
}

.menu-btn {
    display: none;
    width: 38px; height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--panel);
    color: var(--text);
    place-items: center;
    cursor: pointer;
    margin-right: 10px;
}

/* Scrollbars */
.messages::-webkit-scrollbar, .online-list::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb, .online-list::-webkit-scrollbar-thumb {
    background: #2a3143; border-radius: 9px; border: 2px solid transparent; background-clip: content-box;
}
