/* ============================================================
   Hero chat demo — index pages, every locale.

   Mobile-Telegram anatomy in the site's paper / ink / gold palette.
   Markup:  templates/partials/chat_demo.html (one macro, per-locale strings).
   Timing:  the PHASES / DURATIONS table in static/js/site.js; a scene is
            shown while  data-show-from <= phase < data-hide-from.

   Colours come from the page stylesheet (--ink, --gold, --ease-spring).
   Layout uses logical properties, so the Arabic page only needs the
   direction switch and the three physical flips at the end of this file.
   No backdrop-filter and no filter: the frame animates on every phase and
   has to stay cheap on low-end phones.
   ============================================================ */
.chat-frame {
  --tg-out: #f7eccb;
  --tg-in: #ffffff;
  --tg-deep: #8a5e00;
  --tg-tail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 17'%3E%3Cpath d='M6 0v9c0 3.5 2.2 6.4 6 8H0c3.3-1.2 6-4.3 6-8z'/%3E%3C/svg%3E");
  position: relative; width: 100%; max-width: 420px; height: 620px; margin: 0 auto;
  border-radius: 16px; overflow: hidden; border: 1px solid var(--ink);
  box-shadow: 0 24px 48px -16px rgba(24,24,26,0.25);
  display: flex; flex-direction: column;
  font-family: 'Inter', system-ui, sans-serif; color: #1d1d1f;
  background:
    url("/static/public/img/chat-wallpaper.svg") 0 0 / 280px 280px,
    radial-gradient(120% 70% at 0% 0%, #f1e8cf 0%, rgba(241,232,207,0) 62%),
    radial-gradient(110% 70% at 100% 100%, #d8c9a2 0%, rgba(216,201,162,0) 64%),
    linear-gradient(180deg, #ebe4d4 0%, #dfd4ba 100%);
}
.tg-glass {
  background: rgba(255,255,255,0.76);
  box-shadow: 0 1px 3px rgba(60,45,10,0.12), inset 0 0 0 1px rgba(255,255,255,0.6);
}

/* ---------- Header: back / centred title / avatar, floating over the chat ---------- */
.tg-header {
  position: absolute; top: 0; left: 0; right: 0; z-index: 3;
  display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; gap: 8px;
  padding: 10px 10px 22px;
}
/* A strip of the same wallpaper that fades out: older messages slide under it. */
.tg-header::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: -1;
  background:
    url("/static/public/img/chat-wallpaper.svg") 0 0 / 280px 280px,
    linear-gradient(90deg, #f0e7ce 0%, #eae2cf 100%);
  -webkit-mask-image: linear-gradient(180deg, #000 0%, #000 64%, transparent 100%);
  mask-image: linear-gradient(180deg, #000 0%, #000 64%, transparent 100%);
}
.tg-header .tg-back { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); }
.tg-header .tg-title {
  justify-self: center; min-width: 0; border-radius: 999px; padding: 5px 22px 6px;
  display: flex; flex-direction: column; align-items: center; line-height: 1.2;
}
.tg-header .tg-title strong { font-size: 14px; font-weight: 600; color: var(--ink); white-space: nowrap; }
.tg-header .tg-title span { font-size: 11px; color: #85806f; }
.tg-header .tg-ava {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; display: block;
  box-shadow: 0 1px 3px rgba(60,45,10,0.2), 0 0 0 1.5px rgba(255,255,255,0.75);
}

.tg-chat-area {
  flex: 1; min-height: 0; padding: 0 12px 6px;
  display: flex; flex-direction: column; gap: 6px; justify-content: flex-end; overflow: hidden;
}

/* ---------- Bubbles ---------- */
.tg-text-out, .tg-voice, .tg-processing, .tg-welcome, .tg-result {
  position: relative; border-radius: 17px; background: var(--tg-bub);
  font-size: 13.5px; line-height: 1.38;
  box-shadow: 0 1px 1px rgba(60,45,10,0.14);
}
.tg-text-out, .tg-voice { --tg-bub: var(--tg-out); align-self: flex-end; margin-inline-end: 2px; }
.tg-processing, .tg-welcome, .tg-result { --tg-bub: var(--tg-in); }
/* Tails need CSS masks; without them the bubble simply stays fully rounded. */
@supports ((-webkit-mask-image: none) or (mask-image: none)) {
  .tg-text-out, .tg-voice { border-end-end-radius: 5px; }
  .tg-processing, .tg-welcome, .tg-result { border-end-start-radius: 5px; }
  .tg-text-out::after, .tg-voice::after, .tg-processing::after, .tg-welcome::after, .tg-result::after {
    content: ""; position: absolute; bottom: 0; width: 12px; height: 17px; background: var(--tg-bub);
    -webkit-mask: var(--tg-tail) center / 100% 100% no-repeat;
    mask: var(--tg-tail) center / 100% 100% no-repeat;
  }
  .tg-text-out::after, .tg-voice::after { inset-inline-end: -6px; }
  .tg-processing::after, .tg-welcome::after, .tg-result::after { inset-inline-start: -6px; transform: scaleX(-1); }
}

/* Clock times, durations, timecodes and "/start" are Latin runs: keep them LTR
   inside Arabic text so "21:31" and "[00:04]" never reorder. */
.chat-frame .stamp, .chat-frame .rstamp, .chat-frame .dur, .chat-frame .ts, .chat-frame .tx {
  unicode-bidi: isolate; direction: ltr;
}
.chat-frame .stamp, .chat-frame .rstamp {
  font-size: 10.5px; line-height: 1; white-space: nowrap; display: inline-flex; align-items: center; gap: 3px;
}
.chat-frame .stamp { color: #a08638; }
.chat-frame .stamp .ck { width: 15px; height: 9px; color: var(--gold); flex: none; }
.chat-frame .rstamp { color: #a3a3a8; align-self: flex-end; }

.tg-text-out { display: inline-flex; align-items: flex-end; gap: 9px; padding-block: 7px; padding-inline: 12px 10px; }
.tg-text-out .tx { color: var(--tg-deep); }
.tg-text-out .stamp { padding-bottom: 2px; }

/* ---------- Voice message ---------- */
.tg-voice { display: flex; flex-direction: column; gap: 5px; padding-block: 7px 6px; padding-inline: 9px 10px; max-width: 84%; }
.tg-voice .fwd { display: flex; flex-direction: column; gap: 2px; font-size: 12.5px; line-height: 1.25; color: var(--tg-deep); padding-inline-start: 2px; }
.tg-voice .fwd b { font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.tg-voice .fwd .fa {
  width: 16px; height: 16px; border-radius: 50%; flex: none; display: grid; place-items: center;
  background: linear-gradient(180deg, #e9b64a, #c0851a); color: #fff; font-size: 9px; font-weight: 700;
}
.tg-voice .vrow { display: flex; align-items: center; gap: 10px; }
.tg-voice .play { width: 40px; height: 40px; border-radius: 50%; background: var(--gold); color: #fff; display: grid; place-items: center; flex: none; }
.tg-voice .play svg { margin-inline-start: 2px; }
.tg-voice .mid { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tg-voice .wave { display: flex; align-items: center; gap: 1.5px; height: 22px; }
.tg-voice .wave i { width: 2px; border-radius: 1px; background: var(--gold); display: block; flex: none; }
.tg-voice .vmeta { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.tg-voice .dur { font-size: 11.5px; line-height: 1; color: #8a7438; display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; }
.tg-voice .dur::after { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--gold); }

/* ---------- Bot status: reply quote + spinner line ---------- */
.tg-processing {
  align-self: flex-start; margin-inline-start: 2px; max-width: 84%;
  display: flex; flex-direction: column; gap: 5px; padding-block: 7px; padding-inline: 8px 11px; color: #3c3c40;
}
.tg-processing .rq {
  border-inline-start: 3px solid var(--gold); background: rgba(201,145,26,0.11); border-radius: 5px;
  padding-block: 3px 4px; padding-inline: 7px 12px; display: flex; flex-direction: column; line-height: 1.3;
}
.tg-processing .rq b { font-size: 12.5px; font-weight: 600; color: var(--tg-deep); }
.tg-processing .rq span { font-size: 12.5px; color: #77746b; }
.tg-processing .pline { display: flex; align-items: center; gap: 6px; font-style: italic; padding-inline-start: 3px; }
.tg-processing .spin { color: #77746b; font-style: normal; display: inline-block; width: 14px; text-align: center; }
.tg-processing .pdots { display: inline-block; min-width: 16px; text-align: start; }
.tg-processing .pfoot { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; padding-inline-start: 3px; }
.tg-processing .pmeta { font-size: 12.5px; font-style: italic; color: #5c5a54; }

/* ---------- Bot message + inline keyboard ---------- */
.tg-msg-bubble { align-self: flex-start; margin-inline-start: 2px; width: 88%; display: flex; flex-direction: column; gap: 3px; }
.tg-welcome { display: flex; flex-direction: column; gap: 6px; padding: 8px 12px 7px; }
.tg-welcome .wtitle { font-weight: 600; }
.tg-welcome p { margin: 0; color: #2c2c30; }
.tg-result { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px 7px; }
.tg-result .rhead { font-weight: 600; padding-inline-start: 2px; }
.tg-codeblock {
  background: rgba(201,145,26,0.09); border-inline-start: 3px solid var(--gold); border-radius: 6px; overflow: hidden;
  font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 10.5px; line-height: 1.55; color: #222;
}
.tg-codeblock .ctoolbar { padding-block: 5px 2px; padding-inline: 9px 8px; display: flex; justify-content: space-between; align-items: center; font-size: 10px; color: var(--tg-deep); }
.tg-codeblock .ctoolbar svg { width: 12px; height: 12px; }
.tg-codeblock .ccontent { padding: 0 9px 6px; }
.tg-codeblock .ccontent p { margin: 0 0 5px; }
.tg-codeblock .ccontent p:last-child { margin-bottom: 0; }
.tg-codeblock .ts { color: #8d8a80; }
.tg-codeblock .s1 { color: var(--gold); font-weight: 600; }
.tg-codeblock .s2 { color: var(--ink); font-weight: 600; }

.tg-buttons { display: flex; flex-direction: column; gap: 3px; }
.tg-buttons .row { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.tg-buttons .row.single { grid-template-columns: 1fr; }
.tg-buttons .kbtn {
  position: relative; overflow: hidden;
  background: rgba(88,68,26,0.74); color: #fff;
  border-radius: 8px; padding: 9px 6px; font-size: 12.5px; font-weight: 500; line-height: 1.25;
  display: flex; align-items: center; justify-content: center; gap: 5px; text-align: center;
  text-shadow: 0 1px 1px rgba(40,30,5,0.28);
}
/* Narrow phones: long labels ("Zusammenfassung") should still fit half a row. */
@media (max-width: 400px) {
  .tg-buttons .kbtn { font-size: 12px; padding-inline: 4px; gap: 4px; }
}
.tg-buttons .row:last-child .kbtn:first-child { border-end-start-radius: 14px; }
.tg-buttons .row:last-child .kbtn:last-child { border-end-end-radius: 14px; }

/* ---------- Tap marker, pressed button, toast ---------- */
.kbtn .tap {
  position: absolute; left: 50%; top: 50%; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%;
  background: rgba(255,255,255,0.5); box-shadow: 0 0 0 1.5px rgba(255,255,255,0.8);
  animation: tg-tap 0.55s ease-out both; pointer-events: none;
}
@keyframes tg-tap { 0% { transform: scale(0.4); opacity: 0; } 30% { opacity: 1; } 100% { transform: scale(1.3); opacity: 0; } }
.kbtn:has(.tap:not(.scene-hidden)) { background: rgba(52,38,8,0.86); }
.tg-toast { position: absolute; left: 0; right: 0; top: 68px; z-index: 4; display: flex; justify-content: center; pointer-events: none; }
.tg-toast span {
  background: rgba(44,34,10,0.86); color: #fff; font-size: 12.5px; font-weight: 500; line-height: 1.2;
  padding: 8px 15px; border-radius: 999px; box-shadow: 0 4px 14px rgba(40,30,5,0.22);
}

/* ---------- Composer ---------- */
.tg-composer { display: flex; align-items: center; gap: 6px; padding: 6px 10px 10px; }
.tg-composer .tg-menu {
  height: 36px; padding-inline: 11px 14px; border-radius: 999px; background: var(--gold); color: #fff;
  font-size: 13.5px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; flex: none;
  box-shadow: 0 1px 3px rgba(60,45,10,0.18);
}
.tg-composer .tg-ico { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #5f5b50; flex: none; }
.tg-composer .tg-input {
  flex: 1; min-width: 0; height: 36px; border-radius: 999px; padding-inline: 14px 9px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #9a968a; font-size: 14px;
}
.tg-composer .tg-input span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-composer .tg-input svg { color: #8f8b7f; flex: none; }

/* ---------- Scene animation ---------- */
.scene { transition: opacity 0.4s var(--ease-spring), transform 0.4s var(--ease-spring); }
.scene-hidden { display: none !important; }
.scene-entering { opacity: 0; transform: translateY(8px); }
.scene-active { opacity: 1; transform: translateY(0); }
/* Label swaps and tap markers inside a button switch at once. */
.kbtn .scene { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .scene { transition: none; }
  .kbtn .tap { animation: none; }
}

/* ---------- Arabic: mirrored chat ----------
   rtl.css pins the page itself to LTR; the chat is one of the blocks that
   opts back in. Everything logical flips with this one declaration. */
html[dir="rtl"] .chat-frame { direction: rtl; }
html[dir="rtl"] .tg-text-out::after, html[dir="rtl"] .tg-voice::after { transform: scaleX(-1); }
html[dir="rtl"] .tg-processing::after, html[dir="rtl"] .tg-welcome::after, html[dir="rtl"] .tg-result::after { transform: none; }
/* "Back" and "play" point the other way in an RTL interface. */
html[dir="rtl"] .tg-header .tg-back svg, html[dir="rtl"] .tg-voice .play svg { transform: scaleX(-1); }
