/* =====================================================================
   chat.css — «گفتگو با همکلاس»
   تم‌ها: school / spring / summer / autumn / winter / friendly (خودکار بر اساس فصل شمسی)
   طراحی موبایل‌محور؛ بدون inset و بدون تکیه بر gap در flex (سازگار با Safari 13)
===================================================================== */
html.chat-lock, html.chat-lock body { overflow: hidden; }

.chat {
    --c-bg1: #eef4ff; --c-bg2: #ffffff; --c-head: #1e40af; --c-head2: #1d4ed8; --c-me: #dbeafe; --c-me-b: #93c5fd;
    --c-other: #ffffff; --c-text: #1f2937; --c-muted: #4b5563; --c-accent: #1e40af; --c-sys: rgba(30,64,175,.1); --c-sys-t: #1e3a8a;
    position: relative; display: flex; flex-direction: column; overflow: hidden;
    height: min(78vh, 720px); min-height: 460px; border-radius: 18px; box-shadow: 0 10px 30px rgba(0,0,0,.12);
    background: linear-gradient(180deg, var(--c-bg1), var(--c-bg2)); color: var(--c-text);
    font-family: inherit; font-size: 15px; line-height: 1.7; direction: rtl; text-align: right;
}
.chat--t-school { }
.chat--t-spring { --c-bg1: #fdf2f8; --c-bg2: #ecfdf5; --c-head: #be185d; --c-head2: #9d174d; --c-me: #fce7f3; --c-me-b: #f9a8d4; --c-accent: #9d174d; --c-sys: rgba(190,24,93,.09); --c-sys-t: #831843; }
.chat--t-summer { --c-bg1: #fffbeb; --c-bg2: #e0f2fe; --c-head: #0369a1; --c-head2: #075985; --c-me: #fef3c7; --c-me-b: #fcd34d; --c-accent: #075985; --c-sys: rgba(3,105,161,.1); --c-sys-t: #0c4a6e; }
.chat--t-autumn { --c-bg1: #fff7ed; --c-bg2: #fef3c7; --c-head: #9a3412; --c-head2: #7c2d12; --c-me: #ffedd5; --c-me-b: #fdba74; --c-accent: #7c2d12; --c-sys: rgba(154,52,18,.1); --c-sys-t: #7c2d12; }
.chat--t-winter { --c-bg1: #eff6ff; --c-bg2: #e2e8f0; --c-head: #334155; --c-head2: #1e293b; --c-me: #e0f2fe; --c-me-b: #7dd3fc; --c-accent: #1e3a8a; --c-sys: rgba(51,65,85,.1); --c-sys-t: #1e293b; }
.chat--t-friendly { --c-bg1: #f5f3ff; --c-bg2: #ecfeff; --c-head: #6d28d9; --c-head2: #5b21b6; --c-me: #ede9fe; --c-me-b: #c4b5fd; --c-accent: #5b21b6; --c-sys: rgba(109,40,217,.09); --c-sys-t: #4c1d95; }

.chat--full { position: fixed; top: 0; right: 0; left: 0; height: 100%; min-height: 0; border-radius: 0; z-index: 10050; box-shadow: none; }

/* ----- تزئینات متحرک (فقط transform/opacity) ----- */
.chat-bg { position: absolute; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.chat-p { position: absolute; top: -40px; opacity: .55; will-change: transform; animation: chat-fall linear infinite; }
.chat-p--summer.chat-p--1 { animation: chat-sun 60s linear infinite; top: 8px; left: auto; right: 12px !important; opacity: .8; width: 44px !important; height: 44px !important; }
.chat-p--summer { animation-name: chat-rise; top: auto; bottom: -30px; }
.chat-p--summer.chat-p--1 { animation-name: chat-sun; top: 8px; bottom: auto; }
.chat-p--school { animation-name: chat-float; top: 12%; }
.chat-p--school.chat-p--2 { top: 40%; } .chat-p--school.chat-p--3 { top: 70%; } .chat-p--school.chat-p--4 { top: 25%; } .chat-p--school.chat-p--5 { top: 55%; } .chat-p--school.chat-p--6 { top: 82%; } .chat-p--school.chat-p--7 { top: 8%; } .chat-p--school.chat-p--8 { top: 62%; }
.chat-p--friendly { animation-name: chat-float; top: 10%; opacity: .7; }
.chat-p--friendly.chat-p--2 { top: 35%; } .chat-p--friendly.chat-p--3 { top: 60%; } .chat-p--friendly.chat-p--4 { top: 80%; } .chat-p--friendly.chat-p--5 { top: 20%; } .chat-p--friendly.chat-p--6 { top: 48%; } .chat-p--friendly.chat-p--7 { top: 70%; } .chat-p--friendly.chat-p--8 { top: 5%; }
@keyframes chat-fall { 0% { transform: translate3d(0,-40px,0) rotate(0deg); opacity: 0; } 10% { opacity: .6; } 100% { transform: translate3d(40px,115vh,0) rotate(300deg); opacity: .15; } }
@keyframes chat-rise { 0% { transform: translate3d(0,0,0); opacity: 0; } 15% { opacity: .55; } 100% { transform: translate3d(20px,-110vh,0); opacity: 0; } }
@keyframes chat-sun { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
@keyframes chat-float { 0%,100% { transform: translate3d(0,0,0) rotate(-6deg); } 50% { transform: translate3d(14px,-18px,0) rotate(8deg); } }
.chat-scene { position: absolute; bottom: 0; right: 0; left: 0; width: 100%; height: 56px; opacity: .55; }
.chat--full .chat-p:nth-child(n+6), .chat-p:nth-child(n+7) { display: none; }
@media (min-width: 701px) { .chat-p:nth-child(n+7) { display: block; } }
@media (prefers-reduced-motion: reduce) { .chat-p { animation: none !important; opacity: .35; top: 20%; } .chat-p--summer.chat-p--1 { animation: none !important; } .chat * { scroll-behavior: auto !important; transition: none !important; } }

/* ----- سربرگ ----- */
.chat-head { position: relative; z-index: 3; display: flex; align-items: center; background: linear-gradient(90deg, var(--c-head), var(--c-head2)); color: #fff; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); min-height: 56px; }
.chat-head > * + * { margin-right: 8px; }
.chat-titlebox { flex: 1 1 auto; min-width: 0; }
.chat-title { margin: 0; font-size: 17px; font-weight: 800; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 12px; opacity: .92; }
.chat-exit, .chat-people-btn { flex: 0 0 auto; min-height: 44px; min-width: 44px; padding: 6px 12px; border: 1px solid rgba(255,255,255,.55); border-radius: 12px; background: rgba(255,255,255,.16); color: #fff; font: inherit; font-size: 14px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chat-people-btn b { font-weight: 800; }
.chat-adminbar { position: relative; z-index: 3; padding: 6px 8px; background: #fff7ed; border-bottom: 1px solid #fed7aa; display: flex; flex-wrap: wrap; align-items: center; }
.chat-adminbar[hidden], .chat-rules[hidden], .chat-pill[hidden], .chat-closed[hidden], .chat-note[hidden], .chat-stickers[hidden], .chat-emoji[hidden], .chat-counter[hidden], .chat-acts[hidden] { display: none !important; }
.chat-adminbar > * { margin: 3px 3px 3px 0; }
.chat-act { min-height: 40px; padding: 6px 12px; border-radius: 10px; border: 1px solid #d1d5db; background: #fff; color: #1f2937; font: inherit; font-size: 13px; cursor: pointer; }
.chat-act.is-danger { color: #991b1b; border-color: #fca5a5; background: #fef2f2; }
.chat-act.is-ok { color: #166534; border-color: #86efac; background: #f0fdf4; }
.chat-flagbadge { font-size: 12.5px; color: #991b1b; font-weight: 700; padding: 4px 8px; }

.chat-rules { position: relative; z-index: 3; background: rgba(255,255,255,.92); border-bottom: 1px solid rgba(0,0,0,.08); }
.chat-rules-toggle { width: 100%; text-align: right; min-height: 40px; padding: 6px 12px; border: 0; background: transparent; font: inherit; font-size: 13.5px; font-weight: 700; color: var(--c-accent); cursor: pointer; }
.chat-rules-text { display: none; padding: 0 12px 10px; font-size: 13.5px; color: var(--c-text); white-space: pre-wrap; }
.chat-rules.is-open .chat-rules-text { display: block; }

/* ----- نوار آنلاین‌ها (موبایل) و ستون کناری (دسکتاپ) ----- */
.chat-strip { position: relative; z-index: 3; display: block; white-space: nowrap; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; padding: 6px 10px; background: rgba(255,255,255,.72); border-bottom: 1px solid rgba(0,0,0,.06); min-height: 46px; }
.chat-strip .chat-av { margin-left: 8px; }
.chat-main { position: relative; z-index: 2; display: flex; flex: 1 1 auto; min-height: 0; }
.chat-stage { position: relative; flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.chat-side { display: none; flex: 0 0 210px; background: rgba(255,255,255,.78); border-right: 1px solid rgba(0,0,0,.08); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-side-title { padding: 10px 12px; font-weight: 800; font-size: 13.5px; color: var(--c-accent); }
.chat-online { list-style: none; margin: 0; padding: 0 6px 10px; }
.chat-on { display: flex; align-items: center; padding: 6px; border-radius: 10px; }
.chat-on > * + * { margin-right: 9px; }
.chat-on.is-me { background: var(--c-sys); }
.chat-on-t { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.chat-on-n { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-on-t small { color: #15803d; font-size: 12px; }
@media (min-width: 701px) { .chat-side { display: block; } .chat-strip, .chat-people-btn { display: none; } }
.chat--full .chat-side { display: none; }
.chat--full .chat-strip, .chat--full .chat-people-btn { display: block; }
.chat--full .chat-people-btn { display: inline-block; }
@media (max-width: 700px) {
    .chat.show-people .chat-side { display: block; position: absolute; top: 0; bottom: 0; left: 0; z-index: 6; width: 78%; max-width: 280px; box-shadow: 0 0 24px rgba(0,0,0,.25); background: #fff; }
}

/* ----- آواتار ----- */
.chat-av { position: relative; flex: 0 0 auto; display: inline-block; vertical-align: middle; width: 38px; height: 38px; border-radius: 50%; color: #1f2937; font-weight: 800; font-size: 16px; line-height: 38px; text-align: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.chat-av img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.chat-av--sm { width: 32px; height: 32px; line-height: 28px; font-size: 14px; }
.chat-dot { position: absolute; bottom: -2px; left: -2px; width: 11px; height: 11px; border-radius: 50%; background: #22c55e; border: 2px solid #fff; }

/* ----- پیام‌ها ----- */
.chat-msgs { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 12px 10px 8px; scroll-behavior: auto; }
.chat-row { display: flex; align-items: flex-end; margin: 7px 0; }
.chat-row > * + * { margin-right: 8px; }
.chat-row.is-me { flex-direction: row-reverse; }
.chat-row.is-me > * + * { margin-right: 0; margin-left: 8px; }
.chat-row--sys { justify-content: center; }
.chat-sys { display: inline-block; max-width: 90%; background: var(--c-sys); color: var(--c-sys-t); padding: 3px 12px; border-radius: 999px; font-size: 12.5px; text-align: center; }
.chat-welcome .chat-sys { background: #fff; border: 1px dashed var(--c-me-b); padding: 8px 14px; border-radius: 14px; font-size: 13.5px; }
.chat-bubble { position: relative; max-width: 78%; min-width: 64px; padding: 6px 12px 7px; background: var(--c-other); color: var(--c-text); border-radius: 16px 16px 16px 4px; box-shadow: 0 1px 4px rgba(0,0,0,.12); word-wrap: break-word; overflow-wrap: anywhere; }
.chat-row.is-me .chat-bubble { background: var(--c-me); border: 1px solid var(--c-me-b); border-radius: 16px 16px 4px 16px; }
.chat-row.is-adm .chat-bubble { border: 1px solid #f59e0b; background: #fffbeb; }
.chat-meta { display: flex; align-items: baseline; justify-content: space-between; font-size: 12px; color: var(--c-muted); }
.chat-meta > * + * { margin-right: 10px; }
.chat-name { font-weight: 800; color: var(--c-accent); max-width: 140px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11.5px; color: var(--c-muted); }
.chat-text { font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.chat-edited { font-size: 11.5px; color: #92400e; margin-top: 2px; }
.chat-row.is-sticker .chat-bubble { background: transparent; border: 0; box-shadow: none; padding: 0 4px; }
.chat-row.is-sticker .chat-text { font-size: 46px; line-height: 1.2; }
.chat-acts { display: flex; flex-wrap: wrap; margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(0,0,0,.15); }
.chat-acts > * { margin: 3px 0 3px 6px; }
.chat-pill { position: absolute; bottom: 10px; right: 50%; transform: translateX(50%); z-index: 4; min-height: 40px; padding: 6px 16px; border: 0; border-radius: 999px; background: var(--c-head); color: #fff; font: inherit; font-size: 14px; font-weight: 700; box-shadow: 0 4px 14px rgba(0,0,0,.3); cursor: pointer; }
.chat-closed { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 24px; background: rgba(255,255,255,.88); }
.chat-closed-ico { font-size: 54px; }
.chat-closed-t { font-size: 20px; font-weight: 800; color: var(--c-accent); margin: 6px 0; }
.chat-closed-s { font-size: 14px; color: var(--c-muted); max-width: 320px; }
.chat-typing { position: relative; z-index: 3; min-height: 20px; padding: 0 14px; font-size: 12.5px; color: var(--c-muted); }
.chat-note { position: relative; z-index: 3; margin: 0 10px 6px; padding: 7px 12px; border-radius: 10px; background: #fef3c7; color: #78350f; font-size: 13px; border: 1px solid #fcd34d; }

/* ----- نوشتن (چسبیده به پایین + ناحیه امن آیفون) ----- */
.chat-composer { position: relative; z-index: 4; display: flex; align-items: center; background: #fff; border-top: 1px solid rgba(0,0,0,.1); padding: 8px 8px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.chat-composer > * + * { margin-right: 6px; }
.chat-input { flex: 1 1 auto; min-width: 0; height: 48px; padding: 0 14px; border: 1.5px solid #cbd5e1; border-radius: 24px; background: #f8fafc; color: #111827; font: inherit; font-size: 16px; outline: none; -webkit-appearance: none; appearance: none; }
.chat-input:focus { border-color: var(--c-head); background: #fff; }
.chat-ib { flex: 0 0 auto; width: 46px; height: 46px; border: 0; border-radius: 50%; background: var(--c-sys); font-size: 22px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chat-send { flex: 0 0 auto; width: 52px; height: 48px; border: 0; border-radius: 24px; background: var(--c-head); color: #fff; font-size: 20px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chat-send:active { transform: scale(.95); }
.chat-composer.is-off .chat-input, .chat-composer.is-off .chat-send, .chat-composer.is-off .chat-ib { opacity: .5; cursor: not-allowed; }
.chat-counter { position: absolute; top: -18px; left: 16px; font-size: 12px; color: var(--c-muted); background: #fff; padding: 0 6px; border-radius: 8px; }
.chat-counter.is-low { color: #b91c1c; font-weight: 800; }
.chat-stickers { position: relative; z-index: 4; background: #fff; border-top: 1px solid rgba(0,0,0,.08); padding: 6px 8px; white-space: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.chat-st { width: 50px; height: 50px; margin: 0 2px; border: 0; background: transparent; font-size: 30px; cursor: pointer; border-radius: 12px; }
.chat-st:active { background: var(--c-sys); }
.chat-emoji { position: relative; z-index: 4; background: #fff; border-top: 1px solid rgba(0,0,0,.08); max-height: 210px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.chat-emoji-tabs { display: flex; position: sticky; top: 0; background: #f1f5f9; }
.chat-em-tab { flex: 1 1 0; min-height: 42px; border: 0; background: transparent; font-size: 20px; cursor: pointer; }
.chat-em-tab.is-on { background: #fff; box-shadow: inset 0 -3px 0 var(--c-head); }
.chat-emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); padding: 4px; }
.chat-em { height: 42px; border: 0; background: transparent; font-size: 24px; cursor: pointer; border-radius: 8px; }
.chat-em:active { background: var(--c-sys); }
@media (max-width: 380px) { .chat-emoji-grid { grid-template-columns: repeat(7, 1fr); } .chat-bubble { max-width: 84%; } }

/* ----- دیالوگ داخل اتاق ----- */
.chat-dlg-ov { position: absolute; top: 0; right: 0; bottom: 0; left: 0; z-index: 20; display: flex; align-items: center; justify-content: center; background: rgba(15,23,42,.5); padding: 16px; }
.chat-dlg-ov--page { position: fixed; z-index: 10100; }
.chat-dlg { width: 100%; max-width: 380px; max-height: 90%; overflow-y: auto; background: #fff; color: #1f2937; border-radius: 16px; padding: 16px; box-shadow: 0 16px 40px rgba(0,0,0,.35); }
.chat-dlg h4 { margin: 0 0 8px; font-size: 17px; }
.chat-dlg p { margin: 0 0 10px; font-size: 14px; color: #4b5563; }
.chat-dlg-f { display: block; margin-bottom: 10px; }
.chat-dlg-f span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.chat-dlg input, .chat-dlg select, .chat-dlg textarea { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1.5px solid #cbd5e1; border-radius: 10px; font: inherit; font-size: 16px; margin-bottom: 8px; }
.chat-dlg-bar { display: flex; margin-top: 6px; }
.chat-dlg-bar > * + * { margin-right: 8px; }
.chat-dlg-b { flex: 1 1 0; min-height: 46px; border-radius: 12px; border: 1px solid #cbd5e1; background: #f8fafc; font: inherit; font-size: 15px; cursor: pointer; }
.chat-dlg-b.is-ok { background: #1e40af; border-color: #1e40af; color: #fff; font-weight: 700; }
.chat-dlg-err { color: #b91c1c; font-size: 13px; min-height: 18px; }
.chat-blk-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #e5e7eb; font-size: 14px; }

/* ----- کارت ورود (فضای کلاس‌ها / داشبورد) ----- */
.chat-entry { text-align: center; padding: 34px 18px; border-radius: 20px; background: linear-gradient(135deg, #eef4ff, #fdf2f8); border: 1px solid #dbeafe; max-width: 560px; margin: 8px auto; }
.chat-entry-ico { font-size: 54px; }
.chat-entry h3 { margin: 6px 0; font-size: 21px; color: #1e3a8a; }
.chat-entry p { color: #4b5563; font-size: 14.5px; margin: 0 0 16px; }
.chat-entry-btn { min-height: 52px; padding: 12px 28px; font-size: 16px; border-radius: 16px; display: inline-block; }
.chat-badge { display: inline-block; margin-right: 8px; background: #dc2626; color: #fff; font-size: 12px; font-weight: 800; padding: 1px 9px; border-radius: 999px; vertical-align: middle; }
.chat-admin-link { display: block; margin: 14px auto 0; min-height: 40px; background: transparent; border: 0; color: #1e40af; font: inherit; font-size: 13.5px; text-decoration: underline; cursor: pointer; }
.chat-admin-ok { margin-top: 12px; font-size: 13px; color: #166534; }

/* ----- تب «گفتگو» در فضای کلاس و بج ----- */
.chat-tab-badge { display: inline-block; min-width: 18px; height: 18px; line-height: 18px; padding: 0 6px; margin-right: 4px; border-radius: 999px; background: #dc2626; color: #fff; font-size: 11px; font-weight: 800; text-align: center; vertical-align: middle; }

/* ----- پنل مدیریت (CMS) ----- */
.chatmod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); grid-gap: 12px; margin-top: 12px; }
.chatmod-room { background: #fff; border: 1px solid #e5e7eb; border-radius: 14px; padding: 12px 14px; box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.chatmod-room h4 { margin: 0 0 6px; font-size: 16px; }
.chatmod-room .row { display: flex; align-items: center; justify-content: space-between; font-size: 13px; padding: 2px 0; color: #4b5563; }
.chatmod-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.chatmod-pill.on { background: #dcfce7; color: #166534; } .chatmod-pill.off { background: #fee2e2; color: #991b1b; } .chatmod-pill.ro { background: #fef3c7; color: #92400e; }
.chatmod-tabs { display: flex; flex-wrap: wrap; margin: 12px 0; }
.chatmod-tabs button { min-height: 42px; margin: 0 0 6px 6px; padding: 8px 14px; border-radius: 10px; border: 1px solid #d1d5db; background: #fff; font: inherit; cursor: pointer; }
.chatmod-tabs button.is-on { background: #1e40af; color: #fff; border-color: #1e40af; }
.chatmod-live .chat { height: min(70vh, 640px); }
.chat-tab-badge[hidden], .chat-badge[hidden], .dash-bottom__badge[hidden] { display: none !important; }
