* {
    box-sizing: border-box;
}

:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --blue-light: #eff6ff;
    --black: #111827;
    --gray-dark: #374151;
    --gray: #6b7280;
    --gray-light: #e5e7eb;
    --gray-background: #f3f4f6;
    --white: #ffffff;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family:
            -apple-system,
            BlinkMacSystemFont,
            "Segoe UI",
            Roboto,
            Arial,
            sans-serif;
    background: var(--gray-background);
    color: var(--black);
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
    border: none;
    transition:
            background-color 0.2s ease,
            transform 0.1s ease,
            opacity 0.2s ease;
}

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

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

input {
    border: 1px solid var(--gray-light);
    border-radius: 8px;
    padding: 10px 12px;
    outline: none;
    transition:
            border-color 0.2s ease,
            box-shadow 0.2s ease;
}

input:focus {
    border-color: var(--blue);
    box-shadow:
            0 0 0 3px
            rgba(37, 99, 235, 0.15);
}

/* =========================
   AUTH SCREEN
========================= */

#auth-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 420px;
    background: var(--white);
    border-radius: 16px;
    padding: 32px;
    box-shadow:
            0 20px 50px
            rgba(0, 0, 0, 0.12);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo h1 {
    margin: 0;
    font-size: 36px;
    color: var(--blue);
}

.auth-logo p {
    margin-top: 8px;
    color: var(--gray);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-group label {
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-dark);
}

.form-group input {
    width: 100%;
}

#login-button {
    width: 100%;
    padding: 11px;
    border-radius: 8px;
    background: var(--blue);
    color: var(--white);
    font-weight: 600;
}

#login-button:hover {
    background: var(--blue-dark);
}

#login-status {
    display: block;
    margin-top: 16px;
    text-align: center;
    font-size: 14px;
    color: var(--gray);
}

/* =========================
   APPLICATION
========================= */

#app-screen {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* =========================
   HEADER
========================= */

.app-header {
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    background: var(--black);
    color: var(--white);
}

.app-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 700;
}

.app-logo-icon {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--blue);
    color: var(--white);
    font-weight: 800;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

#connection-status {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    color: #d1d5db;
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--gray);
}

#logout-button {
    padding: 8px 14px;
    border-radius: 7px;
    background: #374151;
    color: var(--white);
    font-size: 14px;
}

#logout-button:hover {
    background: #4b5563;
}

/* =========================
   MAIN LAYOUT
========================= */

.app-layout {
    display: flex;
    height: calc(100vh - 64px);
}

/* =========================
   SIDEBAR
========================= */

.sidebar {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--white);
    border-right: 1px solid var(--gray-light);
}

.sidebar-section {
    padding: 18px;
}

.sidebar-section + .sidebar-section {
    border-top: 1px solid var(--gray-light);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.section-header h2 {
    margin: 0;
    font-size: 15px;
    color: var(--gray-dark);
}

.create-room {
    display: flex;
    gap: 8px;
}

.create-room input {
    min-width: 0;
    flex: 1;
}

#create-room-button {
    padding: 0 13px;
    border-radius: 8px;
    background: var(--blue);
    color: var(--white);
    font-weight: 600;
}

#create-room-button:hover {
    background: var(--blue-dark);
}

/* =========================
   ROOMS
========================= */

#rooms {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}

.room-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 10px;
    cursor: pointer;
    transition:
            background-color 0.15s ease,
            transform 0.1s ease;
}

.room-item:hover {
    background: var(--gray-background);
}

.room-item.selected {
    background: var(--blue-light);
}

.room-icon {
    width: 38px;
    height: 38px;
    flex-shrink: 0;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 11px;

    background: var(--blue);
    color: var(--white);

    font-size: 16px;
    font-weight: 700;
}

.room-info {
    min-width: 0;
    flex: 1;
}

.room-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

    font-weight: 600;
    font-size: 14px;
}

.room-unread-badge {
    min-width: 20px;
    height: 20px;

    padding: 0 6px;

    display: none;
    align-items: center;
    justify-content: center;

    border-radius: 10px;

    background: var(--blue);
    color: var(--white);

    font-size: 11px;
    font-weight: 700;

    flex-shrink: 0;
}

.room-unread-badge.visible {
    display: flex;
}
/*
#rooms {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 400px;
    overflow-y: auto;
}

.room-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.room-item:hover {
    background: var(--gray-background);
}

.room-item.active {
    background: var(--blue-light);
    color: var(--blue-dark);
}

.room-icon {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--blue);
    color: var(--white);
    font-weight: 700;
}

.room-info {
    min-width: 0;
    flex: 1;
}

.room-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 600;
}

.room-id {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-top: 2px;
    color: var(--gray);
    font-size: 11px;
}

.delete-room-button {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: transparent;
    color: var(--gray);
    opacity: 0;
    transition:
            opacity 0.2s ease,
            background-color 0.2s ease,
            color 0.2s ease;
}

.room-item:hover
.delete-room-button {
    opacity: 1;
}

.delete-room-button:hover {
    background: var(--danger-light);
    color: var(--danger);
}

.room-unread-badge {
    display: none;
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--danger);
    color: var(--white);
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.room-unread-badge.visible {
    display: inline-block;
}

 */
/* =========================
   INVITATIONS
========================= */

.invitations-section {
    max-height: 300px;
    overflow-y: auto;
}

#invitations {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.invitation-item {
    padding: 12px;
    border-radius: 8px;
    background: var(--blue-light);
    border: 1px solid #dbeafe;
}

.invitation-name {
    margin-bottom: 8px;
    font-weight: 600;
}

.invitation-actions {
    display: flex;
    gap: 8px;
}

.invitation-actions button {
    flex: 1;
    padding: 7px;
    border-radius: 6px;
    font-size: 13px;
}

.accept-invitation {
    background: var(--blue);
    color: var(--white);
}

.decline-invitation {
    background: var(--white);
    color: var(--danger);
    border: 1px solid #fecaca;
}

/* =========================
   CHAT
========================= */

.chat-area {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f9fafb;
}

.chat-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    background: var(--white);
    border-bottom: 1px solid var(--gray-light);
}

#current-room-name {
    font-size: 18px;
    font-weight: 700;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 12px;
    background: var(--white);
    box-shadow:
            0 1px 3px
            rgba(0, 0, 0, 0.08);
}

.message.own {
    align-self: flex-end;
    background: var(--blue);
    color: var(--white);
}

.message-sender {
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    opacity: 0.7;
}

.message-text {
    word-break: break-word;
    line-height: 1.4;
}

.chat-input-area {
    display: flex;
    gap: 10px;
    padding: 16px 24px;
    background: var(--white);
    border-top: 1px solid var(--gray-light);
}

#message-input {
    flex: 1;
    min-width: 0;
}

#send-button {
    padding: 0 20px;
    border-radius: 8px;
    background: var(--blue);
    color: var(--white);
    font-weight: 600;
}

#send-button:hover {
    background: var(--blue-dark);
}

/* =========================
   EMPTY CHAT
========================= */

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gray);
}

.empty-chat-icon {
    font-size: 48px;
    margin-bottom: 12px;
    opacity: 0.5;
}

.empty-chat h2 {
    margin: 0 0 8px;
    color: var(--gray-dark);
}

.empty-chat p {
    margin: 0;
}

/* =========================
   INVITE PANEL
========================= */

.invite-panel {
    padding: 14px 18px;
    background: var(--white);
    border-top: 1px solid var(--gray-light);
}

.invite-panel h3 {
    margin: 0 0 10px;
    font-size: 14px;
}

.invite-form {
    display: flex;
    gap: 8px;
}

#user-id-input {
    flex: 1;
    min-width: 0;
}

#invite-user-button {
    padding: 0 14px;
    border-radius: 8px;
    background: var(--blue);
    color: var(--white);
}

#invite-status {
    margin: 8px 0 0;
    font-size: 13px;
    color: var(--gray);
}

/* =========================
   RESPONSIVE
========================= */

@media (max-width: 800px) {
    .sidebar {
        width: 260px;
    }

    .chat-input-area {
        padding: 12px;
    }

    #messages {
        padding: 16px;
    }
}

@media (max-width: 600px) {
    .app-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: 45%;
        border-right: none;
        border-bottom: 1px solid var(--gray-light);
    }

    .chat-area {
        height: 55%;
    }

    .invitations-section {
        display: none;
    }

    .app-header {
        padding: 0 14px;
    }

    .header-right {
        gap: 8px;
    }

    #connection-status {
        display: none;
    }

    .message {
        max-width: 85%;
    }
}

/* =========================
   ROOM MENU
========================= */

.room-context-menu {
    position: fixed;
    z-index: 1000;

    min-width: 190px;

    padding: 6px;

    background: var(--white);

    border: 1px solid var(--border);
    border-radius: 10px;

    box-shadow:
            0 8px 24px rgba(0, 0, 0, 0.15);

    opacity: 0;
    visibility: hidden;

    transform: scale(0.96);
    transform-origin: top left;

    transition:
            opacity 0.12s ease,
            transform 0.12s ease,
            visibility 0.12s ease;
}

.room-context-menu.visible {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

.room-context-menu-item {
    width: 100%;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 9px 10px;

    border: none;
    border-radius: 7px;

    background: transparent;

    color: var(--text);
    font-size: 14px;

    text-align: left;

    cursor: pointer;
}

.room-context-menu-item:hover {
    background: var(--gray-background);
}

.room-context-menu-item.danger {
    color: var(--danger);
}

.room-context-menu-item.danger:hover {
    background: var(--danger-light);
}