/* 💬 sawavibe.com/chat */
.ch-page { max-width: 1280px; margin: 0 auto; padding: 18px 24px 10px; }
.ch-app {
    display: grid; grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: minmax(0, 1fr) auto;
    grid-template-areas: "main side" "bar bar"; gap: 14px;
    height: 640px; min-height: 420px;
}
.ch-main { grid-area: main; display: flex; flex-direction: column; min-height: 0; position: relative; }
.ch-side { grid-area: side; }
.ch-bar { grid-area: bar; }

.ch-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.ch-title h1 { font-size: 24px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.ch-title p { font-size: 13px; color: #94a3b8; margin-top: 2px; }
.ch-online-btn {
    display: none; align-items: center; gap: 6px; flex-shrink: 0; cursor: pointer; font: inherit; font-weight: 800; font-size: 14px;
    color: #fb923c; background: rgba(249,115,22,.08); border: 1.5px solid #f97316; border-radius: 12px; padding: 7px 14px;
}
.ch-online-btn b { background: #f97316; color: #fff; border-radius: 999px; min-width: 22px; padding: 0 6px; font-size: 12px; line-height: 20px; }

.ch-list {
    flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px 12px;
    background: rgba(15,23,42,.55); border: 1px solid rgba(148,163,184,.16); border-radius: 18px;
    scrollbar-width: thin; scrollbar-color: #334155 transparent;
}
.ch-empty, .ch-loading { text-align: center; color: #94a3b8; padding: 40px 10px; font-size: 15px; }

.ch-msg { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 14px; animation: chIn .25s ease; }
@keyframes chIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ch-av {
    width: 52px; height: 52px; border-radius: 50%; flex-shrink: 0; object-fit: cover; border: 2.5px solid #f97316;
    display: inline-flex; align-items: center; justify-content: center; background: #1e293b; color: #fb923c; font-weight: 800; font-size: 20px;
}
.ch-body { flex: 1; min-width: 0; max-width: 620px; }
.ch-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; padding: 0 4px; }
.ch-name { font-weight: 800; font-size: 15px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-name:hover { color: #fdba74; }
.ch-time { margin-inline-start: auto; font-size: 12px; color: #94a3b8; white-space: nowrap; direction: rtl; }
.ch-bubble {
    background: linear-gradient(180deg, #1f2d44, #18243a); border: 1px solid rgba(148,163,184,.22); border-radius: 16px;
    padding: 10px 16px; font-size: 16px; line-height: 1.7; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
}
.ch-body { display: flex; flex-direction: column; align-items: flex-start; }
.ch-meta { align-self: stretch; }
.ch-bubble { max-width: 100%; }
/* My own messages: other side, orange (the others stay dark blue) */
.ch-msg.mine { flex-direction: row-reverse; }
.ch-msg.mine .ch-body { align-items: flex-end; }
.ch-msg.mine .ch-meta { flex-direction: row-reverse; }
.ch-msg.mine .ch-time { margin-inline-start: 0; margin-left: 0; margin-right: auto; }
.ch-msg.mine .ch-name { color: #fdba74; }
.ch-msg.mine .ch-bubble { background: linear-gradient(135deg, #f97316, #ea580c); border-color: #fb923c; color: #fff; border-radius: 16px 16px 16px 4px;
    box-shadow: 0 4px 14px rgba(234,88,12,.3); }
.ch-msg.mine .ch-bubble a { color: #fff; text-decoration: underline; }
.ch-msg:not(.mine) .ch-bubble { border-radius: 16px 16px 4px 16px; }
.ch-head-btns { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ch-sound { width: 40px; height: 40px; border-radius: 12px; cursor: pointer; font-size: 19px; line-height: 1;
    background: rgba(30,41,59,.8); border: 1px solid #475569; }
.ch-sound[aria-pressed="false"] { opacity: .6; }

/* "+" add friend */
.ch-add {
    width: 22px; height: 22px; flex-shrink: 0; border-radius: 50%; border: 0; cursor: pointer; font: inherit; font-weight: 800; font-size: 16px; line-height: 22px;
    background: #f97316; color: #fff; display: inline-flex; align-items: center; justify-content: center; padding: 0; transition: transform .15s;
}
.ch-add:hover { transform: scale(1.12); }
.ch-add.sent { background: #475569; font-size: 11px; cursor: default; }
.ch-add.friend { background: #16a34a; font-size: 12px; cursor: default; }
.ch-add.incoming { background: #0ea5e9; }
.ch-add[disabled] { opacity: .7; }

.ch-new {
    position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 3; cursor: pointer; font: inherit; font-weight: 800; font-size: 13px;
    background: #f97316; color: #fff; border: 0; border-radius: 999px; padding: 6px 16px; box-shadow: 0 6px 18px rgba(0,0,0,.4);
}

/* Who is online */
.ch-side {
    display: flex; flex-direction: column; min-height: 0;
    background: rgba(15,23,42,.55); border: 1px solid rgba(148,163,184,.16); border-radius: 18px; padding: 14px;
}
.ch-side-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.ch-side-head h2 { font-size: 19px; font-weight: 800; }
.ch-side-head p { font-size: 13px; color: #cbd5e1; margin-top: 2px; }
.ch-side-x { display: none; background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 0 4px; }
.ch-people { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 9px; scrollbar-width: thin; scrollbar-color: #334155 transparent; }
.ch-person {
    display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 14px;
    background: rgba(30,41,59,.65); border: 1px solid rgba(148,163,184,.14);
}
.ch-person .ch-av { width: 46px; height: 46px; font-size: 18px; }
.ch-person-txt { flex: 1; min-width: 0; }
.ch-person-txt a { display: block; font-weight: 800; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ch-person-txt span { font-size: 12px; color: #cbd5e1; display: inline-flex; align-items: center; gap: 5px; }
.ch-person-txt span::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.ch-people .ch-none { color: #94a3b8; font-size: 14px; text-align: center; padding: 20px 6px; }
.ch-shade { display: none; }

/* Writing bar */
.ch-form { display: flex; gap: 10px; align-items: flex-end; }
.ch-input {
    flex: 1; min-width: 0; position: relative; display: flex; align-items: center;
    background: rgba(15,23,42,.75); border: 1.5px solid #475569; border-radius: 16px; padding: 4px 8px 4px 4px;
}
.ch-input:focus-within { border-color: #f97316; }
.ch-input textarea {
    flex: 1; min-width: 0; resize: none; background: none; border: 0; outline: 0; color: #fff; font: inherit; font-size: 16px;
    line-height: 1.5; padding: 10px 8px; max-height: 120px;
}
.ch-input textarea::placeholder { color: #94a3b8; }
.ch-emo-btn { background: none; border: 0; font-size: 24px; cursor: pointer; padding: 4px 6px; line-height: 1; border-inline-start: 1px solid #475569; }
.ch-emo {
    position: absolute; bottom: calc(100% + 8px); left: 0; z-index: 20; width: min(320px, 86vw); max-height: 220px; overflow-y: auto;
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; padding: 8px;
    background: #111c2e; border: 1px solid #334155; border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.ch-emo[hidden] { display: none; }
.ch-emo button { background: none; border: 0; font-size: 22px; padding: 4px 0; cursor: pointer; border-radius: 8px; }
.ch-emo button:hover { background: #1e293b; }
.ch-send {
    display: inline-flex; align-items: center; gap: 8px; flex-shrink: 0; cursor: pointer; font: inherit; font-weight: 800; font-size: 17px;
    color: #fff; background: linear-gradient(135deg, #f97316, #ea580c); border: 0; border-radius: 16px; padding: 0 26px; height: 54px;
    box-shadow: 0 6px 18px rgba(234,88,12,.35);
}
.ch-send svg { width: 22px; height: 22px; transform: scaleX(-1); }
.ch-send[disabled] { opacity: .6; cursor: default; }
.ch-login, .ch-join, .ch-blocked {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 800; font-size: 15px; border-radius: 16px; padding: 14px 20px;
}
.ch-bar:has(.ch-login) { display: flex; gap: 10px; }
.ch-login { flex: 1; background: linear-gradient(135deg, #f97316, #ea580c); color: #fff; }
.ch-join { background: rgba(30,41,59,.8); border: 1px solid #475569; color: #fff; }
.ch-blocked { width: 100%; background: rgba(127,29,29,.35); border: 1px solid #ef4444; color: #fecaca; }

.ch-toast {
    position: fixed; bottom: 90px; left: 50%; transform: translate(-50%, 20px); z-index: 300; opacity: 0; pointer-events: none; transition: .25s;
    background: #0f172a; border: 1px solid #f97316; color: #fff; font-weight: 700; font-size: 14px; padding: 9px 18px; border-radius: 12px; max-width: 90vw; text-align: center;
}
.ch-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Phone */
@media (max-width: 860px) {
    .ch-page { padding: 12px 10px 6px; }
    .ch-app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "bar"; gap: 10px; }
    .ch-title h1 { font-size: 20px; }
    .ch-title p { font-size: 11.5px; }
    .ch-online-btn { display: inline-flex; }
    .ch-list { padding: 12px 8px; }
    .ch-av { width: 46px; height: 46px; font-size: 18px; }
    .ch-bubble { font-size: 15px; padding: 8px 13px; }
    .ch-side {
        position: fixed; top: 0; bottom: 0; left: 0; z-index: 210; width: min(330px, 86vw); border-radius: 0 18px 18px 0;
        background: #0e1a2c; transform: translateX(-105%); transition: transform .25s ease; padding: 16px 12px calc(16px + env(safe-area-inset-bottom));
    }
    .ch-side-x { display: block; }
    .ch-shade { display: block; position: fixed; inset: 0; z-index: 205; background: rgba(0,0,0,.55); opacity: 0; pointer-events: none; transition: opacity .25s; }
    html.ch-side-open .ch-side { transform: none; }
    html.ch-side-open .ch-shade { opacity: 1; pointer-events: auto; }
    .ch-send { padding: 0 16px; height: 50px; font-size: 15px; }
    .ch-send span { display: none; }
    .ch-login, .ch-join { font-size: 14px; padding: 12px 12px; }

    /* Typing: only the messages + the writing bar, sized to what the keyboard leaves */
    html.ch-kb .header, html.ch-kb .svt-box, html.ch-kb .footer, html.ch-kb .mm-btn { display: none !important; }
    html.ch-kb .ch-head { display: none; }
    html.ch-kb .ch-app { position: fixed; left: 0; right: 0; top: var(--ch-top, 0px); height: var(--ch-h, 100%) !important; padding: 8px 8px 6px; z-index: 100;
        background: #0a1628; gap: 8px; }
    html.ch-kb body { overflow: hidden; }
}

/* "👋 تم تسجيل دخول ..." */
.ch-joined { display: flex; justify-content: center; margin: 4px 0 14px; animation: chIn .3s ease; }
.ch-joined span { display: inline-flex; align-items: center; flex-wrap: wrap; justify-content: center; gap: 4px 6px; max-width: 100%;
    background: rgba(34,197,94,.1); border: 1px solid rgba(34,197,94,.35); color: #d1fae5; border-radius: 999px; padding: 5px 14px; font-size: 13.5px; font-weight: 600; }
.ch-joined i { font-style: normal; font-size: 18px; display: inline-block; animation: chWave 1.4s ease 2; transform-origin: 70% 70%; }
.ch-joined a { font-weight: 800; color: #fff; }
.ch-joined small { color: #94a3b8; font-size: 12px; margin-inline-start: 4px; }
@keyframes chWave { 0%, 100% { transform: rotate(0); } 20%, 60% { transform: rotate(18deg); } 40%, 80% { transform: rotate(-10deg); } }
