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

:root {
    --bg: #0a0a0a;
    --surface: #141414;
    --surface-2: #1a1a1a;
    --border: #222;
    --text: #ddd;
    --text-dim: #888;
    --text-muted: #555;
    --accent: #999;
    --hover: #111;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
}

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

/* ─── Centered card layout (login / admin gate) ─── */
.center {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    padding: 24px;
}

.logo {
    font-size: 36px;
    font-weight: 700;
    letter-spacing: -1.5px;
    text-transform: uppercase;
    color: #fff;
    margin-bottom: 4px;
}

.sub {
    font-size: 10px;
    color: var(--text-muted);
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 32px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 20px;
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.card-title {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

input, textarea, select {
    background: #0f0f0f;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    padding: 8px 10px;
    border-radius: 3px;
    outline: none;
    font-family: var(--font);
    width: 100%;
}

input:focus, textarea:focus, select:focus { border-color: var(--text-dim); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

button {
    background: #333;
    border: none;
    color: #ccc;
    font-size: 12px;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 3px;
    cursor: pointer;
    font-family: var(--font);
}
button:hover { background: #444; color: #fff; }
button.ghost {
    background: none;
    color: var(--text-dim);
    border: 1px solid var(--border);
}
button.ghost:hover { color: var(--text); border-color: var(--text-dim); }
button.danger { background: #4a2222; color: #d99; }
button.danger:hover { background: #5a2828; color: #fbb; }

.error {
    color: #d77;
    font-size: 11px;
    min-height: 14px;
}

/* ─── Top bar ─── */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    height: 36px;
}

#app-name {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-dim);
    letter-spacing: 0;
}

#topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 11px;
    color: var(--text-dim);
}

#topbar-right .who { color: var(--text); }
#topbar-right button {
    background: none;
    color: var(--text-dim);
    font-size: 11px;
    padding: 3px 8px;
    font-weight: 500;
}
#topbar-right button:hover { color: var(--text); background: none; }

/* ─── Chat layout ─── */
#chat-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: relative;
}

#main {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* Sidebar */
#sidebar {
    width: 200px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.sidebar-title {
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    padding: 14px 16px;
    letter-spacing: 0.2px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
    background: var(--bg);
}
.sidebar-title #add-channel-btn {
    color: var(--text-dim);
    font-size: 20px;
    font-weight: 400;
    text-decoration: none;
    padding: 0 4px;
    line-height: 1;
    cursor: pointer;
}
.sidebar-title #add-channel-btn:hover { color: var(--text); }
#channels { display: flex; flex-direction: column; padding: 0 0 16px; }

/* Inline new channel form in sidebar */
#new-channel-form {
    padding: 12px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#new-channel-form input[type="text"] {
    padding: 8px 10px;
    font-size: 13px;
}
#new-channel-form label {
    font-size: 11px;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}
#new-channel-form input[type="checkbox"] {
    width: auto;
    cursor: pointer;
}
#new-channel-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}
#new-channel-form button {
    padding: 6px 14px;
    font-size: 11px;
}
#new-channel-form .error { font-size: 10px; }
.channel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    color: var(--text-dim);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
}
.channel-item:hover { background: var(--hover); color: var(--text); }
.channel-item.active { color: #fff; font-weight: 600; }
.channel-item .ch-prefix { color: var(--text-muted); width: 12px; text-align: center; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; }
.lock-icon { width: 10px; height: 10px; display: block; }
#channel-name .lock-icon { width: 12px; height: 12px; display: inline-block; vertical-align: -1px; color: var(--text-dim); }
.channel-item.active .ch-prefix { color: #fff; }
.channel-item .ch-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-item.unread {
    color: var(--text);
    font-weight: 600;
}
.channel-item.unread::after {
    content: '';
    margin-left: auto;
    width: 6px;
    height: 6px;
    background: #5af;
    border-radius: 50%;
    flex-shrink: 0;
}

#channel-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

#channel-header {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
}
#channel-name { font-size: 14px; font-weight: 700; color: #fff; }
#channel-meta { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
#channel-clock { margin-left: auto; font-size: 11px; color: var(--text-dim); letter-spacing: 0.3px; }

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 0 0 24px;
    display: flex;
    flex-direction: column;
}

/* Slack-style row: avatar | (name+time on top, body below) */
.msg {
    display: grid;
    grid-template-columns: 48px 1fr;
    gap: 16px;
    padding: 16px 32px 16px 20px;
    align-items: start;
}

/* 1px dark-grey separator under each message group (not above) */
.msg:not(:has(+ .msg.cont)) { border-bottom: 1px solid #2a2a2a; }


.avatar {
    width: 48px;
    height: 48px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    user-select: none;
    overflow: hidden;
}
.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.msg-content {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    line-height: 1.2;
    margin-bottom: 3px;
}

.msg-name {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
}

.msg-body {
    font-size: 13px;
    line-height: 1.45;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
    min-width: 0;
}

.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Continuation: hide avatar + header but keep grid column to preserve indent */
.msg.cont { padding-top: 3px; padding-bottom: 3px; }
.msg.cont .avatar { visibility: hidden; }
.msg.cont .msg-header { display: none; }
.msg.cont .msg-time-hover {
    font-size: 10px;
    color: var(--text-muted);
    opacity: 0;
    position: absolute;
    left: 20px;
    width: 48px;
    text-align: center;
    line-height: 18px;
}
.msg.cont:hover .msg-time-hover { opacity: 1; }

/* Attachments — bare image/video, no chrome */
.attachment {
    margin-top: 4px;
    max-width: 420px;
    border-radius: 3px;
    overflow: hidden;
}
.attachment img,
.attachment video {
    display: block;
    max-width: 100%;
    max-height: 360px;
    width: auto;
    height: auto;
    cursor: pointer;
    border-radius: 3px;
}
.attachment-name { display: none; }

/* Reactions */
.msg { position: relative; }

.msg-delete {
    position: absolute;
    top: 10px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    padding: 2px 8px;
    border-radius: 3px;
    opacity: 0;
    line-height: 1;
    font-weight: 400;
}
.msg:hover .msg-delete { opacity: 1; }
.msg-delete:hover { color: #d77; background: none; }

.reaction-picker {
    position: absolute;
    left: 84px;
    top: 100%;
    margin-top: -8px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px;
    display: none;
    gap: 2px;
    z-index: 10;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.msg:hover .reaction-picker { display: flex; }
.reaction-picker button {
    background: none;
    border: none;
    font-size: 14px;
    padding: 3px 6px;
    cursor: pointer;
    border-radius: 2px;
    line-height: 1;
}
.reaction-picker button:hover { background: var(--hover); }

.reactions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}
.reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 4px;
    background: none;
    border: none;
    font-size: 14px;
    color: var(--text-dim);
    cursor: pointer;
    line-height: 1;
}
.reaction-pill:hover { color: var(--text); }
.reaction-pill.mine { color: #fff; }

.day-divider {
    align-self: stretch;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin: 20px 24px 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    font-size: 12px;
    padding: 40px 20px;
}

#status {
    padding: 4px 16px;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    min-height: 18px;
}

#status.connected { display: none; }
#status.disconnected { color: #a55; }

/* Composer */
#composer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 14px 24px 20px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

#composer-row {
    display: flex;
    gap: 8px;
}

#composer textarea {
    flex: 1;
    resize: none;
    min-height: 36px;
    max-height: 160px;
    line-height: 1.4;
}

#attach-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0 12px;
    font-size: 16px;
    font-weight: 400;
    border-radius: 3px;
    cursor: pointer;
}
#attach-btn:hover { color: var(--text); border-color: var(--text-dim); background: none; }

#composer button[type="submit"] { align-self: stretch; }

#file-input { display: none; }

/* Pending attachment preview */
#pending {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 11px;
    color: var(--text-dim);
}
#pending img, #pending video {
    height: 48px;
    width: 48px;
    object-fit: cover;
    border-radius: 2px;
    background: #000;
}
#pending .pending-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#pending button {
    background: none;
    color: var(--text-muted);
    padding: 2px 8px;
    font-size: 14px;
}
#pending button:hover { color: #d77; background: none; }

/* Drop overlay */
#drop-overlay {
    position: absolute;
    inset: 0;
    background: rgba(20, 60, 100, 0.35);
    border: 2px dashed rgba(255, 255, 255, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    z-index: 50;
    pointer-events: none;
}
#drop-overlay.show { display: flex; }

/* Lightbox */
#lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.95);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 300;
    cursor: pointer;
}
#lightbox.show { display: flex; }
#lightbox img, #lightbox video {
    max-width: 92vw;
    max-height: 92vh;
}

/* ─── Admin ─── */
#admin-flash {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 12px;
    padding: 8px 16px;
    border-radius: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4);
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}
#admin-flash.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
#admin-flash.error {
    border-color: #5a2828;
    color: #fbb;
}

#admin-shell {
    max-width: 1600px;
    margin: 0 auto;
    padding: 48px 48px;
    font-size: 14px;
}

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 64px;
    align-items: start;
}
.admin-col { min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.admin-col .section-title:first-child { margin-top: 0; }

@media (max-width: 900px) {
    .admin-grid { grid-template-columns: 1fr; gap: 32px; }
}

#admin-shell .section-title {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    margin: 36px 0 16px;
    letter-spacing: 0.3px;
    text-transform: none;
}

#admin-shell .card {
    width: auto;
    padding: 24px;
    gap: 14px;
    border-radius: 6px;
}

#admin-shell .card-title {
    font-size: 13px;
}

#admin-shell input,
#admin-shell select,
#admin-shell textarea {
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 4px;
}

#admin-shell button {
    font-size: 13px;
    padding: 10px 18px;
    border-radius: 4px;
}

#admin-shell .users-table {
    font-size: 13px;
}
#admin-shell .users-table th {
    font-size: 11px;
    padding: 12px 10px;
    letter-spacing: 0.6px;
}
#admin-shell .users-table td {
    padding: 14px 10px;
    font-size: 13px;
    vertical-align: middle;
}
#admin-shell .users-table td.role {
    font-size: 11px;
    letter-spacing: 0.6px;
}

#admin-shell .avatar-drop {
    width: 110px;
    height: 110px;
    font-size: 11px;
    border-radius: 6px;
}

#admin-shell .avatar-drop .placeholder {
    line-height: 1.4;
}

/* User row: avatar cell, pw editor, action buttons */
#admin-shell .avatar-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
#admin-shell .avatar-cell img,
#admin-shell .avatar-cell > div {
    flex-shrink: 0;
}
#admin-shell .upload-pill {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    font-size: 11px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-dim);
    background: none;
    line-height: 1;
}
#admin-shell .upload-pill:hover { color: var(--text); border-color: var(--text-dim); }
#admin-shell button.clear-avatar {
    padding: 4px 8px;
    font-size: 13px;
    line-height: 1;
}

#admin-shell .pw-edit {
    display: flex;
    gap: 6px;
    align-items: center;
    white-space: nowrap;
}
#admin-shell .pw-edit input[type="password"] {
    flex: 1;
    min-width: 100px;
    padding: 7px 10px;
    font-size: 12px;
}
#admin-shell .pw-edit button {
    padding: 7px 14px;
    font-size: 11px;
}
#admin-shell .users-table button.danger {
    padding: 7px 14px;
    font-size: 11px;
}

.section-title {
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 18px 0 8px;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.users-table th, .users-table td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid var(--border);
}

.users-table th {
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    font-weight: 600;
}

.users-table td.role {
    color: var(--text-dim);
    text-transform: uppercase;
    font-size: 10px;
}

.row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; align-self: stretch; }

.avatar-drop {
    width: 88px;
    height: 88px;
    border: 1px dashed var(--border);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    flex-shrink: 0;
    overflow: hidden;
    background: #0f0f0f;
    position: relative;
}
.avatar-drop:hover { border-color: var(--text-dim); color: var(--text-dim); }
.avatar-drop img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #333; }
