:root {
    --primary-bg: #0F172A;
    --secondary-bg: #111827;
    --surface-bg: #1F2937;
    --text-color: #FFFFFF;
    --text-muted: #D1D5DB;
    --accent-color: #3B82F6;
    --accent-hover: #2563EB;
    --sent-bubble-bg: #3B82F6;
    --sent-bubble-text: #FFFFFF;
    --received-bubble-bg: #1F2937;
    --received-bubble-text: #FFFFFF;
    --border-color: #374151;
    --focus-ring: #93C5FD;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --font-family: 'Poppins', sans-serif;
    --error-text: #EF4444;
    --success-color: #10B981;
    --group-color: #10B981;
    --group-hover: #059669;
    --danger-color: #EF4444;
    --glass-bg: rgba(17, 24, 39, 0.85);
    --glass-border: rgba(255, 255, 255, 0.05);
    --ticks-color: rgba(255, 255, 255, 0.5);
    --ticks-read-color: #3B82F6;
    --input-bg: #0F172A;
}

/* Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--primary-bg);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    transition: background-color 0.3s ease, color 0.3s ease;
    background-image: radial-gradient(circle at top right, rgba(59, 130, 246, 0.1), transparent 40%),
        radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.05), transparent 40%);
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Containers */
.container {
    background-color: var(--secondary-bg);
    border-radius: 20px;
    box-shadow: var(--shadow-lg);
    width: 95%;
    max-width: 480px;
    padding: 2.5rem 2rem;
    text-align: center;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.screen.hidden {
    display: none;
    opacity: 0;
    transform: scale(0.95);
}

/* Chat Container Specific */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 90vh;
    max-height: 850px;
    width: 95%;
    max-width: 900px;
    padding: 0;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Typography & Layout */
.logo {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    margin-bottom: 0.5rem;
}

.logo .icon-bg {
    background: linear-gradient(135deg, var(--accent-color), var(--success-color));
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: white;
    font-size: 1.5rem;
    box-shadow: var(--shadow-md);
}

h1 {
    font-size: 2.2rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.tagline {
    color: var(--text-muted);
    margin-bottom: 2.5rem;
    font-weight: 300;
    font-size: 1rem;
}

h2 {
    margin-bottom: 1.5rem;
    font-weight: 600;
    font-size: 1.5rem;
}

.error-text {
    color: var(--error-text);
    font-size: 0.9rem;
    margin-top: 1rem;
    font-weight: 500;
    background: rgba(239, 68, 68, 0.1);
    padding: 10px;
    border-radius: 8px;
}

/* Form Elements */
.input-group {
    position: relative;
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.input-group i {
    position: absolute;
    left: 15px;
    color: var(--text-muted);
}

.input-group input {
    padding-left: 45px;
    margin-bottom: 0;
}

input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    font-size: 1rem;
    font-family: var(--font-family);
    background-color: var(--input-bg);
    color: var(--text-color);
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: var(--secondary-bg);
    box-shadow: 0 0 0 4px var(--focus-ring);
}

button {
    border: none;
    padding: 14px 20px;
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

button:active {
    transform: scale(0.98);
}

.primary-btn {
    background-color: var(--accent-color);
    color: white;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.primary-btn:hover {
    background-color: var(--accent-hover);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
}

.group-btn {
    background-color: var(--group-color);
    color: white;
    box-shadow: 0 4px 14px rgba(16, 185, 129, 0.3);
}

.group-btn:hover {
    background-color: var(--group-hover);
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
    transform: translateY(-1px);
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2rem;
    padding: 0;
    margin: 0;
    background-color: var(--received-bubble-bg);
    color: var(--text-muted);
}

.icon-btn:hover {
    background-color: var(--border-color);
    color: var(--text-color);
}

.icon-btn.danger:hover {
    background-color: var(--error-text);
    color: white;
}

.send-btn {
    background-color: var(--accent-color);
    color: white;
    border-radius: 12px;
}

.send-btn:hover {
    background-color: var(--accent-hover);
    color: white;
}

.divider {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    border-bottom: 1px solid var(--border-color);
}

.divider span {
    padding: 0 10px;
    font-size: 0.9rem;
    font-weight: 500;
}

/* Chat Area */
.chat-header {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--secondary-bg);
    border-radius: 20px 20px 0 0;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.room-icon {
    color: var(--accent-color);
    font-size: 1.2rem;
}

.room-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

#room-code-display {
    color: var(--text-color);
}

.messages-area {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scroll-behavior: smooth;
}

/* Messages */
.message {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: slideInUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    margin-bottom: 1.2rem;
}

.sender-name {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 6px;
    margin-left: 4px;
    margin-right: 4px;
}

.message-bubble {
    position: relative;
    padding: 12px 16px;
    padding-right: 55px;
    border-radius: 18px;
    word-wrap: break-word;
    line-height: 1.5;
    box-shadow: var(--shadow-sm);
    font-size: 0.95rem;
}

.message.sent {
    align-self: flex-end;
    align-items: flex-end;
}

.message.sent .message-bubble {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    color: var(--sent-bubble-text);
    border-bottom-right-radius: 4px;
}

.message.sent .sender-name {
    display: none;
}

/* Hide 'You' */

.message.received {
    align-self: flex-start;
    align-items: flex-start;
}

.message.received .message-bubble {
    background-color: var(--received-bubble-bg);
    color: var(--received-bubble-text);
    border-bottom-left-radius: 4px;
    padding-right: 16px;
}

/* Status Icons */
.message-status {
    position: absolute;
    bottom: 6px;
    right: 12px;
    font-size: 0.7rem;
    color: var(--ticks-color);
}

.message-status .read {
    color: var(--ticks-read-color);
}

.message.received .message-status {
    display: none;
}

/* File Messages */
.file-message {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 260px;
}

.file-icon {
    font-size: 2.5rem;
    color: var(--received-bubble-bg);
    opacity: 0.9;
}

.message.received .file-icon {
    color: var(--accent-color);
}

.file-info {
    text-align: left;
    flex-grow: 1;
    overflow: hidden;
}

.file-info p {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    /* allow multiline wrapping for long names */
    white-space: normal;
    word-break: break-all;
    line-height: 1.3;
}

.file-info .file-size {
    font-size: 0.8rem;
    opacity: 0.8;
}

.download-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: inherit;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s;
    font-size: 1rem;
    text-decoration: none;
}

.message.received .download-btn {
    background: var(--secondary-bg);
    color: var(--accent-color);
}

.download-btn:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.3);
}

.message.received .download-btn:hover {
    background: white;
    box-shadow: var(--shadow-sm);
}

.loader {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Notifications / System Messages */
.notification {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 10px auto;
    background: var(--received-bubble-bg);
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-block;
    align-self: center;
}

.typing-indicator {
    padding: 0 1.5rem 0.5rem;
    font-style: italic;
    color: var(--text-muted);
    height: 24px;
    font-size: 0.85rem;
    flex-shrink: 0;
    text-align: left;
    animation: fadeIn 0.3s;
}

/* Chat Footer */
.chat-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    background: var(--secondary-bg);
    border-radius: 0 0 20px 20px;
}

#message-form {
    display: flex;
    gap: 10px;
    align-items: center;
}

#message-form .file-upload-btn {
    flex-shrink: 0;
    cursor: pointer;
}

#message-input {
    flex-grow: 1;
    height: 44px;
    margin-bottom: 0;
    border-radius: 22px;
}

/* Toasts */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--secondary-bg);
    color: var(--text-color);
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    border-left: 4px solid var(--accent-color);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.info {
    border-left-color: var(--accent-color);
}

.toast.success {
    border-left-color: var(--success-color);
}

.toast.error {
    border-left-color: var(--error-text);
}

.toast i {
    font-size: 1.2rem;
}

.toast.info i {
    color: var(--accent-color);
}

.toast.success i {
    color: var(--success-color);
}

.toast.error i {
    color: var(--error-text);
}

/* Animations */
@keyframes slideInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}



/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 99999;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-overlay .spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay p {
    font-weight: 500;
    color: var(--text-color);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

@media (max-width: 600px) {
    body {
        padding: 0;
        align-items: flex-start;
        /* Better for mobile virtual keyboards */
        min-height: 100vh;
        min-height: 100dvh;
    }

    .container {
        width: 100%;
        max-width: 100%;
        padding: 1.5rem 1rem;
        border-radius: 0;
        min-height: 100vh;
        min-height: 100dvh;
        border: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .chat-container {
        height: 100vh;
        /* Fallback */
        height: 100dvh;
        /* Dynamic viewport height handles Safari/Mobile keyboards */
        max-height: none;
        border-radius: 0;
        padding: 0;
        justify-content: flex-start;
    }

    h1 {
        font-size: 1.8rem;
    }

    .tagline {
        font-size: 0.9rem;
        margin-bottom: 2rem;
    }

    h2 {
        font-size: 1.3rem;
    }

    /* Form & Buttons */
    input[type="text"] {
        padding: 12px 14px;
        font-size: 16px;
        /* Prevents auto-zoom on iOS */
    }

    button {
        padding: 12px 16px;
        font-size: 1rem;
    }

    .input-group input {
        padding-left: 40px;
    }

    /* Chat Area Elements */
    .chat-header {
        padding: 1rem;
        border-radius: 0;
    }

    .room-title {
        font-size: 1rem;
    }

    .messages-area {
        padding: 1rem;
        gap: 0.8rem;
    }

    .message {
        max-width: 90%;
        margin-bottom: 0.8rem;
    }

    .message-bubble {
        padding: 10px 14px;
        padding-right: 45px;
        font-size: 0.9rem;
    }

    .file-message {
        min-width: unset;
        width: 100%;
        gap: 8px;
    }

    .file-icon {
        font-size: 2rem;
    }

    .file-info p {
        font-size: 0.85rem;
        /* Keep wrapping behavior */
        white-space: normal;
        word-break: break-all;
    }

    .chat-footer {
        padding: 0.6rem;
        border-radius: 0;
        padding-bottom: calc(0.6rem + env(safe-area-inset-bottom));
        /* iOS safe area */
    }

    #message-form {
        gap: 6px;
        /* Bring buttons closer */
    }

    #message-input {
        height: 40px;
        font-size: 16px;
        /* Prevents iOS zoom */
        flex-grow: 1;
        /* ensure it takes available space */
        min-width: 0;
        /* allow shrinking below default size if needed */
    }

    .icon-btn {
        width: 36px;
        height: 36px;
    }

    .icon-btn img {
        width: 18px !important;
        height: 18px !important;
    }



    .toast-container {
        top: auto;
        bottom: 20px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        width: 90%;
        align-items: center;
    }

    .toast {
        width: 100%;
        justify-content: center;
        transform: translateY(120%);
    }

    .toast.show {
        transform: translateY(0);
    }
}