/* ═══════════════════════════════════════════
   nanex chat — consistent with nanex.dev
   Font: Inter · Accent: #6fa8dc · BG: #0a0a1a
   ═══════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;700;900&family=JetBrains+Mono:wght@400;700&display=swap');

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

:root {
    --bg-darkest: #060612;
    --bg-dark: #0d0d20;
    --bg-main: #0a0a1a;
    --bg-light: #161630;
    --bg-hover: #1c1c3a;
    --bg-active: #1a1a35;
    --border: rgba(255,255,255,0.07);
    --card-bg: rgba(255,255,255,0.04);
    --card-border: rgba(255,255,255,0.07);
    --text-primary: #d8dce6;
    --text-secondary: #b0b8c8;
    --text-muted: rgba(216,220,230,0.55);
    --text-bright: #f0f2f7;
    --accent: #6fa8dc;
    --accent-hover: #93c5fd;
    --accent-dim: rgba(111,168,220,0.15);
    --green: #57F287;
    --red: #ED4245;
    --yellow: #FEE75C;
    --orange: #FF7F50;
    --owner-color: #FFD700;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --mono: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
}

html, body { height: 100%; }
body {
    font-family: var(--font);
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    overflow: hidden;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(111,168,220,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(111,168,220,0.35); }

/* ═══════════════════
   Auth Page
   ═══════════════════ */
.auth-container {
    display: flex; align-items: center; justify-content: center;
    height: 100vh;
    background: var(--bg-darkest);
    background-image: radial-gradient(ellipse at 50% 0%, rgba(111,168,220,0.08) 0%, transparent 60%);
}
.auth-box {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    backdrop-filter: blur(12px);
    padding: 36px; border-radius: 12px;
    width: 420px; max-width: 90vw;
    box-shadow: 0 16px 48px rgba(0,0,0,.5);
}
.auth-box h1 {
    text-align: center; color: var(--accent);
    font-size: 26px; font-weight: 700; margin-bottom: 4px;
    letter-spacing: -0.5px;
}
.auth-brand {
    display: block; text-align: center;
    font-size: 11px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase; color: var(--text-muted);
    text-decoration: none; margin-bottom: 12px;
}
.auth-brand:hover { color: var(--accent); }
.auth-pw-warn {
    font-size: 12px; color: var(--yellow); opacity: 0.85;
    margin: -4px 0 14px; line-height: 1.4;
}
.auth-box .auth-subtitle {
    text-align: center; color: var(--text-muted);
    font-size: 14px; margin-bottom: 24px;
}
.auth-error {
    color: var(--red); font-size: 13px;
    margin-bottom: 10px; min-height: 18px;
}
.auth-box label {
    display: block; color: var(--text-secondary);
    font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .8px;
    margin-bottom: 6px;
}
.auth-box input[type="text"],
.auth-box input[type="password"] {
    width: 100%; padding: 10px 14px;
    background: rgba(255,255,255,0.04); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-primary);
    font-family: var(--font); font-size: 15px; outline: none;
    margin-bottom: 16px; transition: border-color .2s;
}
.auth-box input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.auth-box button[type="submit"] {
    width: 100%; padding: 12px;
    background: var(--accent); color: #0a0a1a;
    border: none; border-radius: 6px;
    font-family: var(--font); font-size: 15px; font-weight: 700;
    cursor: pointer; transition: background .2s, transform .15s;
    letter-spacing: .3px;
}
.auth-box button[type="submit"]:hover { background: var(--accent-hover); transform: translateY(-1px); }
.auth-box button[type="submit"]:active { transform: translateY(0); }
.auth-toggle {
    text-align: center; margin-top: 16px;
    font-size: 13px; color: var(--text-muted);
}
.auth-toggle a { color: var(--accent); text-decoration: none; cursor: pointer; }
.auth-toggle a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ═══════════════════
   Chat Layout
   ═══════════════════ */
.chat-layout {
    display: flex; height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
    width: 250px; min-width: 250px;
    background: var(--bg-dark);
    display: flex; flex-direction: column;
    border-right: 1px solid var(--border);
}
.sidebar-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
    height: 52px;
    background: rgba(111,168,220,0.03);
}
.sidebar-header h2 {
    font-size: 16px; font-weight: 700;
    color: var(--accent); letter-spacing: -0.3px;
}
.sidebar-brand {
    font-size: 9px; font-weight: 700; letter-spacing: 1px;
    text-transform: uppercase; color: var(--text-muted);
    text-decoration: none; padding: 2px 6px;
    border: 1px solid var(--border); border-radius: 4px;
}
.sidebar-brand:hover { color: var(--accent); border-color: var(--accent); }
.sidebar-header .server-badge {
    font-size: 9px; padding: 2px 6px; border-radius: 4px;
    background: var(--owner-color); color: #000;
    font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.sidebar-section { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-title {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 18px 6px;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-muted);
}
.sidebar-title button {
    background: none; border: none; color: var(--text-muted);
    font-size: 16px; cursor: pointer; padding: 0 4px; line-height: 1;
}
.sidebar-title button:hover { color: var(--accent); }

.ch-item, .dm-item {
    display: flex; align-items: center; gap: 8px;
    padding: 7px 18px; margin: 1px 8px;
    border-radius: 6px; cursor: pointer;
    font-size: 14px; color: var(--text-muted);
    transition: background .15s, color .15s;
}
.ch-item:hover, .dm-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.ch-item.active, .dm-item.active { background: var(--accent-dim); color: var(--accent); }
.ch-item .ch-hash { font-weight: 700; opacity: .5; margin-right: 2px; font-size: 16px; }
.ch-item .ch-delete {
    margin-left: auto; opacity: 0; color: var(--text-muted);
    background: none; border: none; cursor: pointer; font-size: 13px; padding: 2px;
}
.ch-item:hover .ch-delete { opacity: 1; }
.ch-item .ch-delete:hover { color: var(--red); }

.dm-item .dm-avatar {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0;
}
.dm-item .dm-name { font-size: 14px; }
.dm-item .dm-online {
    width: 8px; height: 8px; border-radius: 50%;
    margin-left: auto; flex-shrink: 0;
}

/* ── Sidebar user bar ── */
.sidebar-user {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px;
    background: var(--bg-darkest);
    border-top: 1px solid var(--border);
}
.sidebar-user .user-avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 14px; flex-shrink: 0;
}
.sidebar-user .user-name {
    font-size: 13px; font-weight: 600; color: var(--text-bright);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.sidebar-user .user-role {
    font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
}
.role-owner { color: var(--owner-color); }
.role-admin { color: var(--red); }
.role-mod { color: var(--yellow); }
.role-member { color: var(--text-muted); }
.sidebar-user button {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; font-size: 16px; padding: 4px;
}
.sidebar-user button:hover { color: var(--accent); }

/* ── Main content ── */
.main {
    flex: 1; display: flex; flex-direction: column;
    min-width: 0;
}
.main-header {
    height: 52px; min-height: 52px;
    display: flex; align-items: center; gap: 8px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(111,168,220,0.02);
}
.main-header .header-hash { color: var(--text-muted); font-size: 20px; font-weight: 300; }
.main-header .header-name { color: var(--text-bright); font-size: 15px; font-weight: 600; }
.main-header .header-desc {
    color: var(--text-muted); font-size: 13px;
    margin-left: 12px; padding-left: 12px;
    border-left: 1px solid var(--border);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ── Messages ── */
.messages-wrapper {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 16px 0;
}
.messages { min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }

.msg {
    position: relative;
    padding: 3px 48px 3px 72px;
    min-height: 2.5em;
    transition: background .1s;
}
.msg:hover { background: rgba(111,168,220,0.03); }
.msg .msg-avatar {
    position: absolute; left: 16px; top: 4px;
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 17px;
    cursor: pointer; flex-shrink: 0;
}
.msg .msg-header { display: flex; align-items: baseline; gap: 8px; }
.msg .msg-name {
    font-weight: 600; font-size: 15px; cursor: pointer;
}
.msg .msg-name:hover { text-decoration: underline; }
.msg .msg-badge {
    font-size: 9px; padding: 2px 5px; border-radius: 3px;
    font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
}
.msg-badge-owner { background: var(--owner-color); color: #000; }
.msg-badge-admin { background: var(--red); color: #fff; }
.msg-badge-mod { background: var(--yellow); color: #000; }
.msg .msg-time { font-size: 11px; color: var(--text-muted); }
.msg .msg-content {
    font-size: 15px; line-height: 1.5;
    word-wrap: break-word; overflow-wrap: break-word;
}
.msg .msg-content code {
    background: rgba(111,168,220,0.1); padding: 2px 6px;
    border-radius: 4px; font-size: 13px;
    font-family: var(--mono); border: 1px solid rgba(111,168,220,0.15);
}
.msg .msg-content pre {
    background: var(--bg-darkest); padding: 10px 14px;
    border-radius: 6px; margin: 6px 0;
    border: 1px solid var(--border);
    overflow-x: auto;
}
.msg .msg-content pre code { padding: 0; background: none; border: none; }
.msg .msg-content a { color: var(--accent); text-decoration: none; }
.msg .msg-content a:hover { color: var(--accent-hover); text-decoration: underline; }
.msg .msg-edited { font-size: 10px; color: var(--text-muted); margin-left: 4px; }

.msg-grouped { min-height: 1.4em; padding-top: 0; padding-bottom: 0; }
.msg-grouped .msg-time-hover {
    position: absolute; left: 16px;
    width: 40px; text-align: center;
    font-size: 10px; color: var(--text-muted);
    opacity: 0; transition: opacity .1s;
    top: 50%; transform: translateY(-50%);
}
.msg-grouped:hover .msg-time-hover { opacity: 1; }

.msg-deleted .msg-content { color: var(--text-muted); font-style: italic; }

.msg-actions {
    position: absolute; right: 16px; top: -14px;
    display: none; gap: 2px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 6px; padding: 2px;
}
.msg:hover .msg-actions { display: flex; }
.msg-actions button {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    padding: 4px 8px; font-size: 14px;
    border-radius: 4px;
}
.msg-actions button:hover { background: var(--bg-hover); color: var(--text-primary); }
.msg-actions button.act-delete:hover { color: var(--red); }

.msg-image { margin: 6px 0; }
.msg-image img {
    max-width: 400px; max-height: 300px;
    border-radius: 8px; cursor: pointer;
    display: block; border: 1px solid var(--border);
}
.msg-file {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--card-bg); padding: 8px 14px;
    border-radius: 6px; margin: 4px 0;
    border: 1px solid var(--border);
}
.msg-file a { color: var(--accent); text-decoration: none; font-size: 14px; }
.msg-file a:hover { text-decoration: underline; }

.edit-input {
    width: 100%; padding: 8px 12px;
    background: var(--bg-light); border: 1px solid var(--accent);
    border-radius: 6px; color: var(--text-primary);
    font-family: var(--font); font-size: 15px;
    resize: none; outline: none;
}
.edit-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ── Typing indicator ── */
.typing-indicator {
    padding: 0 20px; height: 24px; min-height: 24px;
    display: flex; align-items: center;
    font-size: 12px; color: var(--text-muted);
}
.typing-indicator .typing-dots {
    display: inline-flex; gap: 3px; margin-right: 8px;
}
.typing-indicator .typing-dots span {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--accent);
    animation: typingBounce 1.4s infinite;
}
.typing-indicator .typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-indicator .typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ── Input area ── */
.input-area {
    padding: 0 16px 16px;
    display: flex; align-items: flex-end; gap: 8px;
    position: relative;
}
.input-area textarea {
    flex: 1; padding: 11px 16px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-family: var(--font); font-size: 15px;
    resize: none; outline: none;
    max-height: 200px; line-height: 1.5;
    transition: border-color .2s;
}
.input-area textarea:focus { border-color: rgba(111,168,220,0.4); }
.input-area textarea::placeholder { color: var(--text-muted); }
.attach-btn, .send-btn {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    font-size: 20px; padding: 8px;
    border-radius: 6px; flex-shrink: 0;
    transition: color .15s;
}
.attach-btn:hover { color: var(--accent); }
.send-btn:hover { color: var(--accent); }
.file-preview {
    position: absolute; bottom: 100%; left: 16px; right: 16px;
    background: var(--bg-dark); border: 1px solid var(--border);
    border-radius: 8px 8px 0 0; padding: 12px;
    display: flex; align-items: center; gap: 12px;
}
.file-preview .fp-name { flex: 1; font-size: 14px; color: var(--text-primary); overflow: hidden; text-overflow: ellipsis; }
.file-preview .fp-size { font-size: 12px; color: var(--text-muted); }
.file-preview .fp-remove {
    background: none; border: none; color: var(--red);
    cursor: pointer; font-size: 18px;
}
.file-preview img {
    max-width: 60px; max-height: 60px; border-radius: 4px;
}

/* ── Users panel ── */
.users-panel {
    width: 240px; min-width: 240px;
    background: var(--bg-dark);
    border-left: 1px solid var(--border);
    overflow-y: auto; padding: 12px 8px;
}
.users-section-title {
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: 1px;
    color: var(--text-muted); padding: 12px 8px 4px;
}
.user-item {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 8px; border-radius: 6px;
    cursor: pointer; transition: background .15s;
}
.user-item:hover { background: var(--bg-hover); }
.user-item .ui-avatar {
    width: 32px; height: 32px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff; font-size: 14px;
    position: relative; flex-shrink: 0;
}
.user-item .ui-status {
    position: absolute; bottom: -1px; right: -1px;
    width: 10px; height: 10px; border-radius: 50%;
    border: 2px solid var(--bg-dark);
}
.ui-status.online { background: var(--green); }
.ui-status.offline { background: var(--text-muted); }
.user-item .ui-name { font-size: 14px; color: var(--text-secondary); }
.user-item .ui-role-badge {
    font-size: 8px; padding: 1px 5px; border-radius: 3px;
    font-weight: 700; margin-left: auto; text-transform: uppercase;
    letter-spacing: .5px;
}
.user-item.banned-user { opacity: 0.4; }
.user-item .ui-crown { font-size: 12px; margin-left: 2px; }

/* ── User context menu ── */
.user-ctx {
    position: fixed; z-index: 100;
    background: var(--bg-darkest); border: 1px solid var(--border);
    border-radius: 6px; padding: 4px; min-width: 180px;
    box-shadow: 0 8px 24px rgba(0,0,0,.6);
}
.user-ctx button {
    display: block; width: 100%;
    background: none; border: none;
    color: var(--text-primary); cursor: pointer;
    padding: 7px 14px; font-size: 13px;
    text-align: left; border-radius: 4px;
    font-family: var(--font);
}
.user-ctx button:hover { background: var(--accent); color: #fff; }
.user-ctx button.ctx-danger { color: var(--red); }
.user-ctx button.ctx-danger:hover { background: var(--red); color: #fff; }
.user-ctx .ctx-divider { height: 1px; background: var(--border); margin: 4px 0; }
.user-ctx .ctx-header {
    padding: 6px 14px 4px; font-size: 10px;
    color: var(--text-muted); font-weight: 700;
    text-transform: uppercase; letter-spacing: .5px;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: rgba(0,0,0,.75);
    display: flex; align-items: center; justify-content: center;
    backdrop-filter: blur(4px);
}
.modal {
    background: var(--bg-main); border: 1px solid var(--border);
    border-radius: 10px;
    padding: 28px; max-width: 440px; width: 90vw;
    box-shadow: 0 16px 48px rgba(0,0,0,.6);
}
.modal h3 { color: var(--text-bright); margin-bottom: 16px; font-weight: 700; }
.modal label {
    display: block; font-size: 11px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .8px;
    color: var(--text-secondary); margin-bottom: 6px;
}
.modal input[type="text"] {
    width: 100%; padding: 10px 14px;
    background: rgba(255,255,255,0.04); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-primary);
    font-family: var(--font); font-size: 15px; outline: none; margin-bottom: 12px;
}
.modal input:focus { border-color: var(--accent); }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.modal-buttons button {
    padding: 9px 22px; border: none; border-radius: 6px;
    font-size: 14px; cursor: pointer; font-weight: 600;
    font-family: var(--font); transition: background .15s;
}
.modal-buttons .btn-cancel { background: transparent; color: var(--text-primary); }
.modal-buttons .btn-cancel:hover { text-decoration: underline; }
.modal-buttons .btn-primary { background: var(--accent); color: #0a0a1a; }
.modal-buttons .btn-primary:hover { background: var(--accent-hover); }
.modal-buttons .btn-danger { background: var(--red); color: #fff; }
.modal-buttons .btn-danger:hover { background: #c03537; }

.image-viewer { background: transparent; padding: 0; max-width: 90vw; width: auto; border: none; }
.image-viewer img { max-width: 90vw; max-height: 85vh; border-radius: 8px; display: block; }

/* ── Empty + Welcome ── */
.empty-state {
    text-align: center; padding: 40px; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { color: var(--text-primary); margin-bottom: 4px; }

.welcome {
    flex: 1; display: flex; align-items: center; justify-content: center;
    text-align: center; color: var(--text-muted);
}
.welcome h2 { color: var(--accent); font-size: 24px; margin-bottom: 8px; letter-spacing: -0.3px; }

/* ═══════════════════
   Avatar Images
   ═══════════════════ */
.has-img { overflow: hidden; }
.has-img img {
    width: 100%; height: 100%;
    object-fit: cover; display: block;
    border-radius: 50%;
}

/* ── Avatar menu ── */
.avatar-menu {
    position: fixed; z-index: 1000;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 6px; padding: 4px;
    min-width: 160px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.avatar-menu button {
    display: block; width: 100%;
    background: none; border: none;
    color: var(--text-primary); font-family: var(--font);
    font-size: 13px; padding: 8px 12px;
    text-align: left; border-radius: 4px;
    cursor: pointer;
}
.avatar-menu button:hover { background: var(--bg-hover); }
.avatar-menu .ctx-danger { color: var(--red); }
.avatar-menu .ctx-danger:hover { background: rgba(237,66,69,0.1); }
.welcome .welcome-sub { color: var(--text-muted); font-size: 14px; }