@media (max-width: 550px) {
    #messages {
        padding: 30px 20px;
    }
    form {
        flex-direction: column;
        align-items: stretch;
    }
    #name {
        width: 100%;
    }
    #message {
        min-width: unset;
    }
    button {
        width: 100%;
    }
}



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

html,
body {
    height: 100%;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: #f1f5f9;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
}

#messages {
    background: rgb(255, 255, 255);
    padding: 40px 50px;
    border-radius: 24px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.10);
    width: 100%;
    max-width: 700px;
    margin: 20px;
}
#messages > div {
    padding: 8px 12px;
    background: #ffffff;   
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 6px;
}

form {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
    justify-content: center;
    margin-top: 50px;
}

input,
button {
    font-size: 1.25rem;
    padding: 16px 20px;
    border-radius: 12px;
    border: 2px solid #d0d9e4;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
}

input:focus {
    border-color: #4a7cf7;
    box-shadow: 0 0 0 4px rgba(74, 124, 247, 0.15);
}

#name {
    width: 120px;
    flex: 0 0 auto;
    background: #f8fafc;
}

#message {
    flex: 1 1 200px;
    min-width: 150px;
    background: #f8fafc;
}

button {
    flex: 0 0 auto;
    background: #4a7cf7;
    color: white;
    font-weight: 600;
    border: none;
    padding: 16px 40px;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: background 0.2s, transform 0.1s;
    box-shadow: 0 4px 12px rgba(74, 124, 247, 0.30);
}

button:hover {
    background: #3a66d9;
}

button:active {
    transform: scale(0.97);
}




.container {
    background: white;
    padding: 32px;
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 400px;
}
h1 {
    text-align: center;
    font-size: 24px;
    margin-bottom: 24px;
    color: #1a1a2e;
}
.roomname {
    text-align: center;
    font-size: 18px;
    margin-top: 24px;
    color: #0f0f29;
}
.auth-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.auth-form input {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
}
.auth-form button {
    padding: 12px;
    background: #4a6cf7;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}
.auth-form button:hover {
    background: #3a56d4;
}
.error-msg {
    color: #dc2626;
    font-size: 14px;
    display: none;
    margin-top: 4px;
}
.switch-text {
    text-align: center;
    margin-top: 12px;
    font-size: 14px;
    color: #6b7280;
}
.switch-text a {
    color: #4a6cf7;
    cursor: pointer;
    text-decoration: underline;
}





/* Room List Cards */
#room-list {
    list-style: none;
    padding: 0;
    margin: 0 0 16px 0;
}
#room-list li {
    padding: 14px 18px;
    margin-bottom: 8px;
    background: #f8fafc;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s ease;
}
#room-list li:hover {
    background: #eef2ff;
    border-color: #4a6cf7;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(74, 108, 247, 0.1);
}
#room-list li .room-name {
    font-weight: 600;
    font-size: 16px;
    color: #1a1a2e;
}
.room-badge {
    font-size: 12px;
    padding: 3px 10px;
    border-radius: 20px;
    background: #e5e7eb;
    color: #4b5563;
    font-weight: 500;
}
.room-badge.public {
    background: #dbeafe;
    color: #1d4ed8;
}
.room-badge.private {
    background: #fef3c7;
    color: #d97706;
}
.room-badge.creator {
    background: #d1fae5;
    color: #059669;
}
.room-badge.not-member {
    background: #fef2f2;
    color: #dc2626;
}



/* ===== CHAT HEADER ===== */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0 12px 0;
    border-bottom: 1.5px solid #e2e8f0;
    flex-wrap: wrap;
    gap: 8px;
}
.room-info {
    display: flex;
    align-items: center;
    gap: 10px;
}
.roomname {
    font-weight: 700;
    font-size: 18px;
    color: #0f172a;
    margin: 0;
}
.status {
    font-size: 13px;
    font-weight: 500;
}
.status.online { color: #16a34a; }
.status.offline { color: #dc2626; }

/* ===== ACTIONS ===== */
.actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.actions input[type="email"] {
    padding: 6px 10px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 13px;
    width: 130px;
    background: #f8fafc;
}
.actions input[type="email"]:focus {
    outline: none;
    border-color: #4a6cf7;
}
.add-member-area {
    display: none;
    align-items: center;
    gap: 6px;
}
.btn-add {
    padding: 6px 14px;
    background: #4a6cf7;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-add:hover { background: #3a56d4; }
.btn-leave {
    padding: 6px 14px;
    background: #f59e0b;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-leave:hover { background: #d97706; }
.btn-logout {
    padding: 6px 14px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-logout:hover { background: #dc2626; }
.add-member-error {
    color: #dc2626;
    font-size: 12px;
    display: none;
}

/* ===== MESSAGE LIST ===== */
.message-list {
    flex: 1;
    min-height: 320px;
    max-height: 400px;
    overflow-y: auto;
    padding: 12px 4px;
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
}
.msg {
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 12px;
    border-left: 3px solid #4a6cf7;
    max-width: 90%;
    align-self: flex-start;
}
.msg.self {
    background: #eef2ff;
    border-left-color: #16a34a;
    align-self: flex-end;
}
.msg .sender {
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
}
.msg .time {
    font-size: 11px;
    color: #94a3b8;
    margin-left: 8px;
}
.msg .body {
    margin-top: 2px;
    font-size: 15px;
    color: #1e293b;
    word-wrap: break-word;
}
.chat-input-area {
    display: flex;
    align-items: center; /* Ensures they stay vertically centered */
    gap: 10px;
    width: 100%;
    padding: 4px 0;
}

.chat-input-area input {
    flex: 1 1 auto;      /* Grow to fill all available space */
    min-width: 0;        
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 15px;
    background: #f8fafc;
}

.chat-input-area button {
    flex: 0 0 auto;       /* Don't grow, don't shrink, stay content-sized */
    width: auto;          /* Override any global 100% width */
    white-space: nowrap;  
    padding: 12px 18px;   
    background: #4a6cf7;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
}


/* ===== TOP BUTTONS ===== */
.chat-top-buttons {
    display: flex;
    gap: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e2e8f0;
}
.chat-top-buttons button {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    text-align: center;
}
.btn-leave {
    background: #f59e0b;
    color: white;
}
.btn-leave:hover {
    background: #d97706;
}
.btn-logout {
    background: #ef4444;
    color: white;
}
.btn-logout:hover {
    background: #dc2626;
}

/* ===== MESSAGE LIST ===== */
.message-list {
    flex: 1;
    min-height: 280px;
    max-height: 350px;
    overflow-y: auto;
    padding: 12px 4px;
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fafafa;
}
.msg {
    padding: 10px 14px;
    background: #f8fafc;
    border-radius: 12px;
    border-left: 3px solid #4a6cf7;
    max-width: 90%;
    align-self: flex-start;
}
.msg.self {
    background: #eef2ff;
    border-left-color: #16a34a;
    align-self: flex-end;
}
.msg .sender {
    font-weight: 600;
    font-size: 13px;
    color: #0f172a;
}
.msg .time {
    font-size: 11px;
    color: #94a3b8;
    margin-left: 8px;
}
.msg .body {
    margin-top: 2px;
    font-size: 15px;
    color: #1e293b;
    word-wrap: break-word;
}

/* ===== INPUT AREA ===== */
.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 4px 0;
    width: 100%;
    box-sizing: border-box;
    flex-wrap: nowrap;
}
.chat-input-area input {
    flex: 1;
    padding: 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 12px;
    font-size: 15px;
    background: #f8fafc;
    min-width: 0;   
}
.chat-input-area input:focus {
    white-space: nowrap;
    flex-shrink: 0;
    outline: none;
    border-color: #4a6cf7;
    background: #ffffff;
}
.chat-input-area button {
    padding: 12px 24px;
    background: #4a6cf7;
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
}
.chat-input-area button:hover {
    background: #3a56d4;
}
.chat-input-area button:disabled,
.chat-input-area input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ===== FOOTER: Room Name + Status ===== */
.chat-footer {
    text-align: center;
    padding-top: 10px;
    border-top: 1px solid #e2e8f0;
    margin-top: 6px;
}
.chat-footer .roomname {
    font-weight: 700;
    font-size: 18px;
    color: #0f172a;
    margin: 0;
}
.chat-footer .status {
    font-size: 13px;
    font-weight: 500;
    display: block;
    margin-top: 2px;
}
.chat-footer .status.online {
    color: #16a34a;
}
.chat-footer .status.offline {
    color: #dc2626;
}




.btn-members {
    padding: 6px 14px;
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.btn-members:hover {
    background: #7c3aed;
}



/* Members Modal */
#members-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

#members-modal > div {
    background: white;
    border-radius: 16px;
    padding: 24px;
    max-width: 400px;
    width: 90%;
    max-height: 80%;
    overflow-y: auto;
}

/* Members List Items */
#members-list div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
}
#members-list div:last-child {
    border-bottom: none;
}

.kick-btn {
    padding: 4px 12px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}
.kick-btn:hover {
    background: #dc2626;
}



/* ============================================================
   CREATE ROOM
   ============================================================ */
.create-room-container {
    margin-top: 20px;
    padding: 20px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    transition: border-color 0.2s;
}

.create-room-container:hover {
    border-color: #cbd5e1;
}

.create-room-title {
    font-size: 16px;
    font-weight: 600;
    color: #0f172a;
    margin: 0 0 12px 0;
}

.create-room-error {
    color: #dc2626;
    font-size: 14px;
    display: none;
    margin-bottom: 10px;
    padding: 8px 12px;
    background: #fef2f2;
    border-radius: 8px;
}

.create-room-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.create-room-input {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: 15px;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.create-room-input:focus {
    outline: none;
    border-color: #4a6cf7;
    box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.15);
}

.create-room-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #475569;
    cursor: pointer;
}

.create-room-checkbox input[type="checkbox"] {
    width: 17px;
    height: 17px;
    accent-color: #4a6cf7;
    cursor: pointer;
    flex-shrink: 0;
}

.create-room-checkbox label {
    cursor: pointer;
    user-select: none;
}

.create-room-btn {
    width: 100%;
    padding: 12px;
    background: #4a6cf7;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.create-room-btn:hover {
    background: #3a56d4;
}

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

.create-room-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}