/* ============================================
   WorkChat - Professional Chat UI
   Responsive: PC / Tablet / Mobile
   ============================================ */

/* ─── CSS Variables ─── */
:root {
    --sidebar-w: 240px;
    --users-w: 220px;
    --bg-sidebar: #1a1d21;
    --bg-sidebar-hover: #27292d;
    --bg-sidebar-active: #3a3d42;
    --bg-main: #ffffff;
    --bg-secondary: #f7f7f8;
    --bg-input: #f0f0f1;
    --bg-modal: rgba(0, 0, 0, 0.55);
    --accent: #5b5fc7;
    --accent-hover: #4a4eb0;
    --accent-light: #eeeeff;
    --text-primary: #1d1d1f;
    --text-secondary: #6e7378;
    --text-sidebar: #c8ccd0;
    --text-sidebar-muted: #72767d;
    --text-sidebar-active: #ffffff;
    --text-system: #8f9095;
    --border: #e3e5e8;
    --border-dark: #2d3035;
    --msg-self-bg: #eeeeff;
    --danger: #e53e3e;
    --danger-hover: #c53030;
    --success: #38a169;
    --shadow: 0 2px 12px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.18);
    --radius: 8px;
    --radius-sm: 4px;
    --mobile-nav-h: 56px;
    --chat-header-h: 52px;
    --input-area-h: 68px;
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Light Theme ─── */
[data-theme="light"] {
    --bg-sidebar: #e8eaed;
    --bg-sidebar-hover: #dadde1;
    --bg-sidebar-active: #c8ccd0;
    --bg-main: #ffffff;
    --bg-secondary: #f5f6f7;
    --bg-input: #ebedf0;
    --text-sidebar: #1c1e21;
    --text-sidebar-muted: #606770;
    --text-sidebar-active: #1c1e21;
    --border-dark: #dadde1;
}

/* ─── Midnight Theme ─── */
[data-theme="midnight"] {
    --bg-sidebar: #0d1117;
    --bg-sidebar-hover: #161b22;
    --bg-sidebar-active: #21262d;
    --bg-main: #0d1117;
    --bg-secondary: #161b22;
    --bg-input: #21262d;
    --bg-modal: rgba(0,0,0,0.8);
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-system: #6e7681;
    --border: #30363d;
    --border-dark: #21262d;
    --msg-self-bg: #1e2d40;
    --accent-light: #1e2d40;
}

[data-theme="midnight"] #msg-input:focus,
[data-theme="midnight"] #lobby-msg-input:focus,
[data-theme="midnight"] .modal-input:focus {
    background: #161b22;
}

[data-theme="midnight"] .modal-box,
[data-theme="midnight"] .settings-panel {
    background: #161b22;
    border-color: #30363d;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
    font-size: 14px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    opacity: var(--app-opacity, 1);
    transition: background 0.2s, color 0.2s, opacity 0.15s;
    overflow: hidden;
}

button { cursor: pointer; font-family: inherit; border: none; outline: none; }
input { font-family: inherit; outline: none; border: none; }
a { color: var(--accent); text-decoration: none; }

/* ─── App Layout ─── */
#app {
    display: grid;
    grid-template-areas: "sidebar main users";
    grid-template-columns: var(--sidebar-w) 1fr var(--users-w);
    height: 100vh;
    max-height: 100dvh;
    overflow: hidden;
}

/* ─── Sidebar ─── */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--border-dark);
}

.sidebar-header {
    padding: 16px 12px 12px;
    border-bottom: 1px solid var(--border-dark);
    flex-shrink: 0;
}

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

.brand-logo {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-sidebar-active);
    letter-spacing: -0.3px;
}

.brand-badge {
    font-size: 10px;
    background: var(--accent);
    color: #fff;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
}

.my-info {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 4px;
    border-radius: var(--radius-sm);
}

.my-avatar {
    width: 28px;
    height: 28px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    color: #fff;
}

#my-name-display {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-sidebar-active);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-actions {
    padding: 10px 12px 6px;
    flex-shrink: 0;
}

.btn-new-room {
    width: 100%;
    background: var(--accent);
    color: #fff;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-new-room:hover { background: var(--accent-hover); }

.rooms-section {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0 12px;
}

.rooms-section::-webkit-scrollbar { width: 4px; }
.rooms-section::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.section-label {
    padding: 10px 16px 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-sidebar-muted);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.room-list-empty {
    padding: 16px;
    font-size: 12px;
    color: var(--text-sidebar-muted);
    line-height: 1.6;
    text-align: center;
}

.room-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 16px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    margin: 1px 8px;
    transition: background 0.1s;
}

.room-item:hover { background: var(--bg-sidebar-hover); }
.room-item.active { background: var(--bg-sidebar-active); }

.room-item-icon {
    font-size: 14px;
    color: var(--text-sidebar-muted);
    flex-shrink: 0;
    width: 16px;
    text-align: center;
}

.room-item.active .room-item-icon { color: var(--text-sidebar-active); }

.room-item-info {
    flex: 1;
    overflow: hidden;
}

.room-item-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-sidebar);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-item.active .room-item-name { color: var(--text-sidebar-active); font-weight: 600; }

.room-item-meta {
    display: block;
    font-size: 11px;
    color: var(--text-sidebar-muted);
    margin-top: 1px;
}

.room-item-full {
    display: block;
    font-size: 10px;
    color: var(--danger);
    margin-top: 1px;
    font-weight: 600;
}

/* Sidebar settings button */
.sidebar-footer {
    padding: 8px 12px;
    border-top: 1px solid var(--border-dark);
    flex-shrink: 0;
}

.btn-settings-sidebar {
    width: 100%;
    background: transparent;
    color: var(--text-sidebar-muted);
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s, color 0.1s;
}

.btn-settings-sidebar:hover { background: var(--bg-sidebar-hover); color: var(--text-sidebar); }

/* ─── Main Area ─── */
.main-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    background: var(--bg-main);
    overflow: hidden;
    min-width: 0;
}

/* Welcome State = Lobby Chat */
#welcome-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lobby-header {
    height: var(--chat-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
    flex-shrink: 0;
    gap: 8px;
}

.lobby-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.lobby-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.lobby-user-count {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-input);
    padding: 2px 8px;
    border-radius: 10px;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
    white-space: nowrap;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-sm-text {
    padding: 7px 14px;
    font-size: 13px;
}

/* Chat State */
#chat-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-header {
    height: var(--chat-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
    flex-shrink: 0;
    gap: 8px;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    overflow: hidden;
}

/* Mobile back button */
#chat-back-btn {
    display: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 18px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    line-height: 1;
}

#chat-back-btn:hover { background: var(--bg-secondary); }

.room-lock-icon { font-size: 14px; flex-shrink: 0; }

#current-room-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.btn-header-invite {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-header-invite:hover {
    background: var(--accent);
    color: #fff;
}

.btn-leave-room {
    background: transparent;
    color: var(--danger, #ef4444);
    border: 1px solid var(--danger, #ef4444);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.btn-leave-room:hover {
    background: var(--danger, #ef4444);
    color: #fff;
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 16px;
    line-height: 1;
    transition: background 0.1s, color 0.1s;
}

.btn-icon:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* Messages */
.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg {
    max-width: 75%;
    padding: 0;
}

.msg-system {
    max-width: 100%;
    text-align: center;
    color: var(--text-system);
    font-size: 12px;
    padding: 4px 0;
    align-self: center;
}

.msg-other {
    align-self: flex-start;
}

.msg-self {
    align-self: flex-end;
}

.msg-header {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 3px;
    padding: 0 2px;
}

.msg-self .msg-header { flex-direction: row-reverse; }

.msg-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
}

.msg-time {
    font-size: 11px;
    color: var(--text-system);
}

.msg-text {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg-self .msg-text {
    background: var(--msg-self-bg);
    color: var(--text-primary);
}

/* Input Area */
.input-area {
    height: var(--input-area-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-main);
    flex-shrink: 0;
}

#msg-input, #lobby-msg-input {
    flex: 1;
    background: var(--bg-input);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    transition: box-shadow 0.15s;
}

#msg-input:focus, #lobby-msg-input:focus {
    box-shadow: 0 0 0 2px var(--accent);
    background: #fff;
}

#msg-input::placeholder, #lobby-msg-input::placeholder { color: var(--text-system); }

.btn-send {
    background: var(--accent);
    color: #fff;
    padding: 10px 18px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-send:hover { background: var(--accent-hover); }

/* ─── Users Panel ─── */
.users-panel {
    grid-area: users;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: transform 0.25s;
}

/* Hidden by default when not in room */
.users-panel:not(.visible) {
    display: none;
}

.users-header {
    height: var(--chat-header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
}

#user-count {
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 10px;
    font-weight: 600;
}

.user-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.user-list::-webkit-scrollbar { width: 4px; }
.user-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    margin: 1px 8px;
    transition: background 0.1s;
}

.user-item:hover { background: var(--bg-input); }
.user-item.me { opacity: 0.8; }

.user-avatar { font-size: 16px; flex-shrink: 0; }

.user-info {
    flex: 1;
    overflow: hidden;
}

.user-name {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    display: inline-block;
    font-size: 10px;
    color: var(--accent);
    font-weight: 700;
    margin-top: 1px;
}

.user-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.user-item:hover .user-actions { opacity: 1; }

.btn-user-action {
    background: transparent;
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    line-height: 1;
    transition: background 0.1s;
}

.btn-user-action:hover { background: var(--bg-input); }
.btn-kick:hover { background: #fee2e2 !important; color: var(--danger); }
.btn-transfer:hover { background: #fffbeb !important; }

.users-footer {
    padding: 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.btn-invite {
    width: 100%;
    background: var(--accent-light);
    color: var(--accent);
    padding: 8px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-invite:hover { background: #ddddf8; }

/* ─── Modals ─── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    backdrop-filter: blur(2px);
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-box {
    background: var(--bg-main);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 28px 24px;
    width: 100%;
    max-width: 380px;
    animation: modalSlideIn 0.2s ease;
}

@keyframes modalSlideIn {
    from { transform: translateY(-16px) scale(0.97); opacity: 0; }
    to { transform: none; opacity: 1; }
}

.modal-box h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 6px;
}

.modal-box h3 {
    font-size: 17px;
    font-weight: 700;
    margin-bottom: 16px;
}

.modal-subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    margin-top: 16px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.modal-label:first-of-type { margin-top: 0; }

.modal-input {
    width: 100%;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color 0.15s, background 0.15s;
}

.modal-input:focus {
    border-color: var(--accent);
    background: #fff;
}

.modal-input::placeholder { color: var(--text-system); }

/* Setup modal specific */
.setup-box .setup-logo {
    font-size: 28px;
    text-align: center;
    margin-bottom: 4px;
}

.setup-box h2 { text-align: center; margin-bottom: 4px; }
.setup-box .modal-subtitle { text-align: center; }

.btn-block {
    width: 100%;
    background: var(--accent);
    color: #fff;
    padding: 12px;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    margin-top: 16px;
    transition: background 0.15s;
}

.btn-block:hover { background: var(--accent-hover); }

/* Room type toggle */
.room-type-group {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.room-type-btn {
    flex: 1;
    padding: 9px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 2px solid transparent;
    transition: all 0.15s;
}

.room-type-btn.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Modal actions */
.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
}

.btn-secondary {
    flex: 1;
    background: var(--bg-input);
    color: var(--text-primary);
    padding: 10px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-secondary:hover { background: var(--border); }

.btn-confirm {
    flex: 2;
    background: var(--accent);
    color: #fff;
    padding: 10px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    transition: background 0.15s;
}

.btn-confirm:hover { background: var(--accent-hover); }

/* ─── Settings Panel ─── */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    height: 100vh;
    background: var(--bg-main);
    border-left: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 900;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.settings-panel.open { transform: none; }

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 16px;
    font-weight: 700;
}

.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.setting-group h4 {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

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

.setting-row .modal-input { flex: 1; }

.btn-sm {
    background: var(--accent);
    color: #fff;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
    transition: background 0.15s;
}

.btn-sm:hover { background: var(--accent-hover); }

/* ─── Theme Selector ─── */
.theme-group {
    display: flex;
    gap: 8px;
}

.theme-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 10px 6px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--bg-input);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.theme-btn:hover { border-color: var(--accent); color: var(--accent); }

.theme-btn.active {
    border-color: var(--accent);
    background: var(--accent-light);
    color: var(--accent);
}

.theme-swatch {
    width: 36px;
    height: 24px;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.1);
}

.theme-swatch-dark   { background: linear-gradient(to right, #1a1d21 50%, #ffffff 50%); }
.theme-swatch-light  { background: linear-gradient(to right, #e8eaed 50%, #ffffff 50%); }
.theme-swatch-midnight { background: linear-gradient(to right, #0d1117 50%, #161b22 50%); }

/* ─── Opacity ─── */
.opacity-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 10px;
}

#opacity-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    height: 4px;
    cursor: pointer;
}

/* ─── Invite User Modal ─── */
.modal-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}
.modal-header-row h3 { margin: 0; }

.invite-user-list {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 12px;
}

.invite-user-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
}
.invite-user-item:last-child { border-bottom: none; }
.invite-user-name { flex: 1; font-size: 0.95rem; }
.btn-send-invite {
    padding: 4px 12px;
    border-radius: 6px;
    border: none;
    background: var(--accent);
    color: #fff;
    font-size: 0.8rem;
    cursor: pointer;
}
.btn-send-invite:hover { opacity: 0.85; }
.invite-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 20px 0;
    font-size: 0.9rem;
}

/* ─── Invite Dialog (incoming invite popup) ─── */
.invite-dialog {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 80px;
    z-index: 9999;
    pointer-events: none;
}
.invite-dialog-box {
    background: var(--bg-secondary);
    border: 1px solid var(--accent);
    border-radius: 12px;
    padding: 20px 24px;
    min-width: 260px;
    max-width: 320px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    pointer-events: all;
    animation: slideDown 0.2s ease;
}
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.invite-dialog-title {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 10px;
    color: var(--accent);
}
.invite-dialog-body {
    font-size: 0.95rem;
    color: var(--text-primary);
    line-height: 1.6;
    margin-bottom: 16px;
}
.invite-dialog-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ─── Toast ─── */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1d1d1f;
    color: #fff;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 9999;
    white-space: nowrap;
    max-width: calc(100vw - 32px);
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ─── Mobile Navigation Bar ─── */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--mobile-nav-h);
    background: var(--bg-main);
    border-top: 1px solid var(--border);
    z-index: 800;
}

.mobile-nav-inner {
    display: flex;
    height: 100%;
}

.mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    color: var(--text-system);
    font-size: 10px;
    font-weight: 600;
    transition: color 0.15s;
}

.mobile-nav-btn .nav-icon { font-size: 20px; line-height: 1; }
.mobile-nav-btn.active { color: var(--accent); }

/* ─── Toggle Members Button (Tablet) ─── */
#btn-toggle-members {
    display: none;
}

/* ─── Tablet (768px ~ 1023px) ─── */
@media (max-width: 1023px) and (min-width: 768px) {
    #app {
        grid-template-areas: "sidebar main";
        grid-template-columns: 200px 1fr;
    }

    .users-panel {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: var(--users-w);
        z-index: 700;
        transform: translateX(100%);
        box-shadow: var(--shadow-lg);
    }

    .users-panel.visible {
        display: flex;
        transform: translateX(0);
    }

    #btn-toggle-members {
        display: flex;
    }

    .sidebar { --sidebar-w: 200px; }
}

/* ─── Mobile (< 768px) ─── */
@media (max-width: 767px) {
    :root { --sidebar-w: 100%; --users-w: 100%; }

    body { overflow: auto; }

    #app {
        grid-template-areas: "main";
        grid-template-columns: 1fr;
        height: calc(100dvh - var(--mobile-nav-h));
        position: relative;
    }

    .sidebar {
        grid-area: main;
        position: fixed;
        inset: 0 0 var(--mobile-nav-h) 0;
        z-index: 100;
        display: flex;
    }

    .main-area {
        position: fixed;
        inset: 0 0 var(--mobile-nav-h) 0;
        z-index: 100;
    }

    .users-panel {
        position: fixed;
        inset: 0 0 var(--mobile-nav-h) 0;
        z-index: 100;
        display: flex;
        border-left: none;
    }

    /* Mobile view switching via data attribute */
    #app[data-mobile-view="rooms"] .sidebar { display: flex; }
    #app[data-mobile-view="rooms"] .main-area { display: none; }
    #app[data-mobile-view="rooms"] .users-panel { display: none !important; }

    #app[data-mobile-view="chat"] .sidebar { display: none; }
    #app[data-mobile-view="chat"] .main-area { display: flex; }
    #app[data-mobile-view="chat"] .users-panel { display: none !important; }

    #app[data-mobile-view="members"] .sidebar { display: none; }
    #app[data-mobile-view="members"] .main-area { display: none; }
    #app[data-mobile-view="members"] .users-panel { display: flex !important; }

    .mobile-nav { display: block; }

    #chat-back-btn { display: flex !important; }

    .modal-box { max-width: 100%; border-radius: 16px; }

    .settings-panel { width: 100%; }

    .toast { bottom: calc(var(--mobile-nav-h) + 12px); }

    .msg { max-width: 85%; }

    .users-panel { display: flex; }
    .users-panel:not(.visible) { display: flex; }
}

/* ─── PC (>= 1024px) ─── */
@media (min-width: 1024px) {
    /* Users panel always visible when in room */
    .users-panel.visible {
        display: flex;
    }
}

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

/* ─── Focus Visible ─── */
button:focus-visible, input:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ─── Room Topic Display ─── */
.room-title-wrap {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.room-topic-display {
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 1px;
}

/* ─── Room Info Panel (in users panel) ─── */
.room-info-panel {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-main);
}

.room-topic-panel {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    word-break: break-word;
    margin-bottom: 4px;
}

.room-capacity-panel {
    font-size: 11px;
    color: var(--text-system);
    font-weight: 600;
}

/* ─── Capacity Slider ─── */
.capacity-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
}

.capacity-slider {
    flex: 1;
    height: 4px;
    accent-color: var(--accent);
}

.capacity-value {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
    min-width: 36px;
    text-align: right;
}

/* ─── Setting Hint ─── */
.setting-hint {
    font-size: 11px;
    color: var(--text-system);
    margin-top: 8px;
    line-height: 1.5;
}

/* ─── Full room indicator ─── */
.room-item.room-full {
    opacity: 0.5;
    cursor: not-allowed;
}

.room-item.room-full:hover { background: transparent; }

/* ─── PWA Installed indicator ─── */
.pwa-ok {
    color: var(--success) !important;
    font-weight: 600 !important;
    font-size: 13px !important;
}

/* ─── PWA Standalone mode (no address bar) ─── */
@media (display-mode: standalone) {
    /* No address bar - use full height */
    body { height: 100vh; }

    /* Slightly adjust for safe areas on mobile */
    #app {
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .mobile-nav {
        padding-bottom: env(safe-area-inset-bottom, 0);
        height: calc(var(--mobile-nav-h) + env(safe-area-inset-bottom, 0px));
    }

    /* Show installed status in settings */
    #pwa-install-group { display: none !important; }
    #pwa-installed-group { display: block !important; }
}

/* ─── Typing Indicator ─── */
.typing-indicator {
    padding: 4px 16px;
    font-size: 0.8rem;
    color: var(--text-system);
    font-style: italic;
    min-height: 22px;
    flex-shrink: 0;
}

/* ─── @mention ─── */
.mention { background: var(--accent-light); color: var(--accent); border-radius: 3px; padding: 0 3px; font-weight: 600; }
.mention-me { background: #fef3c7; color: #d97706; }
[data-theme="dark"] .mention-me, [data-theme="midnight"] .mention-me { background: #3d2e00; color: #fbbf24; }
.msg-mention { border-left: 3px solid #fbbf24; }

/* ─── Reactions ─── */
.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.reaction-badge {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 0.8rem;
    cursor: pointer;
}
.reaction-badge.me { border-color: var(--accent); background: var(--accent-light); }
.reaction-bar {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    display: flex;
    gap: 2px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.reaction-pick {
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
}
.reaction-pick:hover { background: var(--bg-input); }
.msg { position: relative; }

/* ─── Pinned Message ─── */
.pinned-message {
    background: #fef3c7;
    color: #92400e;
    padding: 6px 16px;
    font-size: 0.85rem;
    border-bottom: 1px solid #fde68a;
    flex-shrink: 0;
}
[data-theme="dark"] .pinned-message, [data-theme="midnight"] .pinned-message {
    background: #3d2e00;
    color: #fbbf24;
    border-color: #4d3900;
}

/* ─── Unread Badge ─── */
.unread-badge {
    display: inline-block;
    background: #ef4444;
    color: #fff;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: bold;
    padding: 1px 6px;
    min-width: 18px;
    text-align: center;
    margin-left: 6px;
}

/* ─── DM Button ─── */
.btn-dm {
    background: none;
    border: none;
    color: var(--text-system);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.1s;
}
.btn-dm:hover { background: var(--bg-secondary); color: var(--accent); }

/* ─── Topic Clickable (host) ─── */
.room-topic-host { cursor: pointer; }
.room-topic-host:hover { color: var(--accent); }

/* ─── PWA Window Controls Overlay (Chromium desktop) ─── */
@media (display-mode: window-controls-overlay) {
    /* The title bar area is now part of the web content */
    :root {
        --wco-top: env(titlebar-area-y, 0px);
        --wco-height: env(titlebar-area-height, 0px);
    }

    /* Extend sidebar into title bar space */
    .sidebar {
        padding-top: var(--wco-height);
    }

    .sidebar-header {
        /* Make this area draggable (to move the window) */
        -webkit-app-region: drag;
        app-region: drag;
    }

    /* Interactive elements inside the drag area must opt out */
    .sidebar-header button,
    .sidebar-header input,
    .sidebar-header a,
    .my-info,
    .brand-logo {
        -webkit-app-region: no-drag;
        app-region: no-drag;
    }

    /* Main area also pushed down by title bar height */
    .main-area,
    .users-panel {
        padding-top: var(--wco-height);
    }

    /* Show installed status in settings */
    #pwa-install-group { display: none !important; }
    #pwa-installed-group { display: block !important; }
}

