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

:root {
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 8px;
    --radius-lg: 12px;
    --transition: 0.2s ease;

    --bg-primary: #0f0e17;
    --bg-secondary: #1a1725;
    --bg-tertiary: #252036;
    --bg-input: #1e1930;
    --border-color: #2d2844;
    --text-primary: #e8e4f0;
    --text-secondary: #9d94b0;
    --text-muted: #5c5370;
    --accent: #8B5CF6;
    --accent-dim: rgba(139, 92, 246, 0.15);
    --shadow: 0 4px 24px rgba(15, 14, 23, 0.6);
}

html { height: 100%; }
body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background 0.3s, color 0.3s;
}
/* Safe-area CSS variables for reuse everywhere */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

/* ── Scrollbar ───────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3d3460; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4d4480; }

/* ── Screens ─────────────────────────────────── */
.screen { display: none; height: 100dvh; }
.screen.active { display: flex; }

/* ── Auth Screen ─────────────────────────────── */
#auth-screen {
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    padding: var(--sat) var(--sar) var(--sab) var(--sal);
}
.auth-container {
    width: 100%;
    max-width: 380px;
    padding: 40px 32px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    text-align: center;
}
.auth-logo {
    font-size: 48px;
    margin-bottom: 12px;
    color: var(--accent);
}
.auth-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}
.auth-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 24px;
}

/* ── Forms ────────────────────────────────────── */
.form-group {
    margin-bottom: 16px;
    text-align: left;
}
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="email"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-main);
    transition: border-color var(--transition);
    outline: none;
}
.form-group input:focus {
    border-color: var(--accent);
}
.error-text {
    color: #f87171;
    font-size: 13px;
    margin-top: 12px;
    min-height: 20px;
}

/* ── Buttons ─────────────────────────────────── */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 20px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    transition: opacity var(--transition), transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.96); }

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition), color var(--transition);
    font-size: 16px;
}
.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ── File Input Wrapper ──────────────────────── */
.file-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
.btn-file-select {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-main);
    cursor: pointer;
    transition: background var(--transition);
    white-space: nowrap;
}
.btn-file-select:hover { background: var(--accent-dim); }
.file-input-label {
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Custom Color Picker ─────────────────────── */
.custom-color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}
.color-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color var(--transition), transform 0.1s;
}
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: #fff; }

/* ── HR ──────────────────────────────────────── */
hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}

/* ── Chat Layout ─────────────────────────────── */
#chat-screen {
    display: flex;
    height: 100dvh;
    padding-top: var(--sat);
    padding-left: var(--sal);
    padding-right: var(--sar);
}

/* ── Sidebar ─────────────────────────────────── */
#sidebar {
    width: 260px;
    min-width: 260px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}
.sidebar-title {
    font-size: 16px;
    font-weight: 700;
}
.room-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.room-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 2px;
}
.room-item:hover { background: var(--bg-tertiary); }
.room-item.active { background: var(--accent-dim); }
.room-item-info { overflow: hidden; }
.room-item-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}
.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding: 12px;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 8px;
}
.username-label {
    font-size: 13px;
    font-weight: 500;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Avatars ─────────────────────────────────── */
.avatar-sm { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-msg { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.avatar-wrapper { position: relative; flex-shrink: 0; }
.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-dim);
    color: var(--accent);
    font-weight: 700;
    font-size: 16px;
    font-family: var(--font-main);
}

/* ── Status Dots ─────────────────────────────── */
.status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
}
.status-dot.status-online { background: #22c55e; }
.status-dot.status-offline { background: #6b7280; }

/* ── Main Content ────────────────────────────── */
#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    position: relative;
}

/* ── Empty State ─────────────────────────────── */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; }
.empty-state p { font-size: 16px; }

/* ── Chat Header ─────────────────────────────── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    flex-shrink: 0;
}
.header-info {
    flex: 1;
    min-width: 0;
}
.header-info span { display: block; }
#room-header-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.online-count {
    font-size: 12px;
    color: var(--text-muted);
}
.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── Theme Switcher ──────────────────────────── */
.theme-switcher {
    display: flex;
    gap: 4px;
    margin-left: 8px;
}
.theme-btn {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: border-color var(--transition), transform 0.1s;
}
.theme-btn:hover { transform: scale(1.15); }
.theme-btn.active { border-color: var(--text-primary); }
.theme-btn.theme-purple { background: #8B5CF6; }
.theme-btn.theme-orange { background: #F97316; }
.theme-btn.theme-blue { background: #3B82F6; }
.theme-switcher-settings {
    margin-left: 0;
    gap: 10px;
    padding: 8px 0;
}
.theme-switcher-settings .theme-btn {
    width: 32px;
    height: 32px;
    border-width: 3px;
}
.theme-switcher-settings .theme-btn.active {
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--text-primary);
}

/* ── Messages Container ──────────────────────── */
.messages-container {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
}
.messages {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ── Message Groups ──────────────────────────── */
.message-group {
    display: flex;
    gap: 12px;
    padding: 8px 12px;
    border-radius: var(--radius);
    position: relative;
    animation: messageAppear 0.25s ease;
}
.message-group:hover { background: var(--bg-secondary); }
.msg-avatar-col { flex-shrink: 0; padding-top: 2px; }
.msg-body-col { flex: 1; min-width: 0; }
.msg-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}
.msg-username {
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
}
.msg-username:hover {
    text-decoration: underline;
}
.msg-time {
    font-size: 11px;
    color: var(--text-muted);
}
.msg-content {
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.msg-continuation {
    padding: 2px 12px 2px 60px;
    border-radius: var(--radius);
    position: relative;
    animation: messageAppear 0.25s ease;
}
.msg-continuation:hover { background: var(--bg-secondary); }
.msg-files { margin-top: 6px; }

/* ── Admin Badge ─────────────────────────────── */
.admin-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    color: #fbbf24;
    background: rgba(251, 191, 36, 0.12);
    padding: 1px 6px;
    border-radius: 4px;
    vertical-align: middle;
}
.admin-badge i { font-size: 9px; }

/* ── Typing Indicator ────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 16px 6px;
    font-size: 12px;
    color: var(--text-muted);
}
.typing-dots {
    display: flex;
    gap: 3px;
}
.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingDot 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ── New Message Button ──────────────────────── */
.new-msg-btn {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    z-index: 10;
    animation: bounce 0.4s ease;
    box-shadow: var(--shadow);
}

/* ── Input Bar ───────────────────────────────── */
.input-bar {
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    padding-bottom: env(safe-area-inset-bottom);
    position: relative;
}
.input-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px 12px;
}
.msg-input {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-main);
    padding: 10px 14px;
    resize: none;
    outline: none;
    max-height: 150px;
    line-height: 1.4;
    transition: border-color var(--transition);
}
.msg-input:focus { border-color: var(--accent); }

/* ── Formatting Toolbar ─────────────────────── */
.fmt-toolbar {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 4px;
    display: flex;
    gap: 2px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    animation: fmtFadeIn 0.15s ease;
}
@keyframes fmtFadeIn {
    from { opacity: 0; transform: translateX(-50%) translateY(4px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.fmt-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    transition: all 0.15s ease;
}
.fmt-btn:hover {
    background: var(--accent-dim);
    color: var(--accent);
}

.btn-send {
    color: var(--accent);
    font-size: 18px;
}
.btn-send.disabled { opacity: 0.4; pointer-events: none; }

/* ── File Preview Bar ────────────────────────── */
.file-preview-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    max-height: 120px;
    overflow-y: auto;
}
.file-preview-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    font-size: 12px;
    position: relative;
    animation: filePreviewIn 0.2s ease;
}
.file-preview-name {
    max-width: 120px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.remove-file {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 16px;
    transition: color var(--transition);
}
.remove-file:hover { color: #f87171; }
.file-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: var(--accent);
    border-radius: 0 0 var(--radius) var(--radius);
    transition: width 0.15s ease-out;
}

/* ── Members Panel ───────────────────────────── */
.members-panel {
    width: 0;
    overflow: hidden;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: width 0.25s ease;
    flex-shrink: 0;
}
.members-panel.open {
    width: 240px;
}
.members-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}
.members-panel-title {
    font-size: 14px;
    font-weight: 700;
}
.members-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    border-radius: var(--radius);
    transition: background var(--transition);
}
.member-item:hover { background: var(--bg-tertiary); }
.member-info {
    flex: 1;
    min-width: 0;
}
.member-name {
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}
.member-status {
    font-size: 11px;
    color: var(--text-muted);
}

/* ── Drag Overlay ────────────────────────────── */
.drag-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 14, 23, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    animation: dragOverlayIn 0.2s ease;
}
.drag-overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--accent);
    font-size: 18px;
    font-weight: 600;
}
.drag-overlay-icon { font-size: 48px; }

/* ── Modals ──────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
    /* Safe area on all sides so content never lands under notch/home indicator */
    padding-top: max(16px, var(--sat));
    padding-bottom: max(16px, var(--sab));
    padding-left: max(16px, var(--sal));
    padding-right: max(16px, var(--sar));
}
.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
    box-shadow: var(--shadow);
    animation: modalOpen 0.2s ease;
}
.modal-lg { max-width: 640px; }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.modal-header h2 {
    font-size: 18px;
    font-weight: 700;
}
.btn-close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition);
}
.btn-close-modal:hover { color: var(--text-primary); }

/* ── Invite Body ─────────────────────────────── */
.invite-body {
    display: flex;
    gap: 8px;
}
.invite-link-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
}
.invite-body .btn-primary { width: auto; }

/* ── Lightbox ────────────────────────────────── */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    cursor: pointer;
}
.lightbox img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius);
}
.lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(0,0,0,0.5);
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: var(--radius);
}

/* ── Toast ────────────────────────────────────── */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 10px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-primary);
    box-shadow: var(--shadow);
    animation: toastSlideIn 0.3s ease;
    max-width: 320px;
}
.toast.error { border-color: #f87171; color: #f87171; }
.toast.removing { animation: toastSlideOut 0.3s ease forwards; }

/* ── Upload Progress Overlay ─────────────────── */
.upload-progress-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
}
.upload-progress-bar {
    width: 100%;
    height: 5px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
}
.upload-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.15s ease-out;
    box-shadow: 0 0 8px var(--accent-dim);
}
.upload-progress-text {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    font-family: var(--font-main);
}

/* ── Animations ──────────────────────────────── */
@keyframes messageAppear {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes toastSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes toastSlideOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(40px); }
}
@keyframes modalOpen {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
@keyframes bounce {
    0%, 100% { transform: translateX(-50%) translateY(0); }
    50% { transform: translateX(-50%) translateY(-6px); }
}
@keyframes typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}
@keyframes dragOverlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes emojiSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes filePreviewIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* ── Mobile Only ─────────────────────────────── */
.mobile-only { display: none; }

/* ── Sidebar Backdrop ────────────────────────── */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
}
.sidebar-backdrop.active { display: block; }

/* ── Mobile Responsive ───────────────────────── */
@media (max-width: 768px) {
    .mobile-only { display: flex; }
    #sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        bottom: 0;
        width: 300px;
        min-width: 300px;
        z-index: 50;
        transition: left 0.25s ease;
        padding-top: var(--sat);
    }
    #sidebar.open { left: 0; }
    .members-panel {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 50;
        padding-top: var(--sat);
    }
    .members-panel.open { width: 260px; }
    .theme-switcher { display: none; }
    .theme-switcher-settings { display: flex !important; }
    .msg-actions.touch-visible { opacity: 1 !important; }

    /* Auth screen */
    .auth-container {
        max-width: 100%;
        margin: 0 16px;
        padding: 32px 20px;
    }

    /* Chat header compact */
    .chat-header {
        padding: 8px 10px;
        gap: 8px;
    }
    .header-actions { gap: 0; }
    .header-actions .btn-icon {
        padding: 4px;
        font-size: 14px;
    }
    #room-header-name { font-size: 14px; }
    .online-count { font-size: 11px; }

    /* Messages */
    .messages-container { padding: 8px; }
    .message-group {
        gap: 8px;
        padding: 6px 8px;
    }
    .msg-continuation { padding: 2px 8px 2px 48px; }
    .msg-content { font-size: 13px; }

    /* Input bar */
    .input-row { padding: 8px 8px; gap: 4px; }
    .msg-input {
        font-size: 16px; /* prevents iOS zoom on focus */
        padding: 8px 10px;
    }

    /* Modals fullscreen on mobile — use flex column for proper layout */
    .modal {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
    .modal-content {
        max-width: 100%;
        max-height: 100%;
        width: 100%;
        height: 100%;
        border-radius: 0;
        border: none;
        display: flex;
        flex-direction: column;
        padding: 0;
        /* Safe area padding inside the modal */
        padding-top: var(--sat);
        padding-bottom: var(--sab);
        padding-left: var(--sal);
        padding-right: var(--sar);
        -webkit-overflow-scrolling: touch;
    }
    .modal-content.modal-lg { max-width: 100%; }
    .modal-fullscreen { width: 100%; max-width: 100%; height: 100%; }

    /* Header: fixed at top, never scrolls under notch */
    .modal-header {
        flex-shrink: 0;
        margin-bottom: 0;
        padding: 12px 16px;
        border-bottom: 1px solid var(--border-color);
    }
    .modal-header h2 { font-size: 16px; }

    /* Scrollable body area fills remaining space */
    .modal-content > form,
    .modal-content > .admin-panel-body,
    .modal-content > .shop-items,
    .modal-content > div:not(.modal-header) {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: 12px 16px 24px;
    }
    /* Don't double-pad the header */
    .modal-content > .modal-header { overflow: visible; padding-bottom: 12px; }

    /* Compact form elements */
    .modal-content .form-group { margin-bottom: 12px; }
    .modal-content .form-group label { font-size: 11px; margin-bottom: 4px; }
    .modal-content hr { margin: 8px 0; }
    .modal-content .custom-color-picker {
        gap: 4px;
        padding: 6px;
    }
    .modal-content .color-swatch {
        width: 22px;
        height: 22px;
    }
    .modal-content textarea { font-size: 14px; }
    .modal-content input[type="text"],
    .modal-content input[type="password"],
    .modal-content input[type="number"],
    .modal-content select {
        font-size: 16px; /* prevent iOS zoom */
        padding: 8px 10px;
    }

    /* Admin modal compact */
    .admin-modal .admin-subsection { margin-bottom: 12px; }
    .admin-modal .admin-label { font-size: 12px; }

    /* Emoji picker */
    .emoji-picker {
        left: 0;
        right: 0;
        bottom: 48px;
        width: 100%;
        max-height: 300px;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    }

    /* File attachments */
    .image-att img { max-width: 100%; }
    .video-att video { max-width: 100%; }
    .file-attachment { max-width: 100%; }
    .link-preview-card { max-width: 100%; }

    /* Toast */
    .toast-container {
        left: 16px;
        right: 16px;
        top: auto;
        bottom: 80px;
    }
    .toast { max-width: 100%; }

    /* Music main content on mobile */
    #music-main {
        position: fixed;
        inset: 0;
        z-index: 40;
    }
    .music-content-header {
        padding: 10px 12px;
        gap: 8px;
    }
    .music-content-header h2 { font-size: 15px; }
    .music-content-body { padding: 12px; }

    /* Sidebar footer compact */
    .sidebar-footer { padding: 8px 10px; }
    .sidebar-user { gap: 6px; }
    .username-label { font-size: 12px; }
}

/* ── Loading Chat ────────────────────────────── */
.loading-chat {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}
.loading-chat a { color: var(--accent); }

/* ── Animations ──────────────────────────────────── */
@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
.msg { animation: msgSlideIn 0.2s ease-out; }

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}
.modal-content { animation: modalIn 0.2s ease-out; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.toast { animation: toastIn 0.3s ease-out; }

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
.messages { animation: fadeIn 0.15s ease; }

@keyframes slideRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}
.members-panel.open { animation: slideRight 0.25s ease-out; }

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}
.typing-indicator { animation: pulse 1.5s ease-in-out infinite; }

/* ═══════════════════════════════════════════════
   SETTINGS EXTRAS
   ═══════════════════════════════════════════════ */
.settings-banner-preview {
    margin-bottom: 8px;
}
.settings-banner-preview img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 8px;
}
.settings-lock-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}
.settings-roles-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0 12px;
}
.settings-role-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}
.settings-role-item .role-name-input {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 4px 8px;
    color: var(--text-primary);
    font-size: 13px;
}
.settings-modal textarea {
    width: 100%;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
    color: var(--text-primary);
    font-family: var(--font-main);
    font-size: 14px;
    resize: vertical;
}
.settings-modal textarea:focus {
    border-color: var(--accent);
    outline: none;
}

/* ═══════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION
   ═══════════════════════════════════════════════ */
.mobile-bottom-nav {
    display: none; /* Hidden on desktop */
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 60;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        padding: 4px 0;
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }
    .mobile-bottom-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        padding: 6px 0;
        border: none;
        background: none;
        color: var(--text-muted);
        font-size: 10px;
        font-weight: 500;
        font-family: var(--font-main);
        cursor: pointer;
        transition: color 0.2s;
    }
    .mobile-bottom-tab i {
        font-size: 18px;
    }
    .mobile-bottom-tab.active {
        color: var(--accent);
    }
    .mobile-bottom-tab:hover {
        color: var(--text-secondary);
    }

    /* Add bottom padding to main areas so content isn't hidden behind bottom nav */
    #main-content,
    #music-main,
    #event-main,
    #dm-main {
        padding-bottom: 56px;
    }

    /* Event and DM should fill full screen on mobile */
    #event-main,
    #dm-main {
        position: fixed;
        inset: 0;
        z-index: 40;
        padding-top: var(--sat);
        padding-bottom: 56px;
    }

    /* When audio player is active, increase bottom padding on all main areas */
    body.player-active #main-content,
    body.player-active #music-main,
    body.player-active #event-main,
    body.player-active #dm-main {
        padding-bottom: 140px;
    }

    /* Toast should appear above bottom nav (and player if active) */
    .toast-container {
        bottom: 72px;
    }
    body.player-active .toast-container {
        bottom: 150px;
    }
}

/* ── Form select ───────────────────────── */
.form-select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
}
.form-select:focus {
    border-color: var(--accent);
}
.form-group input[type="number"] {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    outline: none;
}
.form-group input[type="number"]:focus {
    border-color: var(--accent);
}

/* ── Small button variants ─────────────── */
.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
    border-radius: 6px;
}
.btn-danger {
    background: #EF4444;
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    transition: background 0.2s;
}
.btn-danger:hover {
    background: #DC2626;
}

/* ── Admin PXP Panel ───────────────────── */
.admin-pxp-row {
    display: flex;
    gap: 8px;
}
.admin-pxp-row input {
    flex: 1;
}
.admin-pxp-btns {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.admin-pxp-result {
    margin-top: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
}
.admin-pxp-result.success {
    background: rgba(34, 197, 94, 0.15);
    color: #22C55E;
}
.admin-pxp-result.error {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}


/* ═══════════════════════════════════════════════════════════════
   File Preview Enhancements
   ═══════════════════════════════════════════════════════════════ */

.file-preview-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
    flex-shrink: 0;
}

.file-preview-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    border-radius: 8px;
    border: 1px solid var(--border);
    position: relative;
    min-width: 0;
}

.file-preview-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
    font-size: 13px;
}

.file-preview-add-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border: 2px dashed var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.file-preview-add-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

#file-preview-bar {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    max-height: 140px;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════
   Color Dropdown Popup
   ═══════════════════════════════════════════════════════════════ */

.color-dropdown-popup {
    position: absolute;
    bottom: 100%;
    left: 0;
    z-index: 1000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 240px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: fadeIn 0.15s;
}

.icon-dropdown-popup {
    position: absolute;
    bottom: 100%;
    right: 0;
    z-index: 1000;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-width: 280px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: fadeIn 0.15s;
}

.icon-dropdown-popup .role-icon-option {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text);
    transition: all 0.15s;
}

.icon-dropdown-popup .role-icon-option:hover {
    background: var(--accent);
    color: #fff;
}

.icon-dropdown-popup .role-icon-option.active {
    background: var(--accent);
    color: #fff;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════════════
   Admin Panel Styles
   ═══════════════════════════════════════════════════════════════ */

/* Admin panel open button in settings */
.btn-admin-open {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent), #000 20%));
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-admin-open:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}
.btn-admin-open i {
    font-size: 16px;
}

/* Admin modal body */
.admin-modal {
    max-width: 600px;
}
.admin-panel-body {
    padding: 16px;
    max-height: 70vh;
    overflow-y: auto;
}

.admin-subsection {
    margin: 12px 0;
    padding: 12px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border);
}

.admin-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    display: block;
}

.admin-users-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
}

.admin-user-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-primary);
    border-radius: 8px;
    font-size: 13px;
}

.admin-user-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-user-balance {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

.admin-colors-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.admin-color-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    background: var(--bg-primary);
    border-radius: 6px;
    font-size: 11px;
    font-family: var(--font-mono);
}

.admin-color-item .color-swatch {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    flex-shrink: 0;
}

.admin-color-hex {
    color: var(--text-muted);
}

.admin-remove-color-btn {
    color: var(--text-muted) !important;
}

.admin-remove-color-btn:hover {
    color: #f87171 !important;
}

.admin-add-color-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    background: var(--bg-primary);
    border: 2px dashed var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s;
}

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

/* ═══════════════════════════════════════════════════════════════
   Settings Role Items
   ═══════════════════════════════════════════════════════════════ */

.settings-role-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 6px;
}

.settings-role-item .role-name-input {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 8px;
    color: var(--text);
    font-size: 13px;
}

.role-icon-dot {
    border-radius: 6px;
    transition: background 0.15s;
}

.role-icon-dot:hover {
    background: var(--bg-secondary);
}

/* Admin hex picker */
.admin-hex-picker input[type="color"] {
    border: 2px solid var(--border);
    padding: 2px;
}

/* ── Reaction Users Popup ── */
.reaction-users-popup {
    position: fixed;
    z-index: 9999;
    background: var(--bg-secondary, #1e1e2e);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 10px;
    padding: 8px 12px;
    min-width: 140px;
    max-width: 220px;
    max-height: 200px;
    overflow-y: auto;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: fadeInUp 0.15s ease;
}
.reaction-users-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #fff);
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.reaction-user-item {
    font-size: 13px;
    color: var(--text-secondary, #ccc);
    padding: 2px 0;
}
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
