/* Global Styles */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --btn-text-color: #ffffff;
    --bg-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --glass-bg: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(255, 255, 255, 0.2);
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    --card-bg: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    height: 100vh;
    background: var(--bg-gradient);
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.container {
    width: 100%;
    height: 100%;
    max-width: 480px;
    /* Mobile-first limit on desktop, or full screen on mobile */
    background: var(--glass-bg);
    position: relative;
    box-shadow: var(--shadow-lg);
}

@media (min-width: 500px) {
    .container {
        height: 80vh;
        border-radius: 20px;
        overflow: hidden;
    }
}

/* Views Management */
.view {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: transform 0.3s ease-in-out, opacity 0.3s;
    opacity: 0;
    pointer-events: none;
    z-index: 0;
}

.view.active {
    opacity: 1;
    pointer-events: all;
    z-index: 10;
    transform: translateX(0);
}

.view.hidden {
    transform: translateX(100%);
    /* Slide out effect */
}

/* Login View */
#login-view {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.card {
    width: 100%;
    text-align: center;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.theme-selector {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.theme-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid transparent;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s;
}

.theme-btn:hover {
    transform: scale(1.1);
}

.theme-btn.active {
    border-color: var(--text-main);
    transform: scale(1.1);
}

.form-group {
    text-align: left;
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 1rem;
    transition: all 0.2s;
    background: #f9fafb;
}

input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    background: white;
}

.actions {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.btn {
    padding: 0.875rem;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

.btn:active {
    transform: scale(0.98);
}

.btn.primary {
    background-color: var(--primary-color);
    color: var(--btn-text-color);
    box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
}

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

.divider {
    display: flex;
    align-items: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 0.5rem 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #e5e7eb;
}

.divider span {
    padding: 0 0.5rem;
}

.join-group {
    display: flex;
    gap: 0.5rem;
}

.join-group input {
    flex: 2;
    text-align: center;
    letter-spacing: 2px;
}

.btn.secondary {
    flex: 1;
    background-color: #f3f4f6;
    color: var(--text-main);
}

.btn.secondary:hover {
    background-color: #e5e7eb;
}

/* Chat View */
#chat-view {
    display: flex;
    flex-direction: column;
    background: #f8fafc;
}

.chat-header {
    background: white;
    padding: 1rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 20;
}

.room-info {
    display: flex;
    flex-direction: column;
}

.room-info .label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.room-info .code {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: 1px;
}

.btn.text-only {
    background: none;
    color: var(--text-muted);
    padding: 0.5rem;
    font-size: 0.875rem;
}

.btn.text-only:hover {
    color: #ef4444;
    /* Red for leave */
    background: rgba(239, 68, 68, 0.1);
}

.header-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

/* Chat Bubbles */
.message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

.message .meta {
    font-size: 0.75rem;
    margin-bottom: 0.25rem;
    opacity: 0.8;
    font-weight: 600;
}

.message.system {
    align-self: center;
    background: rgba(0, 0, 0, 0.05);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    border-radius: 12px;
    padding: 0.5rem 1rem;
    max-width: 90%;
}

.message.mine {
    align-self: flex-end;
    background-color: var(--primary-color);
    color: var(--btn-text-color);
    border-bottom-right-radius: 4px;
}

.message.theirs {
    align-self: flex-start;
    background-color: white;
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    border-bottom-left-radius: 4px;
}

/* Input Area */
.chat-input-area {
    background: white;
    padding: 1rem;
    border-top: 1px solid #e5e7eb;
}

#chat-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.btn-icon {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0.5rem;
    border-radius: 50%;
    transition: background-color 0.2s, color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: #f3f4f6;
    color: var(--primary-color);
}

#message-input {
    flex: 1;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 24px;
    padding: 0.75rem 1.25rem;
    resize: none;
    font-family: inherit;
    height: 50px;
    line-height: 1.4;
}

.btn-send {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
}

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

.btn-send:disabled {
    background: #e5e7eb;
    cursor: not-allowed;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

#generic-modal {
    z-index: 1100;
    /* Ensure it appears above other modals */
}


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

.modal-content {
    background-color: var(--card-bg);
    padding: 2rem;
    border-radius: 1rem;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    text-align: center;
}

.modal-content h3 {
    margin-bottom: 0.5rem;
    color: var(--txt-color);
}

.modal-content p {
    color: var(--subtitle-color);
    margin-bottom: 1.5rem;
}

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