/* ── Variables ───────────────────────────────────────────────── */
:root {
    --bg:        #1a1a2e;
    --bg2:       #16213e;
    --bg3:       #0f3460;
    --accent:    #e94560;
    --accent2:   #533483;
    --text:      #eaeaea;
    --text-dim:  #888;
    --border:    #2a2a4a;
    --radius:    8px;
    --font:      system-ui, -apple-system, sans-serif;
    --nav-w:     64px;
    --bottom-h:  60px;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    height: 100dvh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── App shell ───────────────────────────────────────────────── */
#app {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#app.no-nav { display: block; }

/* ── Desktop sidebar nav ─────────────────────────────────────── */
#sidenav {
    width: var(--nav-w);
    background: var(--bg2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: .75rem 0;
    gap: .25rem;
    flex-shrink: 0;
}

.nav-logo {
    font-weight: 900;
    font-size: 1.3rem;
    color: var(--accent);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .5rem;
    text-decoration: none;
    border-radius: var(--radius);
}
.nav-logo:hover { background: var(--bg3); }

#sidenav .nav-item {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 1.3rem;
    text-decoration: none;
    color: var(--text-dim);
    transition: background .15s, color .15s;
    position: relative;
}

#sidenav .nav-item img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
}

#sidenav .nav-item:hover,
#sidenav .nav-item.active { background: var(--bg3); color: var(--text); }

.nav-spacer { flex: 1; }

/* ── Mobile bottom nav ───────────────────────────────────────── */
#bottom-nav {
    display: none;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    height: var(--bottom-h);
    flex-shrink: 0;
}

#bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 1.3rem;
    color: var(--text-dim);
    cursor: pointer;
    text-decoration: none;
    padding: .4rem 0;
    position: relative;
}

#bottom-nav .nav-item span {
    font-size: .65rem;
    text-transform: uppercase;
    letter-spacing: .03em;
}

#bottom-nav .nav-item.active,
#bottom-nav .nav-item:hover { color: var(--accent); }

.mention-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: #e55;
    color: #fff;
    font-size: .55rem;
    font-weight: 700;
    width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    line-height: 1;
}

.mention       { color: var(--accent); font-weight: 600; }
.mention-self  { background: color-mix(in srgb, var(--accent) 20%, transparent);
                 color: var(--accent); font-weight: 700;
                 border-radius: 3px; padding: 0 .2em; }

.nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--accent);
    color: #fff;
    font-size: .55rem;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    padding: 0 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    line-height: 1;
}

/* ── Main content ────────────────────────────────────────────── */
#main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-header {
    padding: 1rem 1.25rem .5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.page-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
}

/* ── Settings sections ───────────────────────────────────────── */
.settings-section {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: .6rem;
}

.filter-input {
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .88rem;
    padding: .35rem .7rem;
    outline: none;
    width: 100%;
}
.filter-input:focus { border-color: var(--accent); }

.settings-section h3 {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
    margin-bottom: .2rem;
}

/* ── Stream list ─────────────────────────────────────────────── */
.stream-list {
    flex: 1;
    overflow-y: auto;
}

.stream-item {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    padding: .75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .12s;
}

.stream-item:hover { background: var(--bg2); }

.stream-cont {
    padding-top: .3rem;
    padding-bottom: .3rem;
}

.stream-row {
    display: flex;
    align-items: center;
    gap: .85rem;
}
.stream-row .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }

.stream-icon {
    font-size: 1.4rem;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

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

.stream-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: .5rem;
    margin-bottom: .2rem;
}

.stream-name { font-weight: 600; font-size: .95rem; }
.stream-peer { color: var(--accent2); font-size: .8rem; margin-left: .3rem; }
.stream-time { font-size: .75rem; color: var(--text-dim); flex-shrink: 0; }

.stream-badge {
    font-size: .72rem;
    color: var(--text-dim);
    margin-bottom: .15rem;
    display: flex;
    align-items: center;
    gap: .25rem;
}
.stream-badge-name { font-weight: 600; color: var(--text); }

.stream-badge-toggle {
    cursor: pointer;
    opacity: .5;
    font-size: .9em;
}
.stream-item:hover .stream-badge-toggle { opacity: 1; }

.stream-preview {
    font-size: .85rem;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.stream-preview:has(.poll-preview) {
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
}

.stream-preview .preview-sender { color: var(--text); }

.stream-peer-header {
    padding: .5rem 1.25rem;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.stream-empty {
    padding: 2rem;
    text-align: center;
    color: var(--text-dim);
    font-size: .9rem;
}

.stream-sentinel { height: 1px; }

.stream-end {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-dim);
    font-size: .8rem;
    letter-spacing: .05em;
}

/* ── Chat layout ─────────────────────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.back-btn {
    background: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    padding: .2rem .4rem;
    display: none;
}

.back-btn:hover { color: var(--text); background: none; }

.chat-description {
    padding: .4rem 1rem;
    background: var(--bg2);
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font-size: .8rem;
    flex-shrink: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-title {
    font-weight: 600;
    font-size: 1rem;
    flex: 1;
}

.chat-icon {
    font-size: 1.2rem;
    line-height: 1;
    position: relative;
    user-select: none;
    border-radius: 4px;
    padding: .1rem .15rem;
}
.chat-icon[title]:hover { background: var(--bg3); }

.icon-picker-wrap {
    position: absolute;
    top: 2rem;
    left: 0;
    z-index: 300;
}
.icon-picker-wrap emoji-picker {
    --background: var(--bg2);
    --border-color: var(--border);
    --button-active-background: var(--bg3);
    --button-hover-background: var(--bg3);
    --category-emoji-padding: .25rem;
    --emoji-padding: .25rem;
    --emoji-size: 1.5rem;
    --input-border-color: var(--border);
    --input-font-color: var(--text);
    --input-placeholder-color: var(--text-dim);
    --outline-color: var(--accent);
    --text-color: var(--text);
    --num-columns: 8;
    height: 22rem;
    width: 22rem;
    border-radius: var(--radius);
    box-shadow: 0 4px 20px rgba(0,0,0,.4);
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: .75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.message {
    display: flex;
    gap: .65rem;
    padding: .3rem .4rem;
    border-radius: var(--radius);
}

.chat-notice {
    background: var(--bg2);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: .6rem .9rem;
    font-size: .85rem;
    color: var(--text-dim);
    margin-bottom: .4rem;
}
.message:hover { background: var(--bg2); }
.message.reply { border-left: 2px solid var(--border); padding-left: .75rem; }

@keyframes msg-highlight {
    0%   { background: var(--bg3); }
    100% { background: transparent; }
}
.message.highlight { animation: msg-highlight 1.5s ease-out forwards; }

.message .avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    background: var(--bg3);
}

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

.message .header {
    display: flex;
    align-items: baseline;
    gap: .4rem;
    margin-bottom: .15rem;
    flex-wrap: wrap;
}

.message .sender { font-weight: 600; font-size: .88rem; }
.message .sender.remote { color: var(--accent2); }
.message .time { font-size: .72rem; color: var(--text-dim); }
.message .text { font-size: .92rem; line-height: 1.45; word-break: break-word; }

/* Markdown-rendered message body */
.message .md { font-size: .92rem; line-height: 1.5; word-break: break-word; }
.message .md p, .message .md h1, .message .md h2, .message .md h3, .message .md h4,
.message .md ul, .message .md ol, .message .md blockquote { margin: .2rem 0; }
.message .md h1 { font-size: 1.1rem; font-weight: 700; }
.message .md h2 { font-size: 1rem;   font-weight: 700; }
.message .md h3, .message .md h4 { font-size: .95rem; font-weight: 600; }
.message .md ul  { list-style: disc   inside; padding-left: .5rem; }
.message .md ol  { list-style: decimal inside; padding-left: .5rem; }
.message .md code {
    background: var(--bg3); border-radius: 3px;
    padding: .05em .3em; font-family: monospace; font-size: .85em;
}
.message .md pre {
    background: var(--bg3); border-radius: var(--radius);
    padding: .5rem .75rem; overflow-x: auto; margin: .3rem 0;
}
.message .md pre code { background: none; padding: 0; font-size: .88rem; }
.message .md blockquote {
    border-left: 3px solid var(--border); padding-left: .65rem;
    color: var(--text-dim); margin-left: 0;
}
.message .md a { color: var(--accent); text-decoration: underline; }
.message .md del { opacity: .6; text-decoration: line-through; }

.message img.attach {
    max-width: min(320px, 100%);
    max-height: 240px;
    border-radius: var(--radius);
    margin-top: .35rem;
    cursor: pointer;
    display: block;
}

.message .actions { display: flex; gap: .4rem; margin-top: .2rem; }
.message .actions button {
    background: none;
    color: var(--text-dim);
    font-size: .78rem;
    padding: .1rem .25rem;
}
.message .actions button:hover { color: var(--text); background: none; }
.message .actions .msg-delete { color: var(--text-dim); opacity: .4; }
.message:hover .actions .msg-delete { opacity: 1; }
.message .actions .msg-delete:hover { color: #e55; }
.message .unavailable { color: var(--text-dim); font-style: italic; font-size: .85rem; }

.message .actions .react-btn { position: relative; }

.message .reactions {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
    margin-top: .25rem;
}
.reaction-pill {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 .45rem;
    font-size: .75rem;
    line-height: 1.5;
    cursor: pointer;
    user-select: none;
}
.reaction-pill:hover { background: var(--bg3); }
.reaction-pill.mine {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--bg2));
}

.message .edited-badge {
    font-size: .72rem;
    color: var(--text-dim);
    font-style: italic;
}
.message .edited-badge.clickable {
    cursor: pointer;
    text-decoration: underline dotted;
}

.edit-form {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    margin-top: .2rem;
}
.edit-form textarea {
    font-size: .92rem;
    resize: vertical;
}
.edit-form-actions { display: flex; gap: .4rem; }
.edit-form-actions button { font-size: .8rem; padding: .3rem .7rem; }

.history-panel {
    margin-top: .3rem;
    padding: .4rem .6rem;
    border-left: 2px solid var(--border);
    background: var(--bg2);
    border-radius: var(--radius);
    font-size: .85rem;
}
.history-entry { padding: .25rem 0; border-bottom: 1px solid var(--border); }
.history-entry:last-child { border-bottom: none; }
.history-entry .time { display: block; font-size: .7rem; color: var(--text-dim); }
.history-entry .text { font-size: .85rem; color: var(--text-dim); }

/* ── Poll card ───────────────────────────────────────────────── */
.poll-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem .8rem;
    margin-top: .15rem;
    max-width: 360px;
}
.poll-question {
    font-weight: 600;
    margin-bottom: .55rem;
    font-size: .95rem;
}
.poll-options { display: flex; flex-direction: column; gap: .4rem; }
.poll-option {
    position: relative;
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .35rem .65rem;
    cursor: pointer;
    font-size: .88rem;
    text-align: left;
    overflow: hidden;
    transition: border-color .15s;
}
.poll-option:hover  { border-color: var(--accent); }
.poll-option.voted  { border-color: var(--accent); font-weight: 600; }
.poll-bar {
    position: absolute;
    inset: 0;
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    transform-origin: left;
    pointer-events: none;
    transition: width .35s ease;
}
.poll-option-label { position: relative; flex: 1; }
.poll-option-count {
    position: relative;
    font-size: .78rem;
    color: var(--text-dim);
    white-space: nowrap;
}
.poll-total {
    margin-top: .4rem;
    font-size: .75rem;
    color: var(--text-dim);
}

/* ── Poll stream preview ─────────────────────────────────────── */
.poll-preview {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    white-space: normal;
}
.poll-preview-icon { margin-right: .3rem; }
.poll-preview-question { font-weight: 500; color: var(--text); }
.poll-preview-scores { display: flex; flex-direction: column; gap: .15rem; margin-top: .2rem; }
.poll-preview-bar-row {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-size: .78rem;
    position: relative;
}
.poll-preview-label {
    min-width: 4rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 0;
}
.poll-preview-fill {
    height: .45rem;
    border-radius: 99px;
    background: color-mix(in srgb, var(--accent) 55%, transparent);
    flex-shrink: 0;
    min-width: 2px;
    transition: width .35s ease;
    max-width: 80px;
}
.poll-preview-stat {
    color: var(--text-dim);
    white-space: nowrap;
}

/* ── Create poll modal ───────────────────────────────────────── */
.poll-modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0,0,0,.55);
    display: flex;
    align-items: center;
    justify-content: center;
}
.poll-modal-box {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem 1.4rem;
    width: min(420px, 95vw);
    display: flex;
    flex-direction: column;
    gap: .6rem;
}
.poll-modal-box h3 { margin: 0 0 .2rem; font-size: 1rem; }
.poll-modal-box input[type=text] {
    width: 100%;
    box-sizing: border-box;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: .4rem .65rem;
    font-size: .9rem;
}
.poll-opts-list { display: flex; flex-direction: column; gap: .35rem; }
.poll-opt-row   { display: flex; gap: .4rem; align-items: center; }
.poll-opt-row input { flex: 1; }
.poll-opt-row button { flex-shrink: 0; font-size: .85rem; padding: .3rem .6rem; }
.poll-modal-actions { display: flex; gap: .5rem; justify-content: flex-end; }

/* ── Input area ──────────────────────────────────────────────── */
.input-area {
    border-top: 1px solid var(--border);
    padding: .5rem .75rem;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    flex-shrink: 0;
    background: var(--bg2);
}

.mention-popup {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 -4px 12px rgba(0,0,0,.25);
    overflow: hidden;
    max-width: 280px;
    margin-bottom: .3rem;
}
.mention-item {
    padding: .4rem .75rem;
    cursor: pointer;
    font-size: .88rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.mention-item:hover, .mention-item.sel { background: var(--bg3); color: var(--accent); }

.post-restricted-notice {
    border-top: 1px solid var(--border);
    padding: .6rem .75rem;
    flex-shrink: 0;
    background: var(--bg2);
    color: var(--text-dim);
    font-size: .85rem;
    text-align: center;
}

.input-row {
    display: flex;
    gap: .4rem;
    align-items: flex-end;
}

.drop-zone {
    width: 36px;
    height: 36px;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 1.3rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color .15s, color .15s;
}
.drop-zone.active { border-color: var(--accent); color: var(--accent); }

textarea#message_input {
    flex: 1;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: .45rem .65rem;
    font-size: .9rem;
    font-family: var(--font);
}
textarea#message_input:focus { outline: 2px solid var(--accent); }

.reply-context {
    background: var(--bg3);
    border-radius: var(--radius);
    padding: .3rem .65rem;
    font-size: .82rem;
    color: var(--text-dim);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#image_preview img {
    max-height: 56px;
    border-radius: var(--radius);
}

/* ── Member manager overlay ──────────────────────────────────── */
.overlay {
    position: absolute;
    inset: 0;
    background: var(--bg);
    z-index: 20;
    display: flex;
    flex-direction: column;
}

.overlay-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    flex-shrink: 0;
}

.new-channel-form {
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.new-channel-icon-row {
    display: flex;
    align-items: center;
    gap: .6rem;
}

.new-channel-icon-row .chat-icon {
    font-size: 1.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .3rem .55rem;
}

.new-channel-icon-row input { flex: 1; }

.member_columns {
    display: flex;
    gap: 1rem;
    flex: 1;
    overflow: hidden;
    padding: .75rem 1rem;
}

.member_columns > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}

.col-header {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-bottom: .3rem;
}
.member_columns h4 { font-size: .8rem; color: var(--text-dim); white-space: nowrap; }

.filter-input-sm {
    flex: 1;
    background: var(--bg3);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: .78rem;
    padding: .2rem .5rem;
    outline: none;
    min-width: 0;
}
.filter-input-sm:focus { border-color: var(--accent); }

.member-drop-zone {
    flex: 1;
    list-style: none;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: .4rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .25rem;
}

.member-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .3rem .4rem;
    background: var(--bg2);
    border-radius: calc(var(--radius) - 2px);
    cursor: grab;
    font-size: .88rem;
}
.member-item img {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg3);
}

.mod-toggle, .mod-badge {
    margin-left: auto;
    font-size: .9rem;
}
.mod-toggle { cursor: pointer; }

/* ── Item lists (users, channels, peers) ─────────────────────── */
.item-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .2rem;
}

.item-list li {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .4rem .5rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.item-list li:hover { background: var(--bg3); }

.item-list li a {
    flex: 1;
    color: var(--text);
    text-decoration: none;
    font-size: .92rem;
}

.item-list .icon { font-size: .85rem; color: var(--text-dim); }

.fav-list li { padding: .3rem .5rem; }
.fav-list .icon { margin-right: .1rem; }

.channel-visibility {
    font-size: .8rem;
    opacity: .75;
    margin-right: .3rem;
}

.channel-poster-count {
    font-size: .75rem;
    color: var(--text-dim);
    margin-left: .35rem;
    min-width: 1.5rem;
}

.chat-visibility {
    font-size: .85rem;
    opacity: .8;
    margin-left: .25rem;
}

.chat-creator-tag {
    font-size: .75rem;
    font-weight: 400;
    color: var(--text-dim);
}

.item-list .stream-toggle {
    cursor: pointer;
    font-size: .82rem;
}

.channel-actions {
    display: flex;
    align-items: center;
    gap: .3rem;
    margin-left: auto;
}

/* Fixed-width icon slots, always rendered (empty when not applicable), so
   the same icon lands in the same column on every row regardless of which
   actions a given channel actually offers. */
.channel-actions .action-slot {
    flex: 0 0 1.4rem;
    width: 1.4rem;
    text-align: center;
}
.channel-actions .stream-toggle.action-slot:empty { cursor: default; }

.item-list .trash {
    color: var(--text-dim);
    cursor: pointer;
    opacity: 0;
}
.item-list li:hover .trash:not(:empty) { opacity: 1; }
.item-list .trash:empty { cursor: default; }

.channel-creator {
    font-size: .72rem;
    color: var(--text-dim);
    white-space: nowrap;
    min-width: 2.2rem;
    text-align: right;
    margin-right: .3rem;
}
.own-channel .channel-creator { color: var(--accent2); }

.peers-filter {
    display: flex;
    flex-direction: column;
    gap: .35rem;
}
.peers-filter-input {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: .35rem .6rem;
    font-size: .88rem;
}
.peers-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
}
.peer-chip {
    font-size: .72rem;
    padding: .15rem .5rem;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg2);
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}
.peer-chip:hover { border-color: var(--text-dim); color: var(--text); }
.peer-chip-active { background: var(--bg3); border-color: var(--accent2); color: var(--text); }

.peer-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.peer-online        { background: #4caf50; box-shadow: 0 0 4px #4caf5088; }
.peer-idle          { background: #2d7a2d; }
.peer-was-connected { background: #1a4a1a; }
.peer-awaiting      { background: #b87000; }
.peer-failed        { background: var(--accent); }
.peer-offline       { background: var(--border); }

.peer-badge {
    font-size: .68rem;
    padding: .1rem .4rem;
    border-radius: 4px;
    white-space: nowrap;
}
.badge-pending { background: #b87000; color: #fff; }
.badge-blocked { background: var(--accent); color: #fff; }

.btn-sm {
    font-size: .75rem;
    padding: .15rem .5rem;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--bg3);
    color: var(--text);
    cursor: pointer;
}
.btn-sm:hover { border-color: var(--text-dim); }

.peer-header { cursor: pointer; font-weight: 600; color: var(--accent2); margin-top: .4rem; user-select: none; }
.peer-collapse-arrow { font-size: .7rem; margin-right: .3rem; display: inline-block; }
.peer-header:hover { background: none; }
.peer-channel { padding-left: 1.2rem !important; }
.peer-empty {
    padding-left: 1.2rem !important;
    color: var(--text-dim);
    font-size: .82rem;
    font-style: italic;
    cursor: default;
}
.peer-empty:hover { background: none; }

/* ── User profile page ───────────────────────────────────────── */
.user-profile .avatar-wrap {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.user-profile #user_avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg3);
    flex-shrink: 0;
}

.user-profile h3 { font-size: 1.1rem; }
.user-profile p { font-size: .82rem; color: var(--text-dim); margin-top: .2rem; }

/* ── Login page ──────────────────────────────────────────────── */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    gap: 1.5rem;
    padding: 1.5rem;
    overflow-y: auto;
}

.login-page h1 {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent);
}

.login-wiki-link {
    font-size: .85rem;
    color: var(--text-dim);
    text-decoration: none;
    margin-top: -.75rem;
}
.login-wiki-link:hover { color: var(--accent); }

.login-card {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.login-join-banner {
    background: var(--bg2);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
    font-size: .9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
}

.login-card h2 { font-size: .9rem; color: var(--text-dim); }

/* ── Forms & inputs ──────────────────────────────────────────── */
form {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.inline-form { flex-direction: row; align-items: center; }
.inline-form input { flex: 1; }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
textarea {
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: .45rem .7rem;
    font-size: .9rem;
    width: 100%;
    font-family: var(--font);
}
input:focus, textarea:focus { outline: 2px solid var(--accent); }
input[readonly] { color: var(--text-dim); cursor: default; }

input[type="checkbox"] {
    appearance: none;
    -webkit-appearance: none;
    width: 1em;
    height: 1em;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg2);
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    vertical-align: middle;
}
input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}
input[type="checkbox"]:checked::after {
    content: "";
    position: absolute;
    left: 3px;
    top: 0px;
    width: 4px;
    height: 8px;
    border: 2px solid #fff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}
input[type="checkbox"]:focus { outline: 2px solid var(--accent); }

label { font-size: .85rem; color: var(--text-dim); }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: .4rem;
    color: var(--text-dim);
    font-size: .85rem;
    cursor: pointer;
}

.checkbox-sublabel {
    margin-left: 1.4rem;
    font-size: .8rem;
}

.select-label {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    color: var(--text-dim);
    font-size: .85rem;
}

.select-label select {
    background: var(--bg2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: .4rem .6rem;
    font-size: .85rem;
    font-family: var(--font);
}

button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: .45rem .9rem;
    cursor: pointer;
    font-size: .88rem;
    white-space: nowrap;
    font-family: var(--font);
}
button:hover, .btn:hover { filter: brightness(1.15); }
button.danger  { background: #c0392b; }
button.secondary { background: var(--bg3); }

/* ── Utilities ───────────────────────────────────────────────── */
.hidden { display: none !important; }

.cert-info-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    flex-wrap: wrap;
}

.btn-inline {
    font-size: .75rem;
    padding: .2rem .6rem;
    background: var(--bg3);
    color: var(--text-dim);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    white-space: nowrap;
}
.btn-inline:hover { color: var(--text); border-color: var(--text-dim); }

.user-msg-list  { list-style: none; display: flex; flex-direction: column; gap: .3rem; }
.user-msg-item  { padding: .4rem .5rem; border-radius: var(--radius); background: var(--bg2); }
.user-msg-item:hover { background: var(--bg3); }
.user-msg-top   { display: flex; justify-content: space-between; margin-bottom: .15rem; }
.user-msg-channel { font-size: .75rem; color: var(--text-dim); }
.user-msg-text  { font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.users-table {
    border-collapse: collapse;
    width: max-content;
}
.users-table td { padding: .25rem .3rem; vertical-align: middle; }
.users-table tr:hover td { background: var(--bg3); border-radius: var(--radius); }
.users-table td.td-acts {
    white-space: nowrap;
    width: 1%;
    vertical-align: middle;
}
.users-table .peer-header td {
    padding: .5rem .3rem .15rem;
    font-weight: 600;
    color: var(--accent2);
    cursor: pointer;
    user-select: none;
}
.user-actions {
    display: flex;
    align-items: center;
    gap: .25rem;
}
.user-identity { display: flex; align-items: center; gap: .4rem; cursor: pointer; }
.user-identity .avatar { width: 24px; height: 24px; flex-shrink: 0; }
@keyframes pulse-red {
    0%, 100% { color: var(--accent); }
    50%       { color: #ff8899; }
}
.cert-expiring {
    animation: pulse-red 2s ease-in-out infinite;
    font-weight: 600;
}

.cert-badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 600;
    padding: .15rem .45rem;
    border-radius: 4px;
}
.cert-self-signed { background: var(--bg3); color: var(--text-dim); }
.cert-valid        { background: #1a3a1a;    color: #6fcf6f; }
.cert-detail       { font-size: .78rem; color: var(--text-dim); }

.radio-group {
    display: flex;
    gap: 1.2rem;
    margin-bottom: .6rem;
}
.radio-group label { display: flex; align-items: center; gap: .3rem; cursor: pointer; }

.hint { font-size: .78rem; color: var(--text-dim); font-style: italic; }

.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    border: 1.5px solid var(--text-dim);
    color: var(--text-dim);
    font-size: .65rem;
    font-style: normal;
    font-weight: 700;
    cursor: pointer;
    vertical-align: middle;
    margin-left: .25rem;
    flex-shrink: 0;
    line-height: 1;
    background: none;
    padding: 0;
    position: relative;
}
.info-btn:hover { border-color: var(--accent); color: var(--accent); }

.info-popover {
    position: absolute;
    left: 1.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .6rem .8rem;
    font-size: .78rem;
    color: var(--text);
    font-style: normal;
    font-weight: 400;
    width: 22rem;
    max-width: 80vw;
    box-shadow: 0 4px 16px rgba(0,0,0,.25);
    z-index: 200;
    line-height: 1.5;
    white-space: normal;
    pointer-events: none;
}
.info-btn.open .info-popover { display: block; }
.info-popover { display: none; }

.field-label {
    font-size: .78rem;
    color: var(--text-dim);
    display: block;
}
.field-label .hint { font-style: italic; }

.address-display {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .35rem .65rem;
    font-size: .82rem;
    word-break: break-all;
}
.address-display span { flex: 1; color: var(--text-dim); }
.address-display button { flex-shrink: 0; font-size: .78rem; padding: .2rem .5rem; }

/* ── Error toast ─────────────────────────────────────────────── */
#error {
    position: fixed;
    bottom: calc(var(--bottom-h) + .75rem);
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    padding: .5rem 1rem;
    border-radius: var(--radius);
    font-size: .88rem;
    z-index: 99;
    max-width: 90vw;
    text-align: center;
}

/* ── Search ──────────────────────────────────────────────────── */
.search-panel {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    padding: 1rem;
    flex: 1;
    overflow: hidden;
}
.search-panel input[type="search"] {
    width: 100%;
}
.search-results {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: .4rem;
}
.search-result-item {
    background: var(--bg2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem .75rem;
    cursor: pointer;
    transition: background .12s;
}
.search-result-item:hover { background: var(--bg3); }
.search-result-meta {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .78rem;
    color: var(--text-dim);
    margin-bottom: .25rem;
    flex-wrap: wrap;
}
.search-result-channel { font-weight: 600; color: var(--text); }
.search-result-peer { color: var(--text-dim); font-size: .75rem; }
.search-result-sep { opacity: .4; }
.search-result-time { margin-left: auto; }
.search-result-snippet {
    font-size: .88rem;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.search-result-snippet mark {
    background: color-mix(in srgb, var(--accent) 25%, transparent);
    color: var(--accent);
    border-radius: 2px;
    padding: 0 1px;
}
.search-empty {
    color: var(--text-dim);
    text-align: center;
    padding: 2rem;
    font-size: .9rem;
}

/* ── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Mobile (<768px) ─────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidenav  { display: none; }
    #bottom-nav { display: flex; }

    #error { bottom: calc(var(--bottom-h) + .5rem); }

    .back-btn { display: flex; }

    /* In chat mode, hide bottom nav */
    body.in-chat #bottom-nav { display: none; }
    body.in-chat #main { height: 100dvh; }
}