/* =========================================================
   T-146 المرحلة 2 · ب · صفحة التاجر بنظام الشبكة
   فوق grid/grid.css (الرموز والشبكة والخانات والترويسة). المحادثة نفسها كما هي:
   شاشة واحدة لكل سؤال، والشكل وحده تغيّر — خانات بحدود 1px، زوايا قائمة، وجسم من نقاط يتشكّل لكل شاشة
   السماوي: لا لون نص ولا حد هنا؛ الإشارة الوحيدة نقطة النبض في AP على شاشة الشكر (من المحرك)
   ========================================================= */
:root { --dir: -1; --err: #FF7659; --tj-pad: clamp(18px, 2.6vw, 40px) }
html[dir="ltr"] { --dir: 1 }
html, body { block-size: 100%; overflow: hidden }
html { scroll-behavior: auto }
body { line-height: 1.75; color: var(--t1) }
html[lang="en"] body { font-family: var(--lat); line-height: 1.55 }
input, textarea { font: inherit; color: inherit }
button { touch-action: manipulation }
.lat { direction: ltr; unicode-bidi: isolate }
.sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap }

/* ---------- الإطار: ترويسة، ثم المحادثة وخانة الجسم ---------- */
.app {
  position: relative; z-index: 1;
  inline-size: min(100% - var(--gut) * 2, 1360px); margin-inline: auto;
  block-size: 100vh; block-size: 100dvh;
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr);
  padding-block-end: max(var(--gut), env(safe-area-inset-bottom));
}
.app > .bar { grid-column: 1 / -1; grid-row: 1 }
/* الصفوف مثبّتة: إن غابت خانة الجسم بقيت المحادثة في صف 1fr ولم تنهر إلى صف تلقائي بارتفاع صفر */
.tj-obj { grid-row: 2 }
.stage { grid-row: 3 }

/* الترويسة: خانات كما في الرئيسية — رجوع · الرمز · اللغة */
.app > .bar { position: relative; display: flex; align-items: stretch; block-size: var(--bar); padding-block-start: env(safe-area-inset-top); box-sizing: content-box; background: var(--ink) }
.bar .cell { justify-content: center }
.back, .lang { inline-size: var(--bar); flex: none; padding: 0 !important }
.back svg { inline-size: 18px; block-size: 18px; transform: scaleX(var(--dir)); transition: opacity .3s var(--ease) }
.back[aria-hidden="true"] { pointer-events: none }
.back[aria-hidden="true"] svg { opacity: 0 }
.brand { gap: 12px; margin-inline-end: auto; color: var(--t1) !important; font-family: var(--lat); font-weight: 600; font-size: 14px; letter-spacing: .02em }
.brand span { direction: ltr; unicode-bidi: isolate }
.brand svg { inline-size: 32px; block-size: 21px; display: block; color: var(--w) }
.lang { font-family: var(--lat); font-weight: 700; font-size: 12px; letter-spacing: .12em; color: var(--t1) !important }
html[lang="en"] .lang { font-family: 'Readex Pro', Tahoma, sans-serif; font-size: 16px; letter-spacing: 0 }
@media (hover: hover) and (pointer: fine) { .back:hover, .lang:hover, .brand:hover { background: rgba(255, 255, 255, .05) } }
.back:active, .lang:active { background: var(--w); color: var(--ink) !important }
/* التقدّم: خط 1px على حافة الترويسة يمتلئ بالأبيض */
.progress { position: absolute; inset-inline: 0; inset-block-end: -1px; block-size: 2px; background: transparent; overflow: hidden; z-index: 2; pointer-events: none }
.progress i { position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: 100%; background: var(--w); transform: scaleX(var(--p, 0)); transform-origin: calc(50% - 50% * var(--dir)) 50%; transition: transform .7s var(--ease) }

/* خانة الجسم: مرساة المحرك (data-shape) */
.tj-obj { position: relative; block-size: clamp(140px, 22svh, 260px); --l: var(--line-s); box-shadow: 1px 0 0 0 var(--l), 0 1px 0 0 var(--l), 1px 1px 0 0 var(--l), 1px 0 0 0 var(--l) inset, 0 1px 0 0 var(--l) inset }
.tj-obj .code--t { top: 10px; right: 12px } /* rtl-ok: زخرفة لاتينية بموضع ثابت */
.tj-obj .code--b { bottom: 10px; left: 12px } /* rtl-ok */

/* خانة المحادثة */
.stage { position: relative; overflow: hidden; --l: var(--line-s); box-shadow: 1px 0 0 0 var(--l), 0 1px 0 0 var(--l), 1px 1px 0 0 var(--l), 1px 0 0 0 var(--l) inset, 0 1px 0 0 var(--l) inset }

/* ---------- الشاشات: سؤال واحد لكل شاشة، تصعد وتظهر ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; gap: 18px; padding: var(--tj-pad) var(--tj-pad) max(var(--tj-pad), env(safe-area-inset-bottom));
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  opacity: 0; visibility: hidden; transform: translateY(32px);
  transition: opacity .42s var(--ease), transform .62s var(--ease), visibility 0s linear .62s }
.screen::-webkit-scrollbar { display: none }
.screen.is-active { opacity: 1; visibility: visible; transform: none; transition-delay: 0s }
.screen.is-leaving { opacity: 0; visibility: visible; transform: translateY(var(--leave, -24px)); transition: opacity .28s var(--ease), transform .45s var(--ease) }
.screen__body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; min-block-size: min-content }
.screen__foot { display: grid; gap: 10px }
.screen__body, .screen__foot, .chat, .fields, .done { position: relative; z-index: 1 }
.screen.is-active [data-rise] { animation: rise .7s var(--ease) both; animation-delay: calc(90ms + var(--i, 0) * 80ms) }
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

/* مؤشر الكتابة قبل أن يتكلم الرمز */
.typing { display: none; align-items: center; gap: 10px }
.dots { display: inline-flex; gap: 5px; border: 1px solid var(--line-2); padding: 14px 16px }
.dots i { inline-size: 6px; block-size: 6px; background: var(--t3); animation: blink 1s infinite ease-in-out }
.dots i:nth-child(2) { animation-delay: .15s } .dots i:nth-child(3) { animation-delay: .3s }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0) } 40% { opacity: 1; transform: translateY(-3px) } }
.screen.is-typing .typing { display: flex }
.screen.is-typing .chat > :not(.typing), .screen.is-typing .screen__foot, .screen.is-typing .fields { display: none }

/* ---------- الطباعة ---------- */
.eyebrow { font-size: 13px; color: var(--t2); display: flex; align-items: center; gap: 10px }
.eyebrow::before { content: ""; inline-size: 9px; block-size: 9px; border: 1px solid var(--line-2); flex: none }
.title { font-family: var(--ard); font-weight: 600; font-size: clamp(32px, 9.6vw, 44px); line-height: 1.4; color: var(--t1); text-wrap: balance }
html[lang="en"] .title { font-family: var(--lat); font-weight: 700; letter-spacing: -.03em; line-height: 1.1 }
.lead { font-size: clamp(17px, 4.6vw, 20px); color: var(--t2); max-inline-size: 26em }
.fine { font-size: 13px; color: var(--t3); text-align: center }
.fine a { color: var(--t2); text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 4px; display: inline-flex; align-items: center; min-block-size: 32px }

/* ---------- المحادثة ---------- */
.chat { display: flex; flex-direction: column; gap: 12px; flex: 1; justify-content: center }
.msg { display: flex; align-items: flex-end; gap: 10px; max-inline-size: 100% }
.av { flex: none; inline-size: 32px; block-size: 32px; background: var(--w); color: var(--ink); display: grid; place-items: center }
.av svg { inline-size: 20px; block-size: 13px }
.bubble { border: 1px solid var(--line-2); background: rgba(255, 255, 255, .03); padding: 14px 16px; display: grid; gap: 6px; max-inline-size: calc(100% - 42px) }
.bubble h2 { font-family: var(--ard); font-weight: 600; font-size: clamp(21px, 5.8vw, 26px); line-height: 1.45; color: var(--t1); outline: none }
html[lang="en"] .bubble h2 { font-family: var(--lat); font-weight: 700; letter-spacing: -.02em; line-height: 1.25 }
.bubble p { color: var(--t2); font-size: 15px }
.bubble h3 { font-family: var(--ard); font-weight: 600; font-size: clamp(19px, 5.2vw, 22px); line-height: 1.45; color: var(--t1); outline: none }
html[lang="en"] .bubble h3 { font-family: var(--lat); font-weight: 700; letter-spacing: -.02em; line-height: 1.25 }
.msg--me { justify-content: flex-end }
.msg--me .bubble { background: var(--w); color: var(--ink); border-color: var(--w); font-weight: 500; font-size: 15px }
.msg--me .bubble:empty { display: none }
.msg[hidden], .choices[hidden] { display: none }
.screen.is-active .msg--late:not([hidden]) { animation: rise .5s var(--ease) both }

/* ---------- الخيارات: خانات بخط واحد بين كل خانتين ---------- */
.choices { display: grid; gap: 0 }
.choice { --l: var(--line-s); box-shadow: 1px 0 0 0 var(--l), 0 1px 0 0 var(--l), 1px 1px 0 0 var(--l), 1px 0 0 0 var(--l) inset, 0 1px 0 0 var(--l) inset;
  display: grid; grid-template-columns: 44px 1fr; gap: 4px 14px; align-items: center; text-align: start; min-block-size: 76px; padding: 14px 16px;
  transition: background-color .3s var(--ease), transform .35s var(--ease) }
.choice:active { transform: scale(.985) }
.choice .ic { grid-row: 1 / 3; inline-size: 44px; block-size: 44px; border: 1px solid var(--line-2); display: grid; place-items: center; color: var(--t1); transition: background-color .3s var(--ease), color .3s var(--ease) }
.choice .ic svg { inline-size: 22px; block-size: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round }
.choice b { font-family: var(--ard); font-weight: 600; font-size: 17px; line-height: 1.4; color: var(--t1) }
html[lang="en"] .choice b { font-family: var(--lat); font-weight: 700 }
.choice small { font-size: 13.5px; color: var(--t2); line-height: 1.55 }
.choice[aria-pressed="true"] { background: rgba(255, 255, 255, .08) }
.choice[aria-pressed="true"] .ic { background: var(--w); color: var(--ink); border-color: var(--w) }
@media (hover: hover) and (pointer: fine) { .choice:hover { background: rgba(255, 255, 255, .05) } }
.choices--2 { grid-template-columns: 1fr 1fr }
.choice--sm { grid-template-columns: 1fr; justify-items: start; gap: 8px; min-block-size: 0; padding: 14px }
.choice--sm .ic { grid-row: auto }

/* «شي ثاني»: خانة يكتب فيها التاجر احتياجه */
.custom { display: grid; gap: 12px; padding: 14px; border: 1px solid var(--line-2) }
.custom[hidden] { display: none }
.screen.is-active .custom:not([hidden]) { animation: rise .5s var(--ease) both }

/* ---------- الشفافية (لا سعر، الخط وحده) ---------- */
.pulse-line { display: block; inline-size: 72px; block-size: 1px; background: var(--line-2); position: relative; overflow: hidden }
.pulse-line::after { content: ""; position: absolute; inset: 0; background: var(--w); transform: scaleX(0); transform-origin: calc(50% - 50% * var(--dir)) 50% }
.screen.is-active .pulse-line::after { transform: scaleX(1); transition: transform 1.1s var(--ease) .5s }

/* ---------- الأزرار ---------- */
.cta, .ghost { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-block-size: 58px; padding-inline: 22px; font-weight: 500; font-size: 17px; inline-size: 100%; transition: transform .3s var(--ease), background-color .3s var(--ease), color .3s var(--ease), opacity .3s var(--ease) }
.cta { background: var(--w); color: var(--ink) }
.cta i, .ghost i { font-style: normal; font-family: var(--lat); display: inline-block; transform: scaleX(var(--dir)) }
.cta:active, .ghost:active { transform: scale(.98) }
.ghost { border: 1px solid var(--line-2); color: var(--t1) }
@media (hover: hover) and (pointer: fine) { .cta:hover { background: rgba(255, 255, 255, .86) } .ghost:hover { background: rgba(255, 255, 255, .05); border-color: var(--w) } }
.cta[disabled] { opacity: .85; pointer-events: none }
.spin { display: none; inline-size: 18px; block-size: 18px; border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%; animation: spin .8s linear infinite }
.cta[aria-busy="true"] .spin { display: inline-block }
.cta[aria-busy="true"] i { display: none }
@keyframes spin { to { transform: rotate(360deg) } }

/* ---------- النموذج ---------- */
/* grid.css تستعمل .field للوحة الجسم؛ حقول النموذج محصورة في .stage فلا تتأثر */
html .stage .field { position: static; inset: auto; inline-size: auto; block-size: auto; z-index: auto; pointer-events: auto; opacity: 1; transition: none; display: grid; gap: 6px }
html .stage .field[hidden] { display: none }
.fields { display: grid; gap: 14px }
.stage .field label { font-size: 14px; color: var(--t2) }
.stage .field input, .stage .field textarea { inline-size: 100%; min-block-size: 56px; padding: 14px 16px; border: 1px solid var(--line-2); border-radius: 0; background: rgba(255, 255, 255, .03); font-size: 17px; color: var(--t1); outline: none; transition: border-color .3s var(--ease), background-color .3s var(--ease) }
.stage .field textarea { min-block-size: 92px; resize: none; line-height: 1.6 }
.stage .field input::placeholder, .stage .field textarea::placeholder { color: var(--t4) }
.stage .field input:focus, .stage .field textarea:focus { border-color: var(--w); background: rgba(255, 255, 255, .06) }
.stage .field input[type="tel"] { font-family: var(--lat); letter-spacing: .04em; text-align: start }
html[dir="rtl"] .stage .field input[type="tel"] { text-align: right }
.err { display: none; font-size: 13px; color: var(--err) }
.stage .field.is-invalid input, .stage .field.is-invalid textarea { border-color: var(--err) }
.stage .field.is-invalid .err, .consent.is-invalid .err { display: block }
.consent { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; font-size: 14px; color: var(--t2); line-height: 1.6 }
.consent input { inline-size: 22px; block-size: 22px; margin-block-start: 1px; accent-color: var(--w) }
.consent a { color: var(--t1); white-space: nowrap; text-decoration: underline; text-decoration-color: var(--line-2); text-underline-offset: 4px }
.consent .err { grid-column: 2 }
.alert { display: none; font-size: 14px; color: var(--err); border: 1px solid rgba(255, 118, 89, .45); padding: 10px 14px }
.alert.is-on { display: block }
.alert.is-unsure { color: var(--t1); border-color: var(--line-2) }   /* T-092: قد يكون الطلب وصل، فلا أحمر */
.hp { position: absolute; inset-inline-start: -9999px; inline-size: 1px; block-size: 1px; overflow: hidden }
.screen[data-screen="form"] .chat { flex: 0 0 auto; margin-block-start: auto }
.screen[data-screen="form"] .fields { margin-block-end: auto }

/* ---------- الشكر ---------- */
.done { flex: 1; display: grid; place-content: center; justify-items: center; text-align: center; gap: 16px }
.ring { inline-size: 84px; block-size: 84px; border: 1px solid var(--line-2); display: grid; place-items: center; position: relative; margin-block-end: 6px; color: var(--w) }
.ring::before, .ring::after { content: ""; position: absolute; inset: 0; border: 1px solid rgba(255, 255, 255, .5); animation: ring 2.2s var(--ease) infinite }
.ring::after { animation-delay: 1.1s }
@keyframes ring { from { transform: scale(.7); opacity: .8 } to { transform: scale(1.6); opacity: 0 } }
.ring svg { inline-size: 38px; block-size: 25px }
.done h2 { font-family: var(--ard); font-weight: 600; font-size: clamp(28px, 7.6vw, 36px); line-height: 1.4; color: var(--t1); outline: none; text-wrap: balance }
html[lang="en"] .done h2 { font-family: var(--lat); font-weight: 700; letter-spacing: -.03em; line-height: 1.15 }
.done p { color: var(--t2); max-inline-size: 24em }
.link { display: inline-flex; align-items: center; min-block-size: 48px; padding: 0 20px; border: 1px solid var(--line-2); font-weight: 600; font-size: 15px; color: var(--t1) }
@media (hover: hover) and (pointer: fine) { .link:hover { background: rgba(255, 255, 255, .05); border-color: var(--w) } }

/* ---------- مثال الرد (الطابع المنشور noir وحده) ---------- */
.deco { display: none }
.pulse-path { display: none }
.deco--chat { display: flex; flex-direction: column; gap: 8px; margin-block-start: 6px; padding: 12px; border: 1px solid var(--line); max-inline-size: 360px }
.mini { font-size: 14px; line-height: 1.55; padding: 9px 12px; max-inline-size: 88% }
.mini--in { align-self: flex-start; border: 1px solid var(--line-2); color: var(--t1) }
.mini--out { align-self: flex-end; background: var(--w); color: var(--ink); display: grid; gap: 2px }
.mini__tag { font-size: 11px; font-weight: 500; letter-spacing: .04em; display: flex; align-items: center; gap: 6px; color: rgba(11, 11, 11, .72) }
.mini__tag::before { content: ""; inline-size: 6px; block-size: 6px; background: var(--ink) }
.screen.is-active .mini--in { animation: rise .6s var(--ease) .55s both }
.screen.is-active .mini--out { animation: rise .6s var(--ease) 1.35s both }
@media (max-height: 700px) { .deco--chat { display: none !important } }

/* ---------- جوال وتابلت: الجسم شريط فوق المحادثة، ويغيب حيث يزاحم ---------- */
/* على شاشة الرقم يُخفى الشريط (لوحة المفاتيح تقلّص الشاشة)، وتُخفى لوحة الجسم معه حتى لا يبقى آخر إطار معلّقاً */
@media (max-width: 768px) {
  html[data-tj-screen="form"] .tj-obj, html[data-tj-screen="contact"] .tj-obj { display: none }
  html[data-tj-screen="form"] canvas.field, html[data-tj-screen="contact"] canvas.field { opacity: 0 !important }
}
@media (max-width: 1023px) and (max-height: 640px) {
  .tj-obj { display: none }
  canvas.field { opacity: 0 !important }
}
@media (max-width: 768px) {
  .tj-obj .code--t { display: none }
  .brand span { font-size: 13px }
}
@media (max-width: 379px) { .brand span { display: none } }
@media (max-height: 620px) { .title { font-size: 30px } .choice { min-block-size: 64px; padding: 10px 14px } .choice small { display: none } .screen { gap: 12px } }

/* ---------- التابلت ---------- */
@media (min-width: 768px) {
  .screen { justify-content: safe center }
  .screen::after { content: ""; display: block; flex: none; block-size: 10px }
  .screen__body, .chat { flex: 0 1 auto }
  .screen__foot { margin-block-start: 10px; inline-size: 100%; max-inline-size: 440px; margin-inline-end: auto }
  .screen__foot .fine { text-align: start }
  .screen[data-screen="form"] .chat { margin-block-start: 0 }
  .screen[data-screen="form"] .fields { margin-block-end: 0 }
  .title { font-size: clamp(36px, 4.6vw, 48px) }
  .choices { grid-template-columns: 1fr 1fr }
  .choices.choices--2 { max-inline-size: 560px }
  .choice { min-block-size: 92px; padding: 16px 18px }
  .custom { max-inline-size: 470px }
  .fields { grid-template-columns: 1fr 1fr; column-gap: 18px; max-inline-size: 760px }
  .fields > #qField, .fields > .consent, .fields > .alert { grid-column: 1 / -1 }
  .bubble { max-inline-size: min(56ch, calc(100% - 42px)) }
  .done p { max-inline-size: 30em }
}

/* ---------- المكتب: المحادثة وخانة الجسم جنباً إلى جنب ---------- */
@media (min-width: 1024px) {
  .app { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) }
  .stage { grid-column: 1; grid-row: 2 }
  .tj-obj { grid-column: 2; grid-row: 2; block-size: auto }
  .bubble p { font-size: 16px }
  .lead { font-size: 20px }
  .title { font-size: clamp(40px, 3.4vw, 54px) }
}

/* ---------- الحركة المخفّضة ---------- */
@media (prefers-reduced-motion: reduce) {
  .screen, .screen.is-leaving, .progress i { transition: none }
  .screen.is-active [data-rise], .dots i, .ring::before, .ring::after, .spin, .screen.is-active .mini--in, .screen.is-active .mini--out { animation: none !important }
  .screen.is-active .pulse-line::after { transform: scaleX(1); transition: none }
  .choice:active, .cta:active, .ghost:active { transform: none }
}
