* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f5f7fb;
    color: #333;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
}

/* Header & Info Area */
header {
    background: #fff;
    padding: 12px 16px;
    border-bottom: 1px solid #e1e4e8;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.top-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.username-container {
    display: flex;
    align-items: center;
    background: #f1f3f5;
    padding: 4px 8px;
    border-radius: 20px;
    flex-grow: 1;
    max-width: 200px;
    border: 1px solid #ced4da;
}

.username-container span {
    font-size: 12px;
    color: #666;
    margin-right: 4px;
    font-weight: bold;
}

#nameInput {
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 600;
    width: 100%;
    color: #495057;
    outline: none;
}

#typingIndicator {
    font-size: 12px;
    color: #007aff;
    font-style: italic;
    min-height: 16px;
    font-weight: 500;
}

/* Chat Messages Area */
#chatGrid {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.msg-wrapper {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.msg-wrapper.self {
    align-self: flex-end;
}

.msg-wrapper.other {
    align-self: flex-start;
}

.meta-info {
    font-size: 11px;
    color: #8e8e93;
    margin-bottom: 2px;
    font-weight: 500;
}

.self .meta-info {
    text-align: right;
}

.bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.4;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.self .bubble {
    background: #007aff;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.other .bubble {
    background: #fff;
    border-bottom-left-radius: 4px;
    border: 1px solid #e1e4e8;
}

/* Input Controls Footer */
footer {
    background: #fff;
    padding: 12px 16px;
    border-top: 1px solid #e1e4e8;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

#messageInput {
    flex: 1;
    min-height: 40px;
    max-height: 100px;
    padding: 10px 14px;
    border: 1px solid #ced4da;
    border-radius: 20px;
    font-size: 15px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.3;
}

#messageInput:focus {
    border-color: #007aff;
}

#sendBtn {
    background: #007aff;
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.1s;
}

#sendBtn:active {
    background: #0056b3;
}

#sendBtn:disabled {
    background: #bae0ff;
    cursor: not-allowed;
}

#log {
    padding: 10px;
    background: #f0f0f0;
    border: 1px solid #ccc;
    max-height: 150px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 12px;
}

#status {
    font-size: 13px;
    font-weight: 600;
    color: #ff9800;
    white-space: nowrap;
    margin-left: auto;
    text-align: right;
    line-height: 1.2;
}

#userRoster {
    font-size: 11px;
    color: #8e8e93;
    margin-bottom: 4px;
    overflow-x: auto;
    white-space: nowrap;
    max-width: 100%;
    margin-left: auto;
}

