:root {
    --primary-color: #6366f1;
    /* Indigo */
    --secondary-color: #4f46e5;
    --background-color: #0f172a;
    /* Slate 900 */
    --surface-color: #1e293b;
    /* Slate 800 */
    --text-color: #f8fafc;
    /* Slate 50 */
    --text-muted: #94a3b8;
    /* Slate 400 */

    /* Safe Area Insets */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);

    --nav-height-base: 60px;
    --nav-padding-base: 0.75rem;
}


html,
body {
    margin: 0;
    padding: 0;
    width: 100vw;
    /* Fallback */
    overflow: hidden;
    /* Prevent body scroll */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
}

#app {
    position: relative;
    /* Reset from absolute */
    width: 100%;
    /* Fallback */
    height: var(--app-height);
    /* JS calculated height */
    display: flex;
    flex-direction: column;
    padding-bottom: 0;
    /* Remove padding here, handle in content */
}


/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--surface-color);
    padding-top: var(--nav-padding-base);
    padding-bottom: calc(var(--nav-padding-base) + var(--safe-area-bottom));
    z-index: 9999;
    border-top: 1px solid #333;
    height: auto;
    /* explicit height auto */
}

/* Utilities */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.2s;
}

.btn:hover {
    background-color: var(--secondary-color);
}

.btn-icon {
    background: transparent;
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem;
    transition: transform 0.1s;
}

.btn-icon:active {
    transform: scale(0.9);
}

/* TikTok-style Feed */
.snap-container {
    flex: 1;
    height: auto;
    /* Allow flex to control height */
    width: 100%;
    padding-bottom: calc(var(--nav-height-base) + var(--nav-padding-base) * 2 + var(--safe-area-bottom));
    /* Space for bottom nav */
    overflow-y: scroll;
    scroll-snap-type: y mandatory;
    scrollbar-width: none;
    background: black;
    box-sizing: border-box;
    /* Firefox */
}

.snap-container::-webkit-scrollbar {
    display: none;
    /* Chrome/Safari */
}

.snap-item {
    height: 100%;
    scroll-snap-align: start;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    padding: 1rem;
    box-sizing: border-box;
    border-bottom: 1px solid #333;
}

.snap-item img,
.snap-item video {
    max-height: 70vh;
    width: 100%;
    object-fit: contain;
    background: black;
}

/* --- Chat UI Overhaul --- */

/* Layout */
.full-height-chat {
    flex: 1;
    height: auto;
    width: 100%;
    /* padding-bottom handled by inner container or message list */
    padding-bottom: calc(var(--nav-height-base) + var(--nav-padding-base) * 2 + var(--safe-area-bottom));
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    /* Reset padding */
    background: var(--background-color);
    position: relative;
    /* Context */
    overflow: hidden;
}

/* Conversation List */
.chat-list-header {
    padding: 1rem;
    padding-top: calc(1rem + var(--safe-area-top));
    background: var(--surface-color);
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 1px solid #333;
}

.chat-list-header h1 {
    margin: 0;
    font-size: 1.5rem;
}

.chat-list-item {
    display: flex;
    align-items: center;
    padding: 1rem;
    cursor: pointer;
    border-bottom: 1px solid #1e293b;
    transition: background 0.2s;
}

.chat-list-item:hover {
    background: #1e293b;
}

.avatar-container {
    position: relative;
    margin-right: 1rem;
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-sm {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--background-color);
}

.status-dot.online {
    background: #22c55e;
}

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

.chat-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.chat-name {
    font-weight: 600;
    font-size: 1rem;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chat-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.updated-msg {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80%;
}

.badge {
    background: var(--primary-color);
    color: white;
    border-radius: 50%;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    min-width: 20px;
    text-align: center;
}

/* FAB */
.fab {
    position: fixed;
    bottom: calc(80px + var(--safe-area-bottom));
    /* Above nav bar */
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    transition: transform 0.2s;
    z-index: 20;
}

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

/* Chat Detail */
.chat-detail-header {
    display: flex;
    align-items: center;
    padding: 0.5rem 1rem;
    padding-top: calc(0.5rem + var(--safe-area-top));
    background: var(--surface-color);
    border-bottom: 1px solid #333;
    gap: 1rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.5rem;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: #0b1120;
    /* Slightly darker than background */
}

.message-bubble {
    max-width: 70%;
    padding: 0.5rem 1rem;
    border-radius: 1rem;
    position: relative;
    word-wrap: break-word;
}

.message-bubble.me {
    align-self: flex-end;
    background: #3730a3;
    /* Indigo 800 */
    border-bottom-right-radius: 0.25rem;
}

.message-bubble.them {
    align-self: flex-start;
    background: #334155;
    /* Slate 700 */
    border-bottom-left-radius: 0.25rem;
}

.msg-content {
    margin-bottom: 0.25rem;
}

.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.7);
}

.chat-input-area {
    padding: 0.75rem;
    background: var(--surface-color);
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.chat-input-area input {
    flex: 1;
    padding: 0.75rem 1rem;
    border-radius: 1.5rem;
    /* Pill shape */
    border: 1px solid #334155;
    background: var(--background-color);
    color: white;
    outline: none;
}

.send-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}