:root {
    --main-max-width: 900px;
    --side-nav-width: 71px;
    --top-fixed-offset: 0px;
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-chat: #212121;
    --bg-input: #434343;
    --bg-bubble: #2c2738;
    --bg-bubble-mine: #7241fe;
    --border-primary: #21262d;
    --border-chat: #303030;
    --border-secondary: #30363d;
    --text-primary: #c9d1d9;
    --text-secondary: #8b949e;
    --text-white: #fff;
    --text-muted: #a9a9a9;
    --msg-time: #a9a9a9;
    --link: #58a6ff;
    --accent: #7241fe;
    --accent-light: #a78bfa;
    --success: #238636;
    --success-hover: #2ea043;
    --danger: #da3633;
    --danger-hover: #f85149;
    --hover-overlay: rgba(255,255,255,0.05);
    --shadow: rgba(0,0,0,0.5);
    --sheet-bg: #1a1a1a;
    --sheet-surface: #262626;
    --sheet-surface-hover: #2e2e2e;
    --sheet-border: #3a3a3a;
    --sheet-border-dim: #2a2a2a;
    --sheet-handle: #555;
    --sheet-text: #fff;
    --sheet-gradient-end: #1a1a1a;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg-primary: #ffffff;
        --bg-secondary: #f6f8fa;
        --bg-chat: #ffffff;
        --bg-input: #e8e8ed;
        --bg-bubble: #e9e2f5;
        --bg-bubble-mine: #7241fe;
        --border-primary: #d0d7de;
        --border-chat: #d0d7de;
        --border-secondary: #d8dee4;
        --text-primary: #1f2328;
        --text-secondary: #656d76;
        --text-white: #1f2328;
        --text-muted: #656d76;
        --link: #0969da;
        --accent: #7241fe;
        --accent-light: #7241fe;
        --success: #1a7f37;
        --success-hover: #2da44e;
        --danger: #cf222e;
        --danger-hover: #a40e26;
        --hover-overlay: rgba(0,0,0,0.04);
        --shadow: rgba(0,0,0,0.15);
        --sheet-bg: #f2f2f7;
        --sheet-surface: #ffffff;
        --sheet-surface-hover: #f0f0f0;
        --sheet-border: #d1d1d6;
        --sheet-border-dim: #e5e5ea;
        --sheet-handle: #c7c7cc;
        --sheet-text: #1c1c1e;
        --sheet-gradient-end: #f2f2f7;
    }
}

/* Disable text selection globally, allow in inputs */
*, *::before, *::after {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}
input, textarea, [contenteditable="true"] {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f6f8fa;
    --bg-chat: #ffffff;
    --bg-input: #e8e8ed;
    --bg-bubble: #e9e2f5;
    --bg-bubble-mine: #7241fe;
    --border-primary: #d0d7de;
    --border-chat: #d0d7de;
    --border-secondary: #d8dee4;
    --text-primary: #1f2328;
    --text-secondary: #656d76;
    --text-white: #1f2328;
    --text-muted: #656d76;
    --link: #0969da;
    --accent: #7241fe;
    --accent-light: #7241fe;
    --success: #1a7f37;
    --success-hover: #2da44e;
    --danger: #cf222e;
    --danger-hover: #a40e26;
    --hover-overlay: rgba(0,0,0,0.04);
    --shadow: rgba(0,0,0,0.15);
    --sheet-bg: #f2f2f7;
    --sheet-surface: #ffffff;
    --sheet-surface-hover: #f0f0f0;
    --sheet-border: #d1d1d6;
    --sheet-border-dim: #e5e5ea;
    --sheet-handle: #c7c7cc;
    --sheet-text: #1c1c1e;
    --sheet-gradient-end: #f2f2f7;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { touch-action: manipulation; overscroll-behavior: none; }
body { overscroll-behavior: none; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, monospace; background: var(--bg-primary); color: var(--text-primary); max-width: var(--main-max-width); margin: 0 auto; }
html:has(#chat-area),
body:has(#chat-area) {
    height: 100dvh;
    overflow: hidden;
}
body:has(#chat-area) #install-banner-spacer,
body:has(#chat-area) #notif-prompt-spacer {
    display: none !important;
}
body:has(#chat-area) main {
    height: 100dvh !important;
    overflow: hidden !important;
}

/* ==================== Messenger split-pane shell ==================== */
/* Chats page carries `.msgr-split`; drop the body max-width cap so the
   shell can stretch wide enough to fit list (380-500px) + chat (up to 900px). */
body:has(.msgr-split) { max-width: none; }
body:has(.msgr-split) main {
    /* max-width: calc(500px + 900px); */
    height: 100dvh;
    overflow: hidden;
}
/* Embed (iframe) chat page: full viewport width, no body cap, no side-nav offset. */
body.embed-body {
    max-width: none;
    margin-left: 0;
    margin-right: 0;
}
body.embed-body main { max-width: none; }
body.embed-body .chat-header { max-width: none; margin: 0; left: 0; right: 0; }
.msgr-split {
    display: flex;
    height: 100dvh;
    width: 100%;
}
/* Left-most files panel (iframe of /web/files?embed=1). Activated when URL has
   ?files=1 — server adds `.has-files` to the split container, and the JS
   in chats.html shows/hides the element. */
.msgr-files {
    position: relative;
    flex: 0 0 380px;
    max-width: 500px;
    width: 380px;
    min-width: 0;
    height: 100%;
    overflow: visible;
    border-right: 1px solid var(--border-chat);
    background: var(--bg-chat);
}
.msgr-files[hidden] { display: none; }
.msgr-files-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: var(--bg-chat);
}
/* 2-pane collapse (files + chat or files + list):
   Between 769px (sidenav visible) and ~1030px, three panes don't fit. If a
   chat is open (body.msgr-has-chat), drop the list; otherwise keep list
   next to files. */
@media (min-width: 769px) and (max-width: 1030px) {
    body.msgr-has-chat .msgr-split.has-files > .msgr-list { display: none; }
}
/* Below 769 the side-nav is hidden — split mode is off entirely; hide files
   pane even if the URL had ?files=1 so we stay in single-pane narrow UI. */
@media (max-width: 768px) {
    .msgr-files { display: none !important; }
}
/* min-width floor (320 list + 320 chat = 640) is enforced ONLY as a breakpoint
   — below that we collapse to single-pane so the visible panel can shrink to
   any width. In split mode, panes can still shrink below their preferred
   width when the user drags the divider. */
.msgr-list {
    position: relative;
    flex: 0 0 380px;
    max-width: 500px;
    width: 380px;
    min-width: 0;
    height: 100%;
    overflow-y: auto;
    border-right: 1px solid var(--border-chat);
    background: var(--bg-chat);
}
.msgr-resize-handle {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 10;
    background: transparent;
}
.msgr-resize-handle:hover,
body.msgr-resizing .msgr-resize-handle {
    background: var(--accent, rgba(114, 65, 254, 0.35));
}
body.msgr-resizing { cursor: col-resize; user-select: none; }
body.msgr-resizing iframe { pointer-events: none; }
.msgr-chat {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: var(--bg-chat);
}
.msgr-chat-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: var(--bg-chat);
}
.msgr-chat-mount {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-chat);
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.msgr-chat-mount > #chat-area,
.msgr-chat-mount > .chat-area-flex {
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}
/* chat_view CSS uses position:fixed which assumed iframe viewport; rescope
   to the mount pane so the chat header/input/dropdown stay inside the chat
   pane in the messenger shell. */
.msgr-chat-mount .chat-header {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    max-width: none !important;
}
.msgr-chat-mount .chat-area-flex {
    position: relative;
    height: 100% !important;
    min-height: 0 !important;
}
.msgr-chat-mount .message-list {
    padding-top: 70px !important;
    padding-bottom: 70px !important;
}
.msgr-chat-mount .bottom-fixed {
    position: absolute !important;
    /* bottom: 0 !important; */
    left: 0 !important;
    right: 0 !important;
}
.msgr-chat-mount .chat-menu-dropdown {
    position: absolute !important;
    top: 56px !important;
    right: 16px !important;
}
.msgr-chat-mount #passphrase-gate {
    padding: 1.5rem;
}
.msgr-chat-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 15px;
}
.chat-item.active {
    background: var(--bg-chat-hover, rgba(255,255,255,0.05));
}

/* Narrow: stack into a single pane. Show list by default; when user opens a
   chat we flip `body.msgr-has-chat` to reveal the chat pane full-screen.
   Breakpoint = 320px list + 320px chat (= 640px floor) below which split is
   too cramped to be useful. */
@media (max-width: 639px) {
    body:has(.msgr-split) main { max-width: 100%; }
    .msgr-split { display: block; }
    .msgr-list {
        max-width: 100%;
        flex: none;
        width: 100% !important;
        border-right: 0;
    }
    .msgr-resize-handle { display: none; }
    .msgr-chat { display: none; width: 100%; }
    body.msgr-has-chat .msgr-list { display: none; }
    body.msgr-has-chat .msgr-chat { display: block; height: 100dvh; }
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.top-nav {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: 1.5rem;
}
.brand { font-weight: bold; font-size: 1.3rem; color: var(--text-white); text-decoration: none; }
.brand-name { color: var(--text-white); }
.brand-ext { color: var(--text-secondary); font-weight: normal; }
.nav-links { display: flex; gap: 1.25rem; align-items: center; }
.nav-tab { color: var(--text-secondary); padding-bottom: 2px; border-bottom: 2px solid transparent; transition: color 0.15s, border-color 0.15s; }
.nav-tab:hover { color: var(--text-primary); text-decoration: none; }
.nav-tab.active { color: var(--accent-light); border-bottom-color: var(--accent-light); }
.nav-avatar { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-light); color: #fff; font-weight: 600; font-size: 0.85rem; text-decoration: none; flex-shrink: 0; }
.nav-avatar:hover { text-decoration: none; opacity: 0.85; }
.btn-link { background: none; border: none; color: var(--link); cursor: pointer; font: inherit; }
.inline { display: inline; }

/* Bottom tab bar (always visible for logged-in users) */
.tab-bar {
    position: fixed; bottom: 0; left: 0; right: 0;
    display: flex; justify-content: space-around; align-items: center;
    background: var(--bg-chat); border-top: 1px solid var(--border-chat);
    height: 56px; padding-bottom: env(safe-area-inset-bottom);
    z-index: 200;
}
.tab-item { color: var(--text-muted); text-decoration: none; display: flex; align-items: center; justify-content: center; padding: 8px; }
.tab-item:hover { text-decoration: none; }
.tab-item.active { color: var(--accent); }
.tab-item svg { width: 28px; height: 28px; }
.tab-avatar { padding: 0; }
.tab-avatar-circle { width: 32px; height: 32px; border-radius: 50%; background: var(--border-secondary); font-weight: 600; font-size: 0.85rem; display: flex; align-items: center; justify-content: center; color: var(--text-primary); }
.tab-avatar.active .tab-avatar-circle { background: var(--accent); color: #fff; }
.tab-bar ~ main { padding-bottom: 70px; }
.tab-bar ~ main:has(.chat-area-flex) { padding-bottom: 0; overflow: hidden; height: 100dvh; }

@media (display-mode: standalone) {
    .chat-area-flex { height: 100dvh; }
    .chat-bottom {
        padding-bottom: 8px;
    }
    .bottom-fixed .tab-bar {
        position: static;
    }
}

/* Hide nav during call */
body.in-call .top-nav,
body.in-call .tab-bar,
body.in-call .side-nav { display: none !important; }

h1 { margin-bottom: 1rem; }
h2 { margin: 1.5rem 0 0.5rem; }

table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border-primary); }
th { color: var(--text-secondary); font-weight: 600; }

.info-table th { width: 140px; color: var(--text-secondary); }

.auth-form, .upload-form { max-width: 400px; }
label { display: block; margin-bottom: 0.75rem; color: var(--text-secondary); font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="number"], input[type="file"], select {
    display: block; margin-top: 0.25rem; padding: 0.5rem;
    background: var(--bg-secondary); border: 1px solid var(--border-secondary); border-radius: 4px; color: var(--text-primary); font: inherit;
}
input[type="checkbox"] { display: inline; width: auto; margin-right: 0.5rem; }

button, .btn { display: inline-block; padding: 0.5rem 1rem; background: var(--success); color: #fff; border: none; border-radius: 4px; cursor: pointer; font: inherit; margin-top: 0.5rem; }
button:hover, .btn:hover { background: var(--success-hover); }

.flash { padding: 0.75rem; border-radius: 4px; margin-bottom: 1rem; }
.flash.error { background: #3d1f1f; border: 1px solid #f85149; }
.flash.success { background: #1f3d1f; border: 1px solid #238636; }
.flash.info { background: #1f2d3d; border: 1px solid #58a6ff; }

.hidden { display: none !important; }

.decrypt-section { margin-top: 0.5rem; }
#decrypt-status { margin-top: 0.5rem; color: var(--text-secondary); }
#decrypt-output { margin-top: 0.5rem; padding: 1rem; background: var(--bg-secondary); border: 1px solid var(--border-secondary); border-radius: 4px; max-height: 400px; overflow: auto; white-space: pre-wrap; word-break: break-all; }

/* main { padding-bottom: 2rem; } */

/* Badge */
.badge { display: inline-block; background: var(--danger-hover); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 0.75rem; margin-left: 4px; vertical-align: super; }

/* Chat header */
.chat-header { position: fixed; top: var(--top-fixed-offset); left: 0; right: 0; max-width: var(--main-max-width); margin: 0 auto; background: var(--bg-chat); border-bottom: 1px solid var(--border-chat); padding: 10px 20px; display: flex; align-items: center; gap: 12px; z-index: 50; }
.chat-header h1 { display: none; }
.chat-header .chat-actions .btn-small:not(.call-btn) { display: none; }
.chat-actions { display: flex; gap: 0.5rem; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.85rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-hover); }

.chat-back-btn { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; flex-shrink: 0; }
.chat-back-btn svg { width: 24px; height: 24px; }
.chat-header-avatar { display: flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 50%; color: #fff; font-weight: 600; font-size: 1rem; flex-shrink: 0; }
.chat-header-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.chat-header-name { font-family: Roboto, -apple-system, sans-serif; font-weight: 500; font-size: 18px; color: var(--text-white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-members { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-menu-btn { display: flex; align-items: center; justify-content: center; background: none; border: none; color: var(--accent); cursor: pointer; padding: 4px; flex-shrink: 0; }
.chat-menu-btn svg { width: 22px; height: 22px; }

.chat-menu-dropdown { display: none; position: fixed; top: calc(56px + var(--top-fixed-offset)); right: 20px; background: var(--bg-chat); border: 1px solid var(--border-chat); border-radius: 12px; padding: 8px 0; z-index: 51; box-shadow: 0 8px 24px var(--shadow); min-width: 200px; }
.chat-menu-dropdown.open { display: block; }
.chat-menu-dropdown button { display: block; width: 100%; text-align: left; padding: 10px 16px; background: none; border: none; color: var(--text-white); font: inherit; font-size: 15px; cursor: pointer; }
.chat-menu-dropdown button:hover { background: var(--hover-overlay); }
.chat-menu-dropdown button.btn-danger { color: var(--danger-hover); }

.chat-members-line { display: none; }

.chat-area-flex { display: flex; flex-direction: column;
    height: 100dvh; min-height: 300px; }
.message-list {
    background: var(--bg-chat); border: none; border-radius: 0;
    padding: 20px; padding-bottom: calc(62px + 56px + env(safe-area-inset-bottom)); padding-top: calc(80px + var(--top-fixed-offset));
    flex: 1; overflow-y: auto; margin-bottom: 0; min-height: 0;
}

.bottom-fixed {
    position: fixed;
    bottom: calc(56px + env(safe-area-inset-bottom));
    left: 0;
    right: 0;
    /* max-width: var(--main-max-width); */
    margin: 0 auto;
    z-index: 200;
}
/* Embed (chat iframe inside split-pane): no mobile tab-bar below, so the
   56px gap would leave dead space. Pin to the bottom regardless of viewport. */
body.embed-body .bottom-fixed {
    /* bottom: 0; */
}

.chat-bottom {
    background: var(--bg-chat);
    padding: 8px 16px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.chat-input { display: flex; gap: 0.5rem; align-items: flex-end; }
.chat-input textarea { flex: 1; margin: 0; padding: 10px 16px; background: var(--bg-input); border: none; border-radius: 20px; color: var(--text-white); font: inherit; resize: none; max-height: 120px; overflow-y: auto; line-height: 1.4; }
.chat-input button { margin: 0; background: var(--accent); color: #fff; border-radius: 20px; }
.chat-input button:hover { background: var(--accent); opacity: 0.85; }

body:has(#chat-area) #passphrase-gate {
    padding-top: calc(1rem + var(--top-fixed-offset));
}

.call-btn { background: none; color: var(--accent); font-size: 1.2rem; padding: 4px; }
.call-btn:hover { background: none; opacity: 0.8; }

.file-upload-label { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; background: var(--border-secondary); color: var(--text-primary); border-radius: 4px; cursor: pointer; font-size: 1.1rem; line-height: 1; }
.file-upload-label:hover { background: #3d444d; }

.upload-progress { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--text-secondary); }
.upload-progress-bar { flex: 1; height: 6px; background: var(--border-primary); border-radius: 3px; overflow: hidden; position: relative; }
.upload-progress-fill { height: 100%; background: var(--success); border-radius: 3px; transition: width 0.2s; }
.upload-progress-fill.indeterminate {
    width: 30% !important;
    animation: progress-indeterminate 1.2s ease-in-out infinite;
    transition: none;
}
.upload-progress-fill.error { background: var(--danger); }
@keyframes progress-indeterminate {
    0% { transform: translateX(-120%); }
    100% { transform: translateX(420%); }
}
.file-progress { display: flex; align-items: center; gap: 0.5rem; margin: 0.35rem 0; font-size: 0.78rem; color: var(--text-secondary); }
.file-progress .upload-progress-bar { min-width: 80px; }
.file-progress-text { white-space: nowrap; }

/* Media viewer */
.media-viewer { position: fixed; inset: 0; z-index: 200; user-select: none; -webkit-user-select: none; contain: layout paint; }
.media-viewer.hidden { display: none; }
.media-viewer .mv-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.92); transition: opacity 0.18s; }

.media-viewer .mv-track {
    position: absolute; inset: 0;
    display: flex;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    scroll-behavior: auto;
    touch-action: pan-x;
    scrollbar-width: none;
    -ms-overflow-style: none;
    overscroll-behavior: contain;
}
.media-viewer .mv-track::-webkit-scrollbar { display: none; width: 0; height: 0; }
.media-viewer.mv-zoomed .mv-track { touch-action: none; }

.media-viewer .mv-cell {
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}
.media-viewer .mv-content {
    transform-origin: 50% 50%;
    will-change: transform;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    max-width: 100%;
    max-height: 100%;
}
.media-viewer .mv-content.mv-animating { transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1); }

.media-viewer .mv-cell img.mv-full,
.media-viewer .mv-cell video.mv-full {
    max-width: 100%; max-height: 100vh; display: block;
    -webkit-user-drag: none; user-select: none;
    background: #000;
}
.media-viewer .mv-cell img.mv-thumb {
    max-width: 100%; max-height: 100vh; display: block;
    filter: blur(8px);
    transform: scale(1.02);
    -webkit-user-drag: none; user-select: none;
    background: #000;
}
.media-viewer .mv-cell .mv-spinner-wrap {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    color: #fff; pointer-events: none; z-index: 2;
    text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}
.media-viewer .mv-cell .mv-progress { font-size: 0.85rem; }
.media-viewer .mv-cell .mv-error {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    color: #fff; padding: 12px 18px;
    background: rgba(0,0,0,0.6); border-radius: 8px;
}

.media-viewer .mv-spinner {
    width: 36px; height: 36px; border: 3px solid rgba(255,255,255,0.2);
    border-top-color: #fff; border-radius: 50%; animation: mv-spin 0.9s linear infinite;
}
@keyframes mv-spin { to { transform: rotate(360deg); } }

.media-viewer .mv-zone { position: absolute; top: 0; bottom: 60px; width: 25vw; cursor: pointer; z-index: 3; }
.media-viewer .mv-zone-left { left: 0; }
.media-viewer .mv-zone-right { right: 0; }
.media-viewer.mv-zoomed .mv-zone,
.media-viewer.mv-swiping .mv-zone { pointer-events: none; }

.media-viewer .mv-btn {
    position: absolute; background: rgba(0,0,0,0.45); border: none; color: #fff;
    width: 44px; height: 44px; border-radius: 50%; cursor: pointer; padding: 0;
    font-size: 1.8rem; line-height: 1; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, opacity 0.15s; z-index: 5;
}
.media-viewer .mv-btn:hover { background: rgba(0,0,0,0.75); }
.media-viewer .mv-close { top: 16px; right: 16px; }
.media-viewer .mv-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.media-viewer .mv-next { right: 16px; top: 50%; transform: translateY(-50%); }
.media-viewer .mv-counter {
    position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
    color: #fff; font-size: 0.95rem; background: rgba(0,0,0,0.45);
    padding: 6px 12px; border-radius: 14px; pointer-events: none; z-index: 4;
    transition: opacity 0.15s;
}
.media-viewer .mv-filename {
    position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
    color: #fff; font-size: 0.9rem; background: rgba(0,0,0,0.45);
    padding: 6px 12px; border-radius: 14px; max-width: 80vw;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: none; z-index: 4; transition: opacity 0.15s;
}
.media-viewer.mv-single .mv-zone,
.media-viewer.mv-single .mv-prev,
.media-viewer.mv-single .mv-next { display: none; }
.media-viewer.mv-interacting .mv-btn,
.media-viewer.mv-interacting .mv-counter,
.media-viewer.mv-interacting .mv-filename { opacity: 0; }

/* Modal */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-content { background: var(--bg-secondary); border: 1px solid var(--border-secondary); border-radius: 8px; padding: 1.5rem; min-width: 300px; max-width: 400px; }
.modal-content h2 { margin-bottom: 1rem; }

/* Invitation cards */
.inv-card { border: 1px solid var(--border-primary); border-radius: 4px; padding: 1rem; margin-bottom: 0.75rem; background: var(--bg-secondary); }
.inv-actions { display: flex; gap: 0.5rem; align-items: end; margin-top: 0.5rem; flex-wrap: wrap; }
.inv-actions label { margin: 0; }
.inv-actions input { margin-top: 0.25rem; }

/* Folder upload */
.folder-upload { display: flex; align-items: center; gap: 0.5rem; }

/* Chat list (messenger-style) */
.chat-list-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 12px; margin-bottom: 0; }
.chat-list-header h1 { margin-bottom: 0; font-family: Roboto, -apple-system, sans-serif; font-weight: 500; font-size: 20px; color: var(--text-white); }
.chat-search { display: block; width: calc(100% - 40px); margin: 0 20px 12px; padding: 7px 13px; background: var(--bg-input); border: none; border-radius: 24px; color: var(--text-white); font-size: 15px; font-family: Roboto, -apple-system, sans-serif; }
.chat-search::placeholder { color: var(--text-muted); }
.chat-list { display: flex; flex-direction: column; gap: 0; }
.chat-item { display: flex; align-items: center; gap: 20px; padding: 10px 20px; border-radius: 0; text-decoration: none; color: inherit; transition: background 0.15s; }
.chat-item:hover { background: var(--hover-overlay); text-decoration: none; }
.chat-avatar { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 1.4rem; font-weight: 600; color: #fff; flex-shrink: 0; }
.chat-item-content { flex: 1; min-width: 0; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; }
.chat-item-name { font-family: Roboto, -apple-system, sans-serif; font-weight: 500; font-size: 15px; color: var(--text-white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-family: Roboto, -apple-system, sans-serif; font-weight: 400; font-size: 14px; color: var(--text-muted); white-space: nowrap; margin-left: 0.5rem; flex-shrink: 0; }
.chat-item-preview { font-family: Roboto, -apple-system, sans-serif; font-weight: 400; font-size: 15px; color: var(--text-muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; overflow: hidden; text-overflow: ellipsis; margin-top: 0.15rem; }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 0.15rem; }
.chat-item-badge { display: inline-flex; align-items: center; justify-content: center; background: var(--accent); color: #fff; border-radius: 18px; min-width: 18px; height: 18px; padding: 0 5px; font-size: 14px; font-weight: 500; flex-shrink: 0; }

/* New chat button ("+") */
.chat-new-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border-radius: 32px; background: var(--accent); color: #fff; border: none; cursor: pointer; font-size: 1.4rem; line-height: 1; padding: 0; margin: 0; flex-shrink: 0; transition: opacity 0.15s; }
.chat-new-btn:hover { background: var(--accent); opacity: 0.85; }
.chat-new-btn svg { width: 18px; height: 18px; }

/* Dropdown menu */
.chat-new-menu-wrap { position: relative; }
.chat-new-menu { position: absolute; top: calc(100% + 8px); right: 0; background: var(--bg-chat); border: 1px solid var(--border-chat); border-radius: 15px; padding: 16px 20px; z-index: 90; box-shadow: 0px 19px 37px var(--shadow); min-width: 220px; display: none; }
.chat-new-menu.open { display: block; }
.chat-new-menu-item { display: flex; align-items: center; gap: 15px; padding: 10px 0; color: var(--text-white); text-decoration: none; font-size: 16px; font-weight: 400; cursor: pointer; background: none; border: none; width: 100%; font: inherit; }
.chat-new-menu-item:hover { text-decoration: none; opacity: 0.8; }
.chat-new-menu-item svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--text-muted); }

/* Small screen adjustments */
@media (max-width: 600px) {
    /* body { padding: 0 0.5rem; } */
    .message-wrapper { max-width: 95%; }
}

/* Image preview in chat */
.msg-image { max-width: 300px; max-height: 300px; border-radius: 4px; cursor: pointer; display: block; margin-top: 0.25rem; }

/* System message (missed call etc) */

/* Call overlay */
.call-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.95); z-index: 200;
    display: flex; align-items: center; justify-content: center;
}
.call-overlay.hidden { display: none; }
.call-overlay-inner {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center;
    width: 90vw; height: 90vh;
    max-width: 1200px;
    position: relative;
}

/* Call grid */
.call-grid {
    display: grid; gap: 4px;
    width: 100%; flex: 1; min-height: 0;
}
.call-grid.grid-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.call-grid.grid-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.call-grid.grid-3 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.call-grid.grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }

.call-grid-cell {
    position: relative; background: #000;
    border-radius: 8px; overflow: hidden;
    isolation: isolate;
    min-height: 0;
}
.call-cell-spinner {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    width: 32px; height: 32px;
    border: 3px solid var(--border-secondary);
    border-top-color: var(--link);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 1;
}
@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }
.call-grid-cell video {
    width: 100%; height: 100%;
    /* object-fit: cover; */
    display: block;
}
.call-grid-label {
    position: absolute; bottom: 4px; left: 8px;
    color: #fff; font-size: 0.8rem;
    text-shadow: 0 1px 3px rgba(0,0,0,0.8);
    max-width: calc(100% - 16px);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    z-index: 1;
    pointer-events: none;
}

.local-video {
    position: absolute; bottom: 80px; right: 20px;
    width: 150px; border-radius: 6px;
    border: 2px solid var(--border-secondary); z-index: 210;
}
.call-controls {
    display: flex; gap: 0.75rem; justify-content: center;
    padding: 0.75rem 0; flex-shrink: 0;
}

/* Join banner */
.call-join-banner { display: flex; align-items: center; justify-content: space-between; background: #1f2d3d; border: 1px solid #58a6ff; border-radius: 6px; padding: 0.5rem 0.75rem; margin-bottom: 0.5rem; color: var(--text-primary); font-size: 0.9rem; }
.call-join-banner.hidden { display: none; }

/* Incoming call banner */
.incoming-call-banner {
    position: fixed; top: 56px; left: 0; right: 0; z-index: 49;
    max-width: var(--main-max-width); margin: 0 auto;
    display: flex; align-items: center; justify-content: space-between;
    background: --var(--bg-primary); border-bottom: 1px solid #f85149;
    padding: 0.5rem 0.75rem;
    color: var(--text-primary); font-size: 0.9rem;
    animation: pulse-border 1.5s ease-in-out infinite;
}
.incoming-call-banner.hidden { display: none; }
.incoming-call-banner-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
@keyframes pulse-border {
    0%, 100% { border-color: #f85149; }
    50% { border-color: #ff7b72; }
}

/* Incoming call modal */
.incoming-call-modal { text-align: center; }


/* Call overlay mobile */
@media (max-width: 600px) {
    .call-overlay-inner { width: 100%; height: 100%; padding: 0.5rem; }
    .call-grid { max-height: none; }
    .local-video { width: 90px; bottom: 60px; right: 8px; }
    .call-controls { padding: 0.5rem 0; }
    .call-join-banner { font-size: 0.8rem; padding: 0.4rem 0.5rem; }
}

/* Notification prompt */
.notif-prompt {
    top: 0; left: 0; right: 0; z-index: 60;
    max-width: var(--main-max-width); margin: 0 auto;
    background: var(--bg-primary); border-bottom: 1px solid #58a6ff;
    padding: 0.75rem 1rem;
    display: flex; align-items: center; justify-content: center; gap: 0.75rem;
    font-size: 0.9rem; color: var(--text-primary);
}
.notif-prompt.hidden { display: none; }
.banner-spacer { position: relative !important; z-index: auto !important; visibility: hidden; }
.banner-spacer.hidden { display: none; }
@media (max-width: 600px) {
    .notif-prompt { flex-direction: column; text-align: center; }
}

/* Install banner */
.install-banner {
    position: fixed;
    top: 0; left: 0; right: 0; z-index: 60;
    max-width: var(--main-max-width); margin: 0 auto;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border-secondary);
    padding: 0.76rem 1rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.install-banner.hidden { display: none; }
.install-banner-text { flex: 1; font-size: 0.9rem; color: var(--text-primary); }
.install-banner-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.btn-secondary { background: var(--border-secondary); }
.btn-secondary:hover { background: #3d444d; }
@media (max-width: 600px) {
    .install-banner { flex-direction: column; align-items: stretch; text-align: center; }
    .install-banner-actions { justify-content: center; }
}

/* Profile page */
.profile-page { max-width: 400px; margin: 2rem auto; }
.profile-header { display: flex; flex-direction: column; align-items: center; margin-bottom: 2rem; }
.profile-avatar { width: 80px; height: 80px; border-radius: 50%; background: var(--accent-light); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 600; margin-bottom: 0.75rem; }
.profile-username { font-size: 1.25rem; font-weight: 600; color: var(--text-primary); }
.profile-links { display: flex; flex-direction: column; gap: 2px; margin-bottom: 2rem; }
.profile-link { display: flex; align-items: center; gap: 0.75rem; padding: 0.85rem 1rem; border-radius: 6px; color: var(--text-primary); text-decoration: none; transition: background 0.15s; }
.profile-link:hover { background: var(--bg-secondary); text-decoration: none; }
.profile-link svg { color: var(--text-secondary); flex-shrink: 0; }
.profile-logout { text-align: center; }
.profile-logout .btn { width: 100%; }

/* Theme toggle */
.profile-theme { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; margin-bottom: 2rem; }
.profile-theme-label { color: var(--text-primary); font-size: 1rem; display: flex; align-items: center; gap: 0.75rem; }
.profile-theme-label svg { color: var(--text-secondary); flex-shrink: 0; }
.theme-toggle-btn { display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.4rem 0.75rem; background: var(--bg-secondary); border: 1px solid var(--border-secondary); border-radius: 6px; color: var(--text-primary); cursor: pointer; font: inherit; font-size: 0.85rem; margin: 0; }
.theme-toggle-btn:hover { background: var(--hover-overlay); }
.theme-toggle-btn svg { width: 16px; height: 16px; }

/* Intro page */
.intro-page {
    display: flex; flex-direction: column;
    height: 100dvh; max-width: 900px; margin: 0 auto;
    overflow: hidden;
}
.intro-carousel { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-top: 2rem; }
.intro-slides {
    flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; scrollbar-width: none; min-height: 0;
}
.intro-slides::-webkit-scrollbar { display: none; }
.intro-slide {
    flex: 0 0 100%; scroll-snap-align: start;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2rem 1.5rem; text-align: center; gap: 0.75rem;
}
.intro-icon { color: var(--accent-light); margin-bottom: 0.5rem; }
.intro-title { font-size: 1.5rem; font-weight: 700; color: var(--text-white); margin: 0; }
.intro-subtitle { font-size: 1.1rem; color: var(--accent-light); font-weight: 500; margin: 0; }
.intro-desc { font-size: 0.95rem; color: var(--text-secondary); max-width: 340px; line-height: 1.5; margin: 0; }
.intro-dots { display: flex; justify-content: center; gap: 8px; padding: 1rem 0; }
.intro-dot {
    width: 8px; height: 8px; border-radius: 50%; border: none;
    background: var(--border-secondary); cursor: pointer; padding: 0;
    transition: background 0.2s, transform 0.2s;
}
.intro-dot.active { background: var(--accent); transform: scale(1.3); }
.intro-buttons { padding: 1rem 1.5rem; padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 0.75rem; }
.intro-buttons-row { display: flex; gap: 0.75rem; }
.intro-btn {
    display: flex; align-items: center; justify-content: center;
    padding: 0.85rem 1rem; border-radius: 12px; font: inherit; font-size: 1rem; font-weight: 600;
    text-decoration: none; cursor: pointer; transition: opacity 0.15s;
}
.intro-btn:hover { text-decoration: none; opacity: 0.85; }
.intro-btn-outline {
    flex: 1; background: transparent;
    border: 1px solid var(--border-secondary); color: var(--text-primary);
}
.intro-btn-accent {
    width: 100%; background: var(--accent); color: #fff; border: none;
}
.intro-lang { text-align: center; font-size: 0.85rem; color: var(--text-muted); padding: 0.5rem 0; padding-bottom: max(0.5rem, env(safe-area-inset-bottom)); display: flex; justify-content: center; gap: 0.5rem; }

/* Language switcher */
.lang-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.3rem 0.6rem; border-radius: 16px; border: 1px solid var(--border-secondary); background: transparent; color: var(--text-muted); cursor: pointer; font: inherit; font-size: 0.8rem; font-weight: 500; transition: all 0.15s; margin: 0; }
.lang-btn:hover { background: var(--hover-overlay); color: var(--text-primary); }
.lang-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.profile-lang { display: flex; align-items: center; justify-content: space-between; padding: 0.85rem 1rem; margin-bottom: 0.5rem; }
.profile-lang-btns { display: flex; gap: 0.4rem; }

/* File card in chat */
.file-card { border: 1px solid var(--border-primary); padding: 0.75rem; border-radius: 8px; background: var(--bg-secondary); max-width: 300px; }
.file-card-expired { opacity: 0.5; }
.file-card-expired .file-name { text-decoration: line-through; }
.file-card img.file-preview { max-height: 200px; max-width: 100%; border-radius: 6px; cursor: pointer; display: block; margin-bottom: 0.5rem; }
/* Media preview with reserved aspect-ratio — zero layout shift when thumb loads in. */
.file-preview-wrap {
    width: 100%;
    max-width: 300px;
    aspect-ratio: var(--ar, 1/1);
    max-height: 300px;
    overflow: hidden;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: var(--bg-primary);
    position: relative;
}
.file-preview-wrap > img.file-preview {
    width: 100%;
    height: 100%;
    object-fit: contain;
    max-height: none;
    margin: 0;
    display: block;
}
.file-preview-skeleton {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-secondary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
/* Legacy fallback: images without dimensions keep a known envelope to
   contain the shift when the thumb eventually loads. */
.file-card.has-image:not(.has-dims) { min-height: 180px; }
.file-card .passphrase-input { display: flex; gap: 0.5rem; margin-top: 0.5rem; }
.file-card .passphrase-input input { flex: 1; padding: 0.3rem 0.5rem; background: var(--bg-primary); border: 1px solid var(--border-secondary); border-radius: 4px; color: var(--text-primary); font: inherit; font-size: 0.85rem; }
.file-card .file-meta { color: var(--text-secondary); font-size: 0.85rem; }

/* New file download row inside chat bubbles */
.file-card-noframe { border: none !important; background: none !important; padding: 20px 0 !important; max-width: 322px !important; }
.file-dl-row { align-self: stretch; display: flex; justify-content: space-between; align-items: center; min-width: 0; width: 100%; max-width: 100%; }
.file-dl-row-inner { flex: 1 1 0; display: flex; justify-content: flex-start; align-items: center; min-width: 0; padding-right: 20px; }
.file-dl-btn { padding-left: 20px; padding-right: 20px; border-radius: 8px; display: flex; justify-content: center; align-items: center; cursor: pointer; flex-shrink: 0; }
.file-dl-btn svg { display: block; }
.file-dl-info { flex: 1 1 0; display: flex; flex-direction: column; min-width: 0; }
.file-dl-name { color: #F6F3F5; font-size: 14px; font-family: "Manrope", Roboto, -apple-system, sans-serif; font-weight: 700; line-height: 20px; width: 100%; min-width: 0; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-dl-size { min-height: 15px; color: white; font-size: 10px; font-family: "Manrope", Roboto, -apple-system, sans-serif; font-weight: 500; text-transform: uppercase; line-height: 15px; word-wrap: break-word; }
.file-dl-btn.downloaded svg { width: 24px; height: 32px; }
.file-dl-row-skeleton { pointer-events: none; }
.file-dl-name-skeleton { width: 152px; height: 14px; display: block; }
.file-dl-size-skeleton { width: 64px; height: 10px; display: block; }
.file-dl-btn.transfer-cancellable .dl-stop-icon { opacity: 0; transition: opacity 0.15s ease; }
.file-dl-btn.transfer-cancellable .dl-progress-text { transition: opacity 0.15s ease; }
.file-dl-btn.transfer-cancellable:hover .dl-stop-icon,
.file-dl-btn.transfer-cancellable:focus-visible .dl-stop-icon { opacity: 1; }
.file-dl-btn.transfer-cancellable:hover .dl-progress-text,
.file-dl-btn.transfer-cancellable:focus-visible .dl-progress-text { opacity: 0; }
@media (hover: none), (pointer: coarse) {
    .file-dl-btn.transfer-cancellable .dl-stop-icon { opacity: 1; }
    .file-dl-btn.transfer-cancellable .dl-progress-text { opacity: 0; }
}

/* Chat bubble: folder-preview blends with bubble bg */
.msg-bubble .folder-card.folder-preview { border: none; background: none; padding: 0; max-width: 322px; }
.msg-bubble .folder-card.folder-preview:hover { background: none; }
.msg-bubble .folder-preview-files { padding: 20px 0; gap: 15px; margin-top: 0; display: flex; flex-direction: column; align-items: stretch; width: 100%; }

.folder-card { border: 1px solid var(--border-primary); padding: 0.75rem; border-radius: 8px; background: var(--bg-secondary); max-width: 300px; }
.folder-card:hover { background: var(--hover-overlay); }

.chat-folder-card {
    width: min(322px, 100%);
    max-width: 322px;
    background: #2C2738;
    border-radius: 15px;
    overflow: hidden;
    cursor: pointer;
    outline: none;
}
.msg-row.mine .chat-folder-card {
    background: #7241FE;
}
.msg-row:not(.mine).msg-group-end .chat-folder-card {
    border-bottom-left-radius: 0;
}
.chat-folder-card:hover {
    text-decoration: none;
}
.chat-folder-card:focus-visible {
    box-shadow: 0 0 0 2px rgba(255,255,255,0.32);
}
.chat-folder-card__inner {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 20px 0;
}
.chat-folder-card__icon {
    flex: 0 0 auto;
    padding-left: 20px;
    padding-right: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-folder-card__icon svg {
    display: block;
}
.chat-folder-card__icon-svg--folder {
    width: 30px;
    height: 25px;
}
.chat-folder-card__icon-svg--lock {
    width: 27px;
    height: 29px;
}
.chat-folder-card__body {
    flex: 1 1 0;
    min-width: 0;
    padding-right: 25px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.chat-folder-card__title {
    color: #F6F3F5;
    font-size: 14px;
    font-family: Roboto, -apple-system, sans-serif;
    font-weight: 700;
    line-height: 20px;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}
.chat-folder-card__meta {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex-wrap: wrap;
}
.chat-folder-card__meta-item {
    color: #FFFFFF;
    font-size: 10px;
    font-family: Roboto, -apple-system, sans-serif;
    font-weight: 500;
    line-height: 15px;
    white-space: nowrap;
}

/* Inline folder preview (media grid + file stack) inside chat bubble */
.folder-card.folder-preview {
    display: flex;
    flex-direction: column;
    /* gap: 0.5rem; */
    padding: 0.5rem;
    max-width: 320px;
    cursor: default;
}
.folder-card.folder-preview:hover { background: var(--bg-secondary); }

.folder-preview-grid:empty { display: none; }
.folder-preview-grid {
    display: grid;
    gap: 2px;
    /* Definite intrinsic width so aspect-ratio-driven height resolves BEFORE
       thumbnails load. Without this, the grid lives inside a flex-column
       parent with only max-width, so it collapses to ~20px until images
       provide intrinsic sizing — causing a massive layout shift when they
       finally arrive. `max-width: 100%` keeps it friendly to narrow parents. */
    /*width: 300px;*/
    max-width: 100%;
    border-radius: 8px 8px 0 0;
    overflow: hidden;
    background: var(--border-primary);
}
.folder-preview-grid-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; aspect-ratio: 1/1; }
.folder-preview-grid-2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; aspect-ratio: 2/1; }
.folder-preview-grid-3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr; aspect-ratio: 3/1; }
.folder-preview-grid-4 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 1/1; }
.folder-preview-grid-5 { grid-template-columns: repeat(6, 1fr); grid-template-rows: 1fr 1fr; aspect-ratio: 3/2; }
.folder-preview-grid-5 .folder-preview-cell:nth-child(-n+2) { grid-column: span 3; }
.folder-preview-grid-5 .folder-preview-cell:nth-child(n+3) { grid-column: span 2; }
.folder-preview-grid-6 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 3/2; }
.folder-preview-grid-7 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; aspect-ratio: 1/1; }
.folder-preview-grid-7 .folder-preview-cell:nth-child(7) { grid-column: span 3; }
.folder-preview-grid-8 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; aspect-ratio: 1/1; }
/* .folder-preview-grid-8 .folder-preview-cell:nth-child(7) { grid-column: span 2; } */
.folder-preview-grid-9 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: 1fr 1fr 1fr; aspect-ratio: 1/1; }

.folder-preview-cell {
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
}
.folder-preview-cell-skeleton {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-secondary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.folder-preview-more-skeleton {
    pointer-events: none;
    opacity: 0.6;
}
.folder-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.folder-preview-video-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    color: var(--text-secondary);
    font-size: 1.5rem;
}
.folder-preview-video-placeholder .folder-preview-icon { font-size: 1.75rem; }
.folder-preview-more {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 1.4rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.folder-preview-files {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 0.25rem;
}
.folder-preview-files:empty {
    display: none;
}
.file-dl-name.filename-preserve-ext {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: baseline;
    gap: 0;
    width: 100%;
    max-width: 100%;
    text-overflow: clip;
}
.filename-stem {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.filename-dots,
.filename-ext {
    flex: 0 0 auto;
    white-space: nowrap;
}
.folder-preview-more-files {
    width: 100%;
    padding: 0.5rem;
    background: var(--bg-primary);
    border: 1px dashed var(--border-secondary);
    border-radius: 6px;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.folder-preview-more-files:hover { background: var(--hover-overlay); }

.folder-preview-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.25rem;
    font-size: 0.8rem;
}
.folder-preview-name {
    color: var(--text-secondary);
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1 1 auto;
}
.folder-preview-name:hover { color: var(--link); text-decoration: underline; }
.folder-preview-dl-all { flex: 0 0 auto; }

/* Message skeleton placeholder */
.msg-skeleton {
    height: 1em;
    width: 60%;
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-secondary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    border-radius: 4px;
}
@keyframes skeleton-pulse {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Inline auth views */
.intro-auth {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2rem 1.5rem; gap: 0.5rem; min-height: 0;
}
.intro-auth .intro-icon { margin-bottom: 0.25rem; }
.intro-auth .intro-title { margin-bottom: 0; }
.intro-auth .intro-subtitle { margin-bottom: 0.75rem; }
.intro-auth-form {
    display: flex; flex-direction: column; gap: 0.75rem;
    width: 100%; max-width: 340px;
}
.intro-auth-form input {
    display: block; width: 100%; padding: 0.85rem 1rem;
    background: transparent; border: 1px solid var(--border-secondary);
    border-radius: 12px; color: var(--text-primary); font: inherit; font-size: 1rem;
}
.intro-auth-form input::placeholder { color: var(--text-muted); }
.intro-auth-form input:focus { outline: none; border-color: var(--accent); }
.intro-auth-form .intro-btn-accent { margin-top: 0.25rem; }
.intro-error {
    padding: 0.6rem 0.75rem; border-radius: 8px;
    background: rgba(218, 54, 51, 0.15); border: 1px solid var(--danger);
    color: var(--danger-hover); font-size: 0.9rem; text-align: center;
}
.intro-switch {
    background: none; border: none; color: var(--link); cursor: pointer;
    font: inherit; font-size: 0.95rem; padding: 0.25rem; margin-top: 0.5rem;
}
.intro-switch:hover { text-decoration: underline; background: none; }
.intro-back {
    background: none; border: none; color: var(--text-muted); cursor: pointer;
    font: inherit; font-size: 0.9rem; padding: 0.25rem; margin-top: 0.25rem;
}
.intro-back:hover { color: var(--text-primary); background: none; }

/* Upload bottom sheet */
#upload-sheet-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    z-index: 100; opacity: 0; transition: opacity 0.3s;
    display: none;
}
#upload-sheet-backdrop.visible { opacity: 1; }
#upload-sheet {
    position: fixed; left: 0; right: 0; bottom: 56px;
    max-width: var(--main-max-width); margin: 0 auto;
    height: 95vh;
    background: var(--sheet-bg);
    border-radius: 16px 16px 0 0;
    z-index: 101;
    display: none;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.38s cubic-bezier(0.32, 0.72, 0, 1);
    touch-action: pan-y;
    will-change: transform;
    overflow: hidden;
}
#upload-sheet.open { display: flex; }
.sheet-handle {
    display: flex; justify-content: center; align-items: center;
    padding: 12px 0 4px; cursor: grab; flex-shrink: 0;
}
.sheet-handle-bar {
    width: 40px; height: 5px; border-radius: 3px;
    background: var(--sheet-handle);
}
.sheet-scroll {
    flex: 1; overflow-y: auto; padding: 0 16px 80px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Add files zone */
.sheet-add-files {
    position: relative;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--sheet-surface); border-radius: 14px;
    padding: 28px 16px; cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 14px;
    overflow: hidden;
}
.sheet-add-files:hover, .sheet-add-files:active {
    background: var(--sheet-surface-hover);
}
.sheet-add-files svg { width: 36px; height: 36px; margin-bottom: 8px; color: var(--sheet-text); stroke-width: 1.5; }
.sheet-add-title { font-size: 0.95rem; font-weight: 500; color: var(--sheet-text); }
.sheet-add-sub { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }
#sheet-file-input {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    opacity: 0; cursor: pointer;
    z-index: 2; font-size: 16px;
    -webkit-appearance: none;
    touch-action: auto;
}

/* Options row */
.sheet-options-row {
    display: flex; gap: 20px; margin-bottom: 14px;
    font-size: 0.82rem; color: var(--text-muted);
    justify-content: center;
}
.sheet-options-row label {
    display: inline-flex; align-items: center; gap: 6px;
    margin: 0; cursor: pointer; color: var(--text-muted);
}

/* File list */
.sheet-file-list { margin-bottom: 10px; }
.sheet-file-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--sheet-surface); border-radius: 12px;
    padding: 12px 14px; margin-bottom: 8px;
    position: relative; overflow: hidden;
}
/* Upload progress overlay — semi-transparent, width follows progress. */
.sheet-file-progress-overlay {
    position: absolute; inset: 0 auto 0 0;
    width: var(--upload-progress, 0%);
    background: rgba(114, 65, 254, 0.22);
    pointer-events: none;
    transition: width 0.12s linear;
    z-index: 1;
}
.sheet-file-progress-text {
    font-size: 0.8rem; color: var(--text-muted); flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    z-index: 2;
}
.sheet-file-item.uploaded .sheet-file-progress-overlay,
.sheet-file-item.uploaded .sheet-file-progress-text { display: none; }
.sheet-file-item > * { /*position: relative;*/ z-index: 2; }
.sheet-file-icon-wrap {
    display: flex; align-items: center; justify-content: center;
    width: 36px; height: 36px; flex-shrink: 0;
    color: var(--text-muted);
}
.sheet-file-icon-wrap svg { width: 28px; height: 28px; }
.sheet-file-info { flex: 1; min-width: 0; }
.sheet-file-name {
    font-size: 0.88rem; font-weight: 500; color: var(--sheet-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sheet-file-meta {
    font-size: 0.75rem; color: var(--text-muted); margin-top: 1px;
}
.sheet-file-remove {
    background: none; border: none; color: #e84393; cursor: pointer;
    font-size: 1.3rem; padding: 4px; line-height: 1; flex-shrink: 0;
    font-weight: 300;
}
.sheet-file-remove:hover { color: #fd79a8; background: none; }

/* Image grid */
.sheet-image-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
    margin-bottom: 16px;
}
.sheet-thumb-wrap {
    position: relative;
    overflow: hidden;
    border-radius: 10px;
}
/* Black overlay anchored to top, height shrinks as progress grows. */
.sheet-thumb-black-overlay {
    position: absolute;
    left: 0; right: 0; top: 0;
    height: calc(100% - var(--upload-progress, 0%));
    background: rgba(0, 0, 0, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    pointer-events: none;
    transition: height 0.12s linear;
    z-index: 2;
    overflow: hidden;
}
.sheet-thumb-wrap.uploaded .sheet-thumb-black-overlay { display: none; }
.sheet-thumb-remove {
    position: absolute; top: 4px; right: 4px;
    width: 22px; border-radius: 50%;
    background: rgba(220, 38, 38, 0.85); color: #fff;
    border: none; font-size: 14px; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    z-index: 3; font-weight: 900;
    pointer-events: auto;
}
.sheet-thumb-remove:hover { background: #dc2626; }
.sheet-image-thumb {
    width: 100%; aspect-ratio: 1/1; object-fit: cover;
    border-radius: 10px; background: var(--sheet-surface);
    display: block;
}
video.sheet-image-thumb { pointer-events: none; }
.sheet-thumb-play {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}
.sheet-thumb-play svg { width: 36px; height: 36px; opacity: 0.9; }
#sheet-no-compress:disabled { opacity: 1; }

/* Rejected (too large) file states */
.sheet-file-item.rejected {
    border: 2px solid #e84393;
    opacity: 0.7;
}
.sheet-file-item.rejected .sheet-file-meta {
    color: #e84393;
}
.sheet-thumb-wrap.rejected .sheet-image-thumb {
    border: 2px solid #e84393;
    opacity: 0.5;
}
.sheet-thumb-wrap .sheet-thumb-error {
    position: absolute; bottom: 4px; left: 4px; right: 4px;
    background: rgba(232, 67, 147, 0.9); color: #fff;
    font-size: 0.65rem; text-align: center;
    border-radius: 0 0 8px 8px; padding: 2px 4px;
}

/* Action buttons row */
.sheet-actions-row {
    display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap;
}
.sheet-action-btn {
    padding: 10px 16px; border-radius: 20px;
    background: transparent; border: 1.5px solid var(--sheet-border);
    color: var(--text-muted); font-size: 0.85rem;
    cursor: pointer; transition: all 0.15s;
    display: inline-flex; align-items: center; gap: 7px;
    margin: 0;
}
.sheet-action-btn svg { flex-shrink: 0; }
.sheet-action-btn:hover { border-color: var(--sheet-handle); }
.sheet-action-btn.active {
    border-color: #7241FE; background: #7241FE;
    color: var(--sheet-text);
}
.sheet-action-btn.active svg { stroke: var(--sheet-text); }
.sheet-action-btn.disabled-btn { opacity: 0.4; pointer-events: none; }

/* Shared input style — override global input styles inside sheet */
#upload-sheet input[type="text"],
#upload-sheet input[type="password"],
#upload-sheet input[type="number"],
.sheet-input {
    width: 100%; background: var(--sheet-surface) !important; border: 1px solid var(--sheet-border) !important;
    border-radius: 10px !important; padding: 12px 14px !important; color: var(--text-primary) !important;
    font: inherit; font-size: 0.88rem; margin-top: 4px;
}
#upload-sheet input::placeholder,
.sheet-input::placeholder { color: var(--text-muted); }
.sheet-section-label {
    font-size: 0.88rem; font-weight: 500; color: var(--sheet-text);
    margin-bottom: 4px;
}

/* Folder section */
.sheet-folder-section {
    margin-bottom: 16px;
}

/* Password section */
.sheet-password-section {
    margin-bottom: 16px;
}
.sheet-pp-field {
    display: flex; align-items: center; gap: 10px;
    background: var(--sheet-surface); border: 1px solid var(--sheet-border);
    border-radius: 12px; padding: 12px 14px;
    margin-bottom: 8px;
}
.sheet-pp-icon { color: var(--text-muted); flex-shrink: 0; }
.sheet-pp-input {
    flex: 1; background: none !important; border: none !important;
    color: var(--text-primary) !important; font: inherit; font-size: 0.9rem;
    outline: none; padding: 0 !important; margin: 0 !important;
    border-radius: 0 !important;
}
.sheet-pp-input::placeholder { color: var(--text-muted); }
.sheet-pp-hint {
    color: var(--text-muted); font-size: 0.78rem; flex-shrink: 0;
    font-weight: 500;
}
.sheet-pp-hint.valid { color: #2ecc71; }
.sheet-pp-match { flex-shrink: 0; width: 18px; height: 18px; }
.sheet-pp-match.match {
    color: #2ecc71;
}
.sheet-pp-match.no-match {
    color: #e74c3c;
}
.sheet-pp-warning {
    font-size: 0.78rem; color: var(--text-muted); line-height: 1.45;
    margin-top: 4px; margin-bottom: 0;
}

/* Visibility section */
.sheet-visibility-section {
    background: var(--sheet-surface); border: 1px solid var(--sheet-border); border-radius: 12px;
    padding: 12px 14px; margin-bottom: 16px;
}
.sheet-visibility-section .sheet-vis-desc-wrap { margin-top: 8px; }

/* Strategy section */
.sheet-strategy-section {
    margin-bottom: 16px;
    overflow: hidden;
    border: 1px solid #303030;
    border-radius: 12px;
}
.sheet-strategy-card {
    background: #161618;
    border-bottom: 1px solid #303030;
}
.sheet-strategy-card:last-child {
    border-bottom: none;
}
.sheet-strategy-card.is-selected {
    background: #222222;
}
.sheet-strategy-main {
    display: flex;
    align-items: center;
    gap: 15px;
    min-height: 68px;
    padding: 0 20px;
    outline: none;
}
.sheet-strategy-main[role="button"] {
    cursor: pointer;
}
.sheet-strategy-icon-wrap {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sheet-strategy-icon {
    flex-shrink: 0;
    color: #FFFFFF;
}
#sheet-strategy-card-keep.is-selected .sheet-strategy-icon,
#sheet-strategy-card-downloads.is-selected .sheet-strategy-icon {
    color: #B2A1FF;
}
.sheet-strategy-copy {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
    padding: 14px 0;
}
.sheet-strategy-title {
    color: #FFFFFF;
    font-family: Roboto, sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 20px;
    word-wrap: break-word;
}
.sheet-strategy-meta {
    display: none;
    color: #FFFFFF;
    font-family: Roboto, sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 16px;
    word-wrap: break-word;
}
.sheet-strategy-card.is-selected .sheet-strategy-meta {
    display: block;
}
.sheet-strategy-card.is-editing .sheet-strategy-meta {
    display: none;
}
.sheet-strategy-action {
    margin-left: auto;
    margin-right: -20px;
    align-self: stretch;
    display: flex;
    flex-shrink: 0;
}
.sheet-strategy-icon-btn,
.sheet-strategy-confirm-btn {
    border: 0;
    border-left: 1px solid #303030;
    background: transparent;
    color: #B5B5B5;
    padding: 0 21px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.sheet-strategy-confirm-btn {
    color: #3AED8E;
}
.sheet-strategy-picker {
    display: flex;
    align-items: center;
    height: 67px;
}
.sheet-strategy-wheel,
.sheet-strategy-static-label {
    height: 67px;
    border-left: 1px solid #303030;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    box-sizing: border-box;
    font-family: Roboto, sans-serif;
    font-size: 15px;
    font-weight: 400;
    line-height: 16px;
}
.sheet-strategy-wheel {
    width: 94px;
    flex: 0 0 94px;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    padding: 0 20px;
}
.sheet-strategy-wheel::-webkit-scrollbar {
    display: none;
}
.sheet-strategy-wheel-value {
    width: 67px;
    flex: 0 0 67px;
    padding-left: 0;
    padding-right: 0;
}
.sheet-strategy-wheel-item {
    height: 31px;
    flex: 0 0 31px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #6A6969;
    line-height: 16px;
    text-align: center;
    user-select: none;
}
.sheet-strategy-wheel-spacer {
    height: 18px;
    flex: 0 0 18px;
    pointer-events: none;
}
.sheet-strategy-wheel-item.is-selected {
    color: #FFFFFF;
}
.sheet-strategy-static-label {
    width: 94px;
    flex: 0 0 94px;
    padding: 0 20px;
    align-items: center;
    justify-content: center;
    color: #FFFFFF;
    text-align: center;
}

/* Send button disabled */
#send-btn:disabled { opacity: 0.35; pointer-events: none; }
/* File-label cross mode */
.file-upload-label.sheet-open { color: var(--text-secondary); }
#sheet-upload-status {
    text-align: center; padding: 4px 16px; font-size: 0.82rem;
    color: var(--text-secondary);
}

/* Public/Link-only badges on file cards */
.badge-public,
.badge-link-only {
    display: inline-block;
    margin-top: 0.35rem;
    padding: 0.1rem 0.45rem;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    align-self: flex-start;
}
.badge-public {
    background: rgba(46, 160, 67, 0.18);
    color: #3fb950;
    border: 1px solid rgba(46, 160, 67, 0.4);
}
.badge-link-only {
    background: rgba(139, 148, 158, 0.18);
    color: #8b949e;
    border: 1px solid rgba(139, 148, 158, 0.4);
}

/* Public folder listing */
.public-folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
}
.public-folder-card {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    overflow: hidden;
    text-decoration: none;
    color: inherit;
}
.public-folder-card:hover {
    border-color: var(--accent);
}
.public-folder-thumb {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    background: var(--bg-primary);
}
.public-folder-thumb-doc {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--text-muted);
}
.public-folder-meta {
    display: flex;
    flex-direction: column;
    padding: 0.35rem 0.5rem;
    font-size: 0.8rem;
}
.public-folder-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.public-folder-size {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* ===== Side navbar (desktop) ===== */
.side-nav {
    display: none;
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--side-nav-width);
    background: var(--bg-chat);
    border-right: 1px solid var(--border-chat);
    flex-direction: column; align-items: center;
    padding: 15px 0;
    z-index: 80;
}
.side-nav-top {
    display: flex; flex-direction: column; align-items: center;
    gap: 31px; width: 100%;
}
.side-nav-bottom {
    margin-top: auto;
    display: flex; flex-direction: column; align-items: center;
    gap: 20px; padding-bottom: 8px;
}
.side-nav-logo {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; border-radius: 12px; overflow: hidden;
}
.side-nav-logo img { border-style: solid; border-radius: 12px; border-color: #ffffff29; border-width: 1px; width: 100%; height: 100%; }
.side-nav-item {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 40px;
    color: var(--text-muted); text-decoration: none;
    transition: color 0.15s;
}
.side-nav-item svg { width: 24px; height: 24px; }
.side-nav-item[title="Chats"] svg { width: 28px; height: 26px; }
.side-nav-item:hover { color: var(--text-primary); text-decoration: none; }
.side-nav-item.active { color: var(--accent); }
.side-nav-item.active::before {
    content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
    width: 3px; height: 100%;
    background: var(--accent);
}
.side-nav-item.disabled { opacity: 0.4; pointer-events: none; }
.side-nav-avatar {
    width: 27px; height: 27px; border-radius: 50%;
    background: var(--border-secondary); font-weight: 600; font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-primary); text-decoration: none;
}
a.side-nav-avatar-link { text-decoration: none; }
a.side-nav-avatar-link:hover .side-nav-avatar { background: var(--accent); color: #fff; }
a.side-nav-avatar-link.active .side-nav-avatar { background: var(--accent); color: #fff; }
#side-theme-toggle {
    background: none; border: none; color: var(--text-muted);
    cursor: pointer; padding: 4px; display: flex; align-items: center; justify-content: center;
}
#side-theme-toggle:hover { color: var(--text-primary); }
#side-theme-toggle svg { width: 20px; height: 20px; }
/* Show moon by default (dark), swap in light */
#side-theme-toggle .side-theme-sun { display: none; }
#side-theme-toggle .side-theme-moon { display: block; }
[data-theme="light"] #side-theme-toggle .side-theme-moon { display: none; }
[data-theme="light"] #side-theme-toggle .side-theme-sun { display: block; }
@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) #side-theme-toggle .side-theme-moon { display: none; }
    :root:not([data-theme="dark"]) #side-theme-toggle .side-theme-sun { display: block; }
}

/* ===== Desktop layout: side-nav visible, tab-bar hidden ===== */
@media (min-width: 769px) {
    .side-nav { display: flex; }
    .tab-bar { display: none !important; }
    .tab-bar ~ main { padding-bottom: 0; }
    body { margin-left: var(--side-nav-width); }
    .chat-header { left: var(--side-nav-width); margin-left: 0; }
    .bottom-fixed { left: var(--side-nav-width); margin-left: 0; bottom: 0; }
    body.embed-body .bottom-fixed { left: 0; }
    .chat-area-flex { height: 100dvh; }
    .message-list { padding-bottom: 62px; }
    .incoming-call-banner { left: var(--side-nav-width); margin-left: 0; }
    .notif-prompt { left: var(--side-nav-width); margin-left: 0; }
    .install-banner { left: var(--side-nav-width); margin-left: 0; }
    #upload-sheet { left: var(--side-nav-width); margin-left: 0; bottom: 0; }
}

/* ==================== Files page: standalone split shell ==================== */
/* /web/files (non-embed) is wrapped in .files-split so the existing file-list
   panel sits on the left and an empty placeholder pane holds the future
   file-viewer on the right. /web/files?embed=1 (iframe) skips the wrapper. */
body:has(.files-split) { max-width: none; }
body:has(.files-split) main {
    /* max-width: calc(500px + 900px); */
    height: 100dvh;
    overflow: hidden;
}
.files-split {
    display: flex;
    height: 100dvh;
    width: 100%;
}
.files-split-list {
    position: relative;
    flex: 0 0 380px;
    max-width: 500px;
    width: 380px;
    min-width: 0;
    height: 100%;
    overflow-y: auto;
    border-right: 1px solid var(--border-chat);
    background: var(--bg-chat);
}
/* When files-page lives inside files-split-list or an iframe, let it stretch
   to the full pane height instead of its standalone `100vh - 56px` so an
   empty state doesn't leave a black gap at the bottom. */
body.embed-body { min-height: 100dvh; }
body.embed-body main { min-height: 100dvh; display: flex; flex-direction: column; }
body.embed-body .files-page { min-height: 100%; flex: 1 1 auto; }
.files-split-list .files-page { min-height: 100%; }
.files-split-view {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    position: relative;
    overflow: hidden;
    background: var(--bg-chat);
}
.files-split-empty {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 15px;
}
@media (max-width: 829px) {
    body:has(.files-split) main { max-width: 100%; }
    .files-split { display: block; }
    .files-split-list {
        max-width: 100%;
        flex: none;
        width: 100% !important;
        border-right: 0;
    }
    .files-split-view { display: none; }
}

/* ==================== Files page ==================== */
.files-page {
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 56px);
    position: relative;
}

.files-header {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    padding: 10px 20px;
    height: 58px;
    background: var(--bg-chat);
    border-bottom: 1px solid var(--border-chat);
}
.files-header-spacer { width: 40px; flex: 0 0 40px; }
.files-header-title {
    flex: 1;
    margin: 0;
    text-align: center;
    font-size: 18px;
    font-weight: 500;
    color: var(--text-white);
    opacity: 0.65;
    font-family: Roboto, system-ui, sans-serif;
}
.files-plus-btn,
.files-plus-btn:hover,
.files-plus-btn:focus,
.files-plus-btn:active {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    background: transparent !important;
    border: none;
    outline: none;
    box-shadow: none;
    padding: 0;
    margin: 0;
    border-radius: 0;
    text-decoration: none;
    -webkit-appearance: none;
    appearance: none;
}
.files-plus-btn svg { width: 22px; height: 22px; }
.files-plus-btn:hover { color: var(--text-white); }

.files-tabs {
    display: flex;
    height: 65px;
    background: var(--bg-chat);
    border-bottom: 1px solid var(--border-chat);
    position: sticky;
    top: 58px;
    z-index: 29;
}
.files-tab,
.files-tab:hover,
.files-tab:focus,
.files-tab:active {
    flex: 1 1 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    border: none;
    color: var(--text-white);
    cursor: pointer;
    padding: 0;
    margin: 0;
    position: relative;
    border-radius: 0;
    outline: none;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}
.files-tab svg { stroke: currentColor; fill: none; display: block; }
.files-tab--files svg { width: 18px; height: 23px; }
.files-tab--folders svg { width: 25px; height: 20px; }
.files-tab--media svg { width: 22px; height: 22px; }
.files-tab--audio svg { width: 22px; height: 22px; }
.files-tab--deleted svg { width: 20px; height: 22px; }
.files-tab[aria-selected='true'] {
    color: var(--accent);
    box-shadow: inset 0 -1px 0 0 var(--accent);
}
.files-tab:not([aria-selected='true']):hover {
    background: var(--hover-overlay) !important;
}

[data-panel][hidden] { display: none !important; }

.files-content {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    background: var(--bg-chat);
    padding-top: 10px;
    padding-bottom: 10px;
}
.files-loading, .files-empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 15px;
}

.files-list { display: flex; flex-direction: column; }
.files-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    gap: 25px;
    cursor: pointer;
    transition: background 0.15s;
}
.files-list-row:hover { background: var(--hover-overlay); }
.files-list-row.selected { background: var(--border-chat); }
.files-list-row-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.files-list-row-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    font-family: Roboto, system-ui, sans-serif;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.files-list-row-meta {
    display: flex;
    gap: 10px;
    font-size: 15px;
    color: var(--text-muted);
    font-family: Roboto, system-ui, sans-serif;
}
.files-list-row-right {
    display: flex;
    align-items: center;
    gap: 25px;
}
.files-list-row-icons {
    width: 55px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.files-list-row-icons svg { display: block; }
.files-list-row-icons svg[viewBox="0 0 13 27"] { width: 22px; height: 28px; }
.files-list-row-icons svg[viewBox="0 0 18 18"] { width: 20px; height: 20px; }
.files-list-row-size {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    width: 74px;
}
.files-list-row-size-main {
    font-size: 15px;
    color: var(--text-primary);
    text-transform: uppercase;
    font-weight: 400;
    font-family: Roboto, system-ui, sans-serif;
}
.files-list-row-size-date {
    font-size: 15px;
    color: var(--text-muted);
    font-family: Roboto, system-ui, sans-serif;
}

/* Audio-specific: leading icon */
.files-audio-icon {
    flex: 0 0 41px;
    width: 41px;
    height: 41px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-white);
}
.files-list-row.audio .files-audio-icon svg { width: 39px; height: 39px; }
.files-list-row.audio.playing .files-audio-icon {
    background: var(--text-white);
    color: #000;
    border-color: var(--text-white);
}

/* Media grid */
.files-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
    gap: 8px;
    padding: 0 8px;
}
.files-grid-tile {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-input);
    overflow: hidden;
    cursor: pointer;
}
.files-grid-tile img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.files-grid-thumb-slot {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
}
.files-grid-thumb-slot img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.files-grid-thumb-slot .thumb-loading {
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, #2a2a2a 20%, #333 40%, #2a2a2a 60%);
    background-size: 200% 100%;
    animation: files-thumb-shimmer 1.2s linear infinite;
}
@keyframes files-thumb-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.files-grid-tile .locked-cover {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-white);
}
.files-grid-tile .locked-cover { z-index: 0; }
.files-grid-tile .locked-cover svg { width: 32px; height: 40px; }
.files-grid-tile .video-play {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-white);
    pointer-events: none;
    z-index: 2;
}
.files-grid-tile .video-play svg { width: 48px; height: 48px; opacity: 0.9; }

/* Hover overlay: dim + top-row icons (lock/public) + bottom-row duration/ext. */
.files-grid-hover {
    position: absolute;
    inset: 0;
    background: rgba(7, 7, 7, 0.54);
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
    z-index: 1;
}
.files-grid-tile:hover .files-grid-hover { opacity: 1; }
.files-grid-hover-top {
    position: absolute;
    top: 9px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    gap: 11px;
    color: #fff;
}
.files-grid-hover-top svg { width: 13px; height: 14px; display: block; }
.files-grid-hover-top svg[viewBox="0 0 13 13"] { width: 13px; height: 13px; }
.files-grid-hover-bottom {
    position: absolute;
    bottom: 9px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #F6F3F5;
    font: 500 13px Roboto, system-ui, sans-serif;
}

/* Storage card — sticks to the bottom of its <main> parent so width
   follows main rather than the viewport (lets multiple mains sit side-by-side). */
.files-storage-card {
    position: sticky;
    bottom: 56px;  /* clear mobile tab-bar; desktop override below zeroes it */
    margin: 0 20px 0;
    padding: 20px;
    background: #262626;
    border-radius: 10px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, 0.40);
    z-index: 40;
}
.files-storage-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 15px;
    font-family: Roboto, system-ui, sans-serif;
    margin-bottom: 10px;
}
.files-storage-bar {
    height: 6px;
    background: #D9D9D9;
    position: relative;
    border-radius: 3px;
    overflow: hidden;
}
.files-storage-bar-fill {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s ease;
}

/* Clear-all button (Deleted tab) */
.files-clear-all-btn {
    margin: 10px 20px;
    padding: 10px 20px;
    background: var(--danger);
    color: var(--text-white);
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-family: Roboto, system-ui, sans-serif;
    cursor: pointer;
    align-self: flex-start;
}
.files-clear-all-btn:hover { background: var(--danger-hover); }

@media (min-width: 768px) {
    .files-storage-card { bottom: 0; }
}
/* Embed iframe's inner viewport is narrow (< 768px) even on desktop, so the
   mobile `bottom: 56px` rule kicks in and leaves dead space below the card.
   Force bottom: 0 regardless of inner viewport width for iframe bodies. */
body.embed-body .files-storage-card { bottom: 0; }


/* Files-mode: Upload-submit button inside the sheet */
.sheet-upload-submit {
    display: block;
    width: 100%;
    margin: 16px 0 8px;
    padding: 14px 20px;
    background: var(--accent) !important;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    font-family: Roboto, system-ui, sans-serif;
    cursor: pointer;
    text-align: center;
}
.sheet-upload-submit:hover { background: var(--accent-light) !important; }
.sheet-upload-submit:disabled { opacity: 0.5; cursor: not-allowed; }
.sheet-upload-submit[hidden] { display: none !important; }
/* Uploading state: fill the button with a darker shade up to the current % */
.sheet-upload-submit.uploading {
    background: linear-gradient(to right,
        var(--accent-light, #a78bfa) var(--upload-progress, 0%),
        var(--accent, #7241fe) var(--upload-progress, 0%)) !important;
    cursor: not-allowed;
    opacity: 1 !important;
}
