/* style.css */
:root {
    --bg-color: linear-gradient(135deg, #ff416c, #ff4b2b, #8a2387, #e94057, #f27121);
    --glass-bg: rgba(30, 30, 30, 0.55);
    --glass-border: rgba(255, 255, 255, 0.1);
    --text-color: #ffffff;
    --text-muted: #aaaaaa;
    --sidebar-bg: rgba(20, 20, 20, 0.65);
    --primary-color: #7b61ff;
    --bubble-bg-them: rgba(40, 40, 40, 0.85);
    --bubble-bg-me: #7b61ff;
    --input-bg: rgba(20, 20, 20, 0.5);
    
    /* Animation scale */
    --animation-speed: 0.3s;
}

[data-theme='light'] {
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(200, 200, 200, 0.5);
    --text-color: #111111;
    --text-muted: #555555;
    --sidebar-bg: rgba(245, 245, 245, 0.85);
    --bubble-bg-them: rgba(255, 255, 255, 1);
    --input-bg: rgba(255, 255, 255, 0.85);
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-color);
    background-size: 400% 400%;
    animation: gradientBG 20s ease infinite;
    color: var(--text-color);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    transition: background var(--animation-speed) ease;
}

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

/* Base Glassmorphism Class */
.glassmorphism {
    background: var(--glass-bg);
    backdrop-filter: blur(35px);
    -webkit-backdrop-filter: blur(35px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    transition: background var(--animation-speed) ease, border var(--animation-speed) ease;
}

/* Login Page */
#username-page {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
}
.username-page-container {
    padding: 40px;
    text-align: center;
    width: 350px;
    max-width: 90%;
}
.title {
    margin-bottom: 20px;
    font-size: 24px;
    font-weight: 600;
}
.form-control {
    width: 100%;
    padding: 12px 15px;
    margin-bottom: 15px;
    border: none;
    border-radius: 10px;
    background: var(--input-bg);
    color: var(--text-color);
    outline: none;
    font-family: 'Inter', sans-serif;
    transition: background var(--animation-speed) ease, box-shadow 0.2s ease;
}
.form-control:focus {
    box-shadow: 0 0 0 2px var(--primary-color);
}
.accent-button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.1s ease;
}
.accent-button:hover { background: #6852e0; }
.accent-button:active { transform: scale(0.98); }

/* Main Chat Layout */
#chat-page {
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.app-container {
    width: 100%;
    max-width: 1000px;
    height: 85vh;
    display: flex;
    position: relative;
    border-radius: 20px;
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--glass-border);
    border-radius: 20px 0 0 20px;
}
.sidebar-header {
    padding: 20px 15px 15px 15px;
}
.sidebar-title-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px 10px 15px;
}
.sidebar-title-actions h2 { font-size: 16px; font-weight: 600; }
.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background 0.2s;
}
.icon-btn:hover { background: rgba(123,97,255,0.2); color: var(--text-color); }
.user-list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}
.user-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
}
.user-item:hover { background: rgba(255,255,255,0.05); }
.user-item.active { background: rgba(255,255,255,0.1); }
.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    font-size: 14px;
}
.user-info h4 { font-size: 14px; font-weight: 500; margin-bottom: 2px;}
.user-info p { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;}

.letter-group-header {
    padding: 12px 15px 4px 15px;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
}

.search-container {
    margin-bottom: 5px;
    position: relative;
    padding-left: 40px; /* Offset for absolute icon */
}
.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    pointer-events: none;
}

/* Sidebar Bottom */
.sidebar-bottom {
    padding: 15px;
    border-top: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.disconnect-btn {
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 60, 60, 0.2);
    color: #ff5f56;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.disconnect-btn:hover { background: rgba(255, 60, 60, 0.4); }

.social-links-external {
    position: absolute;
    bottom: 20px;
    display: flex;
    gap: 20px;
    z-index: 10;
}
.social-links-external a {
    color: rgba(255, 255, 255, 0.7);
    transition: color 0.2s, transform 0.2s;
}
.social-links-external a:hover {
    color: #ffffff;
    transform: translateY(-2px);
}
.social-links-external svg {
    width: 28px;
    height: 28px;
}

[data-theme='light'] .social-links-external a {
    color: rgba(0, 0, 0, 0.7);
}
[data-theme='light'] .social-links-external a:hover {
    color: #000000;
}

/* Main Chat Area */
.chat-area {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--glass-border);
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: 15px;
}
.avatar-link {
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}
.avatar-img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--input-bg);
}
.user-details h2 { font-size: 16px; font-weight: 600; margin-bottom: 2px;}
.status { font-size: 12px; color: var(--text-muted); }
.header-actions { display: flex; gap: 5px; }

/* Messages */
.message-list {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    list-style: none;
}
.message {
    display: flex;
    flex-direction: column;
    max-width: 65%;
    animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.message.received { align-self: flex-start; }
.message.sent { align-self: flex-end; }
.message-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.sender-name { font-size: 12px; font-weight: 500; }
.timestamp { font-size: 10px; color: var(--text-muted); }
.message-content {
    padding: 14px 18px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}
.message.received .message-content {
    background: var(--bubble-bg-them);
    border-bottom-left-radius: 4px;
}
.message.sent .message-content {
    background: var(--bubble-bg-me);
    color: white;
    border-bottom-right-radius: 4px;
    align-self: flex-end;
}
.event-message {
    align-self: center;
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 4px 16px;
    border-radius: 20px;
    margin: 5px 0;
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-transform: capitalize;
}

/* Input Area */
.message-form-container {
    padding: 20px;
}
.glass-input {
    display: flex;
    align-items: center;
    background: var(--input-bg);
    border-radius: 20px;
    padding: 5px 15px;
}
.clean-input .form-control {
    padding: 12px 15px;
    margin-bottom: 0;
    background: transparent;
    flex-grow: 1;
}
.search-container .form-control {
    padding: 8px 5px;
    margin-bottom: 0;
    background: transparent;
    border: none;
}
.search-container.glass-input {
    padding-left: 35px;
}
.search-container .form-control:focus {
    box-shadow: none;
}

/* Mobile Responsiveness & Drawer Pattern */
.sidebar-toggle-btn {
    display: none;
}

@media screen and (max-width: 768px) {
    .sidebar-toggle-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: 10px;
    }

    .app-container {
        height: 100vh;
        width: 100vw;
        max-width: none;
        border-radius: 0;
        border: none;
        padding-top: env(safe-area-inset-top);
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        border-radius: 0 20px 20px 0;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 999;
        transition: opacity 0.3s ease;
    }

    .chat-header {
        padding: 12px 15px;
    }

    .message-list {
        padding: 15px;
    }

    .message {
        max-width: 85%;
    }

    .message-content {
        padding: 10px 14px;
        font-size: 13px;
    }

    .social-links-external {
        display: none;
    }

    #chat-page {
        padding: 0;
    }
}

.sidebar-overlay.hidden {
    display: none;
    opacity: 0;
    pointer-events: none;
}

/* Scrollbar styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

.hidden { display: none !important; }
