:root {
    /* Default to Light Theme */
    --shell-bg-light: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 50%, #fff9c4 100%);
    --shell-bg-dark: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --text: #222;
    --muted: #666;
    --accent: #2563eb;
    --danger: #dc2626;
    --border: #e0e0e0;
    --radius: 14px;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.1);
    --font: 'Space Grotesk', 'Helvetica Neue', Arial, sans-serif;
}

/* Dark Theme */
body.dark-mode {
    --bg: #0b0c10;
    --panel: #11131a;
    --panel-2: #161925;
    --text: #f4f6fb;
    --muted: #99a1b3;
    --accent: #6dd3ff;
    --danger: #ff7b7b;
    --border: #1f2433;
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    background: var(--shell-bg-light);
    background-attachment: fixed;
    color: var(--text);
    padding-top: 80px;
    padding-bottom: 80px;
}

body.dark-mode {
    background: var(--shell-bg-dark);
    background-attachment: fixed;
}

.page {
    max-width: 100%;
    margin: 0 auto;
    padding: 24px;
    height: calc(100vh - 160px);
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    letter-spacing: 0.4px;
}

.brand .dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), #e4f8ff);
    box-shadow: 0 0 18px rgba(109, 211, 255, 0.6);
}

.brand .title {
    font-size: 18px;
}

.auth {
    display: flex;
    gap: 10px;
}

button {
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    padding: 10px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}

button:hover {
    transform: translateY(-1px);
    border-color: var(--accent);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

button:active {
    transform: translateY(0);
}

body.dark-mode button {
    background: var(--accent);
    color: #fff;
}

button.ghost {
    background: transparent;
    border-color: var(--border);
}

button.ghost-danger {
    color: var(--danger);
    border-color: rgba(255, 123, 123, 0.4);
}

button#sync-drive {
    color: var(--accent);
    border-color: rgba(109, 211, 255, 0.5);
}

.layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    height: 100%;
    flex: 1;
}

@media (max-width: 900px) {
    .layout {
        grid-template-columns: 1fr;
        position: relative;
    }

    .layout.show-chat .panel.info {
        display: none !important;
    }

    .layout.show-chat .panel.chat {
        display: flex !important;
    }

    .layout.show-peers .panel.chat {
        display: none !important;
    }

    .layout.show-peers .panel.info {
        display: block !important;
    }

    .layout:not(.show-chat):not(.show-peers) .panel.info {
        display: block;
    }

    .layout:not(.show-chat):not(.show-peers) .panel.chat {
        display: none;
    }
}

.panel {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

body.dark-mode .panel {
    background: rgba(30, 30, 30, 0.6);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.panel.info {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.section-header {
    font-size: 13px;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    color: var(--muted);
    margin: 14px 0 8px;
}

.user-card {
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    padding: 12px;
    display: flex;
    gap: 12px;
    align-items: center;
    background: var(--panel-2);
}

.user-card img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.user-card .meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-card .name {
    font-weight: 600;
}

.user-card .email {
    color: var(--muted);
    font-size: 13px;
}

.user-card.empty {
    justify-content: center;
    color: var(--muted);
}

.start-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.input-with-button {
    display: flex;
    align-items: center;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2px;
}

.input-with-button input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: var(--text);
    font-size: 15px;
}

.input-with-button input:focus {
    outline: none;
}

.input-with-button button {
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: var(--accent);
    cursor: pointer;
    font-size: 18px;
    transition: color 0.2s ease;
    margin: 0;
    align-self: auto;
}

.input-with-button button:hover {
    color: var(--text);
    border-color: transparent;
    box-shadow: none;
    transform: none;
}

.start-form input,
.message-form input {
    width: 100%;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    color: var(--text);
    font-size: 15px;
}

.start-form button,
.message-form button {
    align-self: flex-end;
}

.notes {
    padding-left: 18px;
    color: var(--muted);
    line-height: 1.5;
    margin: 0;
}

.chat {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
}

body.dark-mode .chat {
    background: rgba(30, 30, 30, 0.6);
    backdrop-filter: blur(10px) saturate(180%);
    -webkit-backdrop-filter: blur(10px) saturate(180%);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 10px 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.back-button {
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 20px;
    padding: 4px 8px;
    transition: color 0.2s ease, transform 0.2s ease;
}

.back-button:hover {
    color: var(--text);
    transform: translateX(-2px);
    border: none;
    box-shadow: none;
}

.chat-peer {
    font-size: 18px;
    font-weight: 600;
}

.eyebrow {
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.5px;
    font-size: 12px;
}

.status {
    color: var(--muted);
    font-size: 13px;
}

.messages {
    flex: 1;
    min-height: 0;
    margin: 14px 0;
    padding-right: 6px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.messages::-webkit-scrollbar {
    width: 6px;
}

.messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb {
    background: rgba(109, 211, 255, 0.3);
    border-radius: 3px;
}

.messages::-webkit-scrollbar-thumb:hover {
    background: rgba(109, 211, 255, 0.5);
}

.messages .bubble {
    max-width: 72%;
    padding: 12px 14px;
    border-radius: 14px;
    line-height: 1.4;
    position: relative;
    border: 1px solid var(--border);
}

.messages .from-me {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--panel-2), var(--panel));
    border-color: rgba(37, 99, 235, 0.35);
}

body.dark-mode .messages .from-me {
    background: linear-gradient(135deg, #1b2334, #131a27);
    border-color: rgba(109, 211, 255, 0.35);
}

.messages .from-them {
    align-self: flex-start;
    background: var(--panel-2);
}

body.dark-mode .messages .from-them {
    background: #111522;
}

.messages .timestamp {
    display: block;
    margin-top: 6px;
    color: var(--muted);
    font-size: 12px;
}

.messages .empty {
    color: var(--muted);
    text-align: center;
    width: 100%;
    margin-top: 40px;
}

.message-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
    padding-top: 10px;
}

.message-form button {
    white-space: nowrap;
}

@media (max-width: 960px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .topbar {
        flex-direction: column;
        gap: 16px;
        align-items: flex-start;
    }

    .auth {
        width: 100%;
        flex-wrap: wrap;
        justify-content: flex-start;
        gap: 10px;
    }
}

/* Google Sign-In button container */
#google-login-container {
    min-width: 200px;
    min-height: 40px;
    display: flex;
    align-items: center;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding-left: 0.5rem;
    flex-wrap: wrap;
}

.chat-header-actions button {
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.08);
    color: #f4f6fb;
    padding: 0.35rem 0.9rem;
    font-size: 0.85rem;
}

.chat-header-actions button:hover {
    border-color: rgba(109, 211, 255, 0.6);
}

.recent-chats {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    overflow-y: auto;
    padding-right: 8px;
}

.recent-chats::-webkit-scrollbar {
    width: 6px;
}

.recent-chats::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
}

.recent-chats::-webkit-scrollbar-thumb {
    background: rgba(109, 211, 255, 0.3);
    border-radius: 3px;
}

.recent-chats::-webkit-scrollbar-thumb:hover {
    background: rgba(109, 211, 255, 0.5);
}

.recent-chats .empty {
    color: var(--muted);
    font-size: 0.9rem;
    padding: 12px 0;
}

.recent-chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.recent-chat-item:hover {
    background: rgba(109, 211, 255, 0.1);
    border-color: rgba(109, 211, 255, 0.3);
}

.recent-chat-item__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

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

.recent-chat-item__name {
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-chat-item__email {
    font-size: 0.8rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}