:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-glass: rgba(255,255,255,0.05);
    --text-primary: #e8e8f0;
    --text-secondary: #8888aa;
    --accent: #7c5cfc;
    --accent-hover: #6a4ae0;
    --accent-glow: rgba(124,92,252,0.3);
    --danger: #ff4757;
    --success: #2ed573;
    --border: rgba(255,255,255,0.08);
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
}

#app {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}

/* Auth */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: radial-gradient(ellipse at top, rgba(124,92,252,0.15), transparent 60%),
                radial-gradient(ellipse at bottom, rgba(45,52,227,0.1), transparent 60%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 40px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
}

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

.auth-logo {
    width: 56px;
    height: 56px;
    color: var(--accent);
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 28px;
    font-weight: 700;
}

.auth-header p {
    color: var(--text-secondary);
    margin-top: 4px;
}

.auth-form { display:flex; flex-direction:column; gap:16px; }

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

.glass-input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-glass);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color 0.2s;
}

.glass-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.glass-input::placeholder { color: var(--text-secondary); opacity:0.6; }

textarea.glass-input { resize: vertical; min-height:80px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover { background: var(--accent-hover); transform:translateY(-1px); }

.btn-danger {
    background: var(--danger);
    color: white;
    width: 100%;
}

.btn-danger-outline {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    width: 100%;
}

.btn-danger-outline:hover {
    background: rgba(255,71,87,0.1);
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.btn-icon svg { width: 22px; height: 22px; }

.auth-links {
    text-align: center;
    margin-top: 20px;
}

.auth-links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
}

.auth-links a:hover { text-decoration: underline; }

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.alert-error {
    background: rgba(255,71,87,0.15);
    border: 1px solid rgba(255,71,87,0.3);
    color: var(--danger);
}

.alert-success {
    background: rgba(76,175,80,0.15);
    border: 1px solid rgba(76,175,80,0.3);
    color: #4caf50;
}

.alert button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 18px;
}

/* Messenger Layout */
.messenger-layout {
    display: flex;
    height: 100vh;
}

.sidebar {
    width: 360px;
    min-width: 360px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #45aaf2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-actions { display:flex; gap:4px; }

.spinner-sm {
    position: absolute;
    right: 28px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.htmx-indicator { opacity:0; transition:opacity 0.3s; }
.htmx-request .htmx-indicator { opacity:1; }

.stories-bar {
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    overflow-x: auto;
}

.stories-list {
    display: flex;
    gap: 16px;
    padding: 4px 0;
}

.story-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    min-width: 60px;
}

.story-item .story-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    padding: 2px;
    background: linear-gradient(45deg, var(--accent), #45aaf2);
}

.story-item .story-avatar.unseen {
    background: linear-gradient(45deg, var(--accent), #ff6b6b);
}

.story-item .story-avatar .avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    font-weight: 700;
    font-size: 18px;
    color: var(--accent);
}

.story-item .story-avatar .avatar.add-avatar {
    background: var(--accent);
    color: white;
    font-size: 22px;
    font-weight: 400;
}

.story-username {
    font-size: 11px;
    color: var(--text-secondary);
    max-width: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.conversations { flex:1; overflow-y:auto; min-height:0; }

/* Story Viewer */
.story-viewer-container {
    width: 100%;
    max-width: 420px;
    height: 90vh;
    max-height: 700px;
    background: #000;
    border-radius: var(--radius);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.story-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: linear-gradient(180deg, rgba(0,0,0,0.6), transparent);
}

.story-viewer-user {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
}

.story-viewer-user .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}

.viewer-time {
    font-size: 12px;
    opacity: 0.7;
}

.story-viewer-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 16px 16px;
    color: white;
    font-size: 18px;
    text-align: center;
    overflow: hidden;
}

.story-viewer-body img,
.story-viewer-body video {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
}

.story-viewer-nav {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0 8px;
    transform: translateY(-50%);
    pointer-events: none;
}

.story-viewer-nav .btn-icon {
    pointer-events: all;
    color: white;
    font-size: 28px;
    width: 40px;
    height: 40px;
    background: rgba(255,255,255,0.1);
    border-radius: 50%;
}

/* Story Creation */
.story-preview {
    width: 100%;
    height: 180px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border: 1px dashed var(--border);
}

.story-preview img,
.story-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.story-preview-placeholder {
    color: var(--text-secondary);
    font-size: 14px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    cursor: pointer;
    transition: background 0.15s;
}

.conversation-item:hover { background: var(--bg-glass); }

.conversation-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: var(--bg-glass);
    overflow: hidden;
}

.conversation-item .avatar img { width:100%;height:100%;object-fit:cover; }
.conversation-item .avatar span { font-weight:600;font-size:18px;color:var(--accent); }

.conversation-info { flex:1;min-width:0; }

.conversation-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.conversation-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    font-size: 12px;
    color: var(--text-secondary);
}

.badge {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    display: inline-block;
}

.status-dot.online { background: var(--success); }

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    min-height: 0;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-secondary);
}

.chat-placeholder svg { width: 80px;height:80px; }
.chat-placeholder h3 { font-size:20px;color:var(--text-primary); }

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

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

.chat-user-info .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--bg-glass);
}

.chat-actions { display:flex;gap:4px; }

.messages-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    min-height: 0;
}

.messages-container .messages {
    flex: 1;
    padding: 16px 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 0;
    scroll-behavior: smooth;
}

/* Group consecutive messages from same sender — bubble chat style */
.message {
    margin-top: 2px;
}
/* First message in a group gets rounder top corners */
.message.outgoing .message-content {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}
.message.incoming .message-content {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}
/* Singleton or first in group */
.message.outgoing:first-child .message-content,
.message.incoming + .message.outgoing .message-content {
    border-top-right-radius: 18px;
}
.message.incoming:first-child .message-content,
.message.outgoing + .message.incoming .message-content {
    border-top-left-radius: 18px;
}
.message.outgoing + .message.outgoing {
    margin-top: 1px;
}
.message.outgoing + .message.outgoing .message-content {
    border-top-right-radius: 14px;
}
.message.incoming + .message.incoming {
    margin-top: 1px;
}
.message.incoming + .message.incoming .message-content {
    border-top-left-radius: 14px;
}

/* New message slide-in */
@keyframes msgIn {
    from { opacity:0; transform:translateY(8px); }
    to   { opacity:1; transform:translateY(0); }
}
.message:last-of-type {
    animation: msgIn 0.2s ease;
}

/* Scroll-to-bottom button */
.scroll-down-btn {
    position: absolute;
    bottom: 16px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 12px var(--accent-glow);
    z-index: 5;
    transition: all 0.2s;
}
.scroll-down-btn:hover {
    transform: scale(1.08);
}
.scroll-down-btn.visible {
    display: flex;
    animation: fadeIn 0.2s ease;
}
.scroll-down-btn svg {
    width: 20px;
    height: 20px;
}

.messages-container .message-form {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    margin-bottom: 4px;
}

.message.outgoing {
    align-self: flex-end;
    align-items: flex-end;
}

.message.incoming {
    align-self: flex-start;
    align-items: flex-start;
}

.message-content {
    padding: 10px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message.outgoing .message-content {
    background: var(--accent);
    color: white;
}

.message.incoming .message-content {
    background: var(--bg-secondary);
}

.message-media {
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
}

.message-media img,
.message-media video {
    max-width: 300px;
    max-height: 400px;
}

.message-media img,
.message-media video {
    width: 100%;
    display: block;
}

.message-media audio { width:100%; }

.voice-message {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 180px;
    cursor: pointer;
    user-select: none;
}

.voice-circle {
    position: relative;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

.voice-circle svg {
    width: 100%;
    height: 100%;
    transform: rotate(-90deg);
}

.voice-track {
    fill: none;
    stroke: rgba(255,255,255,0.15);
    stroke-width: 3;
}

.voice-progress {
    fill: none;
    stroke: currentColor;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 119.38;
    stroke-dashoffset: 119.38;
    transition: stroke-dashoffset 0.3s linear;
}

.message.outgoing .voice-track { stroke: rgba(255,255,255,0.25); }
.message.incoming .voice-track { stroke: rgba(255,255,255,0.15); }

.voice-icon {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    pointer-events: none;
}

.voice-time, .voice-dur {
    font-size: 13px;
    opacity: 0.7;
    font-variant-numeric: tabular-nums;
}

.voice-dur::before {
    content: '/';
    margin: 0 4px;
    opacity: 0.4;
}

.message.outgoing .voice-time,
.message.outgoing .voice-dur { color: rgba(255,255,255,0.8); }
.message.incoming .voice-time,
.message.incoming .voice-dur { color: var(--text-secondary); }

/* Avatar Upload */
.avatar-upload {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    overflow: hidden;
    position: relative;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Profile Modal */
#profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-glass);
    font-size: 32px;
    font-weight: 700;
    color: var(--accent);
    overflow: hidden;
}

#profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-status .status-dot {
    width: 10px;
    height: 10px;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
    padding: 0 4px;
}

.message.outgoing .message-meta { justify-content: flex-end; }

.message-actions {
    display: none;
    gap: 4px;
    margin-top: 2px;
}

.message:hover .message-actions {
    display: flex;
}

.msg-action {
    font-size: 12px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s;
}

.msg-action:hover { opacity: 1; }

/* Sidebar search bar — tabs stacked above search input */
.sidebar > .search-bar {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

/* Chat search bar — input + button in a row */
#search-bar.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-bar .glass-input {
    flex: 1;
}

.search-results-info {
    padding: 8px 16px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-glass);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}    

.message.encrypted .message-content::before {
    content: '🔒 ';
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 20px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-secondary);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay:0.2s; }
.typing-indicator span:nth-child(3) { animation-delay:0.4s; }

@keyframes typing {
    0%,60%,100% { opacity:0.3;transform:translateY(0); }
    30% { opacity:1;transform:translateY(-4px); }
}

.message-input {
    flex: 1;
    padding: 10px 16px;
    border-radius: 24px;
}

.btn-send {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
}

/* Voice Recording */
#mic-btn {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
    flex-shrink: 0;
}

#mic-btn.recording {
    background: var(--danger);
    color: white;
    animation: micPulse 1s infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(255,71,87,0.6); }
    50% { box-shadow: 0 0 0 8px rgba(255,71,87,0); }
}

#mic-btn svg {
    width: 20px;
    height: 20px;
}

.recording-timer {
    font-family: monospace;
    font-size: 14px;
    color: var(--danger);
    flex-shrink: 0;
    min-width: 36px;
    text-align: center;
}

.btn-send svg { width: 20px;height:20px; }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(4px);
}

.modal {
    width: 100%;
    max-width: 480px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-body hr { border:none;border-top:1px solid var(--border); }

/* Loading & Empty */
.loading, .empty-state, .empty-messages {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--text-secondary);
    font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* Sidebar Tabs */
.sidebar-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    transition: all 0.2s;
}

.tab.active {
    background: var(--accent);
    color: white;
}

.tab:hover:not(.active) {
    background: var(--bg-glass);
}

/* ============================
   Call Overlay — fullscreen UI
   ============================ */
.call-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f0f1a 0%, #1a1a2e 40%, #16213e 100%);
    animation: callFadeIn 0.3s ease;
}
@keyframes callFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes callPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99,102,241,0.5); }
    50%      { box-shadow: 0 0 0 20px rgba(99,102,241,0); }
}

/* Remote video — fills the screen behind */
.call-remote-wrap {
    position: absolute;
    inset: 0;
    overflow: hidden;
    background: #000;
}
.call-remote-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Glass content layer */
.call-content {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    width: 100%;
    max-width: 400px;
}

/* Avatar ring */
.call-avatar-ring {
    width: 128px;
    height: 128px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: callPulse 2s infinite;
    margin-bottom: 8px;
}
.call-avatar-ring .avatar {
    width: 118px;
    height: 118px;
    font-size: 48px;
    font-weight: 700;
    border: 3px solid var(--bg);
}

/* Caller info */
.call-name {
    font-size: 26px;
    font-weight: 700;
    color: #fff;
    margin: 0;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.call-status {
    font-size: 14px;
    color: rgba(255,255,255,0.6);
    margin: 0;
    letter-spacing: 0.3px;
}

/* Call timer */
.call-timer {
    font-size: 16px;
    color: rgba(255,255,255,0.8);
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    display: none;
}

/* Controls row */
.call-controls {
    display: flex;
    gap: 20px;
    margin-top: 32px;
    align-items: center;
}

.call-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(8px);
    color: #fff;
    position: relative;
}
.call-btn:hover {
    background: rgba(255,255,255,0.18);
    transform: scale(1.05);
}
.call-btn:active {
    transform: scale(0.95);
}
.call-btn svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}
.call-btn.active {
    background: rgba(99,102,241,0.35);
}

.call-btn-end {
    width: 64px;
    height: 64px;
    background: #ef4444;
}
.call-btn-end:hover {
    background: #dc2626 !important;
}

/* Muted indicator */
.call-btn.muted {
    background: rgba(239,68,68,0.25);
}

/* Local video PiP */
.call-pip {
    position: absolute;
    top: 24px;
    right: 24px;
    width: 140px;
    height: 200px;
    border-radius: 16px;
    overflow: hidden;
    border: 2px solid rgba(255,255,255,0.15);
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 3;
    background: #1a1a2e;
    cursor: pointer;
    transition: all 0.3s ease;
}
.call-pip:hover {
    transform: scale(1.03);
}
.call-pip video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.call-pip .pip-label {
    position: absolute;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255,255,255,0.4);
    background: rgba(0,0,0,0.5);
    padding: 2px 8px;
    border-radius: 6px;
}

/* Remote muted badge */
.call-muted-badge {
    position: absolute;
    bottom: -4px;
    right: -4px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 3px solid var(--bg);
    z-index: 5;
}
.call-muted-badge svg {
    width: 16px;
    height: 16px;
}

/* Incoming call modal */
.call-incoming-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #0f0f1a 0%, #1a1a2e 50%, #16213e 100%);
    animation: callSlideUp 0.4s ease;
}
@keyframes callSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

.call-incoming-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px;
}

.call-incoming-label {
    font-size: 15px;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin: 0;
}

.call-incoming-actions {
    display: flex;
    gap: 40px;
    margin-top: 24px;
}

.call-btn-answer {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #22c55e;
    color: #fff;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(34,197,94,0.4);
}
.call-btn-answer:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(34,197,94,0.5);
}
.call-btn-answer:active {
    transform: scale(0.95);
}
.call-btn-answer svg {
    width: 32px;
    height: 32px;
}

.call-btn-reject {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ef4444;
    color: #fff;
    transition: all 0.2s ease;
    box-shadow: 0 4px 20px rgba(239,68,68,0.3);
}
.call-btn-reject:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(239,68,68,0.4);
}
.call-btn-reject:active {
    transform: scale(0.95);
}
.call-btn-reject svg {
    width: 32px;
    height: 32px;
}

/* Unread conversation */
.conversation-item.unread {
    background: rgba(124,92,252,0.05);
}

/* Animations */
@keyframes spin { to { transform: translateY(-50%) rotate(360deg); } }

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

.htmx-request .btn-primary {
    opacity: 0.7;
    pointer-events: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
    }
    .sidebar.hidden-mobile {
        display: none;
    }
    .chat-area {
        width: 100%;
    }
    .chat-area.hidden-mobile {
        display: none;
    }
    .back-btn {
        display: flex !important;
    }
}

.back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    padding: 0 8px 0 0;
}

/* Error Toast */
.error-toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius);
    z-index: 9999;
    font-size: 14px;
    animation: toastIn 0.3s ease;
    max-width: 90vw;
    text-align: center;
}

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

/* Loading spinner */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--text-secondary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Date separator */
.date-separator {
    text-align: center;
    padding: 12px 0 8px;
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.date-separator span {
    background: var(--bg-secondary);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Floating new chat button — moved OUT of scrollable area via fixed */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 24px;
    cursor: pointer;
    box-shadow: 0 4px 16px var(--accent-glow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: transform 0.2s;
}

.fab:hover {
    transform: scale(1.1);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
}

/* Conversations container — needs room for FAB at bottom */
.conversations {
    padding-bottom: 72px;
}
