/* ── Real-Time Chat Room — scoped to .chat-app ── */

.chat-app {
    --chat-accent: var(--color-accent, #ff8c00);
}

.chat-app .chat-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 3rem;
    gap: 1.25rem;
}

.chat-app .username-form,
.chat-app .create-room-box {
    position: fixed;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    min-width: min(90vw, 380px);
    width: auto;
    margin: 0;
    background: var(--color-bg-elevated);
    padding: 1.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg, 14px);
    box-shadow: var(--shadow-md);
    animation: chat-pop-in 0.3s ease-out;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
}

@keyframes chat-pop-in {
    0% {
        opacity: 0;
        transform: translate(-50%, -48%) scale(0.97);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.chat-app .create-room-box h2 {
    margin: 0 0 1.25rem;
    font-size: 1.0625rem;
    font-weight: 600;
    color: var(--color-text);
}

.chat-app .username-label,
.chat-app .room-name-label,
.chat-app .room-key-label {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    text-align: left;
}

.chat-app .username-input,
.chat-app .room-name-input,
.chat-app .room-key-input {
    display: block;
    margin-top: 0.375rem;
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    font-size: 0.9375rem;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
}

.chat-app .username-input:focus,
.chat-app .room-name-input:focus,
.chat-app .room-key-input:focus {
    border-color: var(--color-border-strong);
}

.chat-app .username-submit-btn,
.chat-app .create-room-btn {
    padding: 1.05rem 1rem;
    background: linear-gradient(135deg, #ff8c00, #f59e0b);
    color: #050816;
    border: 1px solid rgba(255, 140, 0, 0.35);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    transition: opacity 0.15s ease, transform 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.5rem;
    box-shadow: 0 10px 25px rgba(255, 140, 0, 0.16);
}

.chat-app .username-submit-btn:hover,
.chat-app .create-room-btn:hover {
    opacity: 0.95;
    transform: translateY(-1px);
}

.chat-app .create-room-cancel-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    color: var(--color-text-muted);
    cursor: pointer;
    background: none;
    border: none;
    transition: color 0.15s ease;
}

.chat-app .create-room-cancel-btn:hover {
    color: #f87171;
    transform: none;
}

.chat-app .user-info {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
    background: var(--color-bg-elevated);
    width: 100%;
    max-width: 900px;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-lg, 14px);
    border: 1px solid var(--color-border);
    box-shadow: none;
}

.chat-app .user-info span {
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    margin: 0;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.chat-app .user-info span:first-child {
    color: #60a5fa;
}

.chat-app .user-info span:last-child {
    color: #22c55e;
    font-weight: 500;
}

@media (min-width: 768px) {
    .chat-app .user-info {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
    }
}

.chat-app .renew-button button {
    padding: 0.5rem 1rem;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    transition: border-color 0.15s ease, color 0.15s ease;
    margin: 0;
}

.chat-app .renew-button button:hover {
    border-color: var(--color-border-strong);
    color: var(--color-text);
    background: var(--color-surface);
}

.chat-app .room-container {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1rem;
    width: 100%;
    max-width: 960px;
}

.chat-app .room-card {
    flex: 1 1 280px;
    background: var(--color-bg-elevated);
    padding: 1.25rem;
    border-radius: var(--radius-lg, 14px);
    border: 1px solid var(--color-border);
    box-shadow: none;
    transition: border-color 0.2s ease;
    margin: 0;
    max-height: 480px;
    overflow: auto;
    min-width: min(100%, 280px);
}

.chat-app .room-card:hover {
    transform: none;
    border-color: var(--color-border-strong);
}

.chat-app .room-card h2 {
    margin: 0 0 0.75rem;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-text);
}

.chat-app .room-list,
.chat-app .user-list {
    margin-top: 0.5rem;
    width: 100%;
}

.chat-app .room {
    position: relative;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 0.9rem 0.85rem 0.9rem;
    border-radius: var(--radius-sm, 6px);
    margin: 0.5rem 0;
    font-size: 0.8125rem;
    border: 1px solid var(--color-border);
    background: rgba(255, 255, 255, 0.02);
    transition: border-color 0.15s ease;
    min-height: 4.25rem;
}

.chat-app .open-room {
    border-color: rgba(96, 165, 250, 0.35);
}

.chat-app .current-users {
    border-color: rgba(168, 85, 247, 0.35);
}

.chat-app .private-room {
    border-color: rgba(248, 113, 113, 0.35);
    border-style: dashed;
}

.chat-app .room:hover {
    transform: none;
    border-color: var(--color-border-strong);
}

.chat-app .room span {
    flex-grow: 1;
    margin-right: 0;
}

.chat-app .room-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 0;
    flex: 1;
    padding-right: 3.6rem;
}

.chat-app .lock-and-button-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
    flex-shrink: 0;
    padding-top: 0.2rem;
}

.chat-app .room-lock {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.12);
    color: #f59e0b;
    flex-shrink: 0;
}

.chat-app .join-btn {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.18), rgba(16, 185, 129, 0.16));
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.35);
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    white-space: nowrap;
    transition: transform 0.15s ease, background 0.15s ease;
    flex-shrink: 0;
}

.chat-app .join-btn:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.24), rgba(16, 185, 129, 0.2));
    transform: translateY(-1px);
}

.chat-app .room-remove {
    position: static;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: #fecaca;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    background: rgba(248, 113, 113, 0.12);
    border: 1px solid rgba(248, 113, 113, 0.28);
    border-radius: var(--radius-sm);
    padding: 0;
    line-height: 1;
}

.chat-app .room-remove:hover {
    transform: translateY(-1px);
    background: rgba(248, 113, 113, 0.18);
    color: #fff;
}

.chat-app .room-remove svg {
    font-size: 18px;
}

.chat-app .room-name {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-app .room-id {
    font-size: 0.6875rem;
    font-family: var(--font-mono);
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-app .create-options {
    position: relative;
    width: min(100%, 420px);
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    justify-content: center;
    align-items: center;
    margin: 0 auto;
}

.chat-app .create-rooms {
    display: flex;
    justify-content: center;
    width: 100%;
    margin: 1rem 0 0.75rem;
}

.chat-app .create-btn {
    background: rgba(255, 140, 0, 0.14);
    color: #ffbf69;
    border: 1px solid rgba(255, 140, 0, 0.3);
    padding: 1.05rem 1rem;
    border-radius: var(--radius-sm);
    margin: 0;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    transition: background 0.15s ease, transform 0.15s ease;
}

.chat-app .create-btn.private {
    background: rgba(168, 85, 247, 0.12);
    color: #c084fc;
    border-color: rgba(168, 85, 247, 0.3);
}

.chat-app .create-btn:hover {
    background: rgba(255, 140, 0, 0.22);
    transform: translateY(-1px);
}

.chat-app .create-btn.private:hover {
    background: rgba(168, 85, 247, 0.2);
}

.chat-app .active-chat-container {
    display: flex;
    flex-direction: column;
    width: min(100%, 960px);
    max-width: 960px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg, 14px);
    box-shadow: var(--shadow-sm);
    margin: 0;
    overflow: hidden;
}

.chat-app .chat-header {
    background: var(--color-surface);
    color: var(--color-text);
    padding: 0.875rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--color-border);
}

.chat-app .chat-header h2 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-app .exit-btn {
    background: rgba(248, 113, 113, 0.12);
    color: #f87171;
    border: 1px solid rgba(248, 113, 113, 0.3);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    font-weight: 500;
}

.chat-app .exit-btn:hover {
    background: rgba(248, 113, 113, 0.2);
}

.chat-app .chat-input {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--color-border);
    background: var(--color-bg);
}

.chat-app .chat-input textarea {
    flex-grow: 1;
    resize: none;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    margin-right: 0;
    max-height: 120px;
    overflow-y: auto;
    background: var(--color-bg-elevated);
    color: var(--color-text);
    font-family: inherit;
    font-size: 0.875rem;
    outline: none;
}

.chat-app .send-btn {
    background: linear-gradient(135deg, #ff8c00, #f59e0b);
    color: #050816;
    border: 1px solid rgba(255, 140, 0, 0.35);
    padding: 0.65rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    box-shadow: 0 10px 30px rgba(255, 140, 0, 0.18);
}

.chat-app .send-btn:hover {
    opacity: 0.9;
}

.chat-app .request-pending {
    position: relative;
    width: 100%;
    max-width: 560px;
    background: var(--color-bg-elevated);
    padding: 0.5rem;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid var(--color-border);
}

.chat-app .confirmation-overlay,
.chat-app .alert-message {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    animation: chat-slide-up 0.3s ease-out;
}

@keyframes chat-slide-up {
    0% { opacity: 0; transform: translateX(-50%) translateY(12px); }
    100% { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.chat-app .alert-message {
    background: rgba(7, 11, 24, 0.95);
    padding: 1rem 1.25rem 2.75rem;
    width: min(90vw, 480px);
    height: auto;
    min-height: auto;
    border: 1px solid rgba(255, 140, 0, 0.26);
    border-radius: var(--radius-lg, 14px);
    box-shadow: 0 16px 40px rgba(2, 6, 23, 0.45);
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    animation: chat-slide-up 0.3s ease-out;
}

.chat-app .alert-message button {
    position: absolute;
    bottom: 0.75rem;
    right: 0.75rem;
    background: rgba(34, 197, 94, 0.12);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
    padding: 0.375rem 0.75rem;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
}

.chat-app .confirmation-box {
    background: var(--color-bg-elevated);
    padding: 1.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg, 14px);
    box-shadow: var(--shadow-md);
    color: var(--color-text);
    animation: none;
}

.chat-app .confirmation-buttons button {
    position: relative;
    left: auto;
    padding: 0.5rem 1rem;
    margin: 0.75rem 0.375rem 0 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    background: var(--color-surface);
    color: var(--color-text-secondary);
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.chat-app .chat-messages {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    padding: 1rem;
    min-height: 280px;
    max-height: 45dvh;
    overflow-y: auto;
    gap: 0.25rem;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent);
}

.chat-app .group-messages {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
    margin-bottom: 0.35rem;
}

.chat-app .group-messages.mine {
    align-items: flex-end;
}

.chat-app .group-messages.others {
    align-items: flex-start;
}

.chat-app .my-message,
.chat-app .other-message {
    position: relative;
    max-width: min(82%, 360px);
    word-wrap: break-word;
    padding: 0.625rem 0.875rem;
    margin-bottom: 0;
    animation: chat-fade-in 0.25s ease;
    width: fit-content;
    white-space: pre-wrap;
    font-size: 0.875rem;
    line-height: 1.5;
}

@keyframes chat-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-app .my-message {
    border: 1px solid rgba(255, 140, 0, 0.3);
    background: rgba(255, 140, 0, 0.08);
    color: var(--color-text);
    border-radius: 12px 12px 4px 12px;
    align-self: flex-end;
    margin-right: 0;
}

.chat-app .other-message {
    border: 1px solid rgba(96, 165, 250, 0.3);
    background: rgba(96, 165, 250, 0.08);
    color: var(--color-text);
    border-radius: 12px 12px 12px 4px;
    align-self: flex-start;
    margin-left: 0;
}

.chat-app .message-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.15rem;
}

.chat-app .message-author {
    font-size: 0.6875rem;
    font-family: var(--font-mono);
    font-style: normal;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-app .group-messages.system {
    align-items: center;
}

.chat-app .system-message {
    width: fit-content;
    max-width: min(90%, 420px);
    padding: 0.45rem 0.7rem;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.14);
    color: var(--color-text-secondary);
    font-size: 0.75rem;
    text-align: center;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.chat-app .display-chat {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.chat-app .display-chat > * {
    width: 100%;
}

.chat-app .room-password-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 260;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(2, 6, 23, 0.65);
    backdrop-filter: blur(4px);
}

.chat-app .room-password-modal {
    width: min(100%, 360px);
    padding: 1.25rem;
    border-radius: var(--radius-lg, 14px);
    border: 1px solid var(--color-border);
    background: var(--color-bg-elevated);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.chat-app .room-password-modal h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--color-text);
}

.chat-app .room-password-modal p {
    margin: 0;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

.chat-app .room-password-input {
    width: 100%;
    padding: 0.7rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
}

.chat-app .room-password-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.65rem;
    margin-top: 0.25rem;
}

.chat-app .room-password-cancel,
.chat-app .room-password-submit {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm, 6px);
    padding: 0.55rem 0.8rem;
    cursor: pointer;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.chat-app .room-password-cancel {
    background: var(--color-surface);
    color: var(--color-text-secondary);
}

.chat-app .room-password-submit {
    background: var(--chat-accent);
    border-color: transparent;
    color: var(--color-bg);
}

@media (max-width: 768px) {
    .chat-app .room-container {
        flex-direction: column;
    }

    .chat-app .room-card {
        flex: 1 1 100%;
    }

    .chat-app .active-chat-container {
        max-width: 100%;
    }
}
