/* ═══════════════════════════════════════════════════════════════════════
   spaces — «المساحات» (1.16، القدرة spaces): شاشة المساحة (screens/space.js)، والحبّة «أنت في مساحة»
   (ui/space-pill.js)، وورقة «مساحة جديدة» (ui/space-create.js) وأوراق الأشخاص والإعدادات. شريط «مباشر الآن» في
   الساحة نفسها في saha.css (.sa-spc-*)، والتعليقات والتفاعلات المتحركة في ملف الطبقة (ui/space-live.js).
   الشاشة سطح أزرق ليلي هادئ في السمتين (كسطح المكالمة الداكن الدائم): رموزها تُعاد تعريفها داخل .sp-screen فتتبعها
   مكوّنات ui.css كما هي (.btn .icon-btn .av). الحركة transform/opacity وحدهما، وتقف كلها مع prefers-reduced-motion.
   ═══════════════════════════════════════════════════════════════════════ */

/* «مباشر» — يُستعمل في الشاشة وبطاقات الساحة (ألوان حرفية: يُقرأ على السطحين) */
.sp-live-chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none; height: 22px; padding: 0 9px; border-radius: var(--r-full);
  background: #F0436A; color: #FFFFFF; font-size: 12px; font-weight: 800; line-height: 1; letter-spacing: 0;
}
.sp-live-chip > i { width: 6px; height: 6px; border-radius: 50%; background: #FFFFFF; animation: sp-blink 1.6s ease-in-out infinite; }
@keyframes sp-blink { 50% { opacity: .35; } }

/* ═══ ١. الشاشة ═════════════════════════════════════════════════════ */
.sp-screen {
  /* السطح الدائم — الألوان الحرفية هنا وحدها */
  --sp-fg: #F2F6FF; --sp-fg2: rgba(226, 236, 255, .76); --sp-fg3: rgba(226, 236, 255, .52);
  --sp-card: rgba(255, 255, 255, .065); --sp-line: rgba(255, 255, 255, .10); --sp-ring: #8EC0FF; --sp-solid: #0B1A33;
  --sp-bar-h: 60px;
  /* رموز ui.css داخل السطح: الأزرار والصور وزرّ الأيقونة تتبعها كما هي */
  --fg: var(--sp-fg); --fg-2: var(--sp-fg2); --fg-3: var(--sp-fg3); --bg: var(--sp-solid); --bg-elev: #13274A;
  --bg-2: rgba(255, 255, 255, .08); --bg-3: rgba(255, 255, 255, .14); --sep: var(--sp-line);
  --accent: #7FB2FF; --accent-fg: #08101F; --accent-soft: rgba(127, 178, 255, .16);

  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  overflow: hidden; isolation: isolate;
  background: var(--sp-solid); color: var(--sp-fg); color-scheme: dark;
  -webkit-user-select: none; user-select: none;
}
.sp-bg {
  position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(120% 55% at 50% -6%, rgba(54, 104, 196, .55) 0%, rgba(30, 64, 130, .18) 52%, transparent 74%),
    radial-gradient(90% 46% at 92% 104%, rgba(70, 120, 214, .24) 0%, transparent 70%),
    linear-gradient(180deg, #11264C 0%, #0B1A33 48%, #08111F 100%);
}

/* الرأس */
.sp-top { flex: none; display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 6px; }
.sp-ib { color: var(--sp-fg); }
.sp-ib[hidden] { visibility: hidden; display: inline-flex; }
.sp-top-mid { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 10px; }
.sp-count { display: inline-flex; align-items: center; gap: 4px; color: var(--sp-fg2); font-size: var(--fz-sm); font-weight: 800; }
.sp-count .icon-svg { width: 16px; height: 16px; }
.sp-since { color: var(--sp-fg3); font-size: var(--fz-xs); white-space: nowrap; }

/* شريط الحال (يتّصل، انقطع، الصوت موقوف) */
.sp-conn {
  flex: none; display: flex; align-items: center; gap: 8px; margin: 0 16px 6px; padding: 8px 12px; min-height: 44px;
  border-radius: var(--r-md); background: rgba(255, 255, 255, .08); color: var(--sp-fg2); font-size: var(--fz-sm); font-weight: 700;
}
.sp-conn[hidden] { display: none; }
.sp-conn .icon-svg { width: 18px; height: 18px; flex: none; }
.sp-conn .btn { margin-inline-start: auto; }
.sp-conn[data-kind="lost"], .sp-conn[data-kind="failed"] { background: rgba(240, 67, 106, .14); color: #FFC2CD; }

/* الجسم: يمرّر، وأسفله يتّسع لطبقة التعليقات فوق الشريط */
.sp-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 16px 24px; -webkit-overflow-scrolling: touch; }
.sp-is-live .sp-body { padding-bottom: 34vh; }
.sp-wait { display: grid; place-items: center; min-height: 40vh; color: var(--sp-fg2); }
.sp-titles { position: relative; padding: 6px 2px 0; }
.sp-title { margin: 6px 0 4px; font-size: var(--fz-2xl); font-weight: 800; line-height: 1.32; color: var(--sp-fg); overflow-wrap: anywhere; }
.sp-topic { margin: 0; color: var(--sp-fg2); font-size: var(--fz-md); line-height: 1.55; overflow-wrap: anywhere; }
.sp-adult { display: inline-block; margin-top: 8px; padding: 1px 8px; border-radius: 6px; background: rgba(255, 255, 255, .12); color: var(--sp-fg2); font-size: 12px; font-weight: 800; }

/* المتحدّثون */
.sp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 20px 6px; margin: 24px 0 6px; }
.sp-tile {
  --lvl: 0;
  display: flex; flex-direction: column; align-items: center; gap: 7px; min-width: 0; padding: 4px 2px;
  border: 0; border-radius: var(--r-md); background: none; color: inherit; font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.sp-tile:active { transform: scale(.96); transition: transform var(--dur-1); }
.sp-ava { position: relative; display: block; width: 68px; height: 68px; }
.sp-ava .av { --sz: 68px; font-size: 26px; }
.sp-ring {
  position: absolute; inset: -6px; border-radius: 50%; pointer-events: none;
  border: 3px solid var(--sp-ring); opacity: 0; transform: scale(.92);
  box-shadow: 0 0 0 0 rgba(142, 192, 255, 0);
  transition: opacity 140ms linear, transform 120ms var(--ease), box-shadow 140ms linear;
}
.sp-tile.is-speaking .sp-ring {
  opacity: calc(.5 + var(--lvl) * .5);
  transform: scale(calc(1 + var(--lvl) * .13));
  box-shadow: 0 0 calc(4px + var(--lvl) * 18px) rgba(142, 192, 255, .55);
}
.sp-moff {
  position: absolute; bottom: -3px; inset-inline-end: -3px; display: none; place-items: center;
  width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--sp-solid); background: #24344F; color: #FF9AAB;
}
.sp-moff .icon-svg { width: 14px; height: 14px; }
.sp-tile.is-muted .sp-moff { display: grid; }
.sp-tname { display: flex; align-items: center; justify-content: center; gap: 3px; max-width: 100%; font-size: var(--fz-sm); font-weight: 700; }
.sp-tn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-tag {
  display: inline-block; padding: 1px 8px; border-radius: var(--r-full); font-size: 11px; font-weight: 800;
  background: rgba(127, 178, 255, .16); color: #BFD8FF;
}
.sp-tag.host { background: rgba(255, 206, 110, .16); color: #FFD98F; }
.sp-enter { animation: sp-pop 280ms var(--ease-spring) backwards; }
@keyframes sp-pop { from { opacity: 0; transform: scale(.8); } }

/* عناوين الأقسام، وطلبات الكلام، والمستمعون */
.sp-sec-h { display: flex; align-items: center; gap: 6px; margin: 22px 2px 12px; color: var(--sp-fg2); font-size: var(--fz-sm); font-weight: 800; }
.sp-sec-h .icon-svg { width: 18px; height: 18px; }
.sp-sec-h b { color: var(--sp-fg3); font-weight: 700; }
.sp-hands { margin-top: 18px; padding: 2px 12px 8px; border-radius: var(--r-lg); background: rgba(255, 206, 110, .07); border: 1px solid rgba(255, 206, 110, .16); }
.sp-hands[hidden] { display: none; }
.sp-hands .sp-sec-h { margin: 10px 0 6px; color: #FFD98F; }
.sp-hand-list { display: grid; }
.sp-hand-row { display: flex; align-items: center; gap: 8px; min-height: 52px; }
.sp-hand-row + .sp-hand-row { border-top: 1px solid var(--sp-line); }
.sp-hand-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 6px 0; border: 0; background: none; color: inherit; font: inherit; font-weight: 700; text-align: start; }
.sp-hn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-accept { flex: none; }
.sp-lgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 14px 4px; }
.sp-lis { display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; padding: 2px; border: 0; background: none; color: var(--sp-fg2); font: inherit; font-size: 12px; }
.sp-lis .av { --sz: 46px; font-size: 18px; }
.sp-ln { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-lmore { display: grid; place-items: center; width: 46px; height: 46px; margin: 2px auto 0; border-radius: 50%; background: rgba(255, 255, 255, .1); color: var(--sp-fg2); font-weight: 800; font-size: 13px; }
.sp-lempty { margin: 0 2px; color: var(--sp-fg3); font-size: var(--fz-sm); }

/* بطاقة الحال: مجدولة، انتهت، أُخرجت، خطأ */
.sp-card {
  display: grid; justify-items: center; gap: 10px; margin: 28px 0; padding: 26px 18px 20px; text-align: center;
  border-radius: var(--r-xl); background: var(--sp-card); border: 1px solid var(--sp-line);
}
.sp-card .sp-title { margin: 2px 0 0; font-size: var(--fz-xl); }
.sp-card-acts { display: grid; gap: 8px; width: 100%; margin-top: 12px; }
.sp-card-acts .btn .icon-svg { width: 20px; height: 20px; }
.sp-sched-when { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--r-full); background: rgba(255, 206, 110, .14); color: #FFD98F; font-weight: 800; font-size: var(--fz-sm); }
.sp-sched-when .icon-svg { width: 16px; height: 16px; }
.sp-host-line { display: inline-flex; align-items: center; gap: 8px; max-width: 100%; padding: 4px 8px; border: 0; border-radius: var(--r-full); background: none; color: var(--sp-fg); font: inherit; font-weight: 700; }
.sp-host-line > span[dir] { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-end-ic { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: rgba(255, 255, 255, .08); color: var(--sp-fg2); }
.sp-end-ic .icon-svg { width: 30px; height: 30px; }
.sp-stats { display: flex; gap: 28px; margin-top: 4px; }
.sp-stats:empty { display: none; }
.sp-stats b { display: block; font-size: var(--fz-xl); font-weight: 800; }
.sp-stats small { color: var(--sp-fg3); font-size: var(--fz-xs); }
.sp-screen .btn-plain { background: rgba(255, 255, 255, .07); color: var(--sp-fg); }

/* الطبقة المتحركة (ui/space-live.js · css/space-live.css): وعاء بلا ارتفاع على الحافة العليا للشريط السفلي — الطبقة
   مرسومة فوق حافته (bottom: 100%)، والجسم يتّسع أسفله لها (sp-is-live) فيبقى المستمعون قابلين للتمرير فوقها. */
.sp-live-host { position: relative; z-index: 4; flex: none; height: 0; }

/* الشريط السفلي */
.sp-bar {
  position: relative; z-index: 4; flex: none; display: flex; align-items: center; gap: 8px;
  min-height: var(--sp-bar-h); padding: 8px 12px calc(8px + var(--safe-b));
  background: linear-gradient(to top, rgba(8, 17, 31, .98), rgba(8, 17, 31, .86)); border-top: 1px solid var(--sp-line);
}
.sp-bar[hidden] { display: none; }
.sp-leave {
  flex: none; height: 40px; padding: 0 14px; border: 0; border-radius: var(--r-full);
  background: rgba(240, 67, 106, .16); color: #FF9AAB; font: inherit; font-size: var(--fz-md); font-weight: 800;
}
.sp-leave:active { background: rgba(240, 67, 106, .26); }
.sp-bar.is-typing .sp-leave { display: none; }
.sp-cform { position: relative; flex: 1; min-width: 0; display: flex; }
.sp-cin {
  width: 100%; height: 40px; padding: 0 14px; border-radius: var(--r-full); border: 1px solid var(--sp-line);
  background: rgba(255, 255, 255, .08); color: var(--sp-fg); font: inherit; font-size: var(--fz-md);
  -webkit-user-select: text; user-select: text;
}
.sp-cin::placeholder { color: var(--sp-fg3); }
.sp-cin:focus { outline: none; border-color: rgba(127, 178, 255, .6); background: rgba(255, 255, 255, .11); }
.sp-cin:disabled { opacity: .6; }
.sp-bar.is-typing .sp-cin { padding-inline-end: 44px; }
.sp-send {
  position: absolute; top: 4px; inset-inline-end: 4px; display: grid; place-items: center; width: 32px; height: 32px;
  border: 0; border-radius: 50%; background: var(--accent); color: var(--accent-fg);
}
.sp-send[hidden] { display: none; }
.sp-send .icon-svg { width: 18px; height: 18px; }
.sp-cform.is-busy .sp-send { opacity: .5; }
.sp-act {
  flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(255, 255, 255, .1); color: var(--sp-fg); transition: background-color var(--dur-1), color var(--dur-1);
}
.sp-act .icon-svg { width: 22px; height: 22px; }
.sp-act:active { transform: scale(.92); transition: transform var(--dur-1); }
.sp-act.is-busy { opacity: .6; }
.sp-mic.is-on { background: var(--sp-fg); color: #0B1A33; }
.sp-mic.is-locked { opacity: .45; }
.sp-handbtn.is-on { background: #FFCE6E; color: #3A2600; }
.sp-react-btn { color: #FF8FA3; }
.sp-react-btn[aria-expanded="true"] { background: rgba(255, 143, 163, .18); }
.sp-tray {
  position: absolute; z-index: 6; inset-inline-end: 10px; bottom: calc(var(--sp-bar-h) + var(--safe-b) + 6px);
  display: flex; gap: 2px; padding: 6px; border-radius: var(--r-full);
  background: rgba(19, 39, 74, .97); border: 1px solid var(--sp-line); box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  animation: sp-tray-in 200ms var(--ease-spring) backwards; transform-origin: 80% 100%;
}
[dir="rtl"] .sp-tray { transform-origin: 20% 100%; }
.sp-tray[hidden] { display: none; }
.sp-tray button { width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; font-size: 25px; line-height: 1; }
.sp-tray button:active { background: rgba(255, 255, 255, .1); }
@keyframes sp-tray-in { from { opacity: 0; transform: translateY(8px) scale(.9); } }

/* ═══ ٢. الحبّة «أنت في مساحة» ═══════════════════════════════════════ */
.sp-pill {
  position: fixed; z-index: 35; left: 50%; transform: translateX(-50%);
  bottom: max(calc(var(--bottom-inset) + 12px), calc(var(--safe-b) + 12px));
  display: flex; align-items: center; gap: 2px; width: max-content; max-width: calc(100vw - 160px); min-width: 180px; padding: 4px;
  border-radius: var(--r-full); background: #12284D; color: #F2F6FF; color-scheme: dark;
  box-shadow: 0 8px 24px rgba(8, 17, 31, .32), 0 0 0 1px rgba(255, 255, 255, .06) inset;
}
.sp-pill[hidden] { display: none; }
.sp-pill-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 8px 0 4px; border: 0; background: none; color: inherit; font: inherit; text-align: start; }
.sp-pill-t { display: grid; min-width: 0; line-height: 1.2; }
.sp-pill-t b { font-size: 12px; font-weight: 800; white-space: nowrap; }
.sp-pill-t small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: rgba(226, 236, 255, .72); font-size: 11.5px; }
.sp-pill-ic { flex: none; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, .1); color: #F2F6FF; }
.sp-pill-ic[hidden] { display: none; }
.sp-pill-ic .icon-svg { width: 18px; height: 18px; }
.sp-pill-mic.is-on { background: #F2F6FF; color: #12284D; }
.sp-pill.is-reconnecting .sp-eq { opacity: .5; }
.sp-eq { flex: none; display: inline-flex; align-items: center; justify-content: center; gap: 2px; width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #FF5C7A, #DE3157); }
.sp-eq > i { width: 3px; height: 12px; border-radius: 2px; background: #FFFFFF; transform-origin: 50% 100%; animation: sp-eq 1s ease-in-out infinite; }
.sp-eq > i:nth-child(2) { animation-delay: -.35s; height: 14px; }
.sp-eq > i:nth-child(3) { animation-delay: -.7s; }
@keyframes sp-eq { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }

/* ═══ ٣. الأوراق: مساحة جديدة، الإعدادات، الشخص، المغادرة ═══════════════ */
.sp-form .field { margin-bottom: 12px; }
.sp-form textarea.input { min-height: 72px; }
.sp-count-row { display: flex; justify-content: flex-end; margin-top: -2px; }
.sp-count-row .is-over { color: var(--danger); }
.sp-sw-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 4px 12px; cursor: pointer; }
.sp-sw-row b { display: block; font-weight: 700; font-size: var(--fz-base); }
.sp-sw-row small { display: block; color: var(--fg-3); font-size: var(--fz-sm); margin-top: 2px; }
.sp-when { margin: 4px 0 12px; }
.sp-when button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.sp-when .icon-svg { width: 18px; height: 18px; }
.sp-sched-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sp-sched-row[hidden] { display: none; }
.sp-form-err { margin: 2px 4px 0; color: var(--danger); font-size: var(--fz-sm); font-weight: 600; }
.sp-form-err[hidden] { display: none; }
.sp-form.is-busy { opacity: .75; pointer-events: none; }
.sheet-actions .btn .icon-svg { width: 20px; height: 20px; }
.sp-danger-t { color: var(--danger); }
.sp-p-head { display: flex; align-items: center; gap: 12px; margin: 2px 4px 14px; }
.sp-p-name { display: flex; align-items: center; gap: 4px; font-size: var(--fz-lg); font-weight: 800; }
.sp-p-role { margin-top: 2px; color: var(--fg-3); font-size: var(--fz-sm); }

@media (prefers-reduced-motion: reduce) {
  .sp-live-chip > i, .sp-eq > i { animation: none; }
  .sp-eq > i { transform: scaleY(.7); }
  .sp-enter, .sp-tray { animation: none; }
  .sp-ring { transition: none; }
  .sp-tile.is-speaking .sp-ring { opacity: .9; transform: none; box-shadow: none; }
  .sp-tile:active, .sp-act:active { transform: none; }
}
