:root {
    --ink: #14211B;
    --muted: #55625B;
    --line: #DCE4DF;
    --surface: #FFFFFF;
    --wash: #EFF4F1;
    --brand: #0A7B4F;
    --brand-deep: #064E31;
    --sent: #CDEFDB;
    --received: #FFFFFF;
    --chat-bg: #E8EEEA;
    --online: #22B573;
    --danger: #B3261E;
    --font: "Tajawal", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--chat-bg);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    line-height: 1.5;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.booting .app { visibility: hidden; }

/* ================= الهيكل ================= */
.app {
    display: flex;
    width: 100%;
    max-width: 1280px;
    height: 100vh;
    height: 100dvh;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--line);
}

.sidebar {
    width: clamp(300px, 32%, 400px);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-inline-end: 1px solid var(--line);
    background: var(--surface);
}

.chat-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

/* ================= الأزرار والصور الرمزية ================= */
.btn-quiet {
    background: none;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 6px 14px;
    color: var(--muted);
    font-size: 0.9rem;
}
.btn-quiet:hover { background: var(--wash); color: var(--ink); }

.avatar {
    position: relative;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--c, #4C5A66);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
}

.avatar .dot {
    position: absolute;
    bottom: 0;
    inset-inline-end: 0;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--online);
    border: 2px solid var(--surface);
}

/* ================= القائمة الجانبية ================= */
.sidebar-header, .chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    height: 64px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}

.me {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    margin-inline-start: -8px;
    background: none;
    border: 0;
    border-radius: 12px;
    text-align: start;
}
.me:hover, .chat-peer:hover { background: var(--wash); }
.me .avatar { width: 40px; height: 40px; font-size: 1.05rem; }
.me-name {
    font-weight: 700;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
}
.search input {
    width: 100%;
    background: var(--wash);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 1rem;
    outline: none;
}
.search input:focus { border-color: var(--brand); background: #fff; }

.users-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    overscroll-behavior: contain;
}

.user { border-inline-start: 3px solid transparent; }
.user.active { border-inline-start-color: var(--brand); }

.user-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 11px 14px;
    background: none;
    border: 0;
    text-align: start;
}
.user:hover .user-btn, .user.active .user-btn { background: var(--wash); }

.user-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}
.user-name {
    font-weight: 500;
    font-size: 1.02rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-time { font-size: 0.78rem; color: var(--muted); flex-shrink: 0; }
.user-time.unread { color: var(--brand); font-weight: 700; }
.user-preview {
    font-size: 0.9rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.user-preview.faint { opacity: 0.8; }

.badge {
    flex-shrink: 0;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--brand);
    color: #fff;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

/* حالات القائمة: فارغة / خطأ / تحميل */
.state {
    list-style: none;
    padding: 36px 24px;
    text-align: center;
    color: var(--muted);
    display: grid;
    gap: 10px;
    justify-items: center;
}
.state strong { color: var(--ink); font-size: 1.05rem; }

.skeleton {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
}
.sk-avatar, .sk-line {
    background: linear-gradient(90deg, var(--wash) 25%, #E3EBE6 50%, var(--wash) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s linear infinite;
}
.sk-avatar { width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0; }
.sk-lines { flex: 1; display: grid; gap: 8px; }
.sk-line { height: 12px; border-radius: 6px; }
.sk-line.short { width: 55%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ================= نافذة المحادثة ================= */
.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 24px;
    text-align: center;
    color: var(--muted);
}
.wordmark-lg {
    font-size: 3.5rem;
    font-weight: 700;
    color: var(--brand);
    line-height: 1.2;
}

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

.chat-title { min-width: 0; }
.chat-title h2 {
    font-size: 1.05rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-status { font-size: 0.8rem; color: var(--muted); }
.chat-status.on { color: var(--brand); }

.back-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    margin-inline-start: -8px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--ink);
}
.back-btn:hover { background: var(--wash); }

.messages-container {
    flex: 1;
    min-height: 0;
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    overscroll-behavior: contain;
}
.messages-container .state { margin: auto; padding: 24px; }

.day { align-self: center; margin: 10px 0 4px; }
.day span {
    display: inline-block;
    padding: 3px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.85);
    color: var(--muted);
    font-size: 0.78rem;
}

.message {
    max-width: min(75%, 520px);
    padding: 8px 12px 5px;
    border-radius: 14px;
    box-shadow: 0 1px 0 rgba(20, 33, 27, 0.08);
}
.message p {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font-size: 1rem;
    line-height: 1.55;
}
.message.received {
    background: var(--received);
    align-self: flex-start;
    border-top-right-radius: 4px;
}
.message.sent {
    background: var(--sent);
    align-self: flex-end;
    border-top-left-radius: 4px;
}
.time {
    display: block;
    margin-top: 2px;
    font-size: 0.7rem;
    color: var(--muted);
    text-align: end;
}

/* ================= نموذج الإرسال ================= */
.message-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.message-form input {
    flex: 1;
    min-width: 0;
    background: var(--wash);
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 12px 18px;
    font-size: 1rem;
    outline: none;
}
.message-form input:focus { border-color: var(--brand); background: #fff; }

.message-form button {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.message-form button svg { transform: scaleX(-1); } /* السهم يتجه لليسار في الواجهة العربية */
.message-form button:disabled { opacity: 0.4; cursor: default; }

/* ================= الدخول ================= */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: var(--brand-deep);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
    padding: 24px;
    overflow-y: auto;
}
.login-brand { text-align: center; }
.login-wordmark {
    color: #fff;
    font-size: clamp(3.5rem, 16vw, 6rem);
    font-weight: 700;
    line-height: 1.1;
}
.login-tagline { margin-top: 6px; color: rgba(255, 255, 255, 0.8); font-size: 1.05rem; }

.login-box {
    display: grid;
    gap: 10px;
    width: 100%;
    max-width: 380px;
    padding: 24px;
    background: #fff;
    border-radius: 18px;
}
.login-box label { font-weight: 500; }
.login-box input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    font-size: 1rem;
    outline: none;
}
.login-box input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 123, 79, 0.15); }
.login-error { min-height: 1.4em; color: var(--danger); font-size: 0.9rem; }
.login-box button[type="submit"] {
    padding: 13px;
    border: 0;
    border-radius: 12px;
    background: var(--brand);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
}
.login-box button[type="submit"]:disabled { opacity: 0.6; cursor: default; }

/* ================= التنبيهات ================= */
.toast {
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translate(-50%, 16px);
    max-width: calc(100% - 32px);
    padding: 10px 18px;
    border-radius: 10px;
    background: var(--ink);
    color: #fff;
    font-size: 0.95rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 1300;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.conn-banner {
    position: fixed;
    top: 0;
    inset-inline: 0;
    z-index: 1050;
    padding: 6px 12px;
    background: #FFF1C2;
    color: #5A4300;
    font-size: 0.9rem;
    text-align: center;
}

/* ================= الجوال: قائمة ثم محادثة ================= */
@media (max-width: 768px) {
    .sidebar { width: 100%; border-inline-end: 0; }
    .chat-area { width: 100%; }
    .app[data-view="list"] .chat-area { display: none; }
    .app[data-view="chat"] .sidebar { display: none; }
    .back-btn { display: flex; }
    .messages-container { padding: 12px; }
    .message { max-width: 85%; }
}

/* ================= التثبيت والإشعارات (PWA) ================= */
.pwa-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px 0;
}
.pwa-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--wash);
    border: 1px solid var(--line);
}
.pwa-card p {
    flex: 1;
    min-width: 0;
    font-size: 0.88rem;
    line-height: 1.45;
    color: var(--ink);
}
.pwa-card .btn-quiet {
    flex-shrink: 0;
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    padding: 5px 12px;
}
.pwa-card .btn-quiet:hover { background: var(--brand-deep); color: #fff; }
.pwa-card .btn-quiet:disabled { opacity: 0.6; cursor: default; }
.pwa-card .pwa-dismiss {
    flex-shrink: 0;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 1.3rem;
    line-height: 1;
    padding: 2px 4px;
}

/* عند التشغيل كتطبيق مثبّت: احترام الحواف الآمنة (الشق وشريط الحالة) */
@media (display-mode: standalone) {
    body { padding-top: env(safe-area-inset-top, 0px); background: var(--surface); }
    .app { height: calc(100dvh - env(safe-area-inset-top, 0px)); }
    .conn-banner { padding-top: calc(6px + env(safe-area-inset-top, 0px)); }
}

@media (prefers-reduced-motion: reduce) {
    .sk-avatar, .sk-line { animation: none; }
    .toast { transition: none; }
}

/* ================= شعار الدخول ================= */
.login-logo {
    display: block;
    width: 96px;
    height: 96px;
    margin: 0 auto 16px;
    border-radius: 22px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.login-hint { font-size: 0.82rem; color: var(--muted); line-height: 1.5; }

/* ================= الرد على الرسائل ================= */
.message { position: relative; }
.message.flash { animation: flash-msg 1.2s ease-out; }
@keyframes flash-msg {
    0%   { outline: 3px solid var(--brand); outline-offset: 3px; }
    100% { outline: 3px solid transparent; outline-offset: 3px; }
}

/* زر الرد يظهر عند تمرير المؤشر، وعلى الجوال يُستعمل السحب */
.reply-btn {
    position: absolute;
    top: 4px;
    inset-inline-end: 4px;
    width: 26px;
    height: 26px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: var(--muted);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    opacity: 0;
    transition: opacity 0.15s;
}
.message:hover .reply-btn,
.reply-btn:focus-visible { opacity: 1; }
.reply-btn:hover { color: var(--ink); }
@media (hover: none) { .reply-btn { display: none; } }

.quote {
    display: block;
    width: 100%;
    margin-bottom: 6px;
    padding: 6px 10px;
    border: 0;
    border-inline-start: 3px solid var(--brand);
    border-radius: 8px;
    background: rgba(20, 33, 27, 0.06);
    color: inherit;
    text-align: start;
    cursor: pointer;
}
.message.sent .quote { background: rgba(6, 78, 49, 0.09); }
.quote:hover { background: rgba(20, 33, 27, 0.1); }
.quote b {
    display: block;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--brand-deep);
}
.quote span {
    display: block;
    font-size: 0.88rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* شريط الرد فوق حقل الكتابة */
.reply-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--wash);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.reply-bar-accent {
    width: 3px;
    align-self: stretch;
    border-radius: 2px;
    background: var(--brand);
}
.reply-bar-text {
    flex: 1;
    min-width: 0;
    display: grid;
    gap: 2px;
}
.reply-bar-text b { font-size: 0.9rem; color: var(--brand-deep); }
.reply-bar-text span {
    font-size: 0.9rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.reply-cancel {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--muted);
}
.reply-cancel:hover { background: #fff; color: var(--ink); }

/* ================= شارة التوثيق والتاج (Font Awesome) ================= */
.badges { display: inline-flex; align-items: center; flex-shrink: 0; vertical-align: middle; }
.verified {
    display: inline-flex;
    margin-inline-start: 4px;
    color: var(--brand);
    font-size: 0.9em;
    flex-shrink: 0;
}
.tag-ic { display: inline-flex; margin-inline-start: 4px; font-size: 0.85em; flex-shrink: 0; }
.sv .verified { color: #fff; }

/* ================= علامات الإرسال والقراءة ================= */
.ticks { margin-inline-start: 5px; font-size: 0.7rem; }
.ticks.pending, .ticks.sent { color: #7C8A83; }
.ticks.read { color: #1C8FD6; }
.message.pending { opacity: 0.75; }
.user-preview .ticks { margin-inline: 0 5px; }

/* ================= يكتب… ================= */
.chat-status.typing, .user-preview.typing { color: var(--brand); font-weight: 500; }
.typing-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 2px 16px 6px;
    background: var(--chat-bg);
    color: var(--brand);
    font-size: 0.82rem;
    flex-shrink: 0;
}
.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 7px 10px;
    border-radius: 999px;
    background: #fff;
    box-shadow: 0 1px 0 rgba(20, 33, 27, 0.08);
}
.typing-dots i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
    0%, 60%, 100% { transform: none; opacity: 0.45; }
    30% { transform: translateY(-4px); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) { .typing-dots i { animation: none; } }

.chat-peer {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    padding: 4px 8px;
    margin-inline-start: -4px;
    background: none;
    border: 0;
    border-radius: 12px;
    text-align: start;
}

/* ================= شريط الحالات ================= */
.status-strip {
    display: flex;
    gap: 4px;
    padding: 10px 10px;
    overflow-x: auto;
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    overscroll-behavior-x: contain;
}
.status-item, .status-hit {
    display: grid;
    justify-items: center;
    gap: 4px;
    width: 70px;
    flex-shrink: 0;
    padding: 4px 0;
    background: none;
    border: 0;
    border-radius: 12px;
    color: var(--muted);
    font-size: 0.78rem;
}
.status-item:hover, .status-hit:hover { background: var(--wash); }
.status-item.mine { position: relative; padding: 0; }
.status-item.mine:hover { background: none; }
.status-item.mine .status-hit { width: 100%; }
.status-add {
    position: absolute;
    top: 38px;
    inset-inline-end: 6px;
    width: 22px;
    height: 22px;
    display: grid;
    place-items: center;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 0.6rem;
}
.status-add:hover { background: var(--brand-deep); }
.status-ring {
    display: grid;
    place-items: center;
    width: 58px;
    height: 58px;
    padding: 3px;
    border-radius: 50%;
    background: var(--brand);
}
.status-ring.empty { background: var(--line); }
.status-ring .avatar {
    width: 100%;
    height: 100%;
    font-size: 1.2rem;
    border: 2px solid var(--surface);
}
.status-name {
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ================= عارض الحالة ومحرّرها (ملء الشاشة) ================= */
.sv {
    position: fixed;
    inset: 0;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    background: var(--sv-bg, var(--brand));
    color: #fff;
    overflow: hidden;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sv[hidden] { display: none !important; }
.sv-progress {
    display: flex;
    gap: 4px;
    margin: 10px 12px 0;
}
.sv-progress i {
    position: relative;
    flex: 1;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.35);
    overflow: hidden;
}
.sv-progress i::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #fff;
    transform: scaleX(0);
    transform-origin: right;   /* يمتلئ من اليمين إلى اليسار في الواجهة العربية */
}
.sv-progress i.done::after { transform: scaleX(1); }
.sv-progress i.run::after { animation: sv-fill 8s linear forwards; }
@keyframes sv-fill { to { transform: scaleX(1); } }

.sv-top {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
}
.sv-who { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.sv-who .avatar { width: 40px; height: 40px; font-size: 1rem; border: 2px solid rgba(255, 255, 255, 0.7); }
.sv-who-text { display: grid; min-width: 0; }
.sv-who-text b {
    display: flex;
    align-items: center;
    font-size: 1rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.sv-who-text small { font-size: 0.8rem; opacity: 0.8; }
.sv-close {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.15);
    color: #fff;
    font-size: 1.05rem;
    line-height: 1;
}
.sv-close:hover { background: rgba(0, 0, 0, 0.28); }

.sv-body {
    position: relative;
    z-index: 1;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 28px;
    text-align: center;
    font-size: clamp(1.5rem, 6vw, 2.2rem);
    font-weight: 700;
    line-height: 1.6;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    overflow-y: auto;
}
/* مناطق النقر للتنقل: اليسار للتالي (اتجاه القراءة العربي) واليمين للسابق */
.sv-nav {
    position: absolute;
    top: 120px;
    bottom: 0;
    width: 35%;
    border: 0;
    background: none;
    z-index: 0;
}
.sv-next { inset-inline-start: 0; }
.sv-prev { inset-inline-end: 0; }

.sc-title { font-size: 1rem; }
.sc-text {
    flex: 1;
    min-height: 0;
    width: 100%;
    padding: 24px 28px;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: clamp(1.4rem, 5.5vw, 2rem);
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
}
.sc-text::placeholder { color: rgba(255, 255, 255, 0.7); }
.sc-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px 14px;
}
.sc-swatches { display: flex; flex-wrap: wrap; gap: 8px; flex: 1; min-width: 0; }
.sc-swatch {
    width: 26px;
    height: 26px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 50%;
}
.sc-swatch[aria-pressed="true"] {
    border-color: #fff;
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.2);
}
.sc-count { font-size: 0.85rem; opacity: 0.85; }
.sc-btn {
    padding: 10px 14px;
    border: 0;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.18);
    color: #fff;
    font: inherit;
}
.sc-publish {
    padding: 11px 24px;
    border: 0;
    border-radius: 999px;
    background: #fff;
    color: var(--ink);
    font: inherit;
    font-weight: 700;
}
.sc-publish:disabled { opacity: 0.5; cursor: default; }

/* ================= الملف الشخصي ================= */
.pf {
    position: fixed;
    inset: 0;
    z-index: 1150;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(20, 33, 27, 0.5);
    padding-top: env(safe-area-inset-top, 0px);
}
.pf[hidden] { display: none !important; }
.pf-card {
    position: relative;
    width: 100%;
    max-width: 440px;
    max-height: 92dvh;
    overflow-y: auto;
    display: grid;
    justify-items: center;
    gap: 10px;
    padding: 30px 22px calc(22px + env(safe-area-inset-bottom, 0px));
    border-radius: 22px 22px 0 0;
    background: var(--surface);
    text-align: center;
    overscroll-behavior: contain;
}
@media (min-width: 769px) {
    .pf { align-items: center; }
    .pf-card { border-radius: 22px; }
}
.pf-close {
    position: absolute;
    top: 12px;
    inset-inline-start: 12px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--wash);
    color: var(--muted);
}
.pf-close:hover { color: var(--ink); }
.pf-avatar { width: 92px; height: 92px; font-size: 2.4rem; }
.pf-name {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    overflow-wrap: anywhere;
}
.pf-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.pf-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 999px;
    background: var(--wash);
    color: var(--muted);
    font-size: 0.88rem;
}
.pf-chip .fa-circle-check { color: var(--brand); }
.pf-tag {
    background: color-mix(in srgb, var(--tc) 14%, #fff);
    color: var(--tc);
    font-weight: 700;
}
.pf-presence { font-size: 0.9rem; color: var(--muted); }
.pf-presence.on { color: var(--brand); }

.pf-section {
    width: 100%;
    display: grid;
    gap: 8px;
    margin-top: 6px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    text-align: start;
}
.pf-section h3 { font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.pf-bio { white-space: pre-wrap; overflow-wrap: anywhere; }
.pf-bio.faint { color: var(--muted); }
.pf-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font: inherit;
    outline: none;
    resize: none;
}
.pf-input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(10, 123, 79, 0.15); }
.pf-input:disabled { background: var(--wash); }
.pf-count { justify-self: end; font-size: 0.78rem; color: var(--muted); }

.pf-icons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pf-icon {
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--tc);
    font-size: 1.15rem;
}
.pf-icon:hover { background: var(--wash); }
.pf-icon[aria-pressed="true"] {
    border-color: var(--tc);
    background: color-mix(in srgb, var(--tc) 14%, #fff);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--tc) 35%, transparent);
}
.pf-note { font-size: 0.82rem; color: var(--muted); }
.pf-note.locked { display: flex; align-items: center; gap: 6px; }

.pf-switch {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    padding: 12px 2px 4px;
    border-top: 1px solid var(--line);
    text-align: start;
    cursor: pointer;
}
.pf-switch input { width: 18px; height: 18px; accent-color: var(--brand); }

.pf-actions { display: flex; gap: 10px; width: 100%; margin-top: 8px; }
.pf-btn {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font-weight: 700;
}
.pf-btn:hover { background: var(--wash); }
.pf-btn.primary { border-color: var(--brand); background: var(--brand); color: #fff; }
.pf-btn.primary:hover { background: var(--brand-deep); }
.pf-btn:disabled { opacity: 0.6; cursor: default; }

/* ================= أيقونات الصور الرمزية (التاج وغيره بدل الحرف) ================= */
.avatar.has-ic { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28), 0 1px 3px rgba(20, 33, 27, 0.18); }
.avatar .av-ic { font-size: 0.78em; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.25)); }
.me .avatar .av-ic { font-size: 0.85em; }

/* ================= أزرار الأيقونات في الرؤوس ================= */
.icon-btn {
    flex-shrink: 0;
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--brand);
    font-size: 1.05rem;
}
.icon-btn:hover { background: var(--wash); }
.icon-btn.off { color: #9AA7A0; }

/* ================= المجموعات ================= */
.msg-from {
    display: block;
    margin-bottom: 2px;
    font-size: 0.82rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.gv-list { list-style: none; display: grid; gap: 2px; width: 100%; max-height: 38dvh; overflow-y: auto; text-align: start; }
.gv-row, .gv-member {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 8px 6px;
    border: 0;
    border-radius: 12px;
    background: none;
    text-align: start;
}
.gv-row:hover { background: var(--wash); }
.gv-row.on { background: color-mix(in srgb, var(--brand) 10%, #fff); }
.gv-row .avatar, .gv-member .avatar { width: 38px; height: 38px; font-size: 1rem; }
.gv-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gv-tick { color: var(--brand); font-size: 1.15rem; }
.gv-row .fa-regular { color: #9AA7A0; }
.gv-empty { padding: 14px; text-align: center; color: var(--muted); }
.gv-count { font-size: 0.85rem; color: var(--muted); }
.gv-role {
    padding: 2px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--brand) 12%, #fff);
    color: var(--brand);
    font-size: 0.78rem;
    font-weight: 700;
}
.gv-rm {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--danger);
}
.gv-rm:hover { background: #FBE9E7; }
.pf-btn.danger { color: var(--danger); border-color: #F0C9C5; }
.pf-btn.danger:hover { background: #FBE9E7; }

/* ================= المكالمة الصوتية ================= */
.call {
    position: fixed;
    inset: 0;
    z-index: 1600;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: calc(56px + env(safe-area-inset-top, 0px)) 24px calc(48px + env(safe-area-inset-bottom, 0px));
    background: radial-gradient(circle at 50% 30%, #0B6B45 0%, var(--brand-deep) 70%);
    color: #fff;
}
.call[hidden] { display: none !important; }
.call-body { display: grid; justify-items: center; gap: 12px; text-align: center; }
.call-avatar { width: 128px; height: 128px; font-size: 3.4rem; box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.14); }
.call[data-status="ringing"] .call-avatar,
.call[data-status="incoming"] .call-avatar { animation: call-pulse 1.8s ease-out infinite; }
@keyframes call-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.35); }
    100% { box-shadow: 0 0 0 34px rgba(255, 255, 255, 0); }
}
.call-name { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; overflow-wrap: anywhere; }
.call .verified { color: #fff; }
.call-status { font-size: 1.05rem; color: rgba(255, 255, 255, 0.82); font-variant-numeric: tabular-nums; }
.call-actions { display: flex; justify-content: center; gap: 36px; }
.call-btn {
    display: grid;
    justify-items: center;
    gap: 8px;
    background: none;
    border: 0;
    color: #fff;
    font-size: 0.9rem;
}
.call-btn i {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    font-size: 1.4rem;
}
.call-btn.danger i { background: #D93025; }
.call-btn.ok i { background: #1EA362; }
.call-btn.mute.on i { background: #fff; color: var(--brand-deep); }
.call-btn:active i { transform: scale(0.94); }
@media (prefers-reduced-motion: reduce) { .call-avatar { animation: none !important; } }

/* ================= التثبيت الإجباري ================= */
.gate {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    background: var(--brand-deep);
}
.gate[hidden] { display: none !important; }
.gate-card {
    width: 100%;
    max-width: 400px;
    display: grid;
    justify-items: center;
    gap: 14px;
    padding: 28px 22px;
    border-radius: 22px;
    background: var(--surface);
    text-align: center;
}
.gate-logo { border-radius: 20px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18); }
.gate-card h1 { font-size: 1.35rem; }
.gate-lead { color: var(--muted); line-height: 1.6; }
.gate-btn {
    width: 100%;
    padding: 13px;
    border: 0;
    border-radius: 14px;
    background: var(--brand);
    color: #fff;
    font-size: 1.05rem;
    font-weight: 700;
}
.gate-btn:hover { background: var(--brand-deep); }
.gate-btn:disabled { opacity: 0.6; cursor: default; }
.gate-steps { width: 100%; display: grid; gap: 8px; padding-inline-start: 22px; text-align: start; line-height: 1.55; }
.gate-steps:empty { display: none; }
.gate-note { font-size: 0.9rem; color: var(--muted); line-height: 1.5; }
.gate-note:empty { display: none; }
.gated .app { display: none; }

/* ================= الرسائل الصوتية ================= */
/* مايك عند فراغ الحقل، وزر الإرسال عند وجود نص (بالـ CSS فقط عبر :placeholder-shown) */
.message-form input:not(:placeholder-shown) ~ #micBtn,
.message-form input:placeholder-shown ~ #sendBtn { display: none; }

.rec-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--surface);
    border-top: 1px solid var(--line);
    flex-shrink: 0;
}
.rec-bar button {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    display: grid;
    place-items: center;
}
.rec-cancel { background: var(--wash); color: var(--danger); font-size: 1.05rem; }
.rec-send { background: var(--brand); color: #fff; }
.rec-send svg { transform: scaleX(-1); }
.rec-dot { flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: rec-blink 1.1s ease-in-out infinite; }
@keyframes rec-blink { 50% { opacity: 0.25; } }
.rec-time { flex-shrink: 0; min-width: 40px; font-variant-numeric: tabular-nums; font-weight: 700; }
.rec-wave { flex: 1; min-width: 0; height: 34px; display: flex; align-items: center; gap: 2px; overflow: hidden; }
.rec-wave i { flex: 0 0 3px; height: 8%; border-radius: 2px; background: var(--brand); transition: height 0.08s linear; }

/* فقاعة الرسالة الصوتية */
.message.voice { min-width: min(250px, 78vw); }
.vm { display: flex; align-items: center; gap: 10px; padding: 2px 0; }
.vm-play {
    position: relative;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
}
.vm-play i { font-size: 0.95rem; }
.vm-new {
    position: absolute;
    top: -2px;
    inset-inline-end: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #2F6FDE;
    border: 2px solid var(--received);
}
.vm-main { flex: 1; min-width: 0; display: grid; gap: 3px; }
.vm-wave { display: flex; align-items: center; gap: 2px; height: 30px; cursor: pointer; }
.vm-wave i { flex: 1; min-width: 2px; max-width: 5px; border-radius: 2px; background: rgba(6, 78, 49, 0.28); }
.vm-wave i.on { background: var(--brand); }
.vm-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.vm-speed {
    display: none;
    min-width: 36px;
    padding: 0 8px;
    border: 0;
    border-radius: 999px;
    background: rgba(6, 78, 49, 0.12);
    color: var(--brand-deep);
    font-size: 0.72rem;
    font-weight: 700;
}
.vm.playing .vm-speed { display: inline-block; }

/* الحالة الصوتية: المحرر والعارض */
.sc-voice {
    margin: 0 16px 8px;
    padding: 10px 12px;
    border-radius: 18px;
    background: rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    gap: 10px;
}
.sc-voice .vm { flex: 1; min-width: 0; }
.sc-voice .vm-play { background: #fff; color: var(--ink); }
.sc-voice .vm-wave i { background: rgba(255, 255, 255, 0.4); }
.sc-voice .vm-wave i.on { background: #fff; }
.sc-voice .vm-meta { color: rgba(255, 255, 255, 0.85); }
.sc-voice .vm-speed { background: rgba(255, 255, 255, 0.2); color: #fff; }
.sc-voice .rec-time { color: #fff; }
.sc-voice .rec-wave i { background: #fff; }
.sc-voice .rec-dot { background: #FF6B6B; }
.sc-voice .sc-vbtn {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    display: grid;
    place-items: center;
}

.sv-body .vs { display: grid; gap: 22px; justify-items: center; width: 100%; max-width: 420px; }
.vs-card {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px 18px;
    border: 0;
    border-radius: 26px;
    background: rgba(0, 0, 0, 0.22);
    color: #fff;
}
.vs-btn { flex-shrink: 0; width: 56px; height: 56px; border-radius: 50%; background: #fff; color: var(--ink); display: grid; place-items: center; font-size: 1.2rem; }
.vs-wave { flex: 1; min-width: 0; height: 44px; display: flex; align-items: center; gap: 3px; }
.vs-wave i { flex: 1; min-width: 2px; max-width: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.4); }
.vs-wave i.on { background: #fff; }
.vs-time { flex-shrink: 0; min-width: 42px; font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.vs-caption { font-size: clamp(1.1rem, 4.5vw, 1.5rem); font-weight: 700; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.sv.sv-paused .sv-progress i.run::after { animation-play-state: paused; }

@media (prefers-reduced-motion: reduce) { .rec-dot { animation: none; } .rec-wave i { transition: none; } }

/* ================= الصور ================= */
/* تنقّل الحالات بالنقر: جسم الحالة يعلو أزرار التنقل فيحجبها، فنتركه شفافًا للنقر ونُعيد النقر لبطاقة الصوت فقط */
.sv-body { pointer-events: none; }
.vs-card { pointer-events: auto; }

#attachBtn { background: var(--wash); color: var(--brand); font-size: 1.15rem; }
#attachBtn:hover { background: var(--line); }

/* فقاعة الصورة */
.message.image { width: min(280px, 72vw); padding: 4px 4px 5px; }
.message.image .msg-from { margin: 2px 8px 4px; }
.message.image .quote { width: calc(100% - 8px); margin: 2px 4px 6px; }
.message.image .time { padding: 0 8px; }
.mi-wrap { display: block; }
.mi {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    border: 0;
    border-radius: 11px;
    overflow: hidden;
    background: var(--wash);
    color: var(--muted);
    cursor: zoom-in;
}
.mi img { display: block; width: 100%; height: auto; max-height: 360px; object-fit: cover; }
.mi.broken { min-height: 120px; display: grid; place-items: center; font-size: 0.9rem; cursor: default; }
.mi-cap { padding: 6px 8px 0; }

/* أثناء الرفع: تعتيم خفيف ودائرة تحميل */
.message.pending .mi::after { content: ''; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.28); }
.message.pending .mi::before {
    content: '';
    position: absolute;
    z-index: 1;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: mi-spin 0.8s linear infinite;
}
@keyframes mi-spin { to { transform: rotate(360deg); } }

/* نافذة معاينة الصورة قبل الإرسال */
.is {
    position: fixed;
    inset: 0;
    z-index: 1250;
    display: flex;
    flex-direction: column;
    background: #0D1210;
    color: #fff;
    padding-top: env(safe-area-inset-top, 0px);
}
.is-top { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.is-stage { flex: 1; min-height: 0; position: relative; margin: 4px 12px; }
.is-stage img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; border-radius: 10px; }
.is-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
.is-foot input {
    flex: 1;
    min-width: 0;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 12px 18px;
    font: inherit;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    outline: none;
}
.is-foot input::placeholder { color: rgba(255, 255, 255, 0.65); }
.is-foot input:focus { background: rgba(255, 255, 255, 0.22); border-color: rgba(255, 255, 255, 0.5); }
.is-foot button {
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    display: grid;
    place-items: center;
}
.is-foot button svg { transform: scaleX(-1); }
.is-foot button:disabled { opacity: 0.5; }

/* عرض الصورة كاملة */
.lb {
    position: fixed;
    inset: 0;
    z-index: 1300;
    display: grid;
    place-items: center;
    background: rgba(0, 0, 0, 0.94);
    padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px);
}
.lb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lb-close { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); inset-inline-start: 12px; background: rgba(255, 255, 255, 0.16); }

/* الحالة المصورة: المحرر */
.sc-image {
    position: relative;
    margin: 0 16px 8px;
    border-radius: 18px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.2);
    display: grid;
    place-items: center;
    max-height: 38vh;
}
.sc-image img { display: block; max-width: 100%; max-height: 38vh; object-fit: contain; }
.sc-image .sc-vbtn {
    position: absolute;
    top: 8px;
    inset-inline-start: 8px;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.92);
    color: var(--ink);
    display: grid;
    place-items: center;
}

/* الحالة المصورة: العارض */
.sv.sv-image { background: #0D1210; }
.sv.sv-image .sv-body { padding: 0; align-items: stretch; overflow: hidden; }
.si { position: relative; flex: 1; align-self: stretch; }
.si-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.si-cap {
    position: absolute;
    inset-inline: 0;
    bottom: 0;
    padding: 56px 20px 24px;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.75), transparent);
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 700;
    line-height: 1.6;
    text-align: center;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

@media (prefers-reduced-motion: reduce) {
    .message.pending .mi::before { animation: none; }
}
