/* AirChat - Liquid Glass Design */

:root {
    --glass-bg: rgba(255, 255, 255, 0.45);
    --glass-bg-heavy: rgba(255, 255, 255, 0.65);
    --glass-bg-light: rgba(255, 255, 255, 0.25);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.04);
    --glass-shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.06);
    --glass-blur: 24px;
    --glass-blur-heavy: 40px;

    --accent: #007AFF;
    --accent-hover: #0066DD;
    --accent-glow: rgba(0, 122, 255, 0.25);
    --text: #1d1d1f;
    --text-secondary: rgba(0, 0, 0, 0.45);
    --text-tertiary: rgba(0, 0, 0, 0.3);
    --text-on-glass: rgba(0, 0, 0, 0.75);
    --danger: #FF3B30;
    --success: #34C759;
    --warning: #FF9500;
    --radius: 16px;
    --radius-sm: 12px;
    --radius-lg: 22px;
    --radius-pill: 100px;

    --sidebar-bg: rgba(30, 30, 35, 0.72);
    --sidebar-glass: rgba(255, 255, 255, 0.06);
    --sidebar-text: rgba(255, 255, 255, 0.85);
    --sidebar-text-dim: rgba(255, 255, 255, 0.4);
    --sidebar-active: rgba(255, 255, 255, 0.12);
    --sidebar-hover: rgba(255, 255, 255, 0.07);

    --msg-own: rgba(0, 122, 255, 0.1);
    --msg-other: rgba(0, 0, 0, 0.03);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 25%, #f093fb 50%, #4facfe 75%, #00f2fe 100%);
    background-size: 400% 400%;
    animation: gradientShift 20s ease infinite;
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* === Views === */
.view { display: none; height: 100vh; }
.view.active { display: flex; }

/* === Login === */
.login-container {
    margin: auto;
    width: 100%;
    max-width: 400px;
    padding: 44px;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow-lg);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo h1 {
    font-size: 1.7rem;
    font-weight: 700;
    margin-top: 14px;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 0.88rem;
    margin-top: 6px;
    font-weight: 400;
}

.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 7px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.form-group input {
    width: 100%;
    padding: 13px 16px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    color: var(--text);
    transition: all 0.25s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: rgba(255, 255, 255, 0.7);
}

.form-group input::placeholder { color: var(--text-tertiary); }

.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-pill);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    margin-top: 10px;
    letter-spacing: 0.01em;
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px var(--accent-glow);
    transform: translateY(-1px);
}

.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.error-msg {
    background: rgba(255, 59, 48, 0.1);
    backdrop-filter: blur(8px);
    color: var(--danger);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    margin-bottom: 12px;
    border: 1px solid rgba(255, 59, 48, 0.15);
}

/* === Chat Layout === */
.chat-layout {
    display: flex;
    height: 100vh;
    width: 100%;
    padding: 10px;
    gap: 10px;
}

/* === Sidebar === */
.sidebar {
    width: 270px;
    min-width: 270px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border-radius: var(--radius-lg);
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--glass-shadow);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.05rem;
    color: #fff;
    letter-spacing: -0.01em;
}

.sidebar-section { padding: 6px 0; }

.section-title {
    padding: 8px 18px 4px;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-text-dim);
    font-weight: 600;
}

.workspace-select {
    width: calc(100% - 24px);
    margin: 4px 12px 8px;
    padding: 9px 12px;
    background: var(--sidebar-glass);
    backdrop-filter: blur(8px);
    color: var(--sidebar-text);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    appearance: none;
    cursor: pointer;
}

.workspace-select option { background: #1e1e2e; color: #fff; }

/* People search */
.people-search-wrapper {
    position: relative;
}

.people-search-wrapper input {
    width: 100%;
    padding: 9px 12px;
    background: var(--sidebar-glass);
    backdrop-filter: blur(8px);
    color: var(--sidebar-text);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-pill);
    font-size: 0.82rem;
    outline: none;
    transition: all 0.25s ease;
}

.people-search-wrapper input::placeholder { color: var(--sidebar-text-dim); }

.people-search-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.2);
    background: rgba(255, 255, 255, 0.08);
}

.people-results {
    max-height: 240px;
    overflow-y: auto;
    margin-top: 4px;
}

.people-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s ease;
    color: var(--sidebar-text);
    font-size: 0.85rem;
}

.people-item:hover { background: var(--sidebar-hover); }

.people-item .people-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.72rem;
    flex-shrink: 0;
    position: relative;
}

.people-item .people-presence {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    border: 2px solid var(--bg-sidebar);
}

.people-item .people-presence.online { background: var(--success); }
.people-item .people-presence.offline { background: #64748b; }
.people-item .people-presence.away { background: var(--warning); }

.people-item .people-info { flex: 1; min-width: 0; }
.people-item .people-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-item .people-email { font-size: 0.7rem; color: var(--sidebar-text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.people-item .people-action {
    opacity: 0;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-pill);
    padding: 4px 10px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.people-item:hover .people-action { opacity: 1; }

.nav-list { flex: 1; overflow-y: auto; padding: 0 6px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.88rem;
    transition: all 0.2s ease;
    border-radius: var(--radius-sm);
    margin: 1px 0;
    color: var(--sidebar-text);
}

.nav-item:hover { background: var(--sidebar-hover); }

.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
}

.nav-item .prefix { opacity: 0.4; font-weight: 400; }

/* Pin toggle button in nav items */
.nav-item .pin-toggle {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--sidebar-text-dim);
    cursor: pointer;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
    flex-shrink: 0;
}
.nav-item:hover .pin-toggle { display: inline-flex; }
.nav-item .pin-toggle:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* Collapsible section */
.nav-section-toggle {
    padding: 6px 18px;
    font-size: 0.72rem;
    color: var(--sidebar-text-dim);
    cursor: pointer;
    transition: color 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
    user-select: none;
}
.nav-section-toggle:hover { color: var(--sidebar-text); }
.toggle-arrow { font-size: 0.55rem; transition: transform 0.2s; }
.nav-collapsible { animation: slideDown 0.2s ease; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.unread-badge {
    margin-left: auto;
    background: var(--accent);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: var(--radius-pill);
    min-width: 18px;
    text-align: center;
}

.presence-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 4px currentColor;
}

.presence-dot.online { background: var(--success); color: var(--success); }
.presence-dot.offline { background: rgba(255,255,255,0.2); color: transparent; box-shadow: none; }
.presence-dot.away { background: var(--warning); color: var(--warning); }

.sidebar-footer {
    padding: 14px 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
}

.user-info { display: flex; align-items: center; gap: 10px; }

.avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.82rem;
    flex-shrink: 0;
}

.icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.15rem;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    opacity: 0.6;
    transition: all 0.2s ease;
}

.icon-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* === Chat Main === */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

.chat-header {
    padding: 14px 22px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 58px;
    background: rgba(255, 255, 255, 0.3);
    backdrop-filter: blur(16px);
}

.chat-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text);
}

.chat-topic { font-size: 0.78rem; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 2px; }
.chat-header-actions .icon-btn { color: var(--text-secondary); font-size: 1rem; }

/* === Messages === */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 22px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.message {
    display: flex;
    gap: 12px;
    padding: 8px 12px;
    border-radius: var(--radius);
    transition: background 0.15s ease;
    max-width: 100%;
}

.message:hover { background: rgba(0, 0, 0, 0.03); }
.message .avatar { margin-top: 2px; width: 36px; height: 36px; font-size: 0.78rem; }

.message-content { flex: 1; min-width: 0; }

.message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 3px;
}

.message-author { font-weight: 600; font-size: 0.88rem; color: var(--text); }
.message-time { font-size: 0.72rem; color: var(--text-tertiary); }
.message-text {
    font-size: 0.92rem;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    color: var(--text-on-glass);
}
.message-edited { font-size: 0.68rem; color: var(--text-tertiary); font-style: italic; }

.message-reactions { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }

.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    background: var(--glass-bg-light);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reaction-badge:hover { background: rgba(0, 0, 0, 0.06); }
.reaction-badge.own { border-color: var(--accent); background: rgba(0, 122, 255, 0.08); }

.system-message {
    text-align: center;
    font-size: 0.78rem;
    color: var(--text-secondary);
    padding: 10px 0;
    font-style: italic;
}

.date-separator {
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-tertiary);
    padding: 14px 0;
    position: relative;
}

.date-separator::before, .date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 50px);
    height: 1px;
    background: rgba(0, 0, 0, 0.06);
}

.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

/* === Typing === */
.typing-indicator {
    padding: 4px 22px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-style: italic;
    min-height: 24px;
}

/* === Message Input === */
.message-input-container {
    padding: 12px 22px 16px;
}

.message-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: var(--radius-pill);
    padding: 5px 8px 5px 16px;
    transition: all 0.25s ease;
}

.message-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
    background: rgba(255, 255, 255, 0.7);
}

.message-input-wrapper input {
    flex: 1;
    border: none;
    background: none;
    padding: 10px 4px;
    font-size: 0.92rem;
    outline: none;
    color: var(--text);
}

.message-input-wrapper input::placeholder { color: var(--text-tertiary); }

.attach-btn { color: var(--text-secondary); font-size: 1.05rem; }

.send-btn {
    color: #fff;
    background: var(--accent);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    opacity: 1;
    transition: all 0.2s ease;
}

.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 2px 8px var(--accent-glow);
    transform: scale(1.05);
}

/* === Message Actions (hover toolbar) === */
.message-actions {
    display: none;
    position: absolute;
    top: -4px;
    right: 8px;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 0;
    box-shadow: var(--glass-shadow);
}

.message { position: relative; }
.message:hover .message-actions { display: flex; }
.message-actions button {
    background: none; border: none; cursor: pointer;
    padding: 4px 7px; border-radius: 6px; font-size: 0.85rem;
    transition: background 0.15s;
}
.message-actions button:hover { background: rgba(0,0,0,0.06); }

/* === File Preview === */
.file-preview {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: var(--glass-bg-light);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 4px;
}
.file-preview:hover { background: rgba(0,0,0,0.06); }
.file-icon { font-size: 1.3rem; }
.file-name { font-size: 0.85rem; font-weight: 500; color: var(--accent); }

/* === Context Menu === */
.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow-lg);
    padding: 6px;
    min-width: 180px;
}
.ctx-item {
    padding: 8px 14px;
    font-size: 0.85rem;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ctx-item:hover { background: rgba(0,0,0,0.05); }
.ctx-danger { color: var(--danger); }
.ctx-danger:hover { background: rgba(255,59,48,0.08); }
.ctx-divider { height: 1px; background: rgba(0,0,0,0.06); margin: 4px 8px; }

/* === Emoji Picker === */
.emoji-picker {
    position: fixed;
    z-index: 1000;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow-lg);
    padding: 12px;
    width: 310px;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 2px;
}
.emoji-item {
    font-size: 1.3rem;
    padding: 5px;
    text-align: center;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s;
}
.emoji-item:hover { background: rgba(0,0,0,0.06); transform: scale(1.2); }
.emoji-btn { color: var(--text-secondary); font-size: 1.1rem; }

/* === Thread Panel === */
.thread-panel {
    width: 360px;
    min-width: 360px;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    flex-direction: column;
    overflow: hidden;
    margin-left: 10px;
}

.thread-header {
    padding: 14px 18px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,0.3);
}
.thread-header h3 { font-size: 1rem; font-weight: 600; }

.thread-parent {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    background: rgba(0,0,0,0.02);
}
.thread-parent .message-actions { display: none !important; }

.thread-replies {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}
.thread-replies .message { padding: 6px 0; }

.thread-input-wrapper {
    padding: 12px 16px;
    border-top: 1px solid rgba(0,0,0,0.06);
    display: flex;
    gap: 8px;
    align-items: center;
}
.thread-input-wrapper input {
    flex: 1;
    padding: 10px 14px;
    background: rgba(255,255,255,0.5);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-pill);
    font-size: 0.88rem;
    outline: none;
    color: var(--text);
}
.thread-input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* === Search Panel === */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 900;
    backdrop-filter: blur(4px);
}

.search-panel, .pins-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 560px;
    max-width: 90vw;
    max-height: 70vh;
    z-index: 901;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow-lg);
    flex-direction: column;
    overflow: hidden;
}

.search-panel-header, .pins-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}
.search-panel-header input {
    flex: 1;
    padding: 10px 16px;
    background: rgba(255,255,255,0.5);
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-pill);
    font-size: 0.95rem;
    outline: none;
}
.search-panel-header input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.pins-panel-header h3 { flex: 1; font-size: 1rem; }

.search-results, .pins-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px;
}

.search-result, .pin-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    transition: background 0.15s;
}
.search-result:hover, .pin-item:hover { background: rgba(0,0,0,0.03); }
.search-result-header { display: flex; justify-content: space-between; margin-bottom: 4px; }
.search-result-header strong { font-size: 0.85rem; }
.search-result-header span { font-size: 0.75rem; color: var(--text-tertiary); }
.search-result-text, .pin-content { font-size: 0.88rem; color: var(--text-on-glass); line-height: 1.5; }

.pin-item { display: flex; justify-content: space-between; align-items: start; gap: 12px; }
.pin-unpin {
    background: none; border: 1px solid rgba(0,0,0,0.1); color: var(--text-secondary);
    padding: 4px 10px; border-radius: var(--radius-pill); font-size: 0.72rem;
    cursor: pointer; flex-shrink: 0; transition: all 0.2s;
}
.pin-unpin:hover { border-color: var(--danger); color: var(--danger); }

/* === Sidebar toggle (mobile) === */
.sidebar-toggle { display: none; }

/* === Date separator === */
.date-separator span {
    background: var(--glass-bg-heavy);
    padding: 2px 12px;
    border-radius: var(--radius-pill);
    font-size: 0.72rem;
    position: relative;
    z-index: 1;
}

/* === Toast Notification === */
.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--glass-shadow-lg);
    padding: 14px 18px;
    max-width: 340px;
    cursor: pointer;
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.4s;
    opacity: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.toast-notification.show { transform: translateX(0); opacity: 1; }
.toast-notification strong { font-size: 0.85rem; color: var(--text); }
.toast-notification span { font-size: 0.8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast-notification:hover { box-shadow: var(--glass-shadow-lg), 0 0 0 2px var(--accent-glow); }

/* === Unread indicator === */
.nav-item.has-unread { font-weight: 600; color: #fff; }
.nav-item.has-unread .prefix { opacity: 0.8; }

/* === Code blocks === */
.code-block {
    background: rgba(0,0,0,0.05);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px;
    padding: 10px 14px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.82rem;
    overflow-x: auto;
    margin: 6px 0;
    white-space: pre;
}
code {
    background: rgba(0,0,0,0.05);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.85em;
}

/* === @Mentions === */
.mention {
    color: var(--accent);
    font-weight: 500;
    background: rgba(0, 122, 255, 0.08);
    padding: 1px 4px;
    border-radius: 4px;
    cursor: pointer;
}

/* === Link Preview === */
.link-preview {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 6px 12px;
    background: var(--glass-bg-light);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent);
    font-size: 0.78rem;
}
.link-domain { color: var(--text-secondary); }
.message-text a {
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
}
.message-text a:hover { text-decoration: underline; }

/* === Inline Edit === */
.inline-edit {
    margin-top: 4px;
}
.inline-edit-input {
    width: 100%;
    padding: 8px 12px;
    background: rgba(255,255,255,0.6);
    backdrop-filter: blur(8px);
    border: 1px solid var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    outline: none;
    box-shadow: 0 0 0 3px var(--accent-glow);
    color: var(--text);
}
.inline-edit-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}
.inline-edit-save {
    padding: 4px 14px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
}
.inline-edit-save:hover { background: var(--accent-hover); }
.inline-edit-cancel {
    padding: 4px 14px;
    background: none;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    cursor: pointer;
    color: var(--text-secondary);
}
.inline-edit-cancel:hover { background: rgba(0,0,0,0.04); }
.inline-edit-hint {
    font-size: 0.68rem;
    color: var(--text-tertiary);
    margin-left: auto;
}

/* === Drag & Drop === */
.message-input-container.drag-over {
    background: rgba(0, 122, 255, 0.06);
    border: 2px dashed var(--accent);
    border-radius: var(--radius);
}
.message-input-container.drag-over::after {
    content: 'Rilascia file per inviare';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--accent);
    background: rgba(255,255,255,0.7);
    backdrop-filter: blur(8px);
    border-radius: var(--radius);
    z-index: 5;
}
.message-input-container { position: relative; }

/* === Image Preview in messages === */
.image-preview {
    margin-top: 6px;
    display: inline-block;
    max-width: 360px;
}
.image-preview img {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid rgba(0,0,0,0.06);
    transition: transform 0.2s, box-shadow 0.2s;
}
.image-preview img:hover {
    transform: scale(1.02);
    box-shadow: var(--glass-shadow);
}
.image-name {
    display: block;
    font-size: 0.72rem;
    color: var(--text-tertiary);
    margin-top: 4px;
}

/* === Image Fullscreen === */
.image-fullscreen {
    position: fixed;
    inset: 0;
    z-index: 3000;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
    cursor: zoom-out;
}
.image-fullscreen.show { opacity: 1; }
.image-fullscreen img {
    max-width: 90vw;
    max-height: 90vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: 0 16px 64px rgba(0,0,0,0.4);
}
.image-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    font-size: 1.5rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 0.2s;
}
.image-close:hover { background: rgba(255,255,255,0.3); }

/* === User Profile Panel === */
.profile-panel {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s;
}
.profile-panel.show { opacity: 1; }
.profile-panel-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    backdrop-filter: blur(4px);
}
.profile-card {
    position: relative;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow-lg);
    padding: 40px 36px 30px;
    text-align: center;
    min-width: 280px;
    z-index: 1;
}
.profile-close {
    position: absolute;
    top: 12px;
    right: 12px;
    background: none;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 6px;
}
.profile-close:hover { background: rgba(0,0,0,0.05); }
.profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0 auto 8px;
}
.profile-card h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 4px; }
.profile-email { font-size: 0.82rem; color: var(--text-secondary); margin: 2px 0; }
.profile-username { font-size: 0.78rem; color: var(--accent); margin: 2px 0; }
.profile-actions { margin-top: 18px; }
.profile-actions .btn-primary { width: auto; padding: 10px 24px; font-size: 0.85rem; }

/* === Call Buttons in header === */
.call-btn { font-size: 1rem; }
.call-btn:hover { color: var(--accent); }

/* === Incoming Call Banner === */
.incoming-call {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur-heavy));
    -webkit-backdrop-filter: blur(var(--glass-blur-heavy));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow-lg);
    padding: 18px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    min-width: 380px;
    animation: slideInDown 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes slideInDown {
    from { transform: translateX(-50%) translateY(-100px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

.incoming-call-info { display: flex; align-items: center; gap: 14px; }
.incoming-call-avatar {
    width: 48px; height: 48px; border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #5856d6);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; font-weight: 700;
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,122,255,0.4); }
    50% { box-shadow: 0 0 0 12px rgba(0,122,255,0); }
}
.incoming-call-name { font-weight: 600; font-size: 1rem; }
.incoming-call-type { font-size: 0.8rem; color: var(--text-secondary); }
.incoming-call-actions { display: flex; gap: 10px; }

.call-accept, .call-reject {
    padding: 10px 18px; border: none; border-radius: var(--radius-pill);
    font-weight: 600; font-size: 0.85rem; cursor: pointer;
    transition: all 0.2s;
}
.call-accept { background: var(--success); color: #fff; }
.call-accept:hover { background: #16a34a; transform: scale(1.05); }
.call-reject { background: var(--danger); color: #fff; }
.call-reject:hover { background: #dc2626; transform: scale(1.05); }

/* === Call Overlay (In-Call UI) === */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    background: rgba(15, 15, 20, 0.92);
    backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.call-container {
    width: 100%;
    max-width: 900px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    padding: 20px;
}

.call-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px 16px;
    color: rgba(255,255,255,0.8);
}

.call-header span { font-size: 0.9rem; }
.call-timer { font-family: 'SF Mono', monospace; font-size: 1rem; color: rgba(255,255,255,0.6); }

.call-participants-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    min-height: 0;
}

.call-participant {
    position: relative;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius-lg);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.call-participant video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-lg);
}

.call-participant.audio-only video { display: none; }
.call-participant.audio-only {
    background: linear-gradient(135deg, rgba(99,102,241,0.3), rgba(139,92,246,0.3));
}
.call-participant.audio-only::after {
    content: '🎙️';
    font-size: 3rem;
}

.call-participant-name {
    position: absolute;
    bottom: 10px;
    left: 12px;
    color: #fff;
    font-size: 0.82rem;
    font-weight: 500;
    background: rgba(0,0,0,0.5);
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    backdrop-filter: blur(8px);
}

.call-participant.muted .call-participant-name::after {
    content: ' 🔇';
}

/* Call Controls */
.call-controls {
    display: flex;
    justify-content: center;
    gap: 16px;
    padding-top: 20px;
}

.call-control-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.12);
    color: #fff;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}
.call-control-btn:hover { background: rgba(255,255,255,0.2); transform: scale(1.08); }
.call-control-btn.active { background: rgba(255,255,255,0.25); box-shadow: 0 0 0 2px rgba(255,255,255,0.3); }
.call-end-btn { background: var(--danger) !important; }
.call-end-btn:hover { background: #dc2626 !important; }

/* === Clickable elements === */
.clickable { cursor: pointer; }
.message-author.clickable:hover { text-decoration: underline; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }
.sidebar ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }

/* === Responsive === */
/* === Mobile === */
@media (max-width: 768px) {
    body { background: var(--bg-sidebar); }

    .chat-layout { padding: 0; gap: 0; }

    /* Sidebar: overlay a tutto schermo */
    .sidebar {
        width: 100%;
        min-width: 100%;
        position: fixed;
        z-index: 100;
        height: 100%;
        top: 0; left: 0;
        transform: translateX(-100%);
        transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
        border-radius: 0;
    }
    .sidebar.open { transform: translateX(0); }

    /* Chat main: niente border-radius, full screen */
    .chat-main { border-radius: 0; min-width: 100%; }

    /* Mostra hamburger */
    .sidebar-toggle { display: block; font-size: 1.3rem; margin-right: 8px; }

    /* Header compatto */
    .chat-header { padding: 10px 14px; min-height: 48px; }
    .chat-header h2 { font-size: 0.95rem; }
    .chat-header-actions .icon-btn { padding: 4px 5px; font-size: 0.95rem; }

    /* Messaggi: padding ridotto */
    .messages-container { padding: 10px 12px; }
    .message { padding: 6px 4px; }
    .message .avatar { width: 30px; height: 30px; font-size: 0.7rem; }
    .message-author { font-size: 0.82rem; }
    .message-text { font-size: 0.88rem; }
    .message-time { font-size: 0.68rem; }

    /* Actions: sempre visibili su mobile (no hover) */
    .message-actions { display: flex; position: static; background: none; border: none; box-shadow: none; padding: 0; margin-top: 4px; }
    .message-actions button { font-size: 0.75rem; padding: 2px 5px; }

    /* Input: compatto */
    .message-input-container { padding: 8px 12px 12px; }
    .message-input-wrapper { padding: 3px 6px 3px 12px; }
    .message-input-wrapper input { padding: 8px 4px; font-size: 0.88rem; }
    .send-btn { width: 32px; height: 32px; font-size: 0.9rem; }

    /* Thread: fullscreen */
    .thread-panel {
        position: fixed;
        right: 0; top: 0;
        height: 100%; width: 100%;
        margin: 0; border-radius: 0;
        z-index: 110;
        min-width: unset;
    }

    /* Search/Pins: quasi fullscreen */
    .search-panel, .pins-panel { width: 95vw; max-height: 85vh; }

    /* Login: full width */
    .login-container { padding: 24px; max-width: 100%; }

    /* Emoji picker: bottom fixed */
    .emoji-picker {
        position: fixed;
        bottom: 70px;
        left: 10px;
        right: 10px;
        width: auto;
        top: auto !important;
    }
    .emoji-grid { grid-template-columns: repeat(8, 1fr); }

    /* Context menu */
    .context-menu { min-width: 160px; }

    /* Incoming call: compact */
    .incoming-call { min-width: auto; width: calc(100% - 20px); padding: 14px 16px; }

    /* Call overlay */
    .call-participants-grid { grid-template-columns: 1fr; }
    .call-controls { gap: 12px; }
    .call-control-btn { width: 48px; height: 48px; font-size: 1.1rem; }

    /* Profile card */
    .profile-card { min-width: auto; width: calc(100vw - 40px); }

    /* Image preview */
    .image-preview { max-width: 100%; }

    /* People search */
    .people-results { max-height: 200px; }

    /* Toast */
    .toast-notification { right: 10px; left: 10px; max-width: none; transform: translateX(0) translateY(-100px); }
    .toast-notification.show { transform: translateX(0) translateY(0); }

    /* File preview */
    .file-preview { max-width: 100%; }

    /* Safe area per notch iPhone */
    .chat-header { padding-top: max(10px, env(safe-area-inset-top)); }
    .message-input-container { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .sidebar-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .call-controls { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
}

/* Small phones */
@media (max-width: 380px) {
    .chat-header-actions .call-btn { display: none; }
    .emoji-grid { grid-template-columns: repeat(6, 1fr); }
    .incoming-call { flex-direction: column; text-align: center; }
    .incoming-call-actions { justify-content: center; }
}
