/* ==========================================================
   iOKChat — FULL CHAT SYSTEM LAYOUT (MOBILE + DESKTOP FIXED)
========================================================== */

/* Prevent body scroll on mobile, fix 100vh bug */
html, body {
    margin: 0;
    padding: 0;
    overflow: hidden;
    height: 100%;
    background: #050712;
    color: #f5f5ff;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* Dynamic mobile viewport unit */
:root {
    --vh: 1vh;
}

#app {
    height: calc(var(--vh) * 100);
    display: flex;
    flex-direction: column;
}

/* ==========================================================
   TOP BAR (FIXED)
========================================================== */
.topbar {
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: #050712;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    font-size: 14px;
    color: #fefefe;
}

.top-user {
    font-size: 13px;
    opacity: 0.85;
}

/* ==========================================================
   MAIN AREA LAYOUT
========================================================== */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Views */
.view { padding: 12px; }
.view.hidden { display: none !important; }

/* Auth cards */
.card {
    background: rgba(15,18,30,0.96);
    border-radius: 14px;
    padding: 16px 14px;
    margin-bottom: 12px;
    box-shadow: 0 18px 40px rgba(0,0,0,0.55);
    border: 1px solid rgba(255,255,255,0.06);
}

/* ==========================================================
   CHAT LAYOUT (LEFT BAR + CENTER CHAT)
========================================================== */

.layout-shell {
    display: flex;
    height: calc(var(--vh) * 100 - 56px);
}

/* ============ LEFT ICON BAR ============ */
.side-left {
    width: 58px;
    min-width: 58px;
    background: #050712;
    border-right: 1px solid rgba(255,255,255,0.05);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 6px;
    gap: 6px;
}

.side-left-logo {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    background: linear-gradient(135deg, #ff8a4a, #ffc857);
    margin-bottom: 4px;
}

.side-left-btn {
    width: 38px;
    height: 38px;
    border-radius: 999px;
    border: none;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #d0d4ff;
    font-size: 17px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, transform 0.06s ease;
}

.side-left-btn:hover,
.side-left-btn.active {
    background: rgba(255,255,255,0.10);
    color: #ffffff;
}

.side-left-btn:active {
    transform: scale(0.95);
}

.side-left-spacer { flex: 1; }

/* ==========================================================
   CENTER CHAT COLUMN — FIXED TOP + BOTTOM ON MOBILE
========================================================== */
.chat-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;

    /* True mobile-safe height */
    height: calc(var(--vh) * 100 - 56px);
    overflow-y: auto;
    overflow-x: hidden;
}

.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Chat Room Header (Fixed Under Topbar) */
.chat-header {
    padding: 12px 16px;
    font-size: 16px;
    font-weight: 600;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: #050712;

    position: sticky;
    top: 56px;
    z-index: 50;
    flex-shrink: 0;
}

/* ==========================================================
   MESSAGES SCROLL AREA
========================================================== */
/* Prevent messages from hiding under fixed chat-input */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;

    padding-bottom: 90px;  /* <— CRITICAL: match or exceed chat-input height */

    display: flex;
    flex-direction: column;
    gap: 7px;
    -webkit-overflow-scrolling: touch;
}


/* Messages */
.message {
    display: flex;
    gap: 8px;
    font-size: 13px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 999px;
    overflow: hidden;
    flex-shrink: 0;
    background: rgba(255,255,255,0.03);
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-body { flex: 1; min-width: 0; }

.message-meta {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-size: 11px;
    opacity: 0.85;
}

.message-user { font-weight: 600; }
.message-rank { font-size: 10px; opacity: 0.75; }
.message-time { margin-left: auto; font-size: 10px; opacity: 0.6; }

.message-text {
    font-size: 13px;
    word-wrap: break-word;
}

/* Typing indicator */
.typing {
    height: 20px;
    padding: 0 16px;
    font-size: 11px;
    opacity: 0.7;
    flex-shrink: 0;
}

/* ==========================================================
   FIXED INPUT BAR + ATTACHMENT ICON
========================================================== */
.chat-input {
    position: fixed;
    bottom: 0;
    left: 80px;              /* adjust if you have a sidebar */
    right: 0;

    padding: 10px 12px;
    display: flex;
    align-items: center;
    gap: 8px;

    background: rgba(5,7,18,0.98);
    border-top: 1px solid rgba(255,255,255,0.08);
    z-index: 1000;

    white-space: nowrap;
}


/* ===========================
   Input Field
=========================== */
.chat-input input {
    flex: 1;
    min-width: 0;          /* Prevent overflow pushing icons */
    padding: 9px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.03);
    color: #fff;
    font-size: 13px;
    outline: none;
}

.chat-input input:focus {
    border-color: rgba(122,146,255,0.95);
}

/* ===========================
   Send Button
=========================== */
.chat-input .btn {
    padding-inline: 14px;
    flex-shrink: 0;
}

/* ===========================
   Attachment Button
=========================== */
.chat-attach-btn {
    background: none;
    border: none;
    color: #9aa0b6;
    font-size: 17px;
    cursor: pointer;

    padding: 6px 8px;
    border-radius: 8px;

    height: 32px;          /* Match input height */
    width: 32px;

    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-attach-btn:hover {
    color: #cbd3e5;
    background: rgba(255,255,255,0.05);
}

/* ==========================================================
   LIST WIDGETS (Rooms, Users, Staff)
========================================================== */
.list-column { display:flex; flex-direction:column; gap:6px; }

.list-item {
    display:flex; align-items:center; gap:7px;
    padding:7px 8px;
    border-radius:8px;
    background: rgba(255,255,255,0.02);
}

.list-item.clickable { cursor:pointer; }
.list-item.clickable:hover { background: rgba(255,255,255,0.05); }

.list-avatar {
    width:26px; height:26px;
    border-radius:999px;
    overflow:hidden;
    background: rgba(255,255,255,0.04);
}

.list-avatar img {
    width:100%; height:100%; object-fit:cover;
}

.list-name { font-size:13px; }
.list-rank { margin-left:auto; font-size:11px; opacity:0.75; }

/* Hidden utility */
.hidden { display:none !important; }

/* ==========================================================
   RESPONSIVE ADJUSTMENTS
========================================================== */
@media(max-width:900px){
    .layout-shell {
        height: calc(var(--vh) * 100 - 56px);
    }
    .chat-center {
        height: calc(var(--vh) * 100 - 56px);
    }
}

/* ==========================================================
   TOPBAR AVATAR & POPUP UI (Your Original Code)
========================================================== */

.topbar-right { display:flex; align-items:center; gap:0.5rem; }
.top-avatar-btn { background:transparent; border:none; cursor:pointer; }

.top-avatar-img {
    width:34px; height:34px;
    border-radius:50%;
    object-fit:cover;
    border:2px solid rgba(255,255,255,0.15);
    transition:transform .15s, opacity .15s;
}
.top-avatar-btn:hover .top-avatar-img { transform:scale(1.07); opacity:.9; }

@media(max-width:600px){
    .top-avatar-img { width:30px; height:30px; }
}

.top-user { font-size:.8rem; opacity:.85; }

/* ============================================================
   POPUP OVERLAYS (GLOBAL)
   ============================================================ */

.popup {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.popup.hidden { display: none; }

.popup-content {
    background: #10131a;
    padding: 20px;
    width: 320px;
    border-radius: 10px;
    border: 1px solid #2a2e38;
}

/* User Info Popup */
#userInfoPopup {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
#userInfoPopup.visible { display: flex; }

#userInfoPopup .popupContent {
    background: #111626;
    padding: 20px;
    width: 320px;
    border-radius: 8px;
    color: #fff;
    text-align: center;
    box-shadow: 0 0 25px rgba(0,0,0,0.5);
    animation: popupFade 0.2s ease-out;
}
@keyframes popupFade {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
.popupAvatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    margin-bottom: 12px;
    object-fit: cover;
}
#userInfoPopup .btn {
    width: 100%;
    padding: 10px;
    margin: 8px 0;
    background: #1e2a48;
    border-radius: 6px;
}
#userInfoPopup .btn:hover { background: #26345c; }
.closeBtn {
    background: #822;
}
.closeBtn:hover {
    background: #a33;
}

/* ============================================================
   LARGE PROFILE MODAL
   ============================================================ */

#profileViewBox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.75);
    backdrop-filter: blur(4px);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 40px;
    z-index: 10000;
}
#profileViewBox.visible { display: flex; }

.profileBanner {
    width: 100%;
    height: 180px;
    overflow: hidden;
    border-radius: 10px 10px 0 0;
}
.profileBanner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profileBoxInner {
    background: #1a1f33;
    width: 420px;
    max-width: 95%;
    border-radius: 0 0 14px 14px;
    padding-bottom: 20px;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
    animation: boxFade 0.25s ease-out;
    text-align: center;
}
@keyframes boxFade {
    from { opacity: 0; transform: scale(0.94); }
    to   { opacity: 1; transform: scale(1); }
}

.boxAvatar {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    margin-top: -55px;
    border: 4px solid #1a1f33;
    object-fit: cover;
}

.boxUsername {
    font-size: 1.5rem;
    font-weight: 700;
}
.boxRank { opacity: 0.8; margin-bottom: 5px; }
.boxGender { opacity: 0.8; margin-bottom: 15px; }
.boxBio { opacity: 0.9; padding: 0 20px; margin-bottom: 20px; }
.boxLastActive { font-size: 0.9rem; opacity: 0.7; margin-bottom: 20px; }
.boxControls .btn {
    width: 85%;
    margin: 8px auto;
}

/* ============================================================
   MODAL BOX (GLOBAL)
   ============================================================ */

.modalBox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(5px);
    z-index: 99999;
}
.modalBox.visible { display: flex; }

.modalContent {
    width: 320px;
    padding: 20px;
    background: #121827;
    border-radius: 12px;
    text-align: center;
    color: #fff;
    animation: modalFade .2s ease-out;
}
@keyframes modalFade {
    from { opacity: 0; transform: scale(0.92); }
    to   { opacity: 1; transform: scale(1); }
}
.modalAvatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 12px;
}

/* ============================================================
   PRIVATE MESSAGE PANEL
   ============================================================ */

.pmPanel {
    position: fixed;
    bottom: 0;
    right: 10px;
    width: 300px;
    max-height: 70vh;
    background: #0b0f19;
    border: 1px solid rgba(255,255,255,0.10);
    border-radius: 8px 8px 0 0;
    display: flex;
    flex-direction: column;
    z-index: 9000;
    overflow: hidden;
}

.pmHeader {
    padding: 10px;
    background: #101626;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.pmClose { cursor: pointer; }

.pmBody {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
}

.pmInputBar {
    padding: 8px;
    background: #0f1320;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ============================================================
   ALERT BOX
   ============================================================ */

.alertBox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.alertInner {
    background: #121827;
    padding: 20px;
    width: 260px;
    border-radius: 10px;
    color: #fff;
    text-align: center;
}
.alertText { margin-bottom: 15px; }
.alertBtn {
    background: #26345c;
    border-radius: 6px;
    padding: 8px 12px;
    color: #fff;
}

/* ============================================================
   WARNING / KICK PANEL
   ============================================================ */

.warnBox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.warnInner {
    background: #161d2c;
    padding: 18px;
    width: 260px;
    border-radius: 10px;
    text-align: center;
}
.warnInput {
    width: 100%;
    padding: 8px;
    background: #101626;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.15);
    color: #fff;
    margin-bottom: 12px;
}
.warnBtn {
    background: #ab3434;
    border-radius: 6px;
    padding: 8px 12px;
}

/* ============================================================
   GIFT BOX (IF USED)
   ============================================================ */

.giftBox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.70);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}
.giftHeader {
    font-size: 16px;
    margin-bottom: 10px;
}
.giftItems {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.giftItem {
    width: 64px;
    height: 64px;
    background: #1c2237;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.giftSendBtn {
    margin-top: 12px;
    width: 100%;
    padding: 10px;
    background: #3756d3;
    border-radius: 8px;
}

/* ============================================================
   ROOM LIST PANEL
   ============================================================ */

.roomListBox {
    padding: 10px;
}
.roomListItem {
    padding: 8px;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
}
.roomListUserCount { opacity: 0.7; }
.roomListJoin {
    background: #2e57ff;
    border-radius: 6px;
    padding: 4px 10px;
}

/* ============================================================
   USER LIST PANEL
   ============================================================ */

.userListBox {
    padding: 10px;
}
.userListItem {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px;
    background: rgba(255,255,255,0.02);
    border-radius: 8px;
    margin-bottom: 5px;
}
.userListAvatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
}
.userListName {
    font-size: 14px;
    font-weight: 600;
}
.userListRank {
    margin-left: auto;
    opacity: 0.7;
}
/* =======================================================
   UNIVERSAL UI FOUNDATION FOR iOKChat
   Provides styling for: buttons, inputs, panels, modals,
   form controls, scrollbars, flex utilities, spacing, etc.
   Safe to load globally — does NOT break your layout.
======================================================= */

/* -------------------------------
   BUTTONS
------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.45rem 0.8rem;
    font-size: 0.9rem;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    background: #1a1d2a;
    color: #fff;
    transition: 0.15s ease;
    user-select: none;
}

.btn:hover {
    background: #232735;
}

.btn.small {
    font-size: 0.8rem;
    padding: 0.35rem 0.7rem;
}

.btn.primary {
    background: #2d6cdf;
    border-color: rgba(255,255,255,0.15);
}

.btn.primary:hover {
    background: #3b79ef;
}

.btn.danger {
    background: #b62828;
}

.btn.danger:hover {
    background: #d73333;
}

/* -------------------------------
   INPUTS & TEXTAREAS
------------------------------- */
.input,
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
textarea,
select {
    width: 100%;
    padding: 0.45rem 0.6rem;
    background: #0e101a;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    color: #f5f5f5;
    outline: none;
    font-size: 0.9rem;
    transition: border 0.15s ease, background 0.15s ease;
}

.input:focus,
textarea:focus,
select:focus,
input:focus {
    border-color: #3b79ef;
    background: #131622;
}

textarea {
    resize: vertical;
}

/* -------------------------------
   FILE INPUT
------------------------------- */
input[type="file"] {
    background: transparent;
    color: #ccc;
    font-size: 0.9rem;
    margin-top: 4px;
}

input[type="file"]::-webkit-file-upload-button {
    background: #1a1d2a;
    border: 1px solid rgba(255,255,255,0.15);
    padding: 0.4rem 0.7rem;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
}

input[type="file"]::-webkit-file-upload-button:hover {
    background: #232735;
}

/* -------------------------------
   HEADERS & TITLES
------------------------------- */
h4 {
    font-size: 1rem;
    margin: 0 0 10px 0;
    font-weight: 600;
    color: #fff;
}

/* -------------------------------
   PANELS / SIDE PANEL / MODALS
------------------------------- */
.panel-section {
    padding: 0.4rem 0;
    margin-bottom: 1rem;
}

.modalBox,
.profileBox,
.right-panel {
    background: #060814;
    border-radius: 12px;
    padding: 1rem;
    color: #fff;
}

/* -------------------------------
   LIST ITEMS
------------------------------- */
.list-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem;
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
    margin-bottom: 6px;
    cursor: pointer;
    transition: 0.15s ease;
}

.list-item:hover {
    background: rgba(255,255,255,0.08);
}

.list-avatar img {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    object-fit: cover;
}

/* -------------------------------
   FLEX UTILITIES
------------------------------- */
.flex { display: flex; }
.flex-center { display: flex; align-items:center; justify-content:center; }
.flex-between { display:flex; justify-content:space-between; }
.flex-column { display:flex; flex-direction:column; }

/* -------------------------------
   SPACING UTILITIES
------------------------------- */
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }

/* -------------------------------
   SCROLLBAR (Dark Themed)
------------------------------- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #0a0c14;
}

::-webkit-scrollbar-thumb {
    background: #1a1d2a;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #232735;
}

/* -------------------------------
   GENERAL MODAL BACKDROP
------------------------------- */
.modal-backdrop,
.profileBox {
    background: rgba(0,0,0,0.65);
}

/* -------------------------------
   SAFE BASE DEFAULTS
------------------------------- */
img {
    user-select: none;
}

button {
    user-select: none;
}
.attach-menu {
    position: absolute;
    bottom: 50px;
    left: 12px;
    background: #0d1020;
    border: 1px solid rgba(255, 255, 255, 0.12);
    padding: 4px 0;
    border-radius: 8px;
    width: 140px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

.attach-menu.hidden {
    display: none;
}

.attach-item {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    color: #e0e4ff;
}

.attach-item:hover {
    background: rgba(255, 255, 255, 0.07);
}
/* ============================================================
   AUTO-RESIZE EMBEDDED IMAGES IN CHAT
   No huge photos. Maintain aspect ratio. Never overflow container.
============================================================ */

.chat-embed-image {
    max-width: 240px;
    /* safe size for chat */
    max-height: 240px;
    /* prevents tall images */
    width: auto;
    height: auto;
    display: block;
    border-radius: 6px;
    object-fit: contain;
    background: #000;
    margin-top: 6px;
    margin-bottom: 6px;
}

/* Optional: wrapping container */
.embed-img-wrap {
    max-width: 100%;
    display: flex;
    justify-content: flex-start;
    align-items: center;
}