/* بسیاری از عناصر چت با استایل display:flex/grid تعریف شده‌اند؛ چون این با ویژگی HTML «hidden»
   هم‌رتبه است، بدون این قانون سراسری، «hidden» ست‌شده در جاوااسکریپت اثری نمی‌کرد. */
[hidden] { display: none !important; }

/* ---------- Floating support widget (bottom-right, RTL) ---------- */
.chat-widget { position: fixed; bottom: 24px; right: 24px; z-index: 1500; font-family: var(--font); }
.chat-widget-toggle {
    position: relative; width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
    background: var(--brand); color: #fff; display: grid; place-items: center;
    box-shadow: var(--shadow-brand); transition: var(--t);
}
.chat-widget-toggle:hover { background: var(--brand-dark); transform: translateY(-3px); }
.chat-widget-badge {
    position: absolute; top: -2px; left: -2px; width: 20px; height: 20px; border-radius: 50%;
    background: #ffb300; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
    border: 2px solid #fff;
}

.chat-widget-panel {
    position: absolute; bottom: 74px; right: 0; width: min(360px, 90vw); height: min(540px, 70vh);
    background: #fff; border-radius: 18px; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
    display: flex; flex-direction: column; overflow: hidden;
}
.chat-widget-header {
    background: var(--brand); color: #fff; padding: 14px 18px; display: flex; align-items: center;
    justify-content: space-between; flex-shrink: 0;
}
.chat-widget-header-info { display: flex; flex-direction: column; gap: 2px; }
.chat-widget-title { font-weight: 900; font-size: 15px; }
.chat-widget-agent { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .95; }
.chat-widget-agent img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; }
.chat-widget-close { background: rgba(255,255,255,.2); border: 0; color: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }
.chat-widget-close:hover { background: rgba(255,255,255,.35); }

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

/* pre-chat form */
.chat-preform { padding: 16px 18px; overflow-y: auto; }
.chat-preform-intro { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.chat-preform .form-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.chat-preform label { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.chat-preform input, .chat-preform select, .chat-preform textarea {
    padding: 9px 12px; border: 1.5px solid var(--line); border-radius: 8px; font-family: var(--font); font-size: 13.5px;
}
.chat-preform-error { background: #fdeaea; color: var(--brand); border: 1px solid #f3c1c1; border-radius: 8px; padding: 8px 12px; font-size: 12.5px; margin-bottom: 10px; }

/* thread */
.chat-thread { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.chat-msg { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 13.5px; line-height: 1.7; position: relative; }
.chat-msg-mine { align-self: flex-start; background: var(--brand); color: #fff; border-bottom-left-radius: 4px; }
.chat-msg-theirs { align-self: flex-end; background: var(--gray); color: var(--ink); border-bottom-right-radius: 4px; }
.chat-msg-system { align-self: center; background: transparent; max-width: 100%; text-align: center; }
.chat-msg-system-text { font-size: 12px; color: var(--muted); background: var(--gray); padding: 4px 12px; border-radius: 20px; }
.chat-msg-time { display: block; font-size: 10px; opacity: .75; margin-top: 3px; }
.chat-msg-img { max-width: 100%; border-radius: 8px; display: block; }
.chat-msg-file { color: inherit; text-decoration: underline; }
.chat-msg-quote { font-size: 11px; opacity: .8; border-inline-start: 2px solid currentColor; padding-inline-start: 6px; margin-bottom: 4px; }
.chat-msg-seen::after { content: '✓✓'; font-size: 10px; opacity: .8; margin-inline-start: 4px; }
.chat-msg-edited { font-size: 10px; opacity: .75; font-style: italic; }
.chat-msg-actions { display: inline-flex; gap: 4px; margin-inline-start: 6px; opacity: 0; transition: var(--t); }
.chat-msg-mine:hover .chat-msg-actions { opacity: 1; }
.chat-msg-actions button { background: rgba(255,255,255,.2); border: 0; border-radius: 5px; cursor: pointer; font-size: 11px; padding: 1px 4px; color: inherit; }
.chat-msg-actions button:hover { background: rgba(255,255,255,.4); }

.chat-typing { padding: 0 14px 6px; font-size: 12px; color: var(--muted); }
.chat-reply-preview { display: flex; align-items: center; justify-content: space-between; background: var(--gray); padding: 6px 12px; font-size: 12px; color: var(--ink-soft); }
.chat-reply-preview button { background: none; border: 0; cursor: pointer; color: var(--muted); }

.chat-composer { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-top: 1px solid var(--line); position: relative; }
.chat-restart-btn { margin: 0 12px 12px; width: calc(100% - 24px); }
.chat-icon-btn { background: none; border: 0; cursor: pointer; font-size: 18px; padding: 4px; border-radius: 8px; color: var(--ink-soft); display: grid; place-items: center; }
.chat-icon-btn:hover { background: var(--gray); }
.chat-send-btn { background: var(--brand); color: #fff; }
.chat-send-btn:hover { background: var(--brand-dark); }
#chatMessageInput { flex: 1; border: 1.5px solid var(--line); border-radius: 20px; padding: 8px 14px; font-family: var(--font); font-size: 13.5px; }
.chat-emoji-picker {
    position: absolute; bottom: 54px; right: 12px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow-lg); padding: 8px; display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px;
}
.chat-emoji-picker button { background: none; border: 0; cursor: pointer; font-size: 18px; padding: 4px; border-radius: 6px; }
.chat-emoji-picker button:hover { background: var(--gray); }

@media (max-width: 480px) {
    .chat-widget { bottom: 16px; right: 16px; }
    .chat-widget-panel { width: 92vw; height: 76vh; bottom: 70px; }
}
