/* Support sheet (static/js/support.js opens it in a modal <dialog>) and the /support/ page.
   Phones: an Apple-style bottom sheet with a grabber (drag down to close), safe-area aware for the Android app.
   Desktop: a floating panel anchored above the launcher. Motion: transform/opacity only; data-motion="0" = fades. */

.sp-sheet { position: fixed; inset: auto 0 0; margin: 0 auto; padding: 0; border: 0; inline-size: 100%; max-inline-size: 100%;
  block-size: auto; max-block-size: calc(100dvh - var(--safe-t) - 24px); overflow: hidden; color: var(--ink);
  background: var(--glass-shine), var(--glass-bg-2); -webkit-backdrop-filter: var(--glass-blur); backdrop-filter: var(--glass-blur);  /* thick Liquid Glass (app.css tokens) */
  border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--glass-rim), var(--e3); direction: rtl; text-align: start; overscroll-behavior: contain; }
.sp-sheet[open] { display: flex; flex-direction: column; }
.sp-sheet::backdrop { background: var(--scrim); }
.sp-sheet > .sp-inner { display: flex; flex-direction: column; min-block-size: 0; flex: 1; padding-block-end: var(--safe-b);
  padding-inline: var(--safe-r) var(--safe-l); }
html[data-motion]:not([data-motion="0"]) .sp-sheet[open] { animation: sp-rise var(--dur-3) var(--spring); }
html[data-motion]:not([data-motion="0"]) .sp-sheet[open]::backdrop { animation: sp-fade var(--dur-3) var(--ease-std); }
html[data-motion="0"] .sp-sheet[open], html:not([data-motion]) .sp-sheet[open] { animation: sp-fade var(--dur-2) linear; }
.sp-sheet.is-closing { animation: sp-sink var(--dur-2) var(--ease-std) forwards !important; }
.sp-sheet.is-closing::backdrop { animation: sp-fade var(--dur-2) var(--ease-std) reverse forwards !important; }
html[data-motion="0"] .sp-sheet.is-closing { animation: sp-fade var(--dur-1) linear reverse forwards !important; }
.sp-sheet.is-dragging { animation: none !important; transition: none; }
.sp-sheet.is-settling { transition: transform var(--dur-2) var(--spring); }
@keyframes sp-rise { from { transform: translateY(100%); } }
@keyframes sp-sink { to { transform: translateY(100%); } }
@keyframes sp-fade { from { opacity: 0; } }
body:has(.sp-sheet[open]) { overflow: hidden; }
/* phones: a conversation takes the full sheet height from its first message, so it never jumps while replies arrive */
@media (max-width: 699px) { .sp-sheet:has(.sp-thread, .sp-list) { block-size: calc(100dvh - var(--safe-t) - 24px); } }

@media (min-width: 700px) {
  .sp-sheet { inset: auto; inset-block-end: 88px; inset-inline-start: 24px; margin: 0; inline-size: 400px;
    block-size: min(640px, calc(100dvh - 120px)); max-block-size: none; border-radius: var(--r-xl); box-shadow: var(--e2), 0 30px 80px -30px rgb(0 0 0 / 0.35); }
  .sp-sheet::backdrop { background: rgb(0 0 0 / 0.12); }
  .sp-sheet > .sp-inner { padding: 0; }
  html[data-motion]:not([data-motion="0"]) .sp-sheet[open] { animation: sp-pop var(--dur-3) var(--spring); transform-origin: bottom right; }
  .sp-sheet.is-closing { animation: sp-pop var(--dur-2) var(--ease-std) reverse forwards !important; }
  .sp-grabber { visibility: hidden; block-size: 0 !important; margin: 0 !important; }
}
@keyframes sp-pop { from { opacity: 0; transform: translateY(12px) scale(0.96); } }

/* head: grabber, title row (new · title · close) */
.sp-head { flex: none; display: grid; gap: 2px; padding: 6px 12px 10px; touch-action: none; user-select: none;
  border-block-end: 0.5px solid var(--sep); background: transparent; }
.sp-grabber { justify-self: center; inline-size: 36px; block-size: 5px; border-radius: 3px; margin-block: 2px 4px;
  background: color-mix(in srgb, var(--ink) 22%, transparent); }
.sp-head-row { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.sp-head h2 { margin: 0; text-align: center; font-family: var(--f-display); font-size: var(--fs-md); font-weight: 700; line-height: 1.4; outline: none; }
.sp-sub { margin: 0; text-align: center; font-size: var(--fs-xs); color: var(--ink-2); }
.sp-icon { display: grid; place-items: center; inline-size: 44px; block-size: 44px; border: 0; border-radius: 50%; padding: 0; color: var(--indigo);
  background: transparent; cursor: pointer; text-decoration: none; -webkit-tap-highlight-color: transparent; }
.sp-icon .ic { inline-size: 22px; block-size: 22px; }
.sp-icon[data-sp-close] { color: var(--ink-2); }
.sp-icon[data-sp-close] .ic { inline-size: 16px; block-size: 16px; }
.sp-icon[data-sp-close]::before { content: ""; position: absolute; inline-size: 30px; block-size: 30px; border-radius: 50%; background: var(--paper-2); z-index: -1; }
.sp-icon { position: relative; isolation: isolate; }
.sp-icon:active { transform: scale(0.92); }
@media (hover: hover) and (pointer: fine) { .sp-icon:hover { background: var(--tint); } }

/* body: scrolls; messages and the new-ticket form */
.sp-body { position: relative; flex: 1 1 auto; min-block-size: 0; overflow-y: auto; scrollbar-width: thin; overscroll-behavior: contain; padding: 14px 16px 16px; display: grid; gap: 14px; align-content: start;
  grid-auto-rows: max-content; }  /* never squeeze a row to fit the sheet: the body scrolls instead */
.sp-thread { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.sp-msg { display: grid; gap: 3px; justify-items: start; max-inline-size: 88%; }
.sp-msg.is-user { justify-self: end; justify-items: end; }
.sp-bubble { margin: 0; padding: 9px 13px; border-radius: 18px; font-size: var(--fs-base); line-height: 1.7; overflow-wrap: anywhere;
  background: var(--card); box-shadow: var(--e1); white-space: normal; }
.is-user .sp-bubble { color: var(--on-indigo); background: var(--indigo); box-shadow: none; border-end-end-radius: 6px; }
.is-ai .sp-bubble, .is-staff .sp-bubble { border-end-start-radius: 6px; }
.is-staff .sp-bubble { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--teal) 55%, transparent), var(--e1); }
.sp-who { display: inline-flex; gap: 4px; align-items: center; font-size: var(--fs-2xs); font-weight: 650; color: var(--ink-2); flex-wrap: wrap; }
.sp-who small { font-weight: 500; }
.sp-who .ic { inline-size: 14px; block-size: 14px; color: var(--indigo); }
.is-staff .sp-who .ic { color: var(--teal); }
.sp-msg time, .sp-state { font-size: var(--fs-2xs); color: var(--ink-2); }
.sp-state:empty { display: none; }

/* message motion (support.js adds .sp-in only to messages not on screen yet): a bubble grows out of its own corner,
   the visitor's from the send side, replies from the other; transform/opacity only. data-motion="0": no movement. */
.sp-msg { transform-origin: 100% 100%; }
.sp-msg.is-user { transform-origin: 0% 100%; }
.sp-msg:dir(ltr) { transform-origin: 0% 100%; }
.sp-msg.is-user:dir(ltr) { transform-origin: 100% 100%; }
html[data-motion]:not([data-motion="0"]) .sp-in { animation: sp-msg-in var(--dur-3) var(--spring) both; }
html[data-motion]:not([data-motion="0"]) .sp-note.sp-in, html[data-motion]:not([data-motion="0"]) .sp-err.sp-in { animation-name: sp-view; }
@keyframes sp-msg-in { from { opacity: 0; transform: translateY(12px) scale(0.92); } }
@keyframes sp-view { from { opacity: 0; transform: translateY(6px); } }
html[data-motion]:not([data-motion="0"]) .sp-body.sp-view-in > * { animation: sp-view var(--dur-3) var(--ease-out) both; }
html[data-motion]:not([data-motion="0"]) .sp-body.sp-view-in > :nth-child(2) { animation-delay: 40ms; }
html[data-motion]:not([data-motion="0"]) .sp-body.sp-view-in > :nth-child(n+3) { animation-delay: 80ms; }

/* sending: dimmed until the server has it, then it settles in place; a failed one says so and offers a resend */
.sp-msg.is-pending .sp-bubble { opacity: 0.72; }
html[data-motion]:not([data-motion="0"]) .sp-msg.sp-landed .sp-bubble { animation: sp-land var(--dur-2) var(--ease-std); }
@keyframes sp-land { from { opacity: 0.72; } }
.sp-msg.is-failed .sp-bubble { color: var(--ink); background: color-mix(in srgb, var(--bad) 12%, var(--card));
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--bad) 50%, transparent); }
.sp-msg.is-failed .sp-state { display: inline-flex; gap: 6px; align-items: center; color: var(--bad); font-weight: 600; }
.sp-msg.is-failed .sp-state button { min-block-size: 32px; padding: 0 6px; border: 0; border-radius: 8px; font: inherit; font-weight: 700;
  color: var(--indigo); background: transparent; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
@media (hover: hover) and (pointer: fine) { .sp-msg.is-failed .sp-state button:hover { background: var(--tint); } }

/* typing dots: a soft wave, not a blink */
.sp-typing .sp-bubble { display: inline-flex; gap: 5px; align-items: center; min-block-size: 40px; padding-inline: 16px; }
.sp-typing i { inline-size: 7px; block-size: 7px; border-radius: 50%; background: var(--ink-2); opacity: 0.45; }
html[data-motion]:not([data-motion="0"]) .sp-typing i { animation: sp-wave 1.3s infinite var(--ease-std); }
.sp-typing i:nth-child(2) { animation-delay: 0.16s; }
.sp-typing i:nth-child(3) { animation-delay: 0.32s; }
@keyframes sp-wave { 0%, 60%, 100% { transform: translateY(0); opacity: 0.45; } 30% { transform: translateY(-4px); opacity: 1; } }

/* first load: three soft placeholder bubbles instead of a bare "loading" line */
.sp-skel { display: grid; gap: 10px; padding-block-start: 4px; }
.sp-skel i { display: block; block-size: 40px; border-radius: 18px; background: var(--paper-2); inline-size: 62%; }
.sp-skel i:nth-of-type(2) { inline-size: 44%; justify-self: end; }
.sp-skel i:nth-of-type(3) { inline-size: 70%; }
html[data-motion]:not([data-motion="0"]) .sp-skel i { animation: sp-pulse 1.4s infinite var(--ease-std); }
html[data-motion]:not([data-motion="0"]) .sp-skel i:nth-of-type(2) { animation-delay: 0.15s; }
html[data-motion]:not([data-motion="0"]) .sp-skel i:nth-of-type(3) { animation-delay: 0.3s; }
@keyframes sp-pulse { 50% { opacity: 0.55; } }

/* an empty send: a small shake, the field keeps focus */
html[data-motion]:not([data-motion="0"]) .sp-shake { animation: sp-shake 0.32s var(--ease-std); }
@keyframes sp-shake { 25% { transform: translateX(5px); } 50% { transform: translateX(-4px); } 75% { transform: translateX(2px); } }

.sp-note, .sp-err { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 10px 12px; border-radius: var(--r-md); font-size: var(--fs-sm); line-height: 1.65; }
.sp-note { background: color-mix(in srgb, var(--ok) 12%, var(--card)); }
.sp-note.subtle { background: var(--paper-2); color: var(--ink-2); }
.sp-err { background: color-mix(in srgb, var(--bad) 12%, var(--card)); color: var(--ink); }
.sp-note .ic, .sp-err .ic { flex: none; inline-size: 18px; block-size: 18px; margin-block-start: 2px; }
.sp-note .ic { color: var(--ok); }
.sp-note.subtle .ic { color: var(--ink-2); }
.sp-err .ic { color: var(--bad); }

/* new ticket form: kind tiles (iOS inset-grouped radio rows), fields */
.sp-new { display: grid; gap: 14px; }
.sp-kinds { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; padding: 0; border: 0; min-inline-size: 0; }
.sp-kinds legend { padding: 0; margin-block-end: 8px; font-size: var(--fs-sm); font-weight: 650; }
.sp-kind { position: relative; display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; min-block-size: 64px; padding: 10px;
  border-radius: var(--r-md); background: var(--card); box-shadow: var(--e1); cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: box-shadow var(--dur-2) var(--ease-std), transform var(--dur-1) var(--ease-std); }
.sp-kind:active { transform: scale(0.98); }
.sp-kind input { position: absolute; opacity: 0; inline-size: 1px; block-size: 1px; }
.sp-kind-i { display: grid; place-items: center; inline-size: 30px; block-size: 30px; border-radius: 9px; color: var(--indigo); background: var(--tint); }
.sp-kind-i .ic { inline-size: 18px; block-size: 18px; }
.sp-kind-t { display: grid; gap: 1px; line-height: 1.45; }
.sp-kind-t b { font-size: var(--fs-sm); }
.sp-kind-t small { font-size: var(--fs-2xs); color: var(--ink-2); }
.sp-kind:has(input:checked) { box-shadow: inset 0 0 0 2px var(--indigo), var(--e1); }
.sp-kind:has(input:checked) .sp-kind-i { color: var(--on-indigo); background: var(--indigo); }
.sp-kind:has(input:focus-visible) { outline: 3px solid var(--indigo); outline-offset: 2px; }

.sp-field { display: grid; gap: 6px; }
.sp-field label { font-size: var(--fs-sm); font-weight: 650; }
.sp-field label small { font-weight: 500; color: var(--ink-2); }
.sp-field textarea, .sp-field input, .sp-compose textarea { inline-size: 100%; border: 0; border-radius: var(--r-md); padding: 10px 12px;
  font: inherit; font-size: var(--fs-base); line-height: 1.7; color: var(--ink); background: var(--card); box-shadow: inset 0 0 0 1px var(--hair); resize: none; }
.sp-field input[dir="ltr"] { text-align: left; }
.sp-field textarea:focus-visible, .sp-field input:focus-visible, .sp-compose textarea:focus-visible { outline: 2px solid var(--indigo); outline-offset: 0; }
.sp-help, .sp-count { font-size: var(--fs-xs); color: var(--ink-2); }
.sp-count:empty { display: none; }
.sp-count.is-near { color: var(--bad); }
/* a guest's name and number, first in the form (two columns where there is room) */
.sp-who-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; padding: 12px; border: 0; min-inline-size: 0;
  border-radius: var(--r-md); background: var(--tint); }
.sp-who-form legend { float: inline-start; grid-column: 1 / -1; inline-size: 100%; padding: 0; margin-block-end: 2px; font-size: var(--fs-sm); font-weight: 650; }
.sp-who-form .sp-help { grid-column: 1 / -1; }
@media (max-width: 359px) { .sp-who-form { grid-template-columns: 1fr; } }
.sp-hp { position: absolute !important; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
.sp-wide { inline-size: 100%; justify-content: center; min-block-size: 50px; }
.sp-wide .ic { inline-size: 18px; block-size: 18px; }
.sp-fine { margin: 0; font-size: var(--fs-xs); line-height: 1.7; color: var(--ink-2); }
.sp-fine a { color: var(--indigo); }

.sp-dot { flex: none; inline-size: 10px; block-size: 10px; border-radius: 50%; background: var(--bad); }

/* «گفت‌وگوهای تو»: its own screen (one row per conversation: kind, subject, time, who said the last thing, status),
   reached from the back arrow in a thread or the inbox icon on the start screen. Unread rows are bold with a dot. */
.sp-list { list-style: none; margin: 0; padding: 0; display: grid; border-radius: var(--r-lg); background: var(--card); box-shadow: var(--e1); overflow: hidden; }
.sp-list li + li .sp-row { box-shadow: inset 0 0.5px 0 var(--sep); }
.sp-row { display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center; padding: 12px 14px; min-block-size: 64px;
  color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; transition: background-color var(--dur-2) var(--ease-std); }
.sp-row:active { background: var(--paper-2); }
@media (hover: hover) and (pointer: fine) { .sp-row:hover { background: var(--tint); } }
.sp-row:focus-visible { outline: 3px solid var(--indigo); outline-offset: -3px; }
.sp-row-i { display: grid; place-items: center; inline-size: 40px; block-size: 40px; border-radius: 12px; color: var(--indigo); background: var(--tint); }
.sp-row-i .ic { inline-size: 20px; block-size: 20px; }
.sp-row-i.is-suggestion { color: var(--teal); background: color-mix(in srgb, var(--teal) 14%, transparent); }
.sp-row-i.is-bug { color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }
.sp-row-t { display: grid; gap: 2px; min-inline-size: 0; }
.sp-row-top { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; min-inline-size: 0; }
.sp-row-top b { min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: 600; }
.sp-row-top time { flex: none; font-size: var(--fs-2xs); color: var(--ink-2); }
.sp-row-last { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden;
  font-size: var(--fs-xs); line-height: 1.6; color: var(--ink-2); overflow-wrap: anywhere; }
.sp-row-last em { font-style: normal; font-weight: 600; color: var(--ink); }
.sp-row-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: var(--fs-2xs); color: var(--ink-2); }
.sp-pill { padding: 1px 8px; border-radius: 999px; font-weight: 600; background: var(--paper-2); color: var(--ink-2); }
.sp-pill.is-ok { color: color-mix(in srgb, var(--ok) 80%, var(--ink)); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.sp-pill.is-wait { color: color-mix(in srgb, var(--saffron) 70%, var(--ink)); background: color-mix(in srgb, var(--saffron) 16%, transparent); }
.sp-row.is-unread .sp-row-top b, .sp-row.is-unread .sp-row-last { color: var(--ink); font-weight: 700; }
.sp-row.is-closed .sp-row-i { filter: grayscale(1); opacity: 0.6; }

/* start screen: the latest open conversation as one card above the new-message form */
.sp-continue { border-radius: var(--r-lg); background: var(--card); box-shadow: var(--e1); }
.sp-continue.is-unread { box-shadow: inset 0 0 0 2px var(--indigo), var(--e1); }
.sp-eyebrow { font-size: var(--fs-2xs); font-weight: 700; color: var(--indigo); }
.sp-chev { display: grid; color: var(--ink-2); }
.sp-chev .ic { inline-size: 18px; block-size: 18px; }

/* the unread count on the back arrow / inbox icon */
.sp-badge { position: absolute; inset-block-start: 4px; inset-inline-end: 2px; min-inline-size: 18px; block-size: 18px; padding: 0 5px;
  border-radius: 9px; font-style: normal; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
  color: #fff; background: var(--bad); box-shadow: 0 0 0 2px var(--paper); }

.sp-empty { display: grid; justify-items: center; gap: 6px; padding: 40px 16px; text-align: center; }
.sp-empty-i { display: grid; place-items: center; inline-size: 56px; block-size: 56px; border-radius: 18px; color: var(--indigo); background: var(--tint); margin-block-end: 6px; }
.sp-empty-i .ic { inline-size: 28px; block-size: 28px; }
.sp-empty p { margin: 0; max-inline-size: 30ch; font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.7; }

/* list footer: the «پیام تازه» button stays in reach under the scrolling list */
.sp-foot { flex: none; padding: 10px 16px 12px; border-block-start: 0.5px solid var(--sep); background: color-mix(in srgb, var(--paper) 92%, transparent); }

/* screen changes slide like a navigation stack: forward comes in from the reading end, back from the start */
html[data-motion]:not([data-motion="0"]) .sp-push { animation: sp-push var(--dur-3) var(--ease-out) both; }
html[data-motion]:not([data-motion="0"]) .sp-pop { animation: sp-pop-back var(--dur-3) var(--ease-out) both; }
@keyframes sp-push { from { opacity: 0; transform: translateX(calc(var(--sp-x) * -36px)); } }
@keyframes sp-pop-back { from { opacity: 0; transform: translateX(calc(var(--sp-x) * 36px)); } }
.sp-inner { --sp-x: 1; }
.sp-inner:dir(ltr) { --sp-x: -1; }

/* composer (thread): pinned under the scrolling messages */
.sp-compose { flex: none; display: flex; gap: 8px; align-items: flex-end; padding: 8px 12px 10px; border-block-start: 0.5px solid var(--sep);
  background: color-mix(in srgb, var(--paper) 92%, transparent); }
.sp-compose textarea { flex: 1; min-block-size: 44px; max-block-size: 140px; border-radius: 22px; padding-block: 9px; }
.sp-send { flex: none; display: grid; place-items: center; inline-size: 44px; block-size: 44px; border: 0; border-radius: 50%; padding: 0;
  color: var(--on-indigo); background: var(--indigo); cursor: pointer; transition: transform var(--dur-1) var(--ease-std), opacity var(--dur-2); }
.sp-send .ic { inline-size: 20px; block-size: 20px; }
.sp-send:active { transform: scale(0.92); }
/* the send button wakes up once there is something to send, and its plane flies off on send */
.sp-compose:has(textarea:placeholder-shown) .sp-send:not(:disabled) { opacity: 0.45; transform: scale(0.9); }
html[data-motion]:not([data-motion="0"]) .sp-send { transition: transform var(--dur-2) var(--spring), opacity var(--dur-2) var(--ease-std); }
html[data-motion]:not([data-motion="0"]) .sp-send.is-sent .ic { animation: sp-fly 0.5s var(--ease-out); }
@keyframes sp-fly { 45% { transform: translateY(-18px) scale(0.6); opacity: 0; } 46% { transform: translateY(14px) scale(0.6); opacity: 0; } }
.sp-send:disabled, [data-sp-submit]:disabled { opacity: 0.5; cursor: progress; }

/* /support/ page (no JavaScript, or opened directly) */
.sp-page { padding-block: 16px 40px; }
.sp-card { max-inline-size: 520px; margin-inline: auto; border-radius: var(--r-xl); background: var(--paper); box-shadow: var(--e2); overflow: hidden;
  display: flex; flex-direction: column; }
.sp-card .sp-grabber { display: none; }

@media (prefers-reduced-transparency: reduce) { .sp-compose { background: var(--paper); } }
@media (prefers-contrast: more) { .sp-kind, .sp-bubble { box-shadow: inset 0 0 0 1px var(--line); } }
.sp-reload { margin-inline-start: 4px; padding: 4px 6px; min-block-size: 32px; border: 0; border-radius: 8px; font: inherit; font-weight: 700;
  color: var(--indigo); background: transparent; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
