/* ==========================================================================
   شوفه يشتغل — Watch It Work
   Standalone, reusable landing component (also mountable on /watch later).
   All rules namespaced under .wiw. RTL-first. Dark "product stage" regardless
   of page theme so the citation colours stay consistent.
   Legal content is data-driven from watch-it-work.json — never hardcoded here.
   ========================================================================== */

.wiw {
  /* self-contained palette — falls back to global redesign tokens */
  --wiw-gold: var(--gold-500, #C9A84C);
  --wiw-gold-soft: var(--gold-400, #d6bb6c);
  --wiw-cyan: var(--cyan-400, #22d3ee);
  --wiw-stage-bg: var(--navy-950, #0a1020);
  --wiw-panel: var(--navy-900, #0f172a);
  --wiw-panel-2: #131f37;
  --wiw-border: rgba(255, 255, 255, 0.10);
  --wiw-border-strong: rgba(255, 255, 255, 0.18);
  --wiw-fg: #e8edf6;
  --wiw-muted: #9aa7bd;
  --wiw-ok: #34d399;
  --wiw-amend: #f59e0b;
  --wiw-repeal: #f87171;

  padding: clamp(40px, 7vw, 72px) 0;
  font-family: var(--font-body, 'Tajawal', system-ui, sans-serif);
}

.wiw * { box-sizing: border-box; }

.wiw-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ------------------------------ header ---------------------------------- */
.wiw-head { text-align: center; margin-bottom: clamp(28px, 5vw, 44px); }

.wiw-eyebrow {
  display: inline-block;
  font-size: 13px;
  font-weight: 700;
  color: var(--wiw-gold);
  background: rgba(201, 168, 76, 0.12);
  border: 1px solid rgba(201, 168, 76, 0.28);
  padding: 6px 14px;
  border-radius: 9999px;
  margin-bottom: 16px;
}

.wiw-title {
  font-family: var(--font-heading, 'IBM Plex Sans Arabic', 'Tajawal', sans-serif);
  font-weight: 700;
  font-size: clamp(24px, 4.4vw, 40px);
  line-height: 1.35;
  margin: 0 0 12px;
  color: var(--fg, var(--wiw-fg));
}
.wiw-title-a { color: var(--fg, var(--wiw-fg)); }
.wiw-title-b {
  background: linear-gradient(90deg, var(--wiw-gold), var(--wiw-gold-soft));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: var(--wiw-gold); /* fallback if clip unsupported */
}

.wiw-sub {
  font-size: clamp(14.5px, 2.2vw, 17px);
  color: var(--gray-400, var(--wiw-muted));
  margin: 0 0 22px;
}

.wiw-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.wiw-cta svg { width: 18px; height: 18px; }

/* ------------------------------- stage ---------------------------------- */
.wiw-stage {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr); /* personas (right in RTL) | demo */
  gap: 20px;
  align-items: start;
}

/* --------------------------- persona list ------------------------------- */
.wiw-personas {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.wiw-persona {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  text-align: start;
  padding: 13px 14px;
  border-radius: 14px;
  background: var(--wiw-panel);
  border: 1px solid var(--wiw-border);
  color: var(--wiw-fg);
  cursor: pointer;
  font-family: inherit;
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.wiw-persona:hover { border-color: var(--wiw-border-strong); transform: translateY(-1px); }
.wiw-persona:focus-visible { outline: 2px solid var(--wiw-cyan); outline-offset: 2px; }

.wiw-persona.is-active {
  border-color: var(--wiw-gold);
  /* خلفية كريمية + نص كحلي داكن عالي التباين (بطلب صريح) */
  background: linear-gradient(180deg, var(--gold-100, #fef3c7), var(--gold-200, #fde68a));
  box-shadow: 0 0 0 1px rgba(146,102,13,0.35) inset;
  color: var(--navy-900, #0f172a);
}
.wiw-persona.is-active .wiw-persona-label { color: var(--navy-900, #0f172a); }
.wiw-persona.is-active .wiw-persona-hint { color: var(--navy-700, #334155); }

.wiw-persona-ic {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--wiw-border);
  color: var(--wiw-gold);
}
.wiw-persona-ic svg { width: 20px; height: 20px; }
.wiw-persona.is-active .wiw-persona-ic {
  background: rgba(146,102,13,0.12);
  border-color: rgba(146,102,13,0.35);
  color: var(--gold-700, #92660d);
}

.wiw-persona-body { display: flex; flex-direction: column; min-width: 0; }
.wiw-persona-label { font-weight: 700; font-size: 14.5px; }
.wiw-persona-hint {
  font-size: 11.5px;
  color: var(--wiw-muted);
  opacity: 0;
  max-height: 0;
  transition: opacity .2s ease, max-height .2s ease;
}
.wiw-persona.is-active .wiw-persona-hint { opacity: 1; max-height: 32px; }

/* ------------------------------- demo ----------------------------------- */
.wiw-demo {
  position: relative;
  background: var(--wiw-stage-bg);
  border: 1px solid var(--wiw-border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  min-height: 440px;
  display: flex;
  flex-direction: column;
}

.wiw-demo-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--wiw-border);
  background: rgba(255,255,255,0.02);
}
.wiw-demo-dots { display: inline-flex; gap: 6px; }
.wiw-demo-dots i {
  width: 10px; height: 10px; border-radius: 50%;
  background: rgba(255,255,255,0.16); display: block;
}
.wiw-demo-title {
  font-weight: 700; font-size: 13.5px; color: var(--wiw-fg);
  display: inline-flex; align-items: center; gap: 8px;
}
.wiw-demo-title .wiw-dot-live {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--wiw-ok); box-shadow: 0 0 0 3px rgba(52,211,153,0.18);
}

.wiw-toggle {
  margin-inline-start: auto;
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  color: var(--wiw-fg);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--wiw-border);
  border-radius: 9999px;
  padding: 6px 12px; cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.wiw-toggle:hover { background: rgba(255,255,255,0.12); border-color: var(--wiw-border-strong); }
.wiw-toggle:focus-visible { outline: 2px solid var(--wiw-cyan); outline-offset: 2px; }
.wiw-toggle svg { width: 14px; height: 14px; }

/* thin progress bar under the header */
.wiw-progress { height: 3px; background: rgba(255,255,255,0.06); }
.wiw-progress > span {
  display: block; height: 100%; width: 0;
  background: linear-gradient(90deg, var(--wiw-gold), var(--wiw-gold-soft));
}

.wiw-chat {
  flex: 1;
  padding: 18px 16px 20px;
  overflow: hidden;
}

/* chat messages */
.wiw-msg { display: flex; gap: 10px; margin-bottom: 16px; align-items: flex-start; }
.wiw-avatar {
  flex: 0 0 auto; width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center; font-size: 15px;
}
.wiw-msg-q .wiw-avatar { background: rgba(255,255,255,0.06); border: 1px solid var(--wiw-border); }
.wiw-msg-a .wiw-avatar { background: rgba(201,168,76,0.16); border: 1px solid rgba(201,168,76,0.4); color: var(--wiw-gold); font-weight: 800; }

.wiw-bubble {
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 14.5px;
  line-height: 1.9;
  color: var(--wiw-fg);
  max-width: 100%;
}
.wiw-msg-q .wiw-bubble {
  background: var(--wiw-panel-2);
  border: 1px solid var(--wiw-border);
  border-start-start-radius: 4px;
  font-weight: 600;
}
.wiw-msg-a .wiw-bubble {
  background: var(--wiw-panel);
  border: 1px solid var(--wiw-border);
  border-start-start-radius: 4px;
  width: 100%;
}

/* typing indicator */
.wiw-thinking { display: inline-flex; align-items: center; gap: 6px; }
.wiw-thinking span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--wiw-muted);
  animation: wiw-bounce 1.2s infinite ease-in-out both;
}
.wiw-thinking span:nth-child(2) { animation-delay: .16s; }
.wiw-thinking span:nth-child(3) { animation-delay: .32s; }
.wiw-thinking em {
  font-style: normal; font-size: 12.5px; color: var(--wiw-muted); margin-inline-start: 6px;
}
@keyframes wiw-bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .4; } 40% { transform: scale(1); opacity: 1; } }

.wiw-caret {
  display: inline-block; width: 2px; height: 1.05em;
  vertical-align: -0.18em; margin-inline-start: 1px;
  background: var(--wiw-gold);
  animation: wiw-blink 1s steps(1) infinite;
}
@keyframes wiw-blink { 50% { opacity: 0; } }

/* --------------------------- sources / cards ---------------------------- */
.wiw-sources { margin-top: 6px; }
.wiw-sources-head {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; font-weight: 700; color: var(--wiw-muted);
  margin: 4px 0 10px;
}
.wiw-sources-head .wiw-sources-count {
  font-size: 11px; font-weight: 700; color: var(--wiw-gold);
  background: rgba(201,168,76,0.14); border: 1px solid rgba(201,168,76,0.3);
  border-radius: 9999px; padding: 1px 8px;
}
.wiw-sources-grid { display: grid; gap: 8px; grid-template-columns: 1fr; }
@media (min-width: 768px) {
  .wiw-sources-grid { grid-template-columns: 1fr 1fr; }
}

/* compact single-row citation: «م.X · النظام» + status + two icon links */
.wiw-cite {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  background: var(--wiw-panel-2);
  border: 1px solid var(--wiw-border);
  border-inline-start: 3px solid var(--wiw-gold);
  border-radius: 10px;
  padding: 6px 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .35s ease, transform .35s ease;
}
.wiw-cite.is-in { opacity: 1; transform: none; }
.wiw-cite.is-extra { display: none; }
.wiw-sources.is-expanded .wiw-cite.is-extra { display: flex; }

.wiw-cite-ref {
  display: inline-flex; align-items: center; gap: 6px;
  flex: 1; min-width: 0;
  font-size: 12.5px; font-weight: 700; color: var(--wiw-fg);
  line-height: 1.7;
}
.wiw-cite-num { color: var(--wiw-gold); white-space: nowrap; }
.wiw-cite-sep { color: var(--wiw-muted); }
.wiw-cite-law { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.wiw-cite-status {
  flex: 0 0 auto;
  font-size: 10px; font-weight: 700; padding: 1px 7px; border-radius: 9999px;
  white-space: nowrap;
}
.wiw-cite-status.is-ok { background: rgba(52,211,153,0.14); color: var(--wiw-ok); border: 1px solid rgba(52,211,153,0.3); }
.wiw-cite-status.is-amend { background: rgba(245,158,11,0.14); color: var(--wiw-amend); border: 1px solid rgba(245,158,11,0.3); }
.wiw-cite-status.is-repeal { background: rgba(248,113,113,0.14); color: var(--wiw-repeal); border: 1px solid rgba(248,113,113,0.3); }

.wiw-cite-links { display: inline-flex; gap: 4px; flex: 0 0 auto; }
.wiw-cite-link {
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border-radius: 7px; text-decoration: none;
  background: rgba(34,211,238,0.10); color: var(--wiw-cyan);
  border: 1px solid rgba(34,211,238,0.28);
  transition: background .15s ease;
}
.wiw-cite-link:hover { background: rgba(34,211,238,0.2); }
.wiw-cite-link svg { width: 13px; height: 13px; }

.wiw-sources-more {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 8px;
  font-family: inherit; font-size: 12px; font-weight: 700;
  color: var(--wiw-muted); background: rgba(255,255,255,0.04);
  border: 1px solid var(--wiw-border); border-radius: 9999px;
  padding: 4px 12px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.wiw-sources-more:hover { background: rgba(255,255,255,0.09); color: var(--wiw-fg); }
.wiw-sources-more svg { width: 13px; height: 13px; }

/* full answer (collapsible) */
.wiw-full { margin-top: 12px; border-top: 1px solid var(--wiw-border); padding-top: 10px; }
.wiw-full-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: inherit; font-size: 12.5px; font-weight: 700;
  color: var(--wiw-cyan); background: none; border: 0; cursor: pointer; padding: 4px 0;
}
.wiw-full-toggle svg { width: 14px; height: 14px; transition: transform .2s ease; }
.wiw-full.is-open .wiw-full-toggle svg { transform: rotate(180deg); }
.wiw-full-body {
  display: none;
  margin-top: 10px;
  font-size: 13.5px; line-height: 1.95; color: var(--wiw-fg);
  background: rgba(0,0,0,0.18);
  border: 1px solid var(--wiw-border);
  border-radius: 10px;
  padding: 12px 14px;
  max-height: 340px; overflow-y: auto;
}
.wiw-full.is-open .wiw-full-body { display: block; }
.wiw-full-body h1, .wiw-full-body h2, .wiw-full-body h3 { font-size: 14.5px; margin: 10px 0 6px; color: var(--wiw-gold); }
.wiw-full-body a { color: var(--wiw-cyan); }
.wiw-full-body p { margin: 6px 0; }
.wiw-full-body ul { padding-inline-start: 20px; margin: 6px 0; }

/* ------------------------------ mobile ---------------------------------- */
@media (max-width: 860px) {
  .wiw-stage { grid-template-columns: 1fr; gap: 14px; }
  .wiw-personas {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: 4px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }
  .wiw-persona {
    flex: 0 0 auto;
    width: auto;
    scroll-snap-align: start;
    padding: 10px 12px;
  }
  .wiw-persona-hint { display: none; }
  .wiw-persona-body { flex-direction: row; align-items: center; gap: 8px; }
  .wiw-demo { min-height: 400px; }
}

@media (max-width: 640px) {
  /* never ellipsize the law name on narrow screens — wrap instead */
  .wiw-cite-law { white-space: normal; overflow: visible; text-overflow: clip; }
}

@media (max-width: 460px) {
  .wiw-persona-ic { width: 34px; height: 34px; }
  .wiw-persona-label { font-size: 13.5px; }
}

/* -------------------------- reduced motion ------------------------------ */
@media (prefers-reduced-motion: reduce) {
  .wiw *,
  .wiw *::before,
  .wiw *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .wiw-cite { opacity: 1 !important; transform: none !important; }
  .wiw-caret { display: none !important; }
  .wiw-progress { display: none; }
}
