/* حضور كَيْم: الإشعارات، المساعد الذكي الثابت، الإدخال بالصوت، ربط تيليگرام، والأيقونات المرسومة */
:root {
  --pr-card: var(--q-card, #FBF9F4);
  --pr-ink: var(--q-ink, #173A28);
  --pr-muted: #6B7A70;
  --pr-seal: var(--q-seal, #1F6B43);
  --pr-seal-2: var(--q-seal-2, #2F8F5B);
  --pr-soft: var(--q-seal-soft, #E7F2EB);
  --pr-gold: #B08A3A;
  --pr-bad: #B4412F;
  --pr-warn: #B7791F;
  --pr-line: rgba(23, 58, 40, .10);
  --pr-shadow: 0 18px 40px -16px rgba(18, 40, 28, .38), 0 2px 6px rgba(18, 40, 28, .06);
  --pr-ease: cubic-bezier(.2, .8, .2, 1);
}
html.qaym-dark {
  --pr-card: #15221D; --pr-ink: #E8F0EA; --pr-muted: #9AAAA0; --pr-soft: rgba(47, 143, 91, .16); --pr-line: rgba(232, 240, 234, .10);
  --pr-shadow: 0 18px 40px -16px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .3);
}

/* ---------- الأيقونات بدل الإيموجي ---------- */
.qi { display: inline-block; flex: none; vertical-align: middle; }
.qi-inline { width: 1.05em; height: 1.05em; vertical-align: -0.16em; margin-inline: .08em .28em; stroke-width: 1.8; }
button .qi-inline:only-child, .dock-key .qi-inline:only-child { margin: 0; }
.btn .qi, .btn svg.qi { margin-inline-end: 6px; }
.btn .qi:only-child { margin: 0; }

/* ---------- الإشعارات ---------- */
/* طبقة عليا (popover) حتى تبين فوق النوافذ المفتوحة */
#toasts, #toasts[popover] { position: fixed !important; inset: auto !important; top: 70px !important; inset-inline-start: 22px !important; z-index: 9500 !important; display: flex; flex-direction: column; gap: 10px; pointer-events: none; margin: 0; padding: 0; border: 0; background: transparent; overflow: visible; width: auto; height: auto; color: inherit; }
.vf-pill[popover] { margin: 0; border: 0; overflow: visible; color: #F6F1E4; inset: auto; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); }
#toasts > .toast.rich { animation: none !important; }
.toast.rich {
  pointer-events: auto; position: relative; overflow: hidden; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 12px;
  width: min(380px, calc(100vw - 32px)); max-width: none; box-sizing: border-box; padding: 13px 14px 15px 12px;
  background: var(--pr-card) !important; color: var(--pr-ink) !important; border: 1px solid var(--pr-line) !important; border-radius: 16px !important;
  box-shadow: var(--pr-shadow) !important; border-inline-start: 0 !important;
  opacity: 0; transform: translateY(-14px) scale(.97); transition: opacity .32s var(--pr-ease), transform .42s var(--pr-ease);
}
.toast.rich.on { opacity: 1; transform: none; }
.toast.rich.out { opacity: 0; transform: translateX(-16px) scale(.97); transition-duration: .25s; }
[dir=rtl] .toast.rich.out { transform: translateX(16px) scale(.97); }
.toast.rich::before { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 4px; background: var(--t-accent, var(--pr-seal)); }
.toast-ico { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: var(--t-accent, var(--pr-seal)); background: var(--t-soft, var(--pr-soft)); }
.toast-ico .qi { width: 20px; height: 20px; }
.toast-txt { display: grid; gap: 2px; min-width: 0; line-height: 1.6; padding-top: 1px; }
.toast-txt b { font-size: .86rem; font-weight: 700; color: var(--t-accent, var(--pr-ink)); }
.toast-txt span { font-size: .8rem; color: var(--pr-ink); overflow-wrap: anywhere; }
.toast-act { justify-self: start; margin-top: 6px; font: inherit; font-size: .74rem; font-weight: 600; color: var(--t-accent, var(--pr-seal)); background: var(--t-soft, var(--pr-soft)); border: 0; border-radius: 999px; padding: 4px 12px; cursor: pointer; }
.toast-x { width: 26px; height: 26px; display: grid; place-items: center; border: 0; background: transparent; color: var(--pr-muted); border-radius: 8px; cursor: pointer; opacity: .7; }
.toast-x:hover { background: var(--pr-soft); opacity: 1; }
.toast-bar { position: absolute; inset-inline: 0; bottom: 0; height: 3px; background: var(--t-accent, var(--pr-seal)); opacity: .28; transform-origin: right; animation: toast-time linear forwards; }
[dir=ltr] .toast-bar { transform-origin: left; }
.toast.rich.paused .toast-bar { animation-play-state: paused; }
@keyframes toast-time { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.toast.rich.ok { --t-accent: var(--pr-seal); --t-soft: var(--pr-soft); }
.toast.rich.bad { --t-accent: var(--pr-bad); --t-soft: rgba(180, 65, 47, .10); }
.toast.rich.warn { --t-accent: var(--pr-warn); --t-soft: rgba(183, 121, 31, .12); }
.toast.rich.info { --t-accent: #2D6A8F; --t-soft: rgba(45, 106, 143, .10); }
.toast.rich.ai { --t-accent: var(--pr-gold); --t-soft: rgba(176, 138, 58, .13); }
.toast.rich.ai .toast-ico { background: linear-gradient(135deg, var(--pr-seal), #0F3D27); color: #F3DFA8; }

/* ---------- المساعد الذكي: الكرة الثابتة ---------- */
.copilot-orb, .copilot-drawer, .copilot-hint-bubble { display: none !important; }
.ai-orb {
  position: fixed; left: 20px; bottom: 24px; z-index: 1200; width: 54px; height: 54px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; color: #F3DFA8;
  background: radial-gradient(120% 120% at 30% 20%, #3A9A66 0%, var(--pr-seal) 45%, #0F3D27 100%);
  box-shadow: 0 14px 30px -10px rgba(15, 61, 39, .7), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .3s var(--pr-ease), box-shadow .3s var(--pr-ease);
}
.ai-orb:hover { transform: translateY(-2px) scale(1.04); }
.ai-orb:focus-visible { outline: 3px solid rgba(176, 138, 58, .6); outline-offset: 3px; }
.ai-orb.active { transform: rotate(-12deg) scale(.96); }
.ai-orb-core { position: relative; display: grid; place-items: center; }
.ai-orb-core .qi { width: 24px; height: 24px; animation: ai-twinkle 4.5s ease-in-out infinite; }
.ai-orb-ring { position: absolute; inset: -6px; border-radius: 50%; border: 1.5px solid rgba(47, 143, 91, .35); animation: ai-ring 3.2s ease-out infinite; pointer-events: none; }
@keyframes ai-ring { 0% { transform: scale(.92); opacity: .9; } 70%, 100% { transform: scale(1.22); opacity: 0; } }
@keyframes ai-twinkle { 0%, 100% { transform: rotate(0) scale(1); } 45% { transform: rotate(18deg) scale(1.08); } 55% { transform: rotate(18deg) scale(1.08); } }

/* فقاعة المبادرة: «تحتاج مساعدة؟» */
.ai-hint {
  position: fixed; left: 20px; bottom: 90px; z-index: 1199; width: min(320px, calc(100vw - 40px)); box-sizing: border-box; padding: 12px 14px 12px;
  background: var(--pr-card); color: var(--pr-ink); border: 1px solid var(--pr-line); border-radius: 18px 18px 18px 6px; box-shadow: var(--pr-shadow);
  display: grid; gap: 8px; opacity: 0; transform: translateY(10px) scale(.96); transform-origin: left bottom; transition: opacity .3s var(--pr-ease), transform .4s var(--pr-ease);
}
.ai-hint.on { opacity: 1; transform: none; }
.ai-hint[hidden] { display: none; }
.ai-hint-head { display: flex; align-items: center; justify-content: space-between; }
.ai-hint-badge { display: inline-flex; align-items: center; gap: 6px; font-size: .72rem; font-weight: 700; color: var(--pr-gold); }
.ai-hint-badge .qi { width: 14px; height: 14px; }
.ai-hint-x { width: 24px; height: 24px; border: 0; background: transparent; color: var(--pr-muted); font-size: 1.1rem; line-height: 1; border-radius: 8px; cursor: pointer; }
.ai-hint-x:hover { background: var(--pr-soft); }
.ai-hint-text { font-size: .82rem; line-height: 1.75; }
.ai-hint-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ai-chip { font: inherit; font-size: .72rem; line-height: 1.5; padding: 5px 10px; border-radius: 999px; border: 1px solid rgba(31, 107, 67, .25); background: var(--pr-soft); color: var(--pr-seal); cursor: pointer; text-align: start; }
html.qaym-dark .ai-chip { color: #9FD9B5; }
.ai-chip:hover { border-color: var(--pr-seal); }
.ai-chip.ghost { background: transparent; color: var(--pr-muted); border-color: var(--pr-line); }

/* لوحة المحادثة */
.ai-drawer {
  position: fixed; left: 20px; bottom: 90px; z-index: 9300; width: 400px; max-width: calc(100vw - 32px); height: 580px; max-height: calc(100dvh - 110px);
  display: flex; flex-direction: column; overflow: hidden; background: var(--pr-card); color: var(--pr-ink); border: 1px solid var(--pr-line); border-radius: 22px; box-shadow: 0 30px 70px -24px rgba(10, 40, 25, .55);
  opacity: 0; transform: translateY(14px) scale(.97); transform-origin: left bottom; transition: opacity .25s var(--pr-ease), transform .35s var(--pr-ease);
}
.ai-drawer.on { opacity: 1; transform: none; }
.ai-drawer[hidden] { display: none; }
.ai-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: linear-gradient(135deg, var(--pr-seal), #0F3D27); color: #F6F1E4; }
.ai-head-mark { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: rgba(255, 255, 255, .12); color: #F3DFA8; }
.ai-head > div { flex: 1; min-width: 0; display: grid; }
.ai-head h2 { margin: 0; font-size: .95rem; color: #fff; }
.ai-context { font-size: .66rem; color: rgba(246, 241, 228, .75); }
.ai-close { width: 32px; height: 32px; border: 0; border-radius: 10px; display: grid; place-items: center; background: rgba(255, 255, 255, .1); color: #fff; cursor: pointer; }
.ai-close:hover { background: rgba(255, 255, 255, .2); }
.ai-drawer .copilot-suggestions { padding: 12px 14px; border-bottom: 1px solid var(--pr-line); }
.ai-drawer .copilot-log { padding: 14px; }
.ai-drawer .copilot-bubble.assistant { background: var(--pr-soft); }
.ai-drawer .copilot-bubble.user { background: var(--pr-seal); color: #fff; }
.ai-typing { display: inline-flex; gap: 4px; padding: 4px 0; }
.ai-typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--pr-seal); opacity: .35; animation: ai-dot 1.1s ease-in-out infinite; }
.ai-typing i:nth-child(2) { animation-delay: .15s; } .ai-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes ai-dot { 0%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.ai-err { color: var(--pr-bad); font-size: .74rem; }
.ai-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--pr-line); }
.ai-compose textarea { flex: 1; min-width: 0; resize: none; max-height: 110px; font: inherit; font-size: .8rem; line-height: 1.7; padding: 9px 12px; border-radius: 14px; border: 1px solid var(--pr-line); background: transparent; color: inherit; }
.ai-compose textarea:focus { outline: 2px solid rgba(31, 107, 67, .3); border-color: var(--pr-seal); }
.ai-compose-actions { display: flex; gap: 6px; }
.ai-send, .ai-stop, .ai-mic { width: 38px; height: 38px; border-radius: 12px; border: 0; display: grid; place-items: center; cursor: pointer; }
.ai-send { background: var(--pr-seal); color: #fff; }
.ai-stop { background: var(--pr-bad); color: #fff; }
.ai-mic { background: var(--pr-soft); color: var(--pr-seal); }
.ai-send[hidden], .ai-stop[hidden] { display: none; }
[dir=rtl] .ai-send .qi, [dir=rtl] .copilot-shortcuts .qi { transform: scaleX(-1); }
.ai-notice { font-size: .62rem; color: var(--pr-muted); padding: 0 14px 10px; }
.copilot-shortcuts a { display: inline-flex; align-items: center; gap: 4px; }

/* زر «اسأل كَيْم» برأس الصفحة */
.ai-ask-chip { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: .74rem; font-weight: 600; padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(176, 138, 58, .35); background: rgba(176, 138, 58, .08); color: var(--pr-gold); cursor: pointer; white-space: nowrap; }
.ai-ask-chip:hover { background: rgba(176, 138, 58, .16); }
.ai-ask-chip .qi { width: 15px; height: 15px; }

/* ---------- الإدخال بالصوت ---------- */
.vf-btn { display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: .74rem; font-weight: 600; padding: 6px 12px; margin-inline-start: auto; margin-inline-end: 8px; border-radius: 999px; border: 1px solid rgba(31, 107, 67, .22); background: var(--pr-soft); color: var(--pr-seal); cursor: pointer; transition: background .2s, box-shadow .2s; }
html.qaym-dark .vf-btn { color: #9FD9B5; }
.vf-btn:hover { border-color: var(--pr-seal); }
.vf-btn.on { background: var(--pr-seal); color: #fff; box-shadow: 0 0 0 4px rgba(31, 107, 67, .18); }
.vf-btn .qi { width: 16px; height: 16px; }
.vf-btn.compact { margin: 0; }
.dlg-head { display: flex; align-items: center; gap: 8px; }
.dlg-head h2 { flex: 1; min-width: 0; }
.dlg-head .vf-btn { margin-inline-start: 0; margin-inline-end: 0; }
.vf-bar { display: flex; justify-content: flex-end; grid-column: 1 / -1; margin-bottom: 4px; }
.vf-fieldmic {
  position: absolute; z-index: 5; padding: 0; border: 0; border-radius: 10px; display: grid; place-items: center; cursor: pointer;
  background: var(--pr-soft); color: var(--pr-seal); opacity: 0; transform: scale(.8); pointer-events: none; transition: opacity .18s, transform .2s var(--pr-ease), background .2s;
}
.vf-fieldmic.on { opacity: .9; transform: none; pointer-events: auto; }
.vf-fieldmic:hover { opacity: 1; background: var(--pr-seal); color: #fff; }
.vf-filled { animation: vf-flash 1.1s var(--pr-ease); }
@keyframes vf-flash { 0% { box-shadow: 0 0 0 0 rgba(47, 143, 91, .0); } 25% { box-shadow: 0 0 0 4px rgba(47, 143, 91, .28); background-color: rgba(47, 143, 91, .07); } 100% { box-shadow: 0 0 0 0 rgba(47, 143, 91, 0); } }
.vf-pill {
  position: fixed; left: 50%; bottom: 28px; z-index: 9600; display: flex; align-items: center; gap: 12px; max-width: min(560px, calc(100vw - 32px)); box-sizing: border-box;
  padding: 10px 10px 10px 16px; border-radius: 999px; background: #0F2F20; color: #F6F1E4; box-shadow: 0 20px 44px -14px rgba(0, 0, 0, .55);
  transform: translate(-50%, 20px); opacity: 0; transition: opacity .25s, transform .35s var(--pr-ease);
}
.vf-pill.on { transform: translate(-50%, 0); opacity: 1; }
.vf-live { flex: 1; min-width: 0; font-size: .82rem; line-height: 1.6; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: rtl; }
.vf-wave { display: inline-flex; align-items: center; gap: 3px; height: 22px; padding-inline-start: 4px; }
.vf-wave i { width: 3px; height: 8px; border-radius: 2px; background: #6FCF97; animation: vf-wave 1s ease-in-out infinite; }
.vf-wave i:nth-child(2) { animation-delay: .12s; } .vf-wave i:nth-child(3) { animation-delay: .24s; } .vf-wave i:nth-child(4) { animation-delay: .36s; } .vf-wave i:nth-child(5) { animation-delay: .48s; }
@keyframes vf-wave { 0%, 100% { height: 6px; } 50% { height: 20px; } }
.vf-stop { width: 34px; height: 34px; border-radius: 50%; border: 0; display: grid; place-items: center; background: #E05A47; color: #fff; cursor: pointer; flex: none; }

/* ---------- ربط تيليگرام ---------- */
.tg-card { display: grid; gap: 12px; }
.tg-title { display: flex; align-items: center; gap: 8px; color: #229ED9; }
.tg-title h3 { margin: 0; color: var(--pr-ink); }
.tg-big { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; font-size: .9rem; background: #229ED9 !important; border-color: #229ED9 !important; color: #fff !important; }
.tg-quick-area { display: grid; gap: 8px; justify-items: start; padding: 14px; border-radius: 14px; background: rgba(34, 158, 217, .07); border: 1px solid rgba(34, 158, 217, .2); }
.tg-qr { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.tg-qr svg { border-radius: 10px; border: 1px solid var(--pr-line); background: #fff; }
.tg-wait { display: flex; align-items: center; gap: 10px; font-size: .8rem; color: var(--pr-muted); }
.tg-spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(34, 158, 217, .25); border-top-color: #229ED9; animation: tg-spin .8s linear infinite; }
@keyframes tg-spin { to { transform: rotate(360deg); } }
.tg-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.tg-step { display: flex; gap: 12px; align-items: flex-start; }
.tg-n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .78rem; font-weight: 700; background: var(--pr-soft); color: var(--pr-seal); }
.tg-step .btn { justify-self: start; display: inline-flex; align-items: center; gap: 6px; }
.tg-next { display: grid; gap: 8px; justify-items: start; font-size: .8rem; }
.tg-own > summary, .tg-manual > summary { cursor: pointer; font-size: .8rem; color: var(--pr-muted); padding: 4px 0; }
.tg-own[open] > summary, .tg-manual[open] > summary { margin-bottom: 10px; }
.tg-manual { display: grid; gap: 8px; }
.tg-linked { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 14px; background: var(--pr-soft); }
.tg-linked > div { flex: 1; display: grid; gap: 2px; }
.tg-linked small { color: var(--pr-muted); }
.tg-ok { color: var(--pr-seal); display: grid; }

@media (max-width: 600px) {
  .ai-orb { left: 12px; bottom: 116px; width: 48px; height: 48px; }
  .ai-hint { left: 12px; bottom: 174px; }
  .ai-drawer { left: 8px; right: 8px; width: auto; max-width: none; bottom: 8px; height: calc(100dvh - 16px); max-height: none; border-radius: 20px; }
  #toasts, #toasts[popover] { inset-inline: 12px !important; top: 64px !important; }
  .toast.rich { width: 100%; }
  .vf-btn span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ai-orb-ring, .ai-orb-core .qi, .vf-wave i, .ai-typing i { animation: none !important; }
  .toast.rich, .ai-hint, .ai-drawer, .vf-pill { transition: none; }
}
@media print { .ai-orb, .ai-hint, .ai-drawer, .vf-fieldmic, .vf-pill, .vf-btn, .vf-bar, #toasts { display: none !important; } }
/* لما المساعد يبادر، بطاقة الدعم تتنحى حتى ما يتراكبون */
body.ai-hint-on .sk-support, body:has(.ai-drawer.on) .sk-support { opacity: 0 !important; pointer-events: none !important; transform: translateX(-10px) scale(.96) !important; }

/* المايك داخل الحقل + حالة الاستماع */
.vf-fieldmic { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
.vf-fieldmic .qi { width: 16px; height: 16px; }
.vf-listening { border-color: var(--pr-seal) !important; box-shadow: 0 0 0 4px rgba(47, 143, 91, .18) !important; }
.vf-pill.metered .vf-wave i { animation: none; transition: height .08s linear; }
.vf-pill.busy .vf-wave i { animation: vf-wave 0.7s ease-in-out infinite; background: #E2C77E; }
.vf-stop { background: #2F8F5B; }
.vf-stop:disabled { opacity: .5; }
@media (pointer: coarse) { .vf-fieldmic.on { opacity: 1; } .vf-pill { bottom: calc(16px + env(safe-area-inset-bottom)); } }
.ai-diag { margin-top: 8px !important; font-size: .68rem; color: var(--pr-warn); border-top: 1px dashed var(--pr-line); padding-top: 6px; direction: rtl; overflow-wrap: anywhere; }
.ai-probe { display: grid; gap: 4px; margin-top: 6px; font-size: .7rem; direction: ltr; text-align: left; } .ai-probe .ok { color: var(--pr-seal); } .ai-probe .bad { color: var(--pr-bad); overflow-wrap: anywhere; }
