:root {
    --accent: #1cce5e;
    --accent-hover: #17b350;
    --accent-dim: rgba(28, 206, 94, 0.12);
    --danger: #ff4757;
    --warning: #ffab00;
    --msg-font-size: 15px;

    /* Default (Dark) Theme */
    --bg: #0f1729;
    --surface: rgba(255,255,255,0.04);
    --surface-hover: rgba(255,255,255,0.07);
    --border: rgba(255,255,255,0.08);
    --text: #f1f5f9;
    --text-dim: #64748b;
    --input-bg: rgba(0,0,0,0.25);
    --input-border: rgba(255,255,255,0.1);
    --msg-in: rgba(255,255,255,0.06);
    --msg-out: rgba(28, 206, 94, 0.18);
    --msg-out-border: rgba(28, 206, 94, 0.35);
    --scrollbar: rgba(255,255,255,0.08);
    --panel-msg-area: #0f1729;
}

[data-theme="light"] {
    --accent: #16984b;
    --accent-hover: #117d3d;
    --accent-dim: rgba(22, 152, 75, 0.14);
    --bg: #dcecf7;
    --surface: rgba(255,255,255,0.75);
    --surface-hover: rgba(255,255,255,0.9);
    --border: rgba(0,0,0,0.07);
    --text: #0f1729;
    --text-dim: #64748b;
    --input-bg: rgba(255,255,255,0.9);
    --input-border: rgba(0,0,0,0.12);
    --msg-in: rgba(0,0,0,0.05);
    --msg-out: rgba(28, 206, 94, 0.15);
    --msg-out-border: rgba(28, 206, 94, 0.3);
    --scrollbar: rgba(0,0,0,0.08);
    --panel-msg-area: #f5faff;
}

/* Prevent icon text flash */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-size: 22px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    visibility: hidden;
}
.fonts-loaded .material-symbols-outlined {
    visibility: visible;
}

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

html, body {
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

#app {
    height: 100vh;
    height: 100dvh;
}

/* AUTH SCREEN */
body::before, body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    z-index: -1;
    filter: blur(120px);
    opacity: 0.1;
    pointer-events: none;
}
body::before {
    width: 500px; height: 500px;
    background: var(--accent);
    top: -100px; left: -150px;
}
body::after {
    width: 400px; height: 400px;
    background: #3b82f6;
    bottom: -100px; right: -100px;
}

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

.auth-card {
    width: 100%;
    max-width: 440px;
    padding: 44px 36px;
}

.glass-panel {
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.hidden { display: none !important; }

.header { text-align: center; margin-bottom: 28px; }

.logo-wrapper {
    width: 68px; height: 68px;
    background: var(--accent-dim);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 16px;
    color: var(--accent);
}
.logo-icon { font-size: 32px !important; }
.success-logo { background: rgba(28,206,94,0.2); }

.header h1 { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.subtitle { color: var(--text-dim); font-size: 14px; }

.input-group { position: relative; margin-bottom: 14px; }
.input-group .material-symbols-outlined {
    position: absolute;
    left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--text-dim); font-size: 20px !important;
}

input, textarea {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 13px 14px 13px 44px;
    color: var(--text);
    font-family: inherit;
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    resize: none;
}
input:focus, textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(28,206,94,0.1);
}

button { cursor: pointer; border: none; font-family: inherit; }

.primary-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 13px;
    background: var(--accent);
    color: #fff;
    border-radius: 12px;
    font-size: 15px; font-weight: 600;
    margin-top: 20px;
    transition: background 0.2s, transform 0.1s;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:active { transform: scale(0.99); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.danger-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 12px;
    background: rgba(255, 71, 87, 0.1);
    color: var(--danger);
    border: 1px solid rgba(255, 71, 87, 0.2);
    border-radius: 12px;
    font-size: 14px; font-weight: 600;
    transition: all 0.2s;
}
.danger-btn:hover { background: var(--danger); color: #fff; }

[data-theme="light"] .danger-btn {
    background: #ff4759;
    color: #fffaff;
    border: 1px solid #ff4759;
}
[data-theme="light"] .danger-btn:hover {
    background: #fffaff;
    color: #ff4759;
    border-color: #ff4759;
}

.inline-btn { width: auto; padding: 11px 20px; margin-top: 0; }

.error-box {
    display: flex; align-items: center; gap: 8px;
    background: rgba(255,71,87,0.1);
    color: var(--danger);
    border-radius: 10px; padding: 10px 14px;
    font-size: 14px; margin-bottom: 14px;
}

/* APP LAYOUT */
.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

/* SIDEBAR */
.sidebar {
    width: 260px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    backdrop-filter: blur(20px);
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.collapsed {
    width: 72px;
    min-width: 72px;
}

.sidebar.collapsed .sidebar-title,
.sidebar.collapsed .admin-chip,
.sidebar.collapsed .sidebar-nav .nav-item span:not(.material-symbols-outlined),
.sidebar.collapsed .status-dot {
    display: none !important;
}

.sidebar.collapsed .nav-item {
    justify-content: center;
    padding: 12px 0 !important;
    width: 100% !important;
    font-size: 0 !important;
    gap: 0 !important;
}

.sidebar.collapsed .nav-item .material-symbols-outlined {
    font-size: 24px !important;
    margin: 0 !important;
}

.sidebar.collapsed .sidebar-header {
    justify-content: center;
    padding: 22px 0 16px;
}
.sidebar.collapsed .collapse-btn { transform: rotate(180deg); }
.sidebar.collapsed .logo-icon-sm { display: none !important; margin: 0; }




.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 22px 20px 16px;
    border-bottom: 1px solid var(--border);
}
.logo-icon-sm { color: var(--accent); font-size: 22px !important; }
.sidebar-title { font-weight: 600; font-size: 16px; }

.sidebar-nav { padding: 12px 10px; flex: 1; }

.nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    background: transparent;
    color: var(--text-dim);
    font-size: 14px; font-weight: 500;
    margin-bottom: 4px;
    transition: all 0.2s;
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }

.sidebar-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
}

.admin-chip {
    display: flex; align-items: center; gap: 10px;
    min-width: 0;
}
.admin-chip strong { display: block; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-chip small { color: var(--text-dim); font-size: 12px; }

/* MAIN CONTENT */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: var(--bg);
}

.panel {
    padding: 36px 40px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
    overflow-x: hidden;
    overflow-y: auto; height: 100%;
}

.panel-header { margin-bottom: 24px; }
.panel-header h2 { font-size: 24px; font-weight: 600; margin-bottom: 8px; }
.panel-header p { color: var(--text-dim); font-size: 15px; }

/* Fixed chat panel flex structure */
#panelChat {
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 0;
    max-width: none;
    margin: 0;
}

#chatPanel {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* USERS LIST */
.users-list { display: grid; gap: 10px; }
.user-row {
    display: flex; align-items: center; gap: 14px;
    padding: 16px 20px;
    min-height: 84px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.2s;
}
.user-row:hover { border-color: var(--accent); background: var(--surface-hover); transform: translateY(-1px); }
.user-row-avatar {
    width: 46px; height: 46px;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px;
    flex-shrink: 0;
}
.user-row-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.user-row-name { font-weight: 600; font-size: 16px; display: block; margin-bottom: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row-role { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; }
.user-row-lastmsg { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.user-row-note { font-size: 12px; color: var(--accent); display: flex; align-items: center; gap: 6px; margin-top: 6px; overflow: hidden; }
.user-row-note .material-symbols-outlined { font-size: 15px; flex: 0 0 auto; }
.user-row-note-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.user-row-actions {
    display: flex; gap: 8px; align-items: center;
}
.user-action-btn {
    width: 36px; height: 36px;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    display: flex; align-items: center; justify-content: center;
    transition: 0.2s; cursor: pointer;
}
.user-action-btn:hover { background: var(--surface-hover); color: var(--text); border-color: var(--text-dim); }
.user-action-btn.del-btn:hover { background: rgba(255, 71, 87, 0.15); color: var(--danger); border-color: rgba(255, 71, 87, 0.3); }

/* CHAT AREA */
.chat-main {
    flex: 1;
    display: flex; flex-direction: column;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    background: var(--panel-msg-area);
}

.chat-topbar, .chat-topbar-admin {
    display: flex; align-items: center; gap: 14px;
    padding: 16px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    flex-shrink: 0;
}
.pinned-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 24px;
    background: rgba(76, 154, 255, 0.10);
    border-bottom: 1px solid rgba(76, 154, 255, 0.24);
    cursor: pointer;
}
.pinned-banner-copy {
    min-width: 0;
}
.pinned-banner-label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #4c9aff;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.pinned-banner-text {
    color: var(--text);
    font-size: 14px;
    line-height: 1.35;
    word-break: break-word;
}
.pinned-banner-icon {
    color: #4c9aff;
    flex-shrink: 0;
}

.contact-avatar {
    width: 44px; height: 44px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; color: #fff;
    flex-shrink: 0;
}
.contact-avatar-sm {
    width: 24px; height: 24px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; color: #fff;
    margin-right: 4px;
}

.messages-area {
    flex: 1; overflow-y: auto;
    min-height: 0;
    padding: 24px;
    display: flex; flex-direction: column; gap: 10px;
}
.messages-area::-webkit-scrollbar { width: 6px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

.messages-date-divider {
    text-align: center;
    margin: 20px auto;
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 12px;
    color: var(--text-dim);
    width: fit-content;
}

.msg-wrap { display: flex; flex-direction: column; max-width: 75%; }
.msg-wrap.incoming { align-self: flex-start; align-items: flex-start; }
.msg-wrap.outgoing { align-self: flex-end; align-items: flex-end; }
.msg-wrap.system-message { max-width: 100%; align-self: center; }
.msg-wrap.message-jump-highlight .msg-bubble {
    box-shadow: 0 0 0 2px rgba(255, 71, 87, 0.92), 0 0 28px rgba(255, 71, 87, 0.32);
}
.msg-wrap.message-pinned .msg-bubble {
    box-shadow: 0 0 0 2px rgba(76, 154, 255, 0.85), 0 0 22px rgba(76, 154, 255, 0.16);
}

.msg-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: var(--msg-font-size, 15px);
    line-height: 1.4;
    word-break: break-word;
}
.incoming .msg-bubble { background: var(--msg-in); border-bottom-left-radius: 4px; }
.outgoing .msg-bubble { background: var(--msg-out); border: 1px solid var(--msg-out-border); border-bottom-right-radius: 4px; cursor: context-menu; }
.msg-reply {
    margin-bottom: 10px;
    padding: 10px 12px;
    border-left: 3px solid var(--accent);
    border-radius: 12px;
    background: rgba(255,255,255,0.05);
    cursor: pointer;
}
.msg-reply-author {
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 4px;
}
.msg-reply-text {
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.35;
}

.msg-meta { display: flex; align-items: center; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.incoming .msg-meta { justify-content: flex-start; }
.outgoing .msg-meta { justify-content: flex-end; }
.msg-time { font-size: 11px; color: var(--text-dim); }
.msg-status-group { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.msg-status-separator { font-size: 11px; color: var(--text-dim); }
.typing-indicator {
    pointer-events: none;
}
.typing-bubble {
    display: inline-flex;
    align-items: center;
    min-width: 72px;
    padding: 14px 16px;
}
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.typing-dots span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-dim);
    opacity: 0.35;
    animation: typing-dot 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;
}

@keyframes typing-dot {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-2px);
    }
}
.msg-edited-status { font-size: 11px; color: var(--text-dim); }
.msg-read-status { font-size: 11px; color: var(--accent); font-weight: 600; }
.msg-sender { font-size: 12px; font-weight: 600; color: var(--accent); margin-bottom: 2px; }

.chat-input-bar {
    padding: 16px 24px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}
.chat-compose-row {
    width: 100%;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-compose-row > textarea {
    order: 2;
    flex: 1 1 auto;
    min-width: 0;
}
.chat-compose-row > .composer-actions {
    order: 3;
    display: contents;
}
.chat-compose-row .emoji-picker-wrap {
    order: 1;
    flex: 0 0 auto;
}
.chat-compose-row .attach-btn {
    order: 3;
}
.chat-compose-row .send-btn {
    order: 4;
}
.composer-actions {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.composer-context {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    border: 1px solid rgba(28, 206, 94, 0.28);
    background: rgba(28, 206, 94, 0.08);
}
.composer-context-copy {
    min-width: 0;
}
.composer-context-label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.composer-context-text {
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    word-break: break-word;
}
.composer-context-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    background: transparent;
    flex-shrink: 0;
}

.send-btn {
    width: 48px; height: 48px;
    min-width: 48px;
    flex: 0 0 48px;
    background: var(--accent); color: #fff;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.2s;
}
.send-btn.is-confirm { background: var(--accent-hover); }
.send-btn:hover:not(:disabled) { transform: scale(1.05); }
.send-btn:disabled { opacity: 0.3; }
.emoji-picker-wrap {
    position: relative;
}
.emoji-toggle-btn {
    width: 48px;
    height: 48px;
    min-width: 48px;
    flex: 0 0 48px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
}
.emoji-toggle-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.emoji-picker {
    position: absolute;
    left: 0;
    right: auto;
    bottom: calc(100% + 10px);
    width: 336px;
    max-height: 380px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    border-radius: 18px;
    border: 1px solid rgba(15, 23, 41, 0.12);
    background: rgba(255, 255, 255, 0.98);
    color: #0f1729;
    box-shadow: 0 20px 40px rgba(15, 23, 41, 0.18);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overscroll-behavior: contain;
    touch-action: pan-y;
    user-select: none;
    -webkit-user-select: none;
    z-index: 20;
}
.emoji-picker::-webkit-scrollbar { width: 8px; }
.emoji-picker::-webkit-scrollbar-thumb { background: rgba(15, 23, 41, 0.16); border-radius: 999px; }
.emoji-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.emoji-section + .emoji-section {
    padding-top: 12px;
    border-top: 1px solid rgba(15, 23, 41, 0.08);
}
.emoji-section-title {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
}
.emoji-option {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 12px;
    background: transparent;
    border: 1px solid rgba(15, 23, 41, 0.05);
    color: #0f1729;
    font-size: 22px;
    line-height: 1;
    touch-action: manipulation;
}
.emoji-option:hover {
    background: rgba(15, 23, 41, 0.06);
    border-color: rgba(15, 23, 41, 0.12);
}
.emoji-option:focus-visible {
    outline: none;
    border-color: rgba(28, 206, 94, 0.55);
    box-shadow: 0 0 0 3px rgba(28, 206, 94, 0.16);
}

/* SETTINGS */
.settings-list {
    display: flex; flex-direction: column; gap: 16px; margin-top: 20px;
    -ms-overflow-style: none; scrollbar-width: none;
    overflow-y: auto; overflow-x: hidden;
    padding-bottom: 30px; /* buffer to avoid clipping */
}
.settings-list::-webkit-scrollbar { display: none; }
select.secret-phrase-input {
    background: var(--surface); color: var(--text);
}
select.secret-phrase-input option {
    background: var(--surface); color: var(--text);
}
.settings-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}
.settings-item-info { display: flex; align-items: center; gap: 14px; }
.settings-item-info .material-symbols-outlined { color: var(--text-dim); }
.settings-item-info strong { display: block; font-size: 16px; }
.settings-item-info small { color: var(--text-dim); font-size: 13px; }

.settings-divider { height: 1px; background: var(--border); margin: 8px 0; }

.theme-mode-control {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    border-radius: 16px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    flex-shrink: 0;
    max-width: 100%;
    box-sizing: border-box;
}
.theme-mode-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
}
.theme-mode-btn .material-symbols-outlined {
    color: inherit;
}
.theme-mode-btn:hover {
    color: var(--text);
    background: var(--surface-hover);
}
.theme-mode-btn.is-active {
    color: var(--text);
    background: var(--surface);
    border-color: rgba(28, 206, 94, 0.34);
    box-shadow: 0 0 0 3px rgba(28, 206, 94, 0.12);
}
.theme-mode-dot {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: currentColor;
}

.secret-field-row {
    width: 100%;
    display: flex;
    align-items: stretch;
    gap: 8px;
}
.secret-phrase-input {
    padding: 13px 16px;
    font-family: inherit;
    letter-spacing: 0.01em;
}
.secret-field-btn {
    width: 48px;
    min-width: 48px;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s, color 0.2s, opacity 0.2s;
}
.secret-field-btn:hover:not(:disabled) {
    background: var(--surface-hover);
    border-color: var(--accent);
    color: var(--accent);
}
.secret-field-btn:disabled,
.secret-field-btn.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.password-recovery-actions {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
}
.recovery-trigger-btn {
    width: 100%;
    justify-content: center;
}
.password-recovery-hint {
    color: var(--text-dim);
    font-size: 13px;
}
.password-recovery-hint.is-error {
    color: var(--warning);
}

/* TOGGLE SWITCH */
.toggle {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 26px;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border);
    transition: .4s; border-radius: 34px;
}
.toggle-slider:before {
    position: absolute; content: "";
    height: 18px; width: 18px;
    left: 4px; bottom: 4px;
    background-color: white;
    transition: .4s; border-radius: 50%;
}
input:checked + .toggle-slider { background-color: var(--accent); }
input:checked + .toggle-slider:before { transform: translateX(24px); }

/* MISC */
.copy-group { display: flex; gap: 8px; align-items: center; }
.copy-group input { padding-left: 14px; }
.copy-group button {
    padding: 0 16px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px;
    color: var(--text);
}
.copy-group button:hover { background: var(--accent); color: #fff; }
.invite-box { margin-top: 18px; }
.invite-box label { display: block; margin-bottom: 10px; }
.invite-history-card {
    margin-top: 22px;
    padding: 20px;
    border-radius: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
}
.invite-history-header {
    margin-bottom: 14px;
}
.invite-history-header h3 {
    margin: 0 0 6px;
    font-size: 18px;
}
.invite-history-header p {
    margin: 0;
    color: var(--text-dim);
    font-size: 14px;
}
.invite-table-wrap {
    width: 100%;
    overflow-x: auto;
}
.invite-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}
.invite-table th,
.invite-table td {
    padding: 14px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.invite-table th {
    color: var(--text-dim);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.invite-link-cell {
    min-width: 0;
}
.invite-link-anchor {
    display: block;
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
}
.invite-link-anchor:hover {
    text-decoration: underline;
}
.invite-link-meta {
    margin-top: 6px;
    color: var(--text-dim);
    font-size: 12px;
}
.invite-status-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid transparent;
}
.invite-status-chip .material-symbols-outlined {
    font-size: 18px;
}
.invite-status-active {
    background: rgba(36, 169, 110, 0.12);
    color: #24a96e;
    border-color: rgba(36, 169, 110, 0.2);
}
.invite-status-used {
    background: rgba(231, 76, 60, 0.12);
    color: #e74c3c;
    border-color: rgba(231, 76, 60, 0.2);
}
.invite-status-revoked {
    background: rgba(127, 140, 141, 0.14);
    color: #95a5a6;
    border-color: rgba(127, 140, 141, 0.2);
}
.invite-status-meta {
    margin-top: 8px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.4;
}
.invite-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.invite-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--panel-msg-area);
    color: var(--text);
    cursor: pointer;
    transition: 0.2s ease;
}
.invite-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.invite-action-btn.is-danger:hover {
    border-color: rgba(231, 76, 60, 0.4);
    color: var(--danger);
}
.invite-table-empty {
    text-align: center !important;
    color: var(--text-dim);
    padding: 28px 12px !important;
}

.seed-copy-group {
    align-items: stretch;
    margin-bottom: 20px;
}
.seed-copy-group .seed-phrase-box { margin-bottom: 0; }
.seed-copy-group button {
    min-width: 56px;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
}

.seed-phrase-box {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 20px; border-radius: 16px;
    font-size: 20px; font-weight: 700;
    border: 2px dashed var(--accent);
    margin-bottom: 20px;
    flex: 1;
}

.warning-box {
    background: rgba(255, 171, 0, 0.1);
    color: var(--warning);
    padding: 16px; border-radius: 12px;
    display: flex; gap: 12px; font-size: 14px;
    margin-bottom: 24px; text-align: left;
}
[data-theme="light"] .warning-box {
    background: rgba(184, 120, 0, 0.18);
    color: #8a5a00;
}

.settings-item.vertical-settings {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
}

.volume-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    outline: none;
    padding: 0;
    margin: 0;
}
.volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent);
    cursor: pointer;
    border-radius: 50%;
    border: 3px solid var(--bg);
    box-shadow: 0 0 10px rgba(0,0,0,0.2);
}

.chat-header-info { padding-left: 10px; flex: 1; min-width: 0; }
.chat-header-name-wrapper { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-refresh-btn {
    order: -1;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.chat-refresh-btn .material-symbols-outlined {
    transition: transform 0.2s ease;
}
.chat-refresh-btn:hover {
    color: var(--text-dim);
    border-color: var(--border);
}
.chat-refresh-btn.is-spinning .material-symbols-outlined {
    animation: chat-refresh-spin 0.55s ease;
}
@keyframes chat-refresh-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
.msk-clock { font-size: 11px; color: var(--text-dim); font-weight: 500; display: inline-flex; align-items: center; white-space: nowrap; }
.chat-header-status { font-size: 11px; color: var(--text-dim); display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.chat-header-status:empty { display: none; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.status-dot.online { background: #2ecc71; box-shadow: 0 0 8px rgba(46, 204, 113, 0.4); }
.status-dot.offline { background: #95a5a6; }

/* Slider with small/large labels (font size) */
.slider-with-labels {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
}
.slider-label-sm {
    font-size: 12px;
    color: var(--text-dim);
    flex-shrink: 0;
    font-weight: 600;
    min-width: 14px;
    text-align: center;
}
.slider-label-lg {
    font-size: 18px;
    color: var(--text-dim);
    flex-shrink: 0;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* Settings item wrapping allowed for small controls */
.settings-item {
    flex-wrap: wrap;
}
.settings-item-info {
    min-width: 0;
    flex: 1;
}

/* Debug Log Area */
.debug-log-container {
    position: fixed; bottom: 0; left: 0; width: 100%; height: 300px;
    background: #000; color: #0f0; z-index: 10000; font-family: monospace;
    font-size: 11px; display: flex; flex-direction: column; opacity: 0.9;
    border-top: 2px solid #333;
}
.debug-header { padding: 8px 12px; background: #222; display: flex; justify-content: space-between; border-bottom: 1px solid #333; }
#debugContent { flex: 1; padding: 10px; overflow-y: auto; white-space: pre-wrap; }
.debug-toggle-btn { margin: 10px; padding: 6px 12px; font-size: 11px; opacity: 0.5; cursor: pointer; background: var(--bg); color: var(--text-dim); border: 1px solid var(--border); border-radius: 4px; transition: 0.2s; }
.debug-toggle-btn:hover { opacity: 1; color: var(--text); border-color: var(--accent); }

.chat-header-actions { display: flex; gap: 8px; margin-left: auto; }

.loading-hint { text-align: center; color: var(--text-dim); padding: 40px; }
.icon-btn { background: transparent; color: var(--text-dim); }
.icon-btn:disabled,
.call-action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.call-action-btn {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(28, 206, 94, 0.22);
    transition: transform 0.15s ease, background 0.2s ease, border-color 0.2s ease;
}
.call-action-btn:hover {
    background: rgba(28, 206, 94, 0.2);
    border-color: rgba(28, 206, 94, 0.4);
}
.call-action-btn:active {
    transform: scale(0.97);
}
.call-action-btn .material-symbols-outlined {
    font-size: 21px !important;
}
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(4, 10, 20, 0.7);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
.call-card {
    width: min(100%, 420px);
    padding: 28px 24px 24px;
    text-align: center;
}
.call-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    margin-bottom: 22px;
    border-radius: 999px;
    background: rgba(28, 206, 94, 0.12);
    color: var(--accent);
    font-size: 13px;
    font-weight: 600;
}
.call-avatar {
    width: 88px;
    height: 88px;
    margin: 0 auto 18px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(28, 206, 94, 0.9), rgba(17, 125, 61, 0.95));
    color: #fff;
    font-size: 34px;
    font-weight: 700;
    box-shadow: 0 18px 40px rgba(28, 206, 94, 0.22);
}
.call-card h2 {
    font-size: 24px;
    margin-bottom: 10px;
}
.call-status-text {
    min-height: 24px;
    color: var(--text-dim);
    font-size: 15px;
    line-height: 1.45;
}
.call-timer {
    margin-top: 14px;
    color: var(--text);
    font-size: 28px;
    font-weight: 700;
    letter-spacing: 0.04em;
}
.call-quality-panel {
    margin-top: 18px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    text-align: left;
}
[data-theme="light"] .call-overlay {
    background: rgba(244, 250, 255, 0.92);
}
[data-theme="light"] .call-card {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 24px 64px rgba(44, 72, 110, 0.14);
}
[data-theme="light"] .call-quality-panel {
    background: rgba(248, 251, 255, 0.98);
    border-color: rgba(15, 23, 41, 0.08);
}
[data-theme="light"] .call-toast {
    background: rgba(255, 255, 255, 0.96);
    color: var(--text);
    border: 1px solid rgba(15, 23, 41, 0.08);
}
[data-theme="light"] .call-toast.toast-success {
    background: rgba(18, 142, 84, 0.96);
    color: #fff;
    border-color: transparent;
}
[data-theme="light"] .call-toast.toast-offline {
    background: rgba(196, 67, 83, 0.96);
    color: #fff;
    border-color: transparent;
}
.call-quality-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.call-quality-summary-label {
    color: var(--text-dim);
    font-size: 13px;
}
.call-quality-current {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}
.call-quality-current-btn {
    padding: 0;
    border: 0;
    background: transparent;
    font: inherit;
    line-height: inherit;
}
.call-quality-current-btn.is-clickable {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}
.call-quality-current-btn.is-clickable:hover {
    color: var(--accent);
}
.call-quality-mode-pill {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(28, 206, 94, 0.14);
    color: var(--accent);
    font-size: 12px;
    font-weight: 700;
}
.call-quality-profiles {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.call-quality-profiles.hidden {
    display: none !important;
}
.call-quality-profile-btn {
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.call-quality-profile-btn:hover {
    border-color: rgba(28, 206, 94, 0.32);
    color: var(--text);
}
.call-quality-profile-btn:active {
    transform: scale(0.98);
}
.call-quality-profile-btn.is-active {
    background: rgba(28, 206, 94, 0.14);
    border-color: rgba(28, 206, 94, 0.45);
    color: var(--accent);
}
.call-quality-profile-btn.is-inspecting:not(.is-active) {
    border-color: rgba(255, 255, 255, 0.26);
    color: var(--text);
}
.call-quality-profile-btn.is-readonly {
    opacity: 0.7;
}
.call-quality-details {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}
.call-quality-details.hidden {
    display: none !important;
}
.call-quality-details-title {
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
}
.call-quality-metrics {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin-top: 10px;
}
.call-quality-metrics span {
    font-size: 12px;
    color: var(--text-dim);
}
.call-quality-details-hint {
    margin-top: 10px;
    color: var(--text-dim);
    font-size: 12px;
    line-height: 1.45;
}
.call-actions {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 26px;
}
.call-control-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
    transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.call-control-btn:active {
    transform: scale(0.97);
}
.call-control-btn .material-symbols-outlined {
    font-size: 28px !important;
}
.call-accept-btn {
    background: linear-gradient(135deg, #1cce5e, #16984b);
}
.call-decline-btn {
    background: linear-gradient(135deg, #ff5b6a, #e63d4c);
}
.call-neutral-btn {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text);
    border: 1px solid var(--border);
}
.call-neutral-btn.is-muted {
    background: rgba(255, 171, 0, 0.18);
    color: #ffbf33;
    border-color: rgba(255, 171, 0, 0.3);
}
.call-toast {
    position: fixed;
    left: 50%;
    bottom: 28px;
    transform: translateX(-50%);
    z-index: 1450;
    padding: 12px 18px;
    border-radius: 999px;
    background: rgba(15, 23, 41, 0.92);
    color: #fff;
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
    font-size: 14px;
    line-height: 1.3;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.call-toast.has-icon .material-symbols-outlined {
    font-size: 18px;
}
.call-toast.toast-success {
    background: rgba(14, 124, 72, 0.96);
}
.call-toast.toast-offline {
    background: rgba(121, 31, 44, 0.96);
}
.call-quality-mode-toggle {
    display: inline-flex;
    align-items: center;
    align-self: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    border-radius: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
}
.call-quality-mode-btn {
    min-width: 98px;
    padding: 10px 14px;
    border-radius: 10px;
    background: transparent;
    color: var(--text-dim);
    font-size: 13px;
    font-weight: 700;
    transition: background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
.call-quality-mode-btn.is-active {
    background: rgba(28, 206, 94, 0.15);
    color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(28, 206, 94, 0.22);
}
.call-quality-mode-btn:not(.is-active):hover {
    color: var(--text);
    background: var(--surface-hover);
}
.message-context-menu {
    position: fixed;
    z-index: 1200;
    min-width: 180px;
    padding: 8px;
    background: rgba(15, 23, 41, 0.96);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.28);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}
[data-theme="light"] .message-context-menu {
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.12);
}
.message-context-action {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    text-align: left;
}
.message-context-action:hover {
    background: var(--surface-hover);
    color: var(--accent);
}
.message-context-action .material-symbols-outlined {
    font-size: 18px !important;
    color: inherit;
}
.message-context-action.hidden {
    display: none;
}
.secondary-outline-btn {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    background: #193537;
    color: #f1f5f9;
    border: 1px solid #1cce5e;
    font-size: 14px;
    font-weight: 600;
    transition: transform 0.1s, box-shadow 0.2s;
}
.secondary-outline-btn:hover {
    box-shadow: 0 0 0 3px rgba(28, 206, 94, 0.12);
}
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(4, 10, 20, 0.72);
}
.modal-card {
    width: min(100%, 420px);
    padding: 28px;
}
#manageUserModal .modal-card { max-width: 700px; width: 100%; }

.modal-header-close { position: absolute; top: 12px; right: 16px; background: none; border: none; color: var(--text-dim); cursor: pointer; transition: 0.2s; font-size: 32px; font-weight: 300; padding: 0 4px; }
.modal-header-close:hover { color: var(--text); transform: scale(1.1); }

.modal-card h3 {
    font-size: 22px;
    margin-bottom: 10px;
}
.modal-card p {
    color: var(--text-dim);
    font-size: 14px;
    line-height: 1.5;
}

/* ---- STORAGE BARS ---- */
.storage-bar-wrapper {
    height: 16px;
    background: var(--border);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    width: 100%;
    margin: 8px 0;
}
.storage-bar-segment {
    height: 100%;
    transition: width 0.5s ease;
}
.storage-legend {
    display: flex; gap: 12px; flex-wrap: wrap; margin-top: 10px; font-size: 13px;
}
.storage-legend-item {
    display: flex; align-items: center; gap: 6px; cursor: pointer; transition: 0.2s;
    padding: 4px 8px; border-radius: 6px;
}
.storage-legend-item:hover { background: var(--surface-hover); }
.storage-legend-color { width: 12px; height: 12px; border-radius: 50%; }
.admin-note-field {
    width: 100%;
    min-height: 110px;
    resize: vertical;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 12px 14px;
    font: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.admin-note-field:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.12);
}


.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}
.recovery-modal-card {
    max-width: 460px;
}
.recovery-warning-box {
    margin-top: 18px;
    margin-bottom: 0;
}
.recovery-result-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 18px;
}
.recovery-result-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dim);
}
.modal-danger-btn {
    margin-top: 0;
    background: var(--danger);
    color: #fff;
    border-color: transparent;
}
.unread-badge {
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    box-shadow: 0 4px 10px rgba(255, 71, 87, 0.3);
    animation: badge-pulse 2s infinite;
}

@keyframes badge-pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.system-message {
    display: flex;
    width: 100%;
    justify-content: center !important;
    align-items: center;
    margin: 8px 0;
    pointer-events: none;
}
.system-message span {
    background: var(--surface);
    color: var(--text-dim);
    padding: 5px 14px;
    border-radius: 14px;
    font-size: 12px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.msg-date-separator {
    display: flex;
    width: 100%;
    justify-content: center;
    margin: 14px 0 10px;
    pointer-events: none;
}
.msg-date-separator span {
    background: rgba(15, 23, 41, 0.72);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    backdrop-filter: blur(8px);
}
[data-theme="light"] .msg-date-separator span {
    background: rgba(255, 255, 255, 0.82);
}

/* Mobile back button - only visible on mobile */
.mobile-back-btn {
    display: none !important;
}
.msg-image-attachment {
    max-width: 280px;
    border-radius: 10px;
    overflow: hidden;
    margin: 4px 0;
    cursor: zoom-in;
    display: inline-flex;
    position: relative;
    border: none;
    padding: 0;
    background: transparent;
}
.msg-image-attachment img {
    width: 250px;
    height: 250px;
    display: block;
    object-fit: cover;
    background: rgba(128,128,128,0.15);
    transition: opacity 0.2s;
}
.msg-image-attachment:not(.async-file-image) img[src=""] {
    opacity: 0;
    height: 0;
}
.msg-image-attachment.async-file-image img[src=""] {
    opacity: 0;
}
.file-attachment-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    text-align: center;
    color: var(--text-dim);
    background: rgba(12, 18, 28, 0.45);
    font-size: 13px;
}
.msg-image-attachment.is-loaded .file-attachment-placeholder {
    display: none;
}
.msg-image-attachment.is-error .file-attachment-placeholder {
    background: rgba(120, 24, 24, 0.35);
    color: #ffd5d5;
}
.msg-file-attachment {
    margin: 4px 0;
}
.msg-file-attachment .file-link {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
    transition: background 0.2s;
    width: 100%;
    text-align: left;
    font: inherit;
}
.msg-file-attachment button.file-link {
    appearance: none;
    cursor: pointer;
}
.msg-file-attachment .file-link:hover {
    background: var(--surface-hover);
}
.attach-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.attach-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    transform: scale(1.05);
}
.drag-drop-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(4, 10, 20, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: opacity 0.2s;
}
.drag-drop-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.drag-drop-content {
    border: 3px dashed var(--accent);
    border-radius: 20px;
    padding: 60px;
    text-align: center;
    color: #fff;
    background: rgba(28, 206, 94, 0.1);
}
.drag-drop-icon {
    font-size: 64px;
    color: var(--accent);
    margin-bottom: 16px;
}
.lightbox-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(0,0,0,0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
    transition: opacity 0.2s;
}
.lightbox-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    color: #fff;
    cursor: pointer;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
    padding: 8px;
    display: flex;
}
.lightbox-overlay img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    cursor: default;
}


/* ========== MOBILE ADAPTATION ========== */

@media (max-width: 768px) {
    /* Remove body overflow lock on mobile to allow scrolling where needed */
    html, body { overflow: hidden; }

    /* ---- AUTH ---- */
    .auth-card {
        padding: 28px 20px;
        border-radius: 16px;
    }

    /* ---- ADMIN LAYOUT: sidebar becomes TOP tab bar ---- */
    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100% !important;
        min-width: 0 !important;
        height: 56px;
        flex-direction: row;
        border-right: none;
        border-top: none;
        border-bottom: 1px solid var(--border);
        order: 1; /* moves to TOP */
        backdrop-filter: blur(16px);
        overflow: visible;
        flex-shrink: 0;
    }

    .sidebar-header { display: none !important; }

    .sidebar-nav {
        flex: 1;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-around;
        padding: 0;
        gap: 0;
    }

    .nav-item {
        flex: 1;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 2px;
        padding: 6px 4px !important;
        border-radius: 0;
        margin-bottom: 0;
        font-size: 10px !important;
        height: 56px;
    }

    .nav-item .material-symbols-outlined {
        font-size: 22px !important;
        margin: 0 !important;
    }

    .nav-item span:not(.material-symbols-outlined) {
        display: block !important;
        font-size: 10px;
        line-height: 1.2;
    }

    .sidebar-footer { display: none !important; }

    /* ---- MAIN CONTENT ---- */
    .main-content {
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
        min-height: 0;
        order: 2;
        overflow-y: auto; /* allow panels like settings to scroll */
    }

    /* ---- PANELS: allow scrolling ---- */
    .panel {
        padding: 20px 16px;
        max-width: 100%;
        height: 100%;
        overflow-y: auto;
    }


    /* ---- ADMIN CHAT panel goes full screen on mobile ---- */
    #panelChat {
        position: fixed;
        inset: 0;
        z-index: 500;
        height: 100vh !important;
        height: 100dvh !important;
        /* stays hidden until opened */
        transform: translateX(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: var(--bg);
        min-height: 0;
    }

    #panelChat:not(.hidden) {
        display: flex !important;
        transform: translateX(0);
    }

    /* Back button inside admin chat topbar for mobile */
    .chat-topbar-admin {
        padding: 12px 16px;
    }

    /* Show back arrow and hide X close on mobile */
    .mobile-back-btn {
        display: flex !important;
    }
    #adminCloseChat {
        display: none !important;
    }

    /* ---- USER CHAT LAYOUT ---- */
    /* User app-layout (chatView) mirrors admin: sidebar becomes top tab bar */
    #chatView.app-layout {
        flex-direction: column;
        height: 100vh;
        height: 100dvh;
        overflow: hidden;
    }
    #chatView .sidebar {
        order: 1;
        height: 56px;
        width: 100% !important;
        min-width: 0 !important;
        flex-direction: row;
        border-right: none;
        border-top: none;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }
    #chatView .sidebar-header { display: none !important; }
    #chatView .sidebar-nav {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        padding: 0;
    }
    #chatView .sidebar-footer { display: none !important; }
    #chatView .chat-main {
        order: 2;
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
    }
    #userMainArea {
        height: calc(100vh - 56px);
        height: calc(100dvh - 56px);
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
    }

    #chatPanel {
        height: 100%;
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        min-height: 0;
    }

    .chat-topbar {
        padding: 12px 16px;
    }

    /* ---- MESSAGES AREA ---- */
    .messages-area {
        padding: 12px 10px !important;
        min-height: 0;
    }

    /* ---- BUBBLES ---- */
    .msg-bubble {
        max-width: 88vw !important;
        /* rely on var(--msg-font-size) defined above instead of override */
    }

    /* ---- INPUT BAR ---- */
    .chat-input-bar {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        position: sticky;
        bottom: 0;
        z-index: 5;
    }

    textarea#messageInput,
    textarea#adminMessageInput {
        font-size: 16px; /* prevents iOS zoom */
        padding: 10px 12px;
    }

    .send-btn, .attach-btn, .emoji-toggle-btn {
        width: 44px;
        height: 44px;
        min-width: 44px;
        flex: 0 0 44px;
    }

    /* ---- IMAGE ATTACHMENTS ---- */
    .msg-image-attachment img {
        width: min(220px, 80vw);
        height: min(220px, 80vw);
    }

    /* ---- EMOJI PICKER ---- */
    .emoji-picker {
        left: 0;
        right: auto;
        width: min(312px, calc(100vw - 20px));
        max-width: calc(100vw - 20px);
        max-height: 300px;
    }

    /* ---- MODALS ---- */
    .modal-card {
        max-width: calc(100vw - 32px);
        padding: 20px 16px;
    }

    .call-overlay {
        align-items: stretch;
        padding: 0;
    }
    .call-card {
        width: 100%;
        min-height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 32px 20px;
    }
    .call-card h2 {
        font-size: 26px;
    }
    .call-status-text {
        font-size: 16px;
    }
    .call-actions {
        margin-top: 30px;
        gap: 18px;
    }
    .call-control-btn {
        width: 68px;
        height: 68px;
    }
    .call-toast {
        bottom: calc(20px + env(safe-area-inset-bottom));
        max-width: calc(100vw - 24px);
        white-space: normal;
        text-align: center;
    }
    .call-quality-profiles,
    .call-quality-metrics {
        grid-template-columns: 1fr;
    }
    .call-quality-panel {
        margin-top: 20px;
    }

    /* ---- USER LIST ---- */
    .user-row {
        padding: 12px 14px;
    }

    /* ---- SETTINGS ---- */
    .settings-item {
        align-items: flex-start;
        gap: 14px;
    }
    .theme-mode-control {
        width: 100%;
        justify-content: space-between;
        flex-wrap: nowrap; /* buttons side by side */
        overflow: hidden;
    }
    .theme-mode-btn {
        flex: 1;
        min-width: 0;
        width: auto;
        height: 38px;
        padding: 0 8px;
    }
    .call-quality-mode-toggle {
        width: 100%;
    }
    .call-quality-mode-btn {
        flex: 1;
        min-width: 0;
    }
    .theme-mode-btn .material-symbols-outlined { font-size: 18px !important; }
    .secret-field-row { flex-wrap: wrap; }
    .secret-phrase-input { min-width: 0; }

    /* ---- SETTINGS LIST: make scrollable on mobile ---- */
    .settings-list {
        -webkit-overflow-scrolling: touch;
    }

    /* ---- LIGHTBOX ---- */
    .lightbox-overlay img {
        max-width: 98vw;
        max-height: 85vh;
    }

    /* ---- PINNED BANNER ---- */
    .pinned-banner {
        padding: 8px 14px;
    }

    /* ---- SYSTEM MESSAGES ---- */
    .system-message {
        width: 100%;
        text-align: center;
    }
    .system-message span {
        font-size: 11px;
        padding: 3px 10px;
    }

    /* ---- UPLOAD CONFIRM MODAL ---- */
    #uploadImagePreview {
        max-height: 180px;
    }
}

/* Very small screens */
@media (max-width: 380px) {
    .nav-item span:not(.material-symbols-outlined) {
        display: none !important;
    }
    .nav-item {
        height: 52px;
    }
    .sidebar { height: 52px; }
    .main-content { height: calc(100vh - 52px); height: calc(100dvh - 52px); }
    #userMainArea { height: calc(100vh - 52px); height: calc(100dvh - 52px); }
}

/* Landscape mobile: reduce top bar, allow more chat space */
@media (max-width: 768px) and (orientation: landscape) {
    .sidebar { height: 48px; }
    .nav-item { height: 48px; font-size: 9px !important; }
    .nav-item .material-symbols-outlined { font-size: 18px !important; }
    .main-content { height: calc(100vh - 48px); height: calc(100dvh - 48px); }
    #userMainArea { height: calc(100vh - 48px); height: calc(100dvh - 48px); }
}

.msg-deleted {
    font-style: italic;
    opacity: 0.7;
    user-select: none;
}

.msg-has-history {
    cursor: pointer;
    transition: opacity 0.2s;
}

.msg-has-history:hover {
    opacity: 0.85;
}

.history-item {
    padding: 10px;
    background: var(--surface-hover);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.history-item-meta {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.history-item-body {
    word-break: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    color: var(--text-base);
}
