/* ── Design tokens ─────────────────────────────── */
:root {
    --bg:                  #0c0a1a;
    --surface:             rgba(20, 16, 40, 0.6);
    --surface-hover:       rgba(255,255,255,0.04);
    --border:              rgba(255,255,255,0.08);
    --accent:              #8b5cf6;
    --accent-dark:         #7c3aed;
    --accent-glow:         rgba(139,92,246,0.25);
    --cyan:                #06b6d4;
    --green:               #10b981;
    --red:                 #ef4444;
    --text-1:              #f3f4f6;
    --text-2:              #9ca3af;
    --text-3:              #6b7280;
    --bubble-user:         rgba(139,92,246,0.22);
    --bubble-ai:           rgba(255,255,255,0.04);
    --radius-sm:           8px;
    --radius-md:           14px;
    --radius-lg:           20px;
    --shadow-panel:        0 20px 60px rgba(0,0,0,0.5);
    --font-display:        'Outfit', sans-serif;
    --font-sans:           'Inter', sans-serif;
    --sidebar-w:           260px;
    --sidebar-collapsed-w: 60px;
    --transition:          0.25s ease;
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; overflow: hidden; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text-1);
    height: 100%;
    overflow: hidden;
    display: flex;
}

/* ── Background glows ──────────────────────────── */
body::before,
body::after {
    content: '';
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    pointer-events: none;
    z-index: 0;
}
body::before {
    width: 45vw; height: 45vw;
    background: var(--accent);
    opacity: 0.18;
    top: -10%; left: -10%;
}
body::after {
    width: 50vw; height: 50vw;
    background: var(--cyan);
    opacity: 0.12;
    bottom: -15%; right: -10%;
}

/* ── Auth overlay ──────────────────────────────── */
#auth-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(8, 6, 20, 0.92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    transition: opacity var(--transition), visibility var(--transition);
}
#auth-screen.hidden,
.authed #auth-screen {
    display: none;
}

.auth-logo {
    font-family: var(--font-display);
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: 800;
    letter-spacing: 6px;
    background: linear-gradient(135deg, #fff 0%, var(--accent) 50%, var(--cyan) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}
.auth-subtitle {
    color: var(--text-2);
    font-size: clamp(0.85rem, 2vw, 1rem);
    max-width: 380px;
    line-height: 1.7;
    margin-bottom: 40px;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: clamp(24px, 5vw, 40px);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: var(--shadow-panel);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.auth-card label {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-3);
    letter-spacing: 1.2px;
    text-transform: uppercase;
}
.uuid-input {
    width: 100%;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    color: var(--text-1);
    font-family: 'Courier New', monospace;
    font-size: 0.9rem;
    outline: none;
    text-align: left;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.uuid-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
.uuid-input::placeholder { color: var(--text-3); }
.auth-btn {
    padding: 14px;
    border-radius: var(--radius-sm);
    border: none;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: #fff;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: filter var(--transition), transform var(--transition), box-shadow var(--transition);
    box-shadow: 0 6px 20px var(--accent-glow);
}
.auth-btn:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
    box-shadow: 0 10px 28px var(--accent-glow);
}
.auth-btn:active { transform: translateY(0); }
.auth-error {
    font-size: 0.8rem;
    color: var(--red);
    min-height: 18px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ── App shell — full screen ───────────────────── */
#app {
    position: relative;
    z-index: 1;
    flex: 1;
    height: 100%;
    display: flex;
    overflow: hidden;
    background: var(--surface);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* ── Sidebar ───────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: rgba(8, 6, 20, 0.45);
    overflow: hidden;
    transition: width var(--transition), min-width var(--transition);
}

/* Prevent text wrapping during width transition */
.sidebar-logo, .nav-item, .nav-label, .history-item,
.history-item-title, .logout-btn, .section-label,
.conn-label, .uid-badge {
    white-space: nowrap;
}

/* ── Icon zone: fixed 60px column, always centered ─ */
.nav-icon-zone {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ── Labels/body: fade OUT fast, fade IN delayed (after width) ── */
.sidebar-logo {
    position: absolute;     /* out of flex flow — never moves, only fades */
    left: 14px;
    top: 6px;               /* (44px content - 32px logo) / 2 — explicit avoids sub-pixel issues */
    width: 32px;
    height: 32px;
    overflow: hidden;
    transition: opacity 0.15s ease 0.18s; /* expand: same timing as text labels */
}
.nav-label, .conn-label, .uid-badge, .section-label {
    transition: opacity 0.15s ease 0.18s;
    overflow: hidden;
    white-space: nowrap;
}
.sidebar-body {
    transition: opacity 0.15s ease 0.18s;
}

/* ── Sidebar: collapsed state ──────────────────── */
#sidebar.collapsed {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
}

#sidebar.collapsed .sidebar-logo {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.1s ease; /* same timing as text labels */
}
#sidebar.collapsed .nav-label,
#sidebar.collapsed .conn-label,
#sidebar.collapsed .uid-badge,
#sidebar.collapsed .section-label {
    opacity: 0; pointer-events: none;
    transition: opacity 0.1s ease;
}
#sidebar.collapsed .sidebar-body {
    opacity: 0; pointer-events: none;
    transition: opacity 0.1s ease;
}

/* Nav item: icon zone stays 60px, no dimension changes.
   NO justify-content:center here — that would move the icon to the center of the
   260px sidebar at the moment the class is applied, before the width animates. */
#sidebar.collapsed .nav-item {
    padding: 0;
    border-radius: 0;
    background: none;
    position: relative;
}

/* Circular hover via ::before — left:12px is px (not %), so the circle stays
   at x=30px even while the sidebar width is still animating */
#sidebar.collapsed .nav-item::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s ease;
    pointer-events: none;
}
#sidebar.collapsed .nav-item:hover { background: none; }
#sidebar.collapsed .nav-item:hover::before { background: var(--surface-hover); }

/* Footer — padding:8px 0 same as base, no override needed */
#sidebar.collapsed .connection-block   { border-bottom: none; }
#sidebar.collapsed .logout-btn {
    padding: 0;
    border-radius: 0;
    position: relative;
    /* NO justify-content:center — same reason as nav-item */
}
#sidebar.collapsed .logout-btn::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    transition: background 0.15s ease;
    pointer-events: none;
}
#sidebar.collapsed .logout-btn:hover { background: none; color: #f87171; }
#sidebar.collapsed .logout-btn:hover::before { background: rgba(239,68,68,0.1); }

/* ── Sidebar header ────────────────────────────── */
.sidebar-head {
    height: 45px;       /* fixed — same in both states, no vertical jump */
    padding: 0;         /* no padding in either state → no instant layout change on toggle */
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    flex-shrink: 0;
    position: relative; /* containing block for absolutely-positioned logo */
}

/* 60px fixed zone with margin-left:auto — slides with sidebar right edge during animation.
   In collapsed (60px): auto-margin=0, zone fills header, toggle centered at x=30.
   margin-right:8px gives breathing room from sidebar border in expanded state;
   in collapsed it just adds 8px after the zone (sidebar clips it, invisible). */
.sidebar-head-btns {
    width: var(--sidebar-collapsed-w);
    min-width: var(--sidebar-collapsed-w);
    margin-left: auto;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    line-height: 0;
    transition: color var(--transition), background var(--transition);
    flex-shrink: 0;
}
.icon-btn:hover { color: var(--text-1); background: var(--surface-hover); }

/* Desktop: toggle visible, close hidden */
.sidebar-toggle { display: flex; }
.sidebar-close  { display: none; }

/* ── Sidebar nav ───────────────────────────────── */
.sidebar-nav {
    /* No horizontal padding: nav-icon-zone (60px) at x=0 → icon center at x=30px
       Same in collapsed state — icons never jump position during animation */
    padding: 8px 0;
    flex-shrink: 0;
}

.nav-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0;
    height: 44px;
    padding: 0 10px 0 0;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    transition: background var(--transition), color var(--transition);
}
.nav-item:hover {
    background: rgba(139,92,246,0.12);
    color: var(--text-1);
}

/* ── Sidebar body (history) ────────────────────── */
.sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}
.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
}

.section-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-3);
    padding: 0 6px 0 10px;
    margin-bottom: 4px;
    flex-shrink: 0;
}

/* ── History items ─────────────────────────────── */
#history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-item {
    width: 100%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    cursor: pointer;
    text-align: left;
    overflow: visible;
    transition: background var(--transition), color var(--transition);
}
.history-item > svg { flex-shrink: 0; opacity: 0.6; }
.history-item-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}
.history-item:hover {
    background: var(--surface-hover);
    color: var(--text-1);
}
.history-item:hover > svg { opacity: 1; }
.history-item.active {
    background: rgba(139,92,246,0.12);
    color: var(--text-1);
    border: 1px solid rgba(139,92,246,0.2);
}
.history-item.active > svg { opacity: 1; color: var(--accent); }

.history-menu-btn {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-3);
    cursor: pointer;
    padding: 3px 4px;
    border-radius: 5px;
    line-height: 0;
    opacity: 0;
    transition: opacity var(--transition), background var(--transition), color var(--transition);
}
.history-item:hover .history-menu-btn,
.history-item.active .history-menu-btn { opacity: 1; }
.history-menu-btn:hover { background: rgba(255,255,255,0.1); color: var(--text-1); }

.history-dropdown {
    display: none;
    position: absolute;
    right: 4px;
    top: calc(100% + 2px);
    background: #1a1530;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    z-index: 200;
    min-width: 140px;
    padding: 4px;
}
.history-dropdown.open { display: block; }
.history-dropdown-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border: none;
    background: none;
    color: var(--text-2);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    cursor: pointer;
    border-radius: 6px;
    transition: background var(--transition), color var(--transition);
}
.history-dropdown-item:hover { background: var(--surface-hover); color: var(--text-1); }
.history-dropdown-item.delete-item:hover { background: rgba(239,68,68,0.12); color: var(--red); }

.history-rename-input {
    flex: 1;
    background: rgba(255,255,255,0.08);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text-1);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    padding: 2px 6px;
    outline: none;
    min-width: 0;
}

.history-empty {
    font-size: 0.78rem;
    color: var(--text-3);
    padding: 8px 10px;
    font-style: italic;
    white-space: nowrap;
}

/* ── Sidebar footer ────────────────────────────── */
.sidebar-footer {
    border-top: 1px solid var(--border);
    /* padding: 8px 0 in BOTH states — footer height never changes, border-top never moves */
    padding: 8px 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.connection-block {
    padding: 4px 0;
    display: flex;
    align-items: center;
}
.user-info {
    display: flex;
    flex-direction: column;
    gap: 3px;
    overflow: hidden;
}
.conn-label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-3);
}
.user-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 0.72rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.12);
}
.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.uid-badge {
    font-family: 'Courier New', monospace;
    font-size: 0.7rem;
    color: var(--text-3);
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: fit-content;
    max-width: 100%;
}

.logout-btn {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-3);
    /* height: 44px in BOTH states — footer height stays constant, border-top never moves */
    height: 44px;
    padding: 0 10px 0 0;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0;
    transition: background var(--transition), color var(--transition);
    white-space: nowrap;
}
.logout-btn:hover {
    background: rgba(239,68,68,0.14);
    color: #f87171;
}

/* ── Chat workspace ────────────────────────────── */
#chat-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* ── Empty state: input + welcome centered ─────── */
#chat-workspace:not(.has-messages) {
    justify-content: center;
    align-items: center;
    padding-bottom: 12vh;
}
#chat-workspace:not(.has-messages) .chat-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    border-bottom: none;
    background: transparent;
}
#chat-workspace:not(.has-messages) #messages {
    flex: 0 0 auto;
    overflow: visible;
    padding: 0;
    width: min(680px, calc(100% - 48px));
}
#chat-workspace:not(.has-messages) #empty-state {
    padding: 0 0 24px;
}
#chat-workspace:not(.has-messages) #input-area {
    border-top: none;
    width: min(680px, calc(100% - 48px));
    padding: 0;
}

.chat-topbar {
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.menu-btn {
    display: none;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-2);
    border-radius: var(--radius-sm);
    padding: 7px;
    cursor: pointer;
    line-height: 0;
    transition: color var(--transition), border-color var(--transition);
    flex-shrink: 0;
}
.menu-btn:hover { color: var(--text-1); border-color: var(--accent); }

.chat-title-block { flex: 1; min-width: 0; }
.chat-title-block h2 {
    font-family: var(--font-display);
    font-size: clamp(0.95rem, 2.5vw, 1.1rem);
    font-weight: 600;
    color: var(--text-1);
}

/* ── Messages ──────────────────────────────────── */
#messages {
    flex: 1;
    overflow-y: auto;
    padding: 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    scroll-behavior: smooth;
    min-height: 0;
}
#messages::-webkit-scrollbar { width: 5px; }
#messages::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
}

/* Empty state */
#empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-2);
}
#empty-state h3 {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 3vw, 2rem);
    font-weight: 600;
    color: var(--text-1);
}

/* Bubbles */
.msg {
    display: flex;
    flex-direction: column;
    gap: 0;
    animation: slide-up 0.3s ease forwards;
}
@keyframes slide-up {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.msg.user  { align-self: flex-end; max-width: min(72%, 560px); }
.msg.ai    { align-self: flex-start; max-width: min(88%, 760px); }

.msg-label { display: none; }

.msg-bubble {
    font-size: 0.9rem;
    line-height: 1.7;
    word-break: break-word;
}
.msg.user .msg-bubble {
    background: var(--bubble-user);
    border: 1px solid rgba(139,92,246,0.28);
    border-radius: var(--radius-md);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px rgba(139,92,246,0.1);
    padding: 10px 15px;
    white-space: pre-wrap;
}
.msg.ai .msg-bubble {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    white-space: normal;
    color: var(--text-1);
}
.msg-bubble.error {
    background: rgba(239,68,68,0.08);
    border-color: rgba(239,68,68,0.25);
    color: #fca5a5;
    font-size: 0.85rem;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}
.msg-bubble.error svg { flex-shrink: 0; margin-top: 1px; }

/* Typing indicator */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 18px;
}
.dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: pulse 1.4s infinite ease-in-out;
}
.dot:nth-child(2) { animation-delay: .2s; }
.dot:nth-child(3) { animation-delay: .4s; }
@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
    40%           { transform: scale(1);   opacity: 1; }
}
.typing-status {
    font-size: 0.8rem;
    color: var(--text-3);
    margin-left: 6px;
    animation: fade-status 0.4s ease;
}
@keyframes fade-status {
    from { opacity: 0; transform: translateY(3px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Markdown inside AI bubbles ───────────────── */
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble strong { color: var(--text-1); font-weight: 600; }
.msg-bubble em { color: var(--text-2); font-style: italic; }
.msg-bubble ul, .msg-bubble ol {
    padding-left: 18px;
    margin: 6px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.msg-bubble li { line-height: 1.5; }
.msg-bubble code {
    font-family: 'Courier New', monospace;
    font-size: 0.82em;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 1px 6px;
}
.msg-bubble pre {
    background: rgba(0,0,0,0.35);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    overflow-x: auto;
    margin: 8px 0;
}
.msg-bubble pre code {
    background: none; border: none;
    padding: 0; font-size: 0.85em;
}

/* ── Input area ────────────────────────────────── */
#input-area {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.input-disclaimer {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-3);
    padding-top: 8px;
    display: none;
}
#chat-workspace.has-messages .input-disclaimer { display: block; }

.input-row {
    position: relative;
    display: flex;
    align-items: flex-end;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.04);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}
#chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: 11px 52px 11px 16px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-1);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    outline: none;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.1) transparent;
}
#chat-input::placeholder { color: var(--text-3); }
#chat-input::-webkit-scrollbar { width: 4px; }
#chat-input::-webkit-scrollbar-track { background: transparent; }
#chat-input::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

#send-btn {
    position: absolute;
    right: 8px;
    bottom: 8px;
    transform-origin: right bottom;
    width: 32px; height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px var(--accent-glow);
    opacity: 0;
    pointer-events: none;
    transform: scale(0.75);
    transition: opacity 0.15s ease, transform 0.15s ease, background var(--transition), box-shadow var(--transition);
}
#send-btn.visible {
    opacity: 1;
    pointer-events: auto;
    transform: scale(1);
}
#send-btn:hover {
    background: var(--accent-dark);
    box-shadow: 0 6px 20px var(--accent-glow);
    transform: scale(1) translateY(-1px);
}
#send-btn:active { transform: scale(1) translateY(0); }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: scale(1); }


/* ── Mobile overlay backdrop ───────────────────── */
#sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 50;
}

/* ── Responsive ────────────────────────────────── */
@media (max-width: 640px) {
    /* Remove backdrop-filter so #app doesn't create a stacking context
       that traps the fixed sidebar inside it */
    #app {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: var(--bg);
        isolation: auto;
    }

    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        z-index: 60;
        transform: translateX(-100%);
        width: 280px; min-width: 280px;
        border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
        box-shadow: 4px 0 40px rgba(0,0,0,0.5);
        background: #252060;
        border-right: 1px solid rgba(139, 92, 246, 0.2);
        transition: transform var(--transition);
        contain: none;
    }
    #sidebar.open  { transform: translateX(0); }
    #sidebar.collapsed { width: 280px; min-width: 280px; }

    #sidebar-backdrop {
        z-index: 50;
    }
    #sidebar-backdrop.open { display: block; }

    .sidebar-toggle { display: none; }
    .sidebar-close  { display: none !important; }
    .menu-btn       { display: flex !important; }

    /* Logo: vuelve al flujo flex en mobile (no es absolute) */
    #sidebar .sidebar-logo { position: static; transform: none; }
    #sidebar .sidebar-head { justify-content: flex-start; padding: 14px; height: auto; }
    #sidebar .sidebar-head-btns { display: none; }

    /* On mobile sidebar is always expanded — undo ALL collapsed overrides */
    #sidebar.collapsed .sidebar-logo { opacity: 1; pointer-events: auto; }
    #sidebar.collapsed .nav-label,
    #sidebar.collapsed .conn-label,
    #sidebar.collapsed .uid-badge,
    #sidebar.collapsed .section-label {
        opacity: 1;
        pointer-events: auto;
        display: revert;
    }
    #sidebar.collapsed .sidebar-body { display: flex; }
    #sidebar .nav-item { justify-content: flex-start; padding: 9px 10px; margin: 0; }
    #sidebar .sidebar-footer { padding: 12px 10px; }
    #sidebar .connection-block { border-bottom: none; padding: 4px 6px; }
    #sidebar .connection-block { justify-content: flex-start; }
    #sidebar .logout-btn { justify-content: flex-start; padding: 9px 10px; border: none; width: 100%; }

    .msg { max-width: 88%; }
    #messages { padding: 16px 14px; }
    .chat-topbar { padding: 12px 14px; }
    #input-area { padding: 12px 14px; }
    .input-hint { display: none; }
}

@media (max-width: 360px) {
    .auth-logo { font-size: 2.8rem; }
    .auth-card { padding: 20px; }
}
