/* ================= RESET ================= */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html,
body {
    height: 100%;
    overscroll-behavior: none;
}

/* ================= BODY ================= */
body {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    color: #e5e7eb;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ================= CONTAINER ================= */
.container {
    width: 100%;
    max-width: 1200px;
    height: 92vh;
    background: rgba(15, 23, 42, 0.97);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 24px;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

/* ================= HEADER ================= */
.container h2 {
    padding: 20px 24px;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.025em;
    flex-shrink: 0;
}

/* ================= SIDEBAR ================= */
#sidebar {
    width: 280px;
    background: rgba(15, 23, 42, 0.95);
    border-right: 1px solid rgba(148, 163, 184, 0.1);
    display: none;
    flex-direction: column;
}

.sidebar-header {
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

#chatList {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 14px 20px;
    cursor: pointer;
    border-bottom: 1px solid rgba(148, 163, 184, 0.05);
    font-size: 0.9375rem;
    transition: background-color 0.2s ease;
}

.chat-item:hover {
    background: rgba(56, 189, 248, 0.08);
}

/* ================= CHAT (CENTER COLUMN) ================= */
#chat {
    flex: 1;
    display: none;
    flex-direction: column;
    padding: 24px 0;
    min-height: 0;
}

/* ================= MESSAGES ================= */
#messages {
    flex: 1;
    max-width: 680px;
    margin: 0 auto;
    padding: 28px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 20px;
}

/* ================= MESSAGE BUBBLES ================= */
#messages p {
    max-width: 75%;
    padding: 16px 20px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: 0.9375rem;
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.1);
    animation: messageFadeIn 0.3s ease forwards;
}

#messages p:has(b:contains("You")) {
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #020617;
    margin-left: auto;
    border: none;
    box-shadow: 0 4px 12px rgba(56, 189, 248, 0.2);
}

#messages p:has(b:contains("System")) {
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.2);
    color: #bae6fd;
    margin: 0 auto;
    text-align: center;
}

/* ================= INPUT ================= */
.input-area {
    max-width: 680px;
    margin: 20px auto 0;
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    background: rgba(15, 23, 42, 0.95);
    border-top: 1px solid rgba(148, 163, 184, 0.1);
    border-radius: 20px;
    flex-shrink: 0;
}

.input-area input {
    flex: 1;
    padding: 14px 18px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(30, 41, 59, 0.5);
    color: #e5e7eb;
    font-size: 0.9375rem;
    transition: border-color 0.2s ease;
}

.input-area input:focus {
    outline: none;
    border-color: #38bdf8;
}

.input-area button {
    padding: 14px 24px;
    border-radius: 14px;
    border: none;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9375rem;
    background: linear-gradient(135deg, #38bdf8, #0ea5e9);
    color: #020617;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.input-area button:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 16px rgba(56, 189, 248, 0.3);
}

/* ================= ANIMATIONS ================= */
@keyframes messageFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================= AUTH OVERLAY ================= */
#auth {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}

/* ================= AUTH CARD ================= */
.auth-row {
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 440px;
    padding: 60px 48px;
    border-radius: 32px;
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.15);
    box-shadow:
        0 20px 25px -5px rgba(0, 0, 0, 0.3),
        0 10px 10px -5px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
}

/* ================= INPUTS ================= */
.auth-row input {
    height: 56px;
    width: 100%;
    padding: 0 20px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(30, 41, 59, 0.4);
    color: #f1f5f9;
    font-size: 0.9375rem;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.auth-row input:focus {
    outline: none;
    border-color: #38bdf8;
    background: rgba(30, 41, 59, 0.6);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.auth-row input::placeholder {
    color: #64748b;
}

/* ================= BUTTONS ================= */
.auth-row button {
    height: 64px;
    width: 100%;
    border-radius: 50px;
    border: none;
    font-size: 1.0625rem;
    font-weight: 500;
    letter-spacing: 0.015em;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-top: 8px;
}

/* Primary (Register / Sign up) */
#registerBtn {
    background: #f1f5f9;
    color: #020617;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    margin-bottom: 12px;
}

#registerBtn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
    background: #ffffff;
}

#registerBtn:active {
    transform: translateY(0);
}

/* Secondary (Login) */
#loginBtn {
    background: transparent;
    color: #f1f5f9;
    border: 2px solid rgba(148, 163, 184, 0.3);
}

#loginBtn:hover {
    border-color: rgba(148, 163, 184, 0.5);
    background: rgba(30, 41, 59, 0.3);
}

/* ================= DIVIDER ================= */
.auth-row input:first-of-type {
    margin-top: 16px;
}

/* ================= HIDE AFTER LOGIN ================= */
#auth.hidden {
    display: none !important;
}

/* Show chat after login */
body:has(#auth.hidden) #sidebar,
body:has(#auth.hidden) #chat {
    display: flex;
}

/* ================= MOBILE ================= */
/* ================= MOBILE MENU ================= */
@media (max-width: 768px) {

    /* Sidebar */
    #sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 80%;
        max-width: 300px;
        height: 100dvh;
        background: rgba(15, 23, 42, 0.98);
        z-index: 999;
        display: flex;
        flex-direction: column;
        transition: left 0.3s ease;
        border-right: 1px solid rgba(148, 163, 184, 0.15);
    }

    #sidebar.open {
        left: 0;
    }

    /* Sidebar footer (logout) */
    .sidebar-footer {
        margin-top: auto;
        padding: 16px;
        border-top: 1px solid rgba(148, 163, 184, 0.15);
    }

    #logoutBtn {
        width: 100%;
        height: 48px;
        border-radius: 14px;
        font-size: 0.95rem;
        background: rgba(30, 41, 59, 0.8);
        color: #f1f5f9;
        border: 1px solid rgba(148, 163, 184, 0.25);
    }

    /* Hamburger button */
    #toggleSidebar {
        display: flex;
        position: fixed;
        top: 14px;
        right: 14px;
        z-index: 1001;
        width: 44px;
        height: 44px;
        border-radius: 12px;
        background: rgba(30, 41, 59, 0.9);
        color: #e5e7eb;
        border: 1px solid rgba(148, 163, 184, 0.2);
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
    }

    /* Chat full width */
    #chat {
        width: 100%;
    }
}

/* Desktop: hide hamburger */
#toggleSidebar {
    display: none;
}

/* ===== DESKTOP ===== */
#toggleSidebar {
    display: none;
}



/* ================= SMOOTH SCROLLING ================= */
#messages,
#chatList {
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.3) transparent;
}

#messages::-webkit-scrollbar,
#chatList::-webkit-scrollbar {
    width: 6px;
}

#messages::-webkit-scrollbar-track,
#chatList::-webkit-scrollbar-track {
    background: transparent;
}

#messages::-webkit-scrollbar-thumb,
#chatList::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.3);
    border-radius: 3px;
}

#messages::-webkit-scrollbar-thumb:hover,
#chatList::-webkit-scrollbar-thumb:hover {
    background: rgba(148, 163, 184, 0.5);
}

/* FORCE AUTH VERTICAL STACK (FINAL FIX) */
#auth {
    display: flex;
    align-items: center;
    justify-content: center;
}

#auth .auth-row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    width: 100%;
    max-width: 420px;
}

/* Inputs full width */
#auth input,
#auth button {
    width: 100%;
}

body:not(.logged-in) #logoutBtn {
    display: none;
}


.chat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.delete-chat {
    background: transparent;
    border: none;
    color: #64748b;
    cursor: pointer;
}

.delete-chat:hover {
    color: #ef4444;
}

.input-area button {
    min-width: 72px;
}

.chat-item {
    padding: 16px;
}

/* ================= LOGOUT (SIDEBAR) ================= */

.sidebar-footer {
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid rgba(148, 163, 184, 0.1);
}

#logoutBtn {
    width: 100%;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: rgba(239, 68, 68, 0.12);
    color: #fecaca;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}

#logoutBtn:hover {
    background: rgba(239, 68, 68, 0.25);
}

#logoutBtn:active {
    transform: scale(0.98);
}

/* Hide logout until logged in */
body:not(.logged-in) .sidebar-footer {
    display: none;
}