:root {
    --bg-color: #0f172a;
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #38bdf8;
    --error: #ef4444;
    --success: #10b981;
    --msg-sent: #6366f1;
    --msg-recv: #1e293b;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    /* Added a nice subtle radial gradient background */
    background: radial-gradient(circle at top right, #1e1b4b 0%, var(--bg-color) 40%);
}

.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--panel-border);
}

#app {
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.view {
    display: none;
    width: 100%;
    height: 100%;
}

.view.active {
    display: flex;
}

/* Authentication View */
#auth-view {
    justify-content: center;
    align-items: center;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    border-radius: 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    animation: slideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    justify-content: center;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 10px;
}

.auth-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
}

.subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-bottom: 2rem;
}

.tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 1.5rem;
}

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

.tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

.input-group {
    margin-bottom: 1.25rem;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

input {
    width: 100%;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.2s;
}

input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

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

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error-message {
    color: var(--error);
    font-size: 0.875rem;
    text-align: center;
    margin-top: 1rem;
    min-height: 20px;
}

/* Chat View */
#chat-view {
    padding: 1rem;
    gap: 1rem;
    max-width: 1400px;
    margin: 0 auto;
}

.sidebar {
    width: 320px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.user-profile {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--panel-border);
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: white;
    text-transform: uppercase;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.font-semibold {
    font-weight: 600;
}

.status {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.status.online::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: all 0.2s;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.search-bar {
    padding: 1rem;
}

.search-bar input {
    border-radius: 20px;
    padding: 10px 16px;
}

.contact-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    padding: 12px 1rem;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: background 0.2s;
    border-left: 3px solid transparent;
}

.contact-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.contact-item.active {
    background: rgba(255, 255, 255, 0.08);
    border-left-color: var(--primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.chat-header {
    height: 80px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
}

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

.encryption-badge {
    font-size: 0.75rem;
    color: var(--success);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.message-list {
    flex: 1;
    background: rgba(15, 23, 42, 0.4);
    border-radius: 20px;
    padding: 1.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px solid var(--panel-border);
}

.empty-state {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.message {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    animation: fadeIn 0.3s ease;
}

.message.sent {
    align-self: flex-end;
    background: var(--msg-sent);
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--msg-recv);
    border: 1px solid var(--panel-border);
    border-bottom-left-radius: 4px;
}

.message-input-area {
    border-radius: 20px;
    padding: 12px;
}

#message-form {
    display: flex;
    gap: 12px;
}

#message-input {
    background: transparent;
    border: none;
    flex: 1;
}

#message-input:focus {
    box-shadow: none;
}

#send-btn {
    width: 48px;
    border-radius: 12px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

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

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
}

.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 1000;
}

.toast {
    background: var(--primary);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    animation: slideInRight 0.3s ease;
    transition: all 0.3s ease;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

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

/* Typing Indicator Animation */
.typing-indicator .dot {
    display: inline-block;
    width: 4px;
    height: 4px;
    margin-left: 2px;
    background: currentColor;
    border-radius: 50%;
    animation: typing-dot 1.4s infinite ease-in-out both;
}

.typing-indicator .dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator .dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing-dot {

    0%,
    80%,
    100% {
        transform: scale(0);
        opacity: 0.5;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* --- Advanced Features --- */

/* Message Actions Menu — positioned INSIDE bubble so hover doesn't break */
.message {
    position: relative;
}

.message-actions {
    display: none;
    position: absolute;
    top: -28px;
    right: 4px;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(8px);
    border: 1px solid var(--panel-border);
    border-radius: 10px;
    padding: 2px 4px;
    gap: 2px;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

.message.received .message-actions {
    right: auto;
    left: 4px;
}

.action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 4px;
    border-radius: 8px;
    transition: all 0.2s;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.action-btn.unsend {
    color: var(--error);
}

.action-btn.unsend:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Replied Message Preview */
.replied-to {
    background: rgba(0, 0, 0, 0.2);
    border-left: 3px solid var(--accent);
    padding: 8px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
}

.replied-to .reply-sender {
    font-weight: bold;
    color: var(--text-main);
    margin-bottom: 4px;
}

/* In-progress Reply Bar container */
#reply-preview-bar {
    display: none;
    background: rgba(15, 23, 42, 0.8);
    border-top: 1px solid var(--panel-border);
    padding: 8px 16px;
    align-items: center;
    border-bottom: 1px solid var(--panel-border);
    font-size: 0.85rem;
}

#reply-preview-bar .reply-content {
    flex: 1;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#cancel-reply-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
}

/* File Attachments */
.message-attachment {
    max-width: 100%;
    margin-top: 8px;
    border-radius: 12px;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.file-btn {
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    transition: color 0.2s;
}

.file-btn:hover {
    color: var(--accent);
}

/* Reactions */
.reactions-container {
    position: absolute;
    bottom: -12px;
    display: flex;
    gap: 4px;
    background: var(--bg-color);
    padding: 2px 6px;
    border-radius: 12px;
    border: 1px solid var(--panel-border);
    font-size: 0.75rem;
}

.message.sent .reactions-container {
    right: 8px;
}

.message.received .reactions-container {
    left: 8px;
}

.reaction-badge {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    opacity: 0.8;
}

.reaction-badge:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Unsent Message */
.message.unsent {
    background: transparent;
    border: 1px dashed var(--panel-border);
    color: var(--text-muted);
    font-style: italic;
    padding: 8px 16px;
}

.message.unsent .message-actions {
    display: none;
}

/* Emoji Picker Grid */
.emoji-picker-container {
    position: relative;
    display: flex;
    align-items: center;
}

.emoji-picker-menu {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    z-index: 50;
    display: none;
}

.emoji-picker-menu.active {
    display: grid;
}

.emoji-picker-menu span {
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px;
    text-align: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.emoji-picker-menu span:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ==========================================
   SIDEBAR TABS (Friend System)
   ========================================== */

.sidebar-tabs {
    display: flex;
    padding: 8px;
    gap: 4px;
    border-bottom: 1px solid var(--panel-border);
}

.sidebar-tab {
    flex: 1;
    padding: 8px 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s;
    position: relative;
    white-space: nowrap;
}

.sidebar-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.sidebar-tab.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.badge {
    background: var(--error);
    color: white;
    border-radius: 10px;
    padding: 1px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    margin-left: 4px;
}

/* Section Headers (Received / Sent) */
.section-header {
    padding: 12px 16px 6px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Friend Request Buttons */
.btn-accept,
.btn-reject {
    background: transparent;
    border: 1px solid var(--panel-border);
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-accept {
    border-color: var(--success);
    color: var(--success);
}

.btn-accept:hover {
    background: var(--success);
    color: white;
}

.btn-reject {
    border-color: var(--error);
    color: var(--error);
}

.btn-reject:hover {
    background: var(--error);
    color: white;
}

/* Add Friend Button */
.btn-add-friend {
    background: transparent;
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.btn-add-friend:hover {
    background: var(--primary);
    color: white;
}

/* Friend Tag */
.friend-tag {
    font-size: 0.7rem;
    color: var(--success);
    background: rgba(16, 185, 129, 0.1);
    padding: 3px 8px;
    border-radius: 8px;
    white-space: nowrap;
}

.friend-tag.pending {
    color: var(--text-muted);
    background: rgba(148, 163, 184, 0.1);
}

/* Empty Sidebar */
.empty-sidebar {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ==========================================
   PASSWORD CHANGE MODAL
   ========================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
    animation: fadeIn 0.2s ease;
}

.modal {
    width: 100%;
    max-width: 380px;
    padding: 2rem;
    border-radius: 20px;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal h3 {
    font-size: 1.25rem;
    margin-bottom: 1.5rem;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 1rem;
}

.btn-secondary {
    flex: 1;
    padding: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-muted);
    border: 1px solid var(--panel-border);
    border-radius: 12px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    color: white;
}

.modal .btn-primary {
    flex: 1;
}

/* ==========================================
   TYPING LOADER (WAVE ANIMATION)
   ========================================== */

.typing-loader {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 8px;
    height: 14px;
}

.typing-loader .dot {
    width: 6px;
    height: 6px;
    background-color: var(--text-muted);
    border-radius: 50%;
    animation: typingWave 1.2s infinite ease-in-out both;
    opacity: 0.4;
}

.typing-loader .dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-loader .dot:nth-child(2) {
    animation-delay: 0.1s;
}

.typing-loader .dot:nth-child(3) {
    animation-delay: 0.2s;
}

/* .typing-loader .dot:nth-child(4) { animation-delay: 0.3s; }
.typing-loader .dot:nth-child(5) { animation-delay: 0.4s; } */

@keyframes typingWave {

    0%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    50% {
        transform: scale(1.3);
        opacity: 1;
        background-color: var(--text-muted);
    }
}