* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Inter, Arial, sans-serif;
    background: #f4f7fb;
    color: #172033;
}

a {
    color: #3f6ee8;
    text-decoration: none;
}

button,
input {
    font: inherit;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #315bdc, #6e8eff);
}

.auth-card {
    width: min(430px, calc(100% - 28px));
    background: #fff;
    padding: 32px;
    border-radius: 22px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, .18);
}

.auth-card h1 {
    margin: 0 0 8px;
}

.muted {
    color: #738096;
}

.small {
    font-size: 13px;
}

.auth-form {
    display: grid;
    gap: 10px;
    margin-top: 20px;
}

.auth-form label {
    font-weight: 700;
    font-size: 14px;
}

.auth-form input,
.message-form input {
    width: 100%;
    border: 1px solid #dbe2ef;
    border-radius: 14px;
    padding: 14px 16px;
    outline: none;
}

.auth-form input:focus,
.message-form input:focus {
    border-color: #4f75e8;
    box-shadow: 0 0 0 4px rgba(79, 117, 232, .12);
}

.auth-form button,
.message-form button,
.admin-card button,
.section-title-row button {
    border: 0;
    background: #4169e1;
    color: #fff;
    border-radius: 14px;
    padding: 13px 18px;
    font-weight: 800;
    cursor: pointer;
}

.auth-links {
    text-align: center;
}

.alert {
    padding: 12px 14px;
    border-radius: 14px;
    margin: 14px 0;
}

.alert ul {
    margin: 0;
    padding-left: 20px;
}

.alert-error {
    background: #ffe9e9;
    color: #a22121;
}

.alert-success {
    background: #e7f8ee;
    color: #176339;
}

.admin-box {
    background: #f3f6ff;
    border: 1px dashed #9fb4ff;
    padding: 14px;
    border-radius: 14px;
    margin-top: 16px;
    line-height: 1.65;
}

.app-shell {
    display: grid;
    grid-template-columns: 330px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: #fff;
    border-right: 1px solid #e2e8f0;
    padding: 22px;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 22px;
}

.sidebar h1 {
    margin: 0 0 4px;
    font-size: 24px;
}

.logout-link,
.admin-link {
    display: inline-block;
    background: #edf2ff;
    border-radius: 12px;
    padding: 10px 12px;
    font-weight: 800;
}

.admin-link {
    width: 100%;
    text-align: center;
    margin-bottom: 14px;
}

.room-list,
.user-list {
    display: grid;
    gap: 10px;
}

.room-item,
.user-item {
    display: flex;
    width: 100%;
    border: 0;
    border-radius: 16px;
    padding: 14px;
    background: transparent;
    cursor: pointer;
    align-items: center;
    gap: 12px;
    text-align: left;
}

.room-item.active,
.user-item.active {
    background: #eef4ff;
    color: #2f5fe4;
}

.sidebar-title {
    margin: 28px 0 12px;
    color: #6f7b91;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .08em;
}

.avatar {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #4169e1, #80a1ff);
    color: #fff;
    font-weight: 900;
}

.user-meta {
    display: grid;
    gap: 4px;
    flex: 1;
}

.user-meta small {
    color: #7d8797;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #c1cad8;
}

.status-dot.online {
    background: #35c879;
}

.chat-panel {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-width: 0;
}

.chat-header {
    background: #fff;
    padding: 24px 30px;
    border-bottom: 1px solid #e2e8f0;
}

.chat-header h2 {
    margin: 0 0 6px;
}

.messages {
    padding: 28px 30px;
    overflow-y: auto;
    max-height: calc(100vh - 170px);
}

.message-row {
    display: flex;
    margin-bottom: 18px;
}

.message-row.mine {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(620px, 85%);
    background: #fff;
    border-radius: 18px;
    padding: 14px 16px;
    box-shadow: 0 10px 30px rgba(20, 35, 70, .06);
}

.message-row.mine .message-bubble {
    background: #eaf1ff;
}

.message-top {
    display: flex;
    gap: 14px;
    justify-content: space-between;
    color: #4169e1;
    font-size: 13px;
    margin-bottom: 8px;
}

.message-top time {
    color: #8791a2;
    white-space: nowrap;
}

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

.message-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 14px;
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 20px 30px;
}

.empty-state {
    text-align: center;
    color: #7d8797;
    padding: 70px 20px;
}

.admin-page {
    background: #f4f7fb;
}

.admin-layout {
    max-width: 1180px;
    margin: 0 auto;
    padding: 28px;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: center;
    margin-bottom: 22px;
}

.admin-header h1 {
    margin: 0 0 6px;
}

.admin-header nav {
    display: flex;
    gap: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    margin-bottom: 18px;
}

.stat-card,
.admin-card {
    background: #fff;
    border-radius: 20px;
    padding: 20px;
    box-shadow: 0 12px 35px rgba(20, 35, 70, .06);
}

.stat-card span {
    color: #6f7b91;
}

.stat-card strong {
    display: block;
    font-size: 34px;
    margin-top: 8px;
}

.admin-card {
    margin-bottom: 18px;
}

.admin-card h2 {
    margin: 0 0 16px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid #e7edf6;
    text-align: left;
    vertical-align: middle;
}

th {
    color: #647087;
    font-size: 13px;
    text-transform: uppercase;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 5px 9px;
    background: #edf2ff;
    color: #365bd6;
    font-weight: 800;
    font-size: 12px;
}

.badge.good {
    background: #e7f8ee;
    color: #176339;
}

.badge.bad {
    background: #ffe9e9;
    color: #a22121;
}

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

.actions form {
    margin: 0;
}

button.small {
    padding: 8px 10px;
    border-radius: 10px;
}

button.danger,
.danger {
    background: #e13f55 !important;
}

.section-title-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
}

@media (max-width: 820px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-right: 0;
        border-bottom: 1px solid #e2e8f0;
    }

    .message-form {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .admin-header,
    .section-title-row {
        align-items: stretch;
        flex-direction: column;
    }
}


.admin-layout.narrow {
    max-width: 760px;
}

.password-card {
    max-width: 620px;
}


button.warning,
.warning {
    background: #f59e0b !important;
}

.badge.role-admin {
    background: #fff1f2;
    color: #be123c;
}

.badge.role-moderator {
    background: #fff7ed;
    color: #c2410c;
}

.badge.role-user {
    background: #edf2ff;
    color: #365bd6;
}


.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.private-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.hidden {
    display: none !important;
}

.outline-btn,
.danger-btn {
    border: 0;
    border-radius: 12px;
    padding: 10px 13px;
    font-weight: 800;
    cursor: pointer;
}

.outline-btn {
    background: #edf2ff;
    color: #365bd6;
}

.danger-btn {
    background: #e13f55;
    color: #fff;
}

.message-form input:disabled {
    background: #eef2f7;
    cursor: not-allowed;
}


/* Admin left sidebar layout */
.admin-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.admin-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-bottom: 18px;
    border-bottom: 1px solid #e7edf6;
}

.admin-logo {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 14px;
    background: linear-gradient(135deg, #4169e1, #80a1ff);
    color: #fff;
    font-weight: 900;
}

.admin-brand strong,
.admin-brand small {
    display: block;
}

.admin-brand small {
    color: #738096;
    margin-top: 3px;
}

.admin-side-nav {
    display: grid;
    gap: 8px;
}

.admin-side-nav a {
    display: block;
    padding: 12px 14px;
    border-radius: 14px;
    color: #172033;
    font-weight: 800;
}

.admin-side-nav a:hover {
    background: #eef4ff;
    color: #2f5fe4;
}

.admin-side-nav .logout-side-link {
    margin-top: 14px;
    color: #e13f55;
    background: #fff1f2;
}

.admin-layout {
    width: 100%;
}

.admin-card {
    scroll-margin-top: 24px;
}

.admin-card#reports,
.admin-card#users,
.admin-card#messages {
    border: 1px solid #e7edf6;
}

@media (max-width: 920px) {
    .admin-shell {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        position: relative;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid #e2e8f0;
    }

    .admin-side-nav {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
}


.admin-side-nav a.active {
    background: #eef4ff;
    color: #2f5fe4;
}

.admin-page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
}

.admin-page-card {
    display: grid;
    gap: 8px;
    background: #f8fbff;
    border: 1px solid #e7edf6;
    border-radius: 18px;
    padding: 18px;
    color: #172033;
}

.admin-page-card:hover {
    background: #eef4ff;
    color: #2f5fe4;
}

.admin-page-card strong {
    font-size: 18px;
}

.admin-page-card span {
    color: #738096;
    line-height: 1.45;
}

.stat-link {
    color: #172033;
    text-decoration: none;
}

.stat-link:hover {
    transform: translateY(-1px);
}


.inline-admin-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-top: 16px;
}

.inline-admin-form input {
    border: 1px solid #dbe2ef;
    border-radius: 14px;
    padding: 13px 15px;
    outline: none;
}

.inline-admin-form input:focus {
    border-color: #4f75e8;
    box-shadow: 0 0 0 4px rgba(79, 117, 232, .12);
}

.inline-admin-form button {
    border: 0;
    background: #4169e1;
    color: #fff;
    border-radius: 14px;
    padding: 13px 18px;
    font-weight: 800;
    cursor: pointer;
}

@media (max-width: 720px) {
    .inline-admin-form {
        grid-template-columns: 1fr;
    }
}


/* Modern popup/toast UI */
.toast-stack {
    position: fixed;
    top: 18px;
    right: 18px;
    display: grid;
    gap: 12px;
    z-index: 9999;
    width: min(380px, calc(100vw - 36px));
}

.modern-toast {
    display: grid;
    grid-template-columns: 34px 1fr auto;
    gap: 12px;
    align-items: center;
    background: rgba(255, 255, 255, .96);
    border: 1px solid #e7edf6;
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 20px 70px rgba(17, 24, 39, .16);
    animation: toastIn .22s ease-out;
    backdrop-filter: blur(12px);
}

.modern-toast.success {
    border-left: 5px solid #22c55e;
}

.modern-toast.error {
    border-left: 5px solid #ef4444;
}

.modern-toast.info {
    border-left: 5px solid #4169e1;
}

.modern-toast.leaving {
    animation: toastOut .18s ease-in forwards;
}

.toast-icon {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: 12px;
    background: #eef4ff;
    color: #2f5fe4;
    font-weight: 900;
}

.modern-toast.success .toast-icon {
    background: #e7f8ee;
    color: #176339;
}

.modern-toast.error .toast-icon {
    background: #ffe9e9;
    color: #a22121;
}

.toast-message {
    color: #172033;
    line-height: 1.35;
    font-weight: 700;
}

.toast-close {
    border: 0;
    background: transparent;
    color: #738096;
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}

.modern-modal-overlay {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(15, 23, 42, .48);
    z-index: 10000;
    animation: fadeIn .16s ease-out;
    backdrop-filter: blur(8px);
}

.modern-modal-overlay.leaving {
    animation: fadeOut .16s ease-in forwards;
}

.modern-modal {
    width: min(440px, 100%);
    background: #fff;
    border-radius: 24px;
    padding: 24px;
    box-shadow: 0 28px 90px rgba(15, 23, 42, .32);
    animation: modalIn .18s ease-out;
}

.modern-modal-icon {
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 16px;
    background: #eef4ff;
    color: #2f5fe4;
    font-weight: 900;
    font-size: 24px;
    margin-bottom: 14px;
}

.modern-modal-icon.danger {
    background: #ffe9e9;
    color: #a22121;
}

.modern-modal h3 {
    margin: 0 0 8px;
    font-size: 22px;
}

.modern-modal p {
    margin: 0 0 18px;
    color: #647087;
    line-height: 1.5;
}

.modern-modal-input {
    width: 100%;
    resize: vertical;
    border: 1px solid #dbe2ef;
    border-radius: 16px;
    padding: 13px 15px;
    outline: none;
    margin-bottom: 18px;
    font: inherit;
}

.modern-modal-input:focus {
    border-color: #4f75e8;
    box-shadow: 0 0 0 4px rgba(79, 117, 232, .12);
}

.modern-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modern-modal-actions button {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 900;
    cursor: pointer;
}

.modal-cancel {
    background: #eef2f7;
    color: #172033;
}

.modal-confirm {
    background: #4169e1;
    color: #fff;
}

.modal-confirm.danger {
    background: #e13f55;
}

.alert-inline-hidden {
    display: none !important;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-8px) scale(.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-8px) scale(.98); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(10px) scale(.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 560px) {
    .toast-stack {
        top: 12px;
        right: 12px;
        width: calc(100vw - 24px);
    }

    .modern-modal-actions {
        display: grid;
    }
}


/* Private chat emoji picker */
.message-form {
    position: relative;
}

.emoji-button {
    border: 0;
    background: #eef4ff;
    color: #172033;
    border-radius: 14px;
    padding: 0 14px;
    font-size: 22px;
    cursor: pointer;
    min-height: 48px;
}

.emoji-button:hover {
    background: #dfe9ff;
}

.emoji-picker {
    position: absolute;
    left: 30px;
    bottom: 82px;
    width: min(330px, calc(100vw - 60px));
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 8px;
    background: #fff;
    border: 1px solid #e7edf6;
    border-radius: 20px;
    padding: 14px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, .18);
    z-index: 40;
}

.emoji-picker button {
    border: 0;
    background: #f4f7fb;
    border-radius: 12px;
    padding: 9px;
    font-size: 22px;
    cursor: pointer;
}

.emoji-picker button:hover {
    background: #eef4ff;
    transform: translateY(-1px);
}

@media (min-width: 821px) {
    .message-form {
        grid-template-columns: auto 1fr auto;
    }
}

@media (max-width: 820px) {
    .emoji-button {
        width: 100%;
    }

    .emoji-picker {
        left: 20px;
        bottom: 146px;
    }
}


/* Fix room send button width */
.message-form {
    grid-template-columns: 1fr auto !important;
}

.message-form.private-mode {
    grid-template-columns: auto 1fr auto !important;
}

.message-form > button[type="submit"] {
    width: auto;
    min-width: 120px;
    white-space: nowrap;
}

.message-form .emoji-button.hidden {
    display: none !important;
}

@media (max-width: 820px) {
    .message-form {
        grid-template-columns: 1fr auto !important;
    }

    .message-form.private-mode {
        grid-template-columns: auto 1fr auto !important;
    }

    .message-form > button[type="submit"] {
        min-width: 96px;
    }

    .emoji-button {
        width: auto !important;
    }
}


/* WebRTC private audio/video calls */
.call-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.call-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .54);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 9500;
    backdrop-filter: blur(8px);
}

.call-card {
    width: min(760px, 100%);
    background: #ffffff;
    border-radius: 26px;
    box-shadow: 0 30px 100px rgba(15, 23, 42, .32);
    overflow: hidden;
}

.call-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 20px 22px;
    border-bottom: 1px solid #e7edf6;
}

.call-header h3 {
    margin: 0 0 4px;
}

.call-header p {
    margin: 0;
    color: #738096;
}

.call-end-btn {
    border: 0;
    background: #e13f55;
    color: #fff;
    border-radius: 14px;
    padding: 12px 18px;
    font-weight: 900;
    cursor: pointer;
}

.call-video-area {
    position: relative;
    background: #0f172a;
    min-height: 420px;
    display: grid;
    place-items: center;
}

#remoteVideo {
    width: 100%;
    height: 100%;
    max-height: 520px;
    object-fit: cover;
    background: #0f172a;
}

#localVideo {
    position: absolute;
    right: 18px;
    bottom: 18px;
    width: 180px;
    height: 120px;
    object-fit: cover;
    border: 3px solid #fff;
    border-radius: 18px;
    background: #172033;
    box-shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

.call-audio-area {
    min-height: 320px;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #eef4ff, #ffffff);
    text-align: center;
    padding: 40px;
}

.call-audio-avatar {
    width: 92px;
    height: 92px;
    display: grid;
    place-items: center;
    border-radius: 30px;
    background: #4169e1;
    color: #fff;
    font-size: 42px;
    box-shadow: 0 18px 60px rgba(65, 105, 225, .28);
}

.call-audio-area strong {
    font-size: 24px;
}

.call-audio-area span {
    color: #738096;
}

@media (max-width: 700px) {
    .private-actions {
        justify-content: flex-start;
    }

    .call-video-area {
        min-height: 320px;
    }

    #localVideo {
        width: 120px;
        height: 86px;
    }

    .call-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .call-end-btn {
        width: 100%;
    }
}


.call-btn:disabled {
    opacity: .45;
    cursor: not-allowed;
    filter: grayscale(.3);
}


/* Webcam-first video call fixes */
.call-video-area::before {
    content: "Waiting for remote video...";
    position: absolute;
    color: rgba(255,255,255,.7);
    font-weight: 800;
    z-index: 0;
}

#remoteVideo {
    position: relative;
    z-index: 1;
}

#localVideo {
    z-index: 2;
}

#localVideo[srcObject] {
    background: #111827;
}
