/* ===== Theme variables ===== */
:root,
[data-theme="noir"] {
    --bg: #f4f4f6;
    --card-bg: #ffffff;
    --surface: #f4f4f6;
    --header-bg: #0b0b0c;
    --header-text: #ffffff;
    --header-sub: #d4d4d8;
    --text: #0b0b0c;
    --text-muted: #6e6e73;
    --border: #e6e6e9;
    --input-bg: #f4f4f6;
    --accent: #0b0b0c;
    --accent-text: #ffffff;
    --bubble-bg: #ffffff;
    --bubble-border: #e6e6e9;
}

[data-theme="paper"] {
    --bg: #f7f3ec;
    --card-bg: #fffdf9;
    --surface: #f3ede2;
    --header-bg: #2b2520;
    --header-text: #fdfaf4;
    --header-sub: #cbbfa9;
    --text: #2b2520;
    --text-muted: #8a7d68;
    --border: #e8dfcd;
    --input-bg: #f3ede2;
    --accent: #2b2520;
    --accent-text: #fdfaf4;
    --bubble-bg: #fffdf9;
    --bubble-border: #e8dfcd;
}

[data-theme="midnight"] {
    --bg: #0d0d0f;
    --card-bg: #16161a;
    --surface: #101013;
    --header-bg: #000000;
    --header-text: #f2f2f4;
    --header-sub: #8a8a90;
    --text: #f2f2f4;
    --text-muted: #9a9aa0;
    --border: #26262b;
    --input-bg: #1c1c20;
    --accent: #f2f2f4;
    --accent-text: #0d0d0f;
    --bubble-bg: #1c1c20;
    --bubble-border: #2a2a30;
}

[data-theme="ocean"] {
    --bg: #eef2f6;
    --card-bg: #ffffff;
    --surface: #e8eef3;
    --header-bg: #0f2742;
    --header-text: #eaf2fb;
    --header-sub: #9db8d1;
    --text: #10243a;
    --text-muted: #5b7895;
    --border: #d7e3ee;
    --input-bg: #e8eef3;
    --accent: #1f6fb2;
    --accent-text: #ffffff;
    --bubble-bg: #ffffff;
    --bubble-border: #d7e3ee;
}

[data-theme="sunset"] {
    --bg: #fdf2ec;
    --card-bg: #fffaf7;
    --surface: #fbe9e0;
    --header-bg: #c1452b;
    --header-text: #fff7f2;
    --header-sub: #f0c4b4;
    --text: #3a221a;
    --text-muted: #9c6a55;
    --border: #f3d9cb;
    --input-bg: #fbe9e0;
    --accent: #e0592f;
    --accent-text: #ffffff;
    --bubble-bg: #fffaf7;
    --bubble-border: #f3d9cb;
}

:root {
    --radius-lg: 22px;
    --radius-md: 16px;
    --radius-sm: 10px;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.10);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; text-decoration: none; }

/* ---------- Auth pages (login / register) ---------- */

.auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    background: var(--card-bg);
    width: 100%;
    max-width: 380px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    padding: 36px 32px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 28px;
}

.auth-brand .mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
}

.auth-brand .name {
    font-weight: 700;
    font-size: 17px;
    letter-spacing: -0.2px;
}

.auth-card h1 {
    font-size: 21px;
    margin: 0 0 6px;
    letter-spacing: -0.3px;
}

.auth-card p.subtitle {
    color: var(--text-muted);
    font-size: 13.5px;
    margin: 0 0 24px;
}

.field { margin-bottom: 14px; }

.field label {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.field input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.field input:focus {
    border-color: var(--accent);
    background: var(--card-bg);
}

.btn-primary {
    width: 100%;
    padding: 12px 14px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 14.5px;
    cursor: pointer;
    margin-top: 6px;
    transition: opacity 0.15s ease;
}

.btn-primary:hover { opacity: 0.85; }

.auth-foot {
    text-align: center;
    margin-top: 18px;
    font-size: 13px;
    color: var(--text-muted);
}

.auth-foot a {
    font-weight: 600;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}

.alert {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    color: var(--text);
    font-size: 13px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}

.alert.success { border-left-color: #34c759; }

/* ---------- Shared: avatar / dropdown menu ---------- */

.avatar-circle {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--text-muted);
    color: var(--card-bg);
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.menu-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 4px 8px 4px 4px;
    border-radius: 20px;
    transition: background 0.15s ease;
    position: relative;
}

.menu-trigger:hover { background: rgba(255, 255, 255, 0.08); }

.menu-trigger .chev {
    font-size: 9px;
    color: var(--header-sub);
}

.dropdown-wrap { position: relative; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    min-width: 180px;
    padding: 6px;
    display: none;
    z-index: 50;
}

.dropdown-menu.open { display: block; }

.dropdown-menu a, .dropdown-menu button.dd-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    color: var(--text);
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.dropdown-menu a:hover, .dropdown-menu button.dd-item:hover {
    background: var(--surface);
}

.dropdown-menu .dd-icon {
    width: 16px;
    text-align: center;
    opacity: 0.7;
}

.dropdown-menu hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 6px 2px;
}

.dropdown-menu .dd-danger { color: #d23b32; }

/* ---------- Lobby (room list) ---------- */

.lobby-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.lobby-card {
    background: var(--card-bg);
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.lobby-header {
    padding: 16px 18px;
    background: var(--header-bg);
    color: var(--header-text);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.lobby-header .title {
    font-weight: 700;
    font-size: 16px;
    letter-spacing: -0.2px;
}

.lobby-header .menu-trigger .uname {
    font-size: 12.5px;
    color: var(--header-sub);
}

.room-list {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.room-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 10px;
    border-radius: var(--radius-md);
    transition: background 0.15s ease;
}

.room-row:hover { background: var(--surface); }

.room-row .room-icon {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    flex-shrink: 0;
    overflow: hidden;
}

.room-row .room-icon img { width: 100%; height: 100%; object-fit: cover; }

.room-row .room-meta { flex: 1; min-width: 0; }

.room-row .room-name {
    font-weight: 600;
    font-size: 14.5px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-row .room-sub {
    font-size: 12px;
    color: var(--text-muted);
}

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

.lobby-footer {
    padding: 14px 16px;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.lobby-footer .new-room-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.lobby-footer input[type="text"] {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13.5px;
    background: var(--input-bg);
    color: var(--text);
    outline: none;
}

.lobby-footer input[type="text"]:focus {
    border-color: var(--accent);
    background: var(--card-bg);
}

.lobby-footer button {
    border: none;
    padding: 11px 18px;
    border-radius: 20px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 13.5px;
    cursor: pointer;
    white-space: nowrap;
}

.icon-picker-label {
    width: 42px;
    height: 42px;
    border-radius: 13px;
    border: 1px dashed var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    overflow: hidden;
}

.icon-picker-label img { width: 100%; height: 100%; object-fit: cover; }

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

.chat-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chat-container {
    background: var(--card-bg);
    width: 100%;
    max-width: 500px;
    height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: visible;
}

.chat-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.chat-header .back-link {
    color: var(--header-sub);
    font-size: 19px;
    line-height: 1;
    padding: 4px;
}

.chat-header .room-icon-sm {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
    flex-shrink: 0;
}

.chat-header .room-icon-sm img { width: 100%; height: 100%; object-fit: cover; }

.chat-header .room-title-wrap { flex: 1; min-width: 0; }

.chat-header .room-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header .room-sub {
    font-size: 11px;
    color: var(--header-sub);
}

.chat-box {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-box::-webkit-scrollbar { width: 6px; }
.chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.empty-state {
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
    margin-top: 30px;
}

.msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    max-width: 85%;
}

.msg-row.own { align-self: flex-end; flex-direction: row-reverse; }

.msg-row .mini-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--text-muted);
    color: var(--card-bg);
    font-size: 10.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.msg-row .mini-avatar img { width: 100%; height: 100%; object-fit: cover; }

.msg-bubble {
    background: var(--bubble-bg);
    border: 1px solid var(--bubble-border);
    color: var(--text);
    padding: 9px 13px;
    border-radius: var(--radius-md);
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.msg-row.own .msg-bubble {
    background: var(--accent);
    color: var(--accent-text);
    border-color: var(--accent);
}

.msg-bubble .name-tag {
    font-weight: 700;
    font-size: 11.5px;
    display: block;
    margin-bottom: 2px;
    color: var(--text-muted);
}

.msg-row.own .msg-bubble .name-tag { color: var(--accent-text); opacity: 0.75; }

.msg-bubble .time-tag {
    font-size: 10px;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    margin-left: 6px;
}

.msg-row.own .msg-bubble .time-tag { color: var(--accent-text); opacity: 0.65; }

.chat-img {
    max-width: 100%;
    max-height: 200px;
    border-radius: var(--radius-sm);
    margin-top: 6px;
    display: block;
    cursor: pointer;
}

.input-area {
    padding: 12px;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

.form-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

input[type="text"].msg-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease;
}

input[type="text"].msg-input:focus {
    border-color: var(--accent);
    background: var(--card-bg);
}

.btn-send {
    border: none;
    padding: 11px 20px;
    border-radius: 22px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    background: var(--accent);
    color: var(--accent-text);
    transition: opacity 0.15s ease;
}

.btn-send:hover { opacity: 0.85; }

.file-label {
    background: var(--surface);
    color: var(--text-muted);
    border: 1px solid var(--border);
    width: 42px;
    height: 42px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s ease;
}

.file-label:hover { background: var(--border); }

#file-input { display: none; }

/* ---------- Settings page ---------- */

.settings-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.settings-card {
    background: var(--card-bg);
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.settings-header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-header .back-link {
    color: var(--header-sub);
    font-size: 19px;
}

.settings-header .title {
    font-weight: 700;
    font-size: 16px;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 22px;
}

.settings-section { margin-bottom: 28px; }

.settings-section h2 {
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin: 0 0 14px;
}

.avatar-upload-row {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-upload-row .avatar-circle {
    width: 64px;
    height: 64px;
    font-size: 22px;
}

.avatar-upload-row .upload-btn {
    padding: 9px 16px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.theme-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.theme-option {
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px;
    cursor: pointer;
    background: var(--surface);
    transition: border-color 0.15s ease, transform 0.1s ease;
}

.theme-option:hover { transform: translateY(-1px); }

.theme-option.active { border-color: var(--accent); }

.theme-swatch {
    height: 44px;
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    display: flex;
    overflow: hidden;
    border: 1px solid rgba(0,0,0,0.06);
}

.theme-swatch span { flex: 1; }

.theme-option .theme-label {
    font-size: 12.5px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.theme-option .check {
    font-size: 11px;
    color: var(--accent);
    visibility: hidden;
}

.theme-option.active .check { visibility: visible; }

/* ---------- Responsive: small / Chromebook-class screens ---------- */

html, body { overflow-x: hidden; }

@media (max-width: 640px) {
    .chat-screen, .lobby-screen, .settings-screen { padding: 0; }

    .chat-container, .lobby-card, .settings-card {
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .chat-header, .lobby-header, .settings-header {
        border-radius: 0;
    }

    .input-area, .room-list { border-radius: 0; }

    .auth-screen { padding: 16px; }
    .auth-card { padding: 28px 22px; }
}

@media (max-width: 380px) {
    .room-row .room-sub { display: none; }
    .chat-header .room-sub { display: none; }
    .msg-row { max-width: 92%; }
    .lobby-footer input[type="text"] { font-size: 13px; }
}

@media (min-height: 0) and (max-height: 600px) {
    .chat-container, .lobby-card { height: 96vh; height: 96dvh; }
    .settings-card { max-height: 96vh; max-height: 96dvh; }
}

/* ---------- Settings: tabbed layout ---------- */

.settings-card { max-width: 560px; }

.settings-shell {
    display: flex;
    flex: 1;
    min-height: 0;
}

.settings-nav {
    width: 168px;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    padding: 14px 8px;
    overflow-y: auto;
}

.settings-nav button {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border: none;
    background: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    margin-bottom: 2px;
}

.settings-nav button .nav-icon { width: 16px; text-align: center; opacity: 0.8; }

.settings-nav button:hover { background: var(--surface); color: var(--text); }

.settings-nav button.active {
    background: var(--accent);
    color: var(--accent-text);
}

.settings-panes {
    flex: 1;
    overflow-y: auto;
    padding: 22px;
    min-width: 0;
}

.settings-pane { display: none; }
.settings-pane.active { display: block; }

@media (max-width: 640px) {
    .settings-shell { flex-direction: column; }
    .settings-nav {
        width: 100%;
        display: flex;
        gap: 4px;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 10px 12px;
    }
    .settings-nav button { width: auto; white-space: nowrap; margin-bottom: 0; }
}

/* ---------- Settings: shared field styles ---------- */

.settings-pane h2 {
    font-size: 12.5px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    margin: 0 0 14px;
}

.settings-pane .pane-intro {
    font-size: 12.5px;
    color: var(--text-muted);
    margin: -8px 0 18px;
    line-height: 1.5;
}

.settings-pane textarea {
    width: 100%;
    min-height: 70px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font-size: 13.5px;
    font-family: inherit;
    resize: vertical;
    outline: none;
}

.settings-pane textarea:focus { border-color: var(--accent); background: var(--card-bg); }

.char-count {
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.settings-pane input[type="password"], .settings-pane input[type="text"] {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font-size: 13.5px;
    outline: none;
    margin-bottom: 10px;
}

.settings-pane input:focus { border-color: var(--accent); background: var(--card-bg); }

.btn-save {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

.btn-save:hover { opacity: 0.88; }

.save-status {
    font-size: 12px;
    color: #34c759;
    margin-left: 10px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.save-status.show { opacity: 1; }

/* ---------- Settings: appearance toggle row ---------- */

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 1px solid var(--border);
}

.toggle-row .toggle-label { font-size: 13.5px; font-weight: 600; }
.toggle-row .toggle-sub { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.switch {
    position: relative;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.15s ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: var(--card-bg);
    border-radius: 50%;
    transition: transform 0.15s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* Compact message density */
[data-density="compact"] .msg-bubble { padding: 6px 11px; font-size: 13px; }
[data-density="compact"] .chat-box { gap: 6px; padding: 12px; }
[data-density="compact"] .mini-avatar { width: 20px; height: 20px; }

/* ---------- Settings: rooms management ---------- */

.settings-room-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.settings-room-row .room-icon {
    width: 36px;
    height: 36px;
    border-radius: 11px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    overflow: hidden;
    flex-shrink: 0;
}

.settings-room-row .room-icon img { width: 100%; height: 100%; object-fit: cover; }

.settings-room-row .room-meta { flex: 1; min-width: 0; }
.settings-room-row .room-name { font-weight: 600; font-size: 13.5px; }
.settings-room-row .room-sub { font-size: 11px; color: var(--text-muted); }

.btn-danger {
    padding: 7px 13px;
    border: 1px solid #d23b32;
    border-radius: var(--radius-sm);
    background: transparent;
    color: #d23b32;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    flex-shrink: 0;
}

.btn-danger:hover { background: #d23b32; color: #fff; }

.empty-owned {
    color: var(--text-muted);
    font-size: 12.5px;
    padding: 14px 0;
}

/* ---------- Settings: about ---------- */

.about-block {
    text-align: center;
    padding: 10px 0 22px;
}

.about-block .about-mark {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 19px;
    margin: 0 auto 12px;
}

.about-block .about-name { font-weight: 700; font-size: 16px; }
.about-block .about-version { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

.about-list {
    border-top: 1px solid var(--border);
}

.about-list .about-row {
    display: flex;
    justify-content: space-between;
    padding: 11px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.about-list .about-row .k { color: var(--text-muted); }
.about-list .about-row .v { font-weight: 600; }

/* ===================================================================
   App shell — Discord-style layout (server rail + main panel)
   =================================================================== */

html, body { height: 100%; }

.app-shell {
    display: flex;
    height: 100vh;
    height: 100dvh;
    width: 100%;
    overflow: hidden;
    background: var(--bg);
}

/* ---------- Server rail (left icon column) ---------- */

.server-rail {
    width: 76px;
    flex-shrink: 0;
    background: var(--header-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 14px 0 10px;
    gap: 10px;
    overflow-y: auto;
    overflow-x: visible;
}

.server-rail::-webkit-scrollbar { width: 0; }

.rail-item {
    position: relative;
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: rgba(255,255,255,0.08);
    color: var(--header-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 15px;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
    transition: border-radius 0.15s ease, background 0.15s ease;
    text-decoration: none;
}

.rail-item img { width: 100%; height: 100%; object-fit: cover; }

.rail-item:hover { border-radius: 14px; background: rgba(255,255,255,0.16); }

.rail-item.active {
    border-radius: 14px;
    background: var(--accent-text);
    color: var(--accent);
}

.rail-item.active::before {
    content: "";
    position: absolute;
    left: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 26px;
    border-radius: 0 4px 4px 0;
    background: var(--accent-text);
}

/* Tooltip on hover — name of the room/action */
.rail-item[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: calc(100% + 14px);
    top: 50%;
    transform: translateY(-50%) scale(0.92);
    background: #0b0b0c;
    color: #fff;
    font-size: 12.5px;
    font-weight: 600;
    padding: 6px 10px;
    border-radius: 8px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.12s ease, transform 0.12s ease;
    z-index: 80;
}

.rail-item[data-tooltip]:hover::after {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}

.rail-divider {
    width: 32px;
    height: 2px;
    background: rgba(255,255,255,0.12);
    border-radius: 2px;
    flex-shrink: 0;
}

.rail-rooms {
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding: 2px 0;
}

.rail-add {
    font-size: 22px;
    font-weight: 400;
    color: #ffffff;
    background: rgba(255,255,255,0.08);
}

.rail-add:hover { background: #34c759; color: #fff; }

.rail-bottom {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.rail-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s ease;
    flex-shrink: 0;
}

.rail-avatar:hover { border-color: rgba(255,255,255,0.3); }
.rail-avatar img { width: 100%; height: 100%; object-fit: cover; }
.rail-avatar .avatar-circle { width: 100%; height: 100%; font-size: 15px; }

/* ---------- Main panel ---------- */

.main-panel {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--card-bg);
}

.main-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.main-header .room-icon-sm {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    overflow: hidden;
    flex-shrink: 0;
}

.main-header .room-icon-sm img { width: 100%; height: 100%; object-fit: cover; }

.main-header .room-title-wrap { flex: 1; min-width: 0; }

.main-header .room-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-header .room-sub {
    font-size: 11.5px;
    color: var(--text-muted);
}

.main-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    padding: 20px;
    text-align: center;
}

.main-empty .mark {
    width: 56px;
    height: 56px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    color: var(--text);
    margin-bottom: 6px;
}

.main-empty .empty-title { font-size: 15px; font-weight: 700; color: var(--text); }
.main-empty .empty-sub { font-size: 13px; max-width: 280px; }

/* Reuse .chat-box / .msg-row / .msg-bubble / .input-area styles inside main-panel,
   just override the rounded-corner / shadow rules that assumed a floating card. */
.main-panel .chat-box { flex: 1; }
.main-panel .input-area { border-radius: 0; }

/* ---------- Create room modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}

.modal-backdrop.open { display: flex; }

.modal-box {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 360px;
    padding: 24px;
}

.modal-box h3 {
    margin: 0 0 4px;
    font-size: 17px;
    color: var(--text);
}

.modal-box p {
    margin: 0 0 18px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.modal-box .new-room-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 14px;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-actions .btn-cancel {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: none;
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
}

/* ---------- Responsive: collapse rail on small screens ---------- */

@media (max-width: 640px) {
    .app-shell { flex-direction: column; }

    .server-rail {
        width: 100%;
        height: 64px;
        flex-direction: row;
        padding: 8px 12px;
        overflow-x: auto;
        overflow-y: visible;
    }

    .rail-rooms { flex-direction: row; overflow-x: auto; overflow-y: visible; flex: 1; }
    .rail-divider { width: 2px; height: 28px; }
    .rail-bottom { flex-direction: row; }
    .rail-item[data-tooltip]::after { left: 50%; top: calc(100% + 10px); transform: translateX(-50%) scale(0.92); }
    .rail-item[data-tooltip]:hover::after { transform: translateX(-50%) scale(1); }

    .main-header { padding: 12px 14px; }
}

/* ---------- App shell (Discord-style sidebar + full-bleed chat) ---------- */

.app-shell {
    height: 100vh;
    height: 100dvh;
    width: 100%;
    display: flex;
    overflow: hidden;
    background: var(--surface);
}

.app-sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--card-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
}

.sidebar-brand {
    padding: 16px 16px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-brand .mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--accent-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    flex-shrink: 0;
}

.sidebar-brand .name {
    font-weight: 700;
    font-size: 14.5px;
    letter-spacing: -0.2px;
}

.sidebar-rooms {
    flex: 1;
    overflow-y: auto;
    padding: 10px 8px;
}

.sidebar-rooms::-webkit-scrollbar { width: 5px; }
.sidebar-rooms::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sidebar-section-label {
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    padding: 6px 8px 6px;
}

.sidebar-room {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 2px;
    transition: background 0.12s ease;
}

.sidebar-room:hover { background: var(--surface); }

.sidebar-room.active { background: var(--accent); }
.sidebar-room.active .sidebar-room-name { color: var(--accent-text); }
.sidebar-room.active .sidebar-room-sub { color: var(--accent-text); opacity: 0.7; }

.sidebar-room .room-icon {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    color: var(--text);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-room .room-icon img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-room-meta { flex: 1; min-width: 0; }

.sidebar-room-name {
    font-size: 13.5px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-room-sub {
    font-size: 10.5px;
    color: var(--text-muted);
}

.sidebar-empty {
    color: var(--text-muted);
    font-size: 12px;
    padding: 16px 10px;
    text-align: center;
}

.sidebar-new-room-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    border: 1px dashed var(--border);
    margin: 4px 2px 8px;
}

.sidebar-new-room-btn:hover { background: var(--surface); color: var(--text); }

.sidebar-new-room-btn .plus-icon {
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* User panel pinned to sidebar bottom */
.sidebar-userbar {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 8px;
    position: relative;
}

.sidebar-userbar .menu-trigger {
    width: 100%;
    border-radius: var(--radius-sm);
    padding: 6px 8px;
}

.sidebar-userbar .menu-trigger:hover { background: var(--surface); }

.sidebar-userbar .uname {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-userbar .dropdown-menu {
    bottom: calc(100% + 6px);
    top: auto;
    left: 0;
    right: auto;
}

/* Main chat pane */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100%;
}

.main-topbar {
    flex-shrink: 0;
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.main-topbar .sidebar-toggle {
    display: none;
    font-size: 18px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

.main-topbar .room-icon-sm {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 12px;
    overflow: hidden;
    flex-shrink: 0;
}

.main-topbar .room-icon-sm img { width: 100%; height: 100%; object-fit: cover; }

.main-topbar .room-title {
    font-weight: 700;
    font-size: 14.5px;
}

.main-chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.main-chat-box::-webkit-scrollbar { width: 6px; }
.main-chat-box::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.main-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 10px;
    color: var(--text-muted);
    text-align: center;
    padding: 20px;
}

.main-empty .big-mark {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.main-input-area {
    flex-shrink: 0;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    padding: 14px 18px;
}

/* New-room popover */
.new-room-popover {
    position: absolute;
    bottom: 56px;
    left: 8px;
    right: 8px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    padding: 14px;
    display: none;
    z-index: 60;
}

.new-room-popover.open { display: block; }

.new-room-popover h3 {
    font-size: 12.5px;
    margin: 0 0 10px;
    font-weight: 700;
}

.new-room-popover .icon-name-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Mobile: collapsible sidebar */
@media (max-width: 760px) {
    .app-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow);
    }
    .app-sidebar.open { transform: translateX(0); }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 90;
    }
    .sidebar-overlay.open { display: block; }

    .main-topbar .sidebar-toggle { display: block; }
}

/* ---------- Additional themes ---------- */

[data-theme="pink"] {
    --bg: #fdf1f5;
    --card-bg: #fffafc;
    --surface: #fbe6ee;
    --header-bg: #7d2c52;
    --header-text: #fff5f8;
    --header-sub: #e8b9cd;
    --text: #3a1a28;
    --text-muted: #9c6e80;
    --border: #f3d6e3;
    --input-bg: #fbe6ee;
    --accent: #c2487a;
    --accent-text: #ffffff;
    --bubble-bg: #fffafc;
    --bubble-border: #f3d6e3;
}

[data-theme="purple"] {
    --bg: #f5f1fb;
    --card-bg: #fdfbff;
    --surface: #ece3f7;
    --header-bg: #3d2a5c;
    --header-text: #f6f1fb;
    --header-sub: #c9b8de;
    --text: #2a1f3d;
    --text-muted: #7d6a95;
    --border: #e0d3f0;
    --input-bg: #ece3f7;
    --accent: #7048a8;
    --accent-text: #ffffff;
    --bubble-bg: #fdfbff;
    --bubble-border: #e0d3f0;
}

[data-theme="desert"] {
    --bg: #f6efe2;
    --card-bg: #fffdf7;
    --surface: #efe2cc;
    --header-bg: #7a5230;
    --header-text: #fdf6ec;
    --header-sub: #d9bd96;
    --text: #4a3520;
    --text-muted: #9c8467;
    --border: #e8d7b8;
    --input-bg: #efe2cc;
    --accent: #b5793b;
    --accent-text: #ffffff;
    --bubble-bg: #fffdf7;
    --bubble-border: #e8d7b8;
}

/* ---------- Presence dot ---------- */

.avatar-wrap { position: relative; display: inline-flex; flex-shrink: 0; }

.status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--text-muted);
    border: 2px solid var(--card-bg);
}

.status-dot.online { background: #34c759; }

/* ---------- Role badges ---------- */

.role-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.4px;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    text-transform: uppercase;
    vertical-align: middle;
}

.role-badge.owner { background: #e8b923; color: #3a2c00; }
.role-badge.admin { background: #4a90d9; color: #ffffff; }

/* ---------- Friends pane ---------- */

.friends-tabs {
    display: flex;
    gap: 6px;
    padding: 12px 18px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.friends-tab {
    padding: 9px 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
}

.friends-tab.active { color: var(--text); border-bottom-color: var(--accent); }

.friends-body { flex: 1; overflow-y: auto; padding: 16px 18px; }

.add-friend-row {
    display: flex;
    gap: 8px;
    margin-bottom: 18px;
}

.add-friend-row input {
    flex: 1;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 13.5px;
    outline: none;
}

.add-friend-row input:focus { border-color: var(--accent); background: var(--card-bg); }

.add-friend-row button {
    border: none;
    padding: 11px 18px;
    border-radius: 20px;
    background: var(--accent);
    color: var(--accent-text);
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
}

.friend-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
}

.friend-row:hover { background: var(--surface); }

.friend-row .friend-meta { flex: 1; min-width: 0; }
.friend-row .friend-name { font-weight: 600; font-size: 13.5px; }
.friend-row .friend-sub { font-size: 11.5px; color: var(--text-muted); }

.friend-row .friend-actions { display: flex; gap: 6px; }

.btn-mini {
    padding: 6px 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
}

.btn-mini:hover { background: var(--surface); }
.btn-mini.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn-mini.danger { color: #d23b32; border-color: #d23b32; }
.btn-mini.danger:hover { background: #d23b32; color: #fff; }

.friends-empty {
    color: var(--text-muted);
    font-size: 12.5px;
    text-align: center;
    padding: 30px 10px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.sidebar-nav-item:hover { background: var(--surface); }
.sidebar-nav-item.active { background: var(--accent); color: var(--accent-text); }
.sidebar-nav-item .nav-emoji { width: 20px; text-align: center; }

.friend-req-badge {
    background: #d23b32;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    border-radius: 10px;
    padding: 1px 6px;
    margin-left: auto;
}

/* ---------- Profile modal ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-overlay.open { display: flex; }

.profile-modal {
    background: var(--card-bg);
    width: 100%;
    max-width: 340px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.profile-modal .profile-banner {
    background: var(--header-bg);
    height: 64px;
    position: relative;
}

.profile-modal .profile-avatar-row {
    padding: 0 20px;
    margin-top: -32px;
}

.profile-modal .profile-avatar-row .avatar-circle {
    width: 64px;
    height: 64px;
    font-size: 22px;
    border: 4px solid var(--card-bg);
}

.profile-modal .profile-body { padding: 14px 20px 20px; }

.profile-modal .profile-name {
    font-weight: 700;
    font-size: 16px;
    display: flex;
    align-items: center;
}

.profile-modal .profile-sub {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

.profile-modal .profile-bio {
    font-size: 13px;
    color: var(--text);
    margin-top: 14px;
    line-height: 1.5;
}

.profile-modal .profile-actions {
    margin-top: 18px;
    display: flex;
    gap: 8px;
}

.profile-modal .profile-close {
    position: absolute;
    top: 10px;
    right: 12px;
    color: rgba(255,255,255,0.85);
    font-size: 18px;
    cursor: pointer;
}

.name-tag-clickable { cursor: pointer; }
.name-tag-clickable:hover { text-decoration: underline; }

/* ---------- Roles settings tab ---------- */

.role-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.role-row .role-meta { flex: 1; min-width: 0; font-size: 13px; font-weight: 600; }

.role-row select {
    padding: 7px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font-size: 12.5px;
}

/* ===== Additional themes ===== */

[data-theme="forest"] {
    --bg: #eef3ec;
    --card-bg: #f8fcf7;
    --surface: #e0eedc;
    --header-bg: #1e3d22;
    --header-text: #edf6ea;
    --header-sub: #8db88f;
    --text: #1a2e1c;
    --text-muted: #5a7c5c;
    --border: #cee0cb;
    --input-bg: #e0eedc;
    --accent: #2d6e32;
    --accent-text: #ffffff;
    --bubble-bg: #f8fcf7;
    --bubble-border: #cee0cb;
}

[data-theme="slate"] {
    --bg: #eef0f4;
    --card-bg: #f8f9fb;
    --surface: #e2e6ed;
    --header-bg: #1e2a3a;
    --header-text: #e8edf4;
    --header-sub: #8a9ab0;
    --text: #1a2232;
    --text-muted: #5c6e84;
    --border: #d0d8e4;
    --input-bg: #e2e6ed;
    --accent: #3a5a8a;
    --accent-text: #ffffff;
    --bubble-bg: #f8f9fb;
    --bubble-border: #d0d8e4;
}

[data-theme="carbon"] {
    --bg: #181818;
    --card-bg: #212121;
    --surface: #161616;
    --header-bg: #111111;
    --header-text: #e8e8e8;
    --header-sub: #888888;
    --text: #e8e8e8;
    --text-muted: #888888;
    --border: #303030;
    --input-bg: #2a2a2a;
    --accent: #e8e8e8;
    --accent-text: #111111;
    --bubble-bg: #2a2a2a;
    --bubble-border: #303030;
}

[data-theme="lavender"] {
    --bg: #f2f0fa;
    --card-bg: #faf9fd;
    --surface: #e8e4f5;
    --header-bg: #4a3d6e;
    --header-text: #f2f0fa;
    --header-sub: #b8aed6;
    --text: #2a2240;
    --text-muted: #7868a0;
    --border: #dcd6f0;
    --input-bg: #e8e4f5;
    --accent: #6a5aac;
    --accent-text: #ffffff;
    --bubble-bg: #faf9fd;
    --bubble-border: #dcd6f0;
}

[data-theme="mint"] {
    --bg: #eef8f5;
    --card-bg: #f8fdfc;
    --surface: #d8f0ea;
    --header-bg: #1a4a3c;
    --header-text: #eaf8f4;
    --header-sub: #7abcaa;
    --text: #162e28;
    --text-muted: #4a8070;
    --border: #c0e4d8;
    --input-bg: #d8f0ea;
    --accent: #1e7a60;
    --accent-text: #ffffff;
    --bubble-bg: #f8fdfc;
    --bubble-border: #c0e4d8;
}

/* ===== Mobile layout fixes ===== */

/* Always show a top nav bar so there's always a way to open sidebar on mobile */
.app-topnav {
    display: none;
    background: var(--header-bg);
    color: var(--header-text);
    padding: 12px 16px;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    z-index: 10;
}

@media (max-width: 760px) {
    .app-topnav { display: flex; }
    .app-topnav .sidebar-toggle { color: var(--header-text); font-size: 18px; cursor: pointer; }
    .app-topnav .nav-title { font-weight: 700; font-size: 15px; flex: 1; }
}

/* ===== Clickable links in messages ===== */

.msg-link {
    color: var(--accent);
    text-decoration: underline;
    word-break: break-all;
}

.msg-row.own .msg-link { color: var(--accent-text); opacity: 0.9; }

/* ===== Voice call UI ===== */

.call-bar {
    background: #1a5c2a;
    color: #ffffff;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.call-bar .call-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    animation: pulse 1.5s infinite;
    flex-shrink: 0;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(0.85); }
}

.call-bar .call-label { flex: 1; }

.call-bar .call-participants {
    display: flex;
    gap: -4px;
}

.call-bar .call-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #1a5c2a;
    background: #2d8a40;
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: -4px;
    overflow: hidden;
}

.call-bar .call-avatar:first-child { margin-left: 0; }
.call-bar .call-avatar img { width: 100%; height: 100%; object-fit: cover; }

.call-btn {
    border: none;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
}

.call-btn.join  { background: #4ade80; color: #0a2e14; }
.call-btn.leave { background: #ef4444; color: #ffffff; }
.call-btn.mute  { background: rgba(255,255,255,0.15); color: #ffffff; }
.call-btn.mute.muted { background: #ef4444; }

.call-start-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 15px;
    color: var(--text-muted);
    transition: background 0.15s ease;
    flex-shrink: 0;
}

.call-start-btn:hover { background: var(--surface); color: var(--text); }
.call-start-btn.in-call { background: #1a5c2a; color: #4ade80; border-color: #1a5c2a; }

/* ===== Private channel UI ===== */

.lock-icon {
    font-size: 10px;
    opacity: 0.6;
    margin-left: 4px;
}

.invite-modal-content {
    padding: 20px;
}

.invite-modal-content h3 { margin: 0 0 14px; font-size: 15px; }

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.member-row .member-name { flex: 1; font-size: 13.5px; font-weight: 600; }

/* ===== Dev mode ===== */

.dev-panel {
    background: #0a0a0a;
    color: #00ff88;
    font-family: ui-monospace, monospace;
    font-size: 11px;
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-top: 14px;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.dev-toggle-row {
    padding: 10px 0;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    font-weight: 600;
}

/* ===== Settings: theme grid wider for more themes ===== */
.theme-grid { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 500px) {
    .theme-grid { grid-template-columns: repeat(2, 1fr); }
}
