:root {
    --bg-color: #f4f6f8;
    --card-bg: #ffffff;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
}

.login-box .form-row { display:flex; align-items:center; gap:8px; margin-bottom:10px; }
.login-box .form-row .input-label { width:92px; margin-bottom:0; text-align:right; color:var(--text-muted); font-size:0.95rem; }
.login-box .form-row input[type="text"] { flex:1; padding:8px; border-radius:6px; border:1px solid var(--border-color); }

.container {
    width: 100%;
    max-width: 960px;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.01);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: 85vh;
}

header {
    background: var(--card-bg);
    padding: 18px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 8px;
}

header h1::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    background-color: #10b981;
    border-radius: 50%;
}

.user-meta {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 12px;
}

.logout-btn {
    color: #ef4444;
    text-decoration: none;
    font-size: 0.8125rem;
    padding: 4px 10px;
    border-radius: 6px;
    background: #fef2f2;
    transition: all 0.2s;
}

.logout-btn:hover {
    background: #fee2e2;
}

.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.chat-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
}

.chat-box {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background-color: #fafafa;
    -webkit-overflow-scrolling: touch;
}

.sidebar {
    width: 220px;
    border-left: 1px solid var(--border-color);
    background: #ffffff;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;

}

/* Room hamburger menu styles */
.room-controls { display:inline-block; position:relative; margin-left:8px; vertical-align:middle; }
.hamburger { background:none; border:0; font-size:18px; cursor:pointer; padding:6px 8px; border-radius:6px; color:var(--text-color); }
.hamburger:focus { outline:2px solid rgba(0,0,0,0.08); }
.room-menu { display:none; position:absolute; left:0; top:calc(100% + 8px); background:var(--card-bg); border:1px solid #e6e6e6; box-shadow:0 6px 18px rgba(0,0,0,0.08); border-radius:8px; padding:6px; z-index:1200; min-width:160px; }
.room-menu.open { display:block; }
.room-menu .menu-item { display:block; width:100%; background:none; border:0; padding:8px 12px; text-align:left; cursor:pointer; font-size:0.95rem; color:var(--text-color); }
.room-menu .menu-item:hover { background:rgba(0,0,0,0.03); }

.sidebar-title {
    font-size: 0.8125rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.online-count {
    background: #e0e7ff;
    color: var(--primary);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.user-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-main);
    padding: 6px 8px;
    border-radius: 6px;
    background: #f9fafb;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #10b981;
    border-radius: 50%;
    flex-shrink: 0;
}

.message-item {
    display: flex;
    flex-direction: column;
    max-width: 75%;
    word-break: break-word;
}

.message-other {
    align-self: flex-start;
}

.message-other .bubble {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    border-radius: 16px 16px 16px 4px;
}

.message-own {
    align-self: flex-end;
    align-items: flex-end;
}

.message-own .bubble {
    background: var(--primary);
    color: #ffffff;
    border-radius: 16px 16px 4px 16px;
}

.message-own .username {
    display: none;
}

.message-own .time {
    text-align: right;
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
    padding: 0 4px;
}

.username {
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.username .username-hash {
    font-weight: 500;
    font-size: 0.7rem;
    color: rgba(0,0,0,0.45);
    margin-left: 6px;
}

.time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.bubble {
    padding: 10px 14px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
    display: inline-block;
}

.message-content {
    font-size: 0.9375rem;
    line-height: 1.5;
}

.attachment-card {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 8px;
    display: inline-block;
}

.message-own .attachment-card {
    background: rgba(255, 255, 255, 0.15);
}

.attachment-name {
    font-size: 0.8125rem;
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 500;
}

.attachment-img {
    margin-top: 6px;
    max-width: 220px;
    max-height: 160px;
    border-radius: 8px;
    display: block;
    object-fit: cover;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.attachment-img:hover {
    transform: scale(1.02);
}

.footer-form {
    padding: 12px 16px;
    background: var(--card-bg);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
}

.input-group {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}

input[type="text"] {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9375rem;
    outline: none;
    transition: border 0.2s;
}

input[type="text"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.file-label {
    cursor: pointer;
    padding: 10px 14px;
    background: #f3f4f6;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.875rem;
    color: var(--text-main);
    transition: background 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    user-select: none;
    flex-shrink: 0;
    gap: 6px;
}

.file-label:hover {
    background: #e5e7eb;
}

input[type="file"] {
    display: none;
}

button {
    padding: 10px 16px;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9375rem;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

button:hover {
    background: var(--primary-hover);
}

.file-preview-name {
    font-size: 0.75rem;
    color: var(--primary);
    margin-top: 6px;
    display: none;
    font-weight: 500;
}

.login-box {
    margin: auto;
    padding: 32px;
    text-align: center;
    width: 100%;
    max-width: 360px;
}

.login-box h2 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.login-box .login-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 18px;
    line-height: 1.4;
}

.login-box p {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-box input[type="text"] {
    width: 100%;
    margin-bottom: 16px;
}

.login-box button {
    width: 100%;
}

.geo-status {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 8px;
}

.image-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.75);
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(2px);
}

.image-modal-content {
    max-width: 90%;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #ffffff;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    user-select: none;
}

@media (max-width: 640px) {
    body { padding: 0; }
    .container { border-radius: 0; height: 100vh; max-width: 100%; }
    .main-layout { flex-direction: column-reverse; }
    .sidebar { width: 100%; border-left: none; border-bottom: 1px solid var(--border-color); padding: 10px 16px; max-height: 80px; }
    .user-list { flex-direction: row; flex-wrap: wrap; gap: 6px; }
    .chat-box { padding: 16px; }
    .file-label { padding: 10px; }
    button { padding: 10px 12px; }
    .message-item { max-width: 88%; }
}
