:root {
    /* Modern Dark Theme Palette */
    --bg-color: #020617;
    /* Slate 950 - Darker, richer */
    --bg-gradient: radial-gradient(circle at top right, #1e1b4b, #020617);

    --primary: #0ea5e9;
    /* Sky 500 */
    --primary-glow: rgba(14, 165, 233, 0.5);
    --primary-dark: #0284c7;

    --secondary: #64748b;
    --accent: #f472b6;
    /* Pink 400 */

    --glass-bg: rgba(15, 23, 42, 0.65);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-highlight: rgba(255, 255, 255, 0.05);

    --text-main: #f8fafc;
    --text-muted: #94a3b8;

    /* Message Bubbles - Gradient for 'Me' */
    --message-me-bg: linear-gradient(135deg, #0ea5e9 0%, #2563eb 100%);
    --message-me-text: #ffffff;

    --message-other-bg: rgba(51, 65, 85, 0.8);
    /* Slate 700 with opacity */
    --message-other-text: #f1f5f9;

    --font-family: 'Outfit', sans-serif;

    --header-height: 65px;
    --input-area-height: 70px;
    /* Base height approx */
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    /* Remove blue tap highlight on mobile */
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    background-image: var(--bg-gradient);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    /* Mobile viewport fix */
    overflow: hidden;
    position: relative;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* Background Animation - Optimized */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
}

.blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 25s infinite ease-in-out;
}

.blob-1 {
    width: 50vw;
    height: 50vw;
    background: #3b82f6;
    top: -10vh;
    left: -10vw;
}

.blob-2 {
    width: 40vw;
    height: 40vw;
    background: #8b5cf6;
    bottom: -10vh;
    right: -10vw;
    animation-delay: -5s;
}

.blob-3 {
    width: 30vw;
    height: 30vw;
    background: #ec4899;
    top: 40%;
    left: 40%;
    animation-delay: -10s;
    opacity: 0.3;
}

@keyframes float {

    0%,
    100% {
        transform: translate(0, 0) scale(1);
    }

    33% {
        transform: translate(30px, -50px) scale(1.1);
    }

    66% {
        transform: translate(-20px, 20px) scale(0.9);
    }
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Screens */
.screen {
    display: none;
    height: 100%;
    width: 100%;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

.screen.active {
    display: flex;
    opacity: 1;
}

/* Login Screen - Beautified */
#login-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    /* Slight dim */
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-top: 1px solid var(--glass-highlight);
    border-radius: 32px;
    padding: 48px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    text-align: center;
    transform: translateY(20px);
    animation: slideUpFade 0.6s ease-out forwards;
}

@keyframes slideUpFade {
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.brand {
    margin-bottom: 36px;
}

.brand i {
    font-size: 3.5rem;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 12px;
    display: inline-block;
    filter: drop-shadow(0 4px 10px rgba(14, 165, 233, 0.3));
}

.brand h1 {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: -1px;
    color: #fff;
    margin-bottom: 4px;
}

.brand p {
    color: var(--text-muted);
    font-size: 1rem;
    font-weight: 300;
}

.input-group {
    margin-bottom: 24px;
    text-align: left;
    position: relative;
}

.input-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    margin-left: 8px;
    font-weight: 500;
}

input[type="text"],
input[type="password"] {
    width: 100%;
    padding: 16px 20px;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    color: #fff;
    font-size: 1.05rem;
    font-family: var(--font-family);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    outline: none;
}

input:focus {
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 4px rgba(14, 165, 233, 0.15);
    transform: translateY(-1px);
}

.btn-primary {
    width: 100%;
    padding: 18px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%);
    color: white;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    font-family: var(--font-family);
    box-shadow: 0 4px 20px rgba(14, 165, 233, 0.3);
    margin-top: 10px;
}

.btn-primary:hover {
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 8px 30px rgba(14, 165, 233, 0.4);
}

.btn-primary:active {
    transform: translateY(0) scale(0.98);
}

.error-msg {
    color: #ef4444;
    font-size: 0.9rem;
    margin-top: 20px;
    min-height: 24px;
    font-weight: 500;
}

.policy-link {
    display: block;
    margin-top: 25px;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-decoration: none;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.policy-link:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Chat Screen */
.chat-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.85);
    /* More opaque */
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    position: relative;
    z-index: 50;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.logo-small {
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, rgba(56, 189, 248, 0.2), rgba(37, 99, 235, 0.2));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.4rem;
    box-shadow: 0 0 15px rgba(56, 189, 248, 0.1);
}

.header-info h2 {
    font-size: 1.15rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 2px;
}

.header-info span {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    box-shadow: 0 0 8px #10b981;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    transition: all 0.2s;
}

.icon-btn:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--glass-border);
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    scroll-behavior: smooth;
    /* Fancy background pattern on top of gradient */
    background-image: radial-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 30px 30px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    /* reduced gap closer messages */
    padding-bottom: 10px;
}

.message-date-divider {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 24px 0;
    position: relative;
    font-weight: 500;
    opacity: 0.8;
}

.message-date-divider span {
    background: rgba(15, 23, 42, 0.8);
    padding: 4px 12px;
    border-radius: 12px;
}

/* Messages */
.message {
    max-width: 85%;
    display: flex;
    flex-direction: column;
    animation: messageEntry 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    transform-origin: bottom center;
}

@keyframes messageEntry {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.mine {
    align-self: flex-end;
    align-items: flex-end;
}

.message.theirs {
    align-self: flex-start;
    align-items: flex-start;
}

.message-sender {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    margin-left: 14px;
}

.message.mine .message-sender {
    margin-right: 14px;
    margin-left: 0;
    display: none;
    /* Usually don't show my own name */
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 22px;
    position: relative;
    word-wrap: break-word;
    font-size: 1rem;
    line-height: 1.5;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.message.mine .message-bubble {
    background: var(--message-me-bg);
    color: var(--message-me-text);
    border-bottom-right-radius: 4px;
    /* Distinctive shape */
}

.message.theirs .message-bubble {
    background: var(--message-other-bg);
    color: var(--message-other-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--glass-border);
}

.message-time {
    font-size: 0.7rem;
    opacity: 0.7;
    margin-top: 4px;
    display: block;
    text-align: right;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    /* Time always on right */
    align-items: center;
    gap: 8px;
    margin-top: 2px;
}

.delete-msg-btn {
    background: transparent;
    border: none;
    color: currentColor;
    /* Inherit text color */
    cursor: pointer;
    padding: 4px;
    font-size: 0.9rem;
    border-radius: 50%;
    opacity: 0.5;
    transition: all 0.2s;
    display: flex;
}

.delete-msg-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.2);
}

/* Media Messages */
.message-media {
    max-width: 100%;
    border-radius: 18px;
    overflow: hidden;
    margin-bottom: 4px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
}

.message-media img,
.message-media video {
    width: 100%;
    max-height: 350px;
    object-fit: cover;
    display: block;
    cursor: pointer;
    transition: transform 0.3s;
}

.message-media img:hover {
    transform: scale(1.02);
}

/* Input Area - Floats above bottom */
.chat-input-area {
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    /* Safe area for iPhone X+ */
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    flex-shrink: 0;
}

#message-form {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(30, 41, 59, 0.6);
    padding: 8px;
    border-radius: 28px;
    /* Pill shape */
    border: 1px solid var(--glass-border);
    transition: all 0.3s;
}

#message-form:focus-within {
    background: rgba(30, 41, 59, 0.9);
    border-color: rgba(56, 189, 248, 0.3);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.upload-btn {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--primary);
    background: rgba(56, 189, 248, 0.1);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
}

.upload-btn:hover {
    background: rgba(56, 189, 248, 0.2);
    transform: rotate(90deg);
}

#message-input {
    flex: 1;
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 10px;
    color: #fff;
    font-size: 1rem;
}

#message-input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.send-btn {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
    font-size: 1.2rem;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.send-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(14, 165, 233, 0.5);
}

.upload-progress {
    color: var(--primary);
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    padding: 8px;
    background: rgba(56, 189, 248, 0.1);
    border-radius: 12px;
}

.upload-progress.hidden {
    display: none;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Scroll to bottom button (optional enhancement) */
.scroll-bottom {
    position: absolute;
    bottom: 90px;
    right: 20px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}

.scroll-bottom.visible {
    opacity: 1;
    visibility: visible;
}

/* Mobile Responsiveness Fine-Tuning */
@media (max-width: 600px) {
    .glass-card {
        padding: 40px 24px;
        margin: 0 10px;
    }

    .blob-1 {
        width: 80vw;
        height: 80vw;
    }

    .blob-2 {
        width: 70vw;
        height: 70vw;
    }

    .message {
        max-width: 88%;
    }

    .message-bubble {
        padding: 10px 16px;
        font-size: 0.95rem;
    }

    .logo-small {
        width: 36px;
        height: 36px;
    }

    .header-info h2 {
        font-size: 1rem;
    }
}