:root {
    --bg: #0e1116;
    --panel: #161b22;
    --panel-2: #1c2330;
    --border: #2a3038;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #2f81f7;
    --danger: #f7544f;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9rem; }

.screen { height: 100vh; }

/* --- Auth --- */
#auth-screen, #setup-screen, #reset-screen { display: flex; align-items: center; justify-content: center; }

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 340px;
}
.card h1 { margin: 0 0 0.25rem; }

.tabs { display: flex; gap: 0.5rem; margin: 1rem 0; }
.tab {
    flex: 1; background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem; cursor: pointer;
}
.tab.active { color: var(--text); border-color: var(--accent); }

.form { display: flex; flex-direction: column; gap: 0.6rem; }

input {
    background: var(--panel-2); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px; padding: 0.6rem;
    font-size: 0.95rem;
}
input:focus { outline: none; border-color: var(--accent); }

button {
    background: var(--accent); color: #fff; border: none; border-radius: 8px;
    padding: 0.6rem 0.9rem; cursor: pointer; font-size: 0.95rem;
}
button:hover { filter: brightness(1.1); }

.link {
    background: none; color: var(--muted); padding: 0.3rem 0; text-align: left;
}
.link:hover { color: var(--text); }
.link.danger { color: var(--danger); }

.error { color: var(--danger); font-size: 0.85rem; min-height: 1rem; }

/* --- App --- */
#app-screen { display: flex; }

.sidebar {
    width: 260px; background: var(--panel); border-right: 1px solid var(--border);
    display: flex; flex-direction: column; padding: 1rem; gap: 0.75rem;
}
.sidebar-head { display: flex; justify-content: space-between; align-items: center; }
.me-row { display: flex; align-items: center; gap: 0.4rem; }
.me { font-weight: 600; }

.profile-avatar-row { display: flex; align-items: center; gap: 0.8rem; }
.profile-avatar {
    width: 56px; height: 56px; border-radius: 50%; cursor: pointer;
    background: var(--panel-2); overflow: hidden;
    flex: 0 0 56px;
}
.profile-avatar:hover { opacity: 0.8; }
.profile-avatar img { width: 56px; height: 56px; display: block; object-fit: cover; }
.profile-avatar-row input { flex: 1; min-width: 0; }
.modal-divider { height: 1px; background: var(--border); margin: 0.3rem 0; }

.admin-btn {
    width: 100%; background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px; padding: 0.45rem;
    font-size: 0.82rem; margin-top: auto;
}
.admin-btn:hover { color: var(--text); border-color: var(--accent); }

.new-conv-btn {
    width: 100%; margin-bottom: 0.5rem;
}

.search-results {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 10;
    background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
    list-style: none; margin: 0.25rem 0 0; padding: 0.3rem 0;
    max-height: 200px; overflow-y: auto; scrollbar-width: none;
}
.search-results::-webkit-scrollbar { display: none; }
.search-results li {
    padding: 0.45rem 0.7rem; cursor: pointer; color: var(--muted); font-size: 0.9rem;
}
.search-results li:hover { background: var(--panel-2); color: var(--text); }

#space-add-member-form { position: relative; }

/* --- Avatar --- */
.avatar {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
    font-size: 0.72rem; font-weight: 700; color: #fff; text-transform: uppercase;
}

/* --- Avatar wrapper with online overlay --- */
.avatar-wrap {
    position: relative; display: inline-flex; flex-shrink: 0;
}
.avatar-wrap .status-dot {
    position: absolute; right: -1px; bottom: -1px;
    border: 2px solid var(--panel);
}

/* --- Online dot --- */
.status-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
}
.status-dot.online { background: #3fb950; }
.status-dot.offline { background: #555; }

/* --- Modal --- */
.modal {
    position: fixed; inset: 0; z-index: 100;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.55);
}
.modal-box {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    padding: 1.5rem; width: 400px; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.8rem; }
.modal-close { background: none; color: var(--muted); font-size: 1.3rem; border: none; cursor: pointer; }
.modal-tabs { display: flex; gap: 0.4rem; margin-bottom: 0.8rem; }
.mtab {
    flex: 1; background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px;
    padding: 0.5rem; cursor: pointer; font-size: 0.9rem; transition: all 0.15s;
}
.mtab.active {
    background: var(--accent); color: #fff;
    border-color: var(--accent); font-weight: 600;
}
.modal-body { display: flex; flex-direction: column; gap: 0.5rem; }
.modal-body input:not([type=checkbox]), .modal-body select { width: 100%; }
.modal-list {
    list-style: none; margin: 0; padding: 0;
    max-height: 300px; overflow-y: auto; scrollbar-width: none;
}
.modal-list::-webkit-scrollbar { display: none; }
.modal-list li {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.45rem 0.5rem; border-radius: 6px; cursor: pointer; font-size: 0.9rem;
}
.modal-list li:hover { background: var(--panel-2); }
.modal-list li .dm-link { flex: 1; display: flex; align-items: center; gap: 0.4rem; }
.modal-list.checkable li { cursor: default; justify-content: flex-start; }
.modal-list.checkable input[type=checkbox] { flex-shrink: 0; }
#add-members-section { margin-top: 0.6rem; display: flex; flex-direction: column; gap: 0.5rem; }
#add-members-submit { align-self: flex-start; }
.room-actions button { flex: 0 0 auto; width: 2.4rem; padding: 0.5rem 0; text-align: center; }

.room-list {
    list-style: none; margin: 0; padding: 0; flex: 1;
    overflow-y: auto; scrollbar-width: none;
    display: flex; flex-direction: column; gap: 0.3rem;
}
.room-list::-webkit-scrollbar { display: none; }
.room-list li {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.55rem 0.6rem; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.room-list li:hover { background: var(--panel-2); color: var(--text); }
.room-list li.active { background: var(--panel-2); color: var(--text); }
.room-list li .avatar { flex-shrink: 0; }
.room-list li .room-name { flex: 1; position: relative; }
.room-list li .room-name.unread { color: #fff; font-weight: 700; }
.unread-dot {
    display: inline-block; width: 10px; height: 10px; border-radius: 50%;
    background: var(--danger); flex-shrink: 0; margin-left: auto;
}

.invite-code { font-family: monospace; font-size: 0.8rem; word-break: break-all; color: var(--accent); }

.chat { flex: 1; display: flex; flex-direction: column; }
.chat-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.room-title-wrap { display: flex; flex-direction: column; }
.room-subtitle { font-size: 0.72rem; font-weight: 400; color: var(--muted); }
.chat-head-actions { display: flex; gap: 0.4rem; align-items: center; }
.chat-action-btn {
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
    width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
    font-size: 1rem; cursor: pointer; color: var(--muted); transition: background 0.15s;
    padding: 0;
}
.chat-action-btn:hover { background: var(--border); color: var(--text); }
.chat-action-btn.danger:hover { background: rgba(247,84,79,0.15); color: var(--danger); }
.member-search { position: relative; }
.member-search input { width: 180px; padding: 0.35rem 0.55rem; font-size: 0.85rem; }

.messages { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.6rem; }
.messages.select-mode { padding-left: 2.2rem; }

.msg { max-width: 70%; padding: 0.5rem 0.75rem; border-radius: 10px; background: var(--panel-2); }
.msg.mine { align-self: flex-end; background: #1f3a5f; }
.msg .meta { font-size: 0.72rem; color: var(--muted); margin-bottom: 0.2rem; display: flex; align-items: center; gap: 0.3rem; }
.msg .read-status { font-size: 0.72rem; text-align: right; margin-top: 0.15rem; }
.msg .read-status.read { color: #3fb950; }
.msg .read-status.partial { color: #d29922; }
.msg .read-status.unread { color: #8b949e; }

.dm-link { cursor: pointer; display: inline-flex; align-items: center; gap: 0.35rem; }
.dm-link:hover { opacity: 0.8; }
.msg img, .msg video {
    max-width: 280px; max-height: 280px; border-radius: 8px; display: block;
    width: auto; height: auto; object-fit: contain; cursor: pointer;
}
.msg audio { width: 240px; display: block; }

/* --- Image lightbox --- */
#lightbox {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,0.85); cursor: pointer;
}
#lightbox img {
    max-width: 90vw; max-height: 90vh; object-fit: contain;
    border-radius: 8px;
}

.attachment { display: flex; flex-direction: column; gap: 0.35rem; }
.file-card {
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
    padding: 0.6rem 0.8rem; word-break: break-all;
}
.attachment-bar { display: flex; gap: 0.6rem; align-items: center; font-size: 0.78rem; }
.attachment-name { color: var(--muted); word-break: break-all; }
.attachment-bar .link { padding: 0; }

.message-form { display: flex; gap: 0.5rem; padding: 1rem; border-top: 1px solid var(--border); }

.delete-bar {
    display: flex; gap: 0.8rem; align-items: center;
    padding: 0.5rem 1rem; border-top: 1px solid var(--border);
    font-size: 0.85rem; color: var(--muted);
}

.msg .msg-select {
    position: absolute; left: -28px; top: 50%; transform: translateY(-50%);
    cursor: pointer;
}
.msg { position: relative; }
.message-form input[type=text] { flex: 1; }
.file-label {
    display: flex; align-items: center; padding: 0 0.6rem; cursor: pointer;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px;
}

/* --- Admin --- */
#admin-screen { display: flex; flex-direction: column; }
.admin-head {
    display: flex; align-items: center; gap: 1rem;
    padding: 0.85rem 1rem; border-bottom: 1px solid var(--border);
}
.admin-tabs { display: flex; gap: 0.4rem; flex: 1; }
.atab {
    background: var(--panel-2); color: var(--muted);
    border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.8rem;
}
.atab.active { color: var(--text); border-color: var(--accent); }

.admin-body { flex: 1; overflow-y: auto; padding: 1rem; }
.admin-panel { max-width: 1000px; }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td {
    text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
.grid th { color: var(--muted); font-weight: 600; }
.grid td .link { padding: 0 0.5rem 0 0; }

.inline-form { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.inline-form input { flex: 1; max-width: 360px; }

.stacked-form { display: flex; flex-direction: column; gap: 0.7rem; max-width: 460px; }
.stacked-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; color: var(--muted); }
.stacked-form label.row { flex-direction: row; align-items: center; gap: 0.5rem; color: var(--text); }
.form-actions { display: flex; gap: 0.5rem; margin: 0.8rem 0 0 0; flex-wrap: wrap; justify-content: center; }
#aum-status-msg:empty { display: none; }
.form-actions button { font-size: 0.82rem; padding: 0.45rem 0.7rem; }
.btn-danger { background: var(--danger) !important; }
button.secondary { background: var(--panel-2); border: 1px solid var(--border); }
.admin-actions-bar { display: flex; gap: 0.5rem; padding: 0.5rem 0; margin-bottom: 0.5rem; align-items: center; }
.admin-actions-bar button:disabled { opacity: 0.4; cursor: default; }
.admin-actions-bar button { font-size: 0.82rem; padding: 0.4rem 0.7rem; }
#arm-add-section { position: relative; }
#arm-members li { justify-content: space-between; }
#aum-spaces { margin: 0.3rem 0 0 0; }
#aum-spaces label { display: flex; align-items: center; gap: 0.5rem; padding: 0.25rem 0; cursor: pointer; font-size: 0.9rem; }
#aum-spaces input[type=checkbox] { width: auto; flex-shrink: 0; }
