/* Fursa UI v2 — «راصد» panel. chat-assistant.js builds the messages
   (.chat-msg, .chat-msg-user/-assistant, .chat-msg-body, .chat-typing
   .chat-dots, .chat-msg-status-error); these rules style them. Every rule is
   prefixed with #chat-assistant so it out-ranks app.css's older .chat-* rules.
   Panel placement (under the header from 769px, a sheet on phones) lives in
   shell.css. */

/* -- placement ------------------------------------------------------------
   One set of numbers for the launcher and the panel, so they share a gutter
   and the panel can never cross a screen edge: it is pinned at the launcher's
   gutter on the reading-start side, its width is capped by the viewport
   (100% of a fixed box is the viewport without its scrollbar, unlike 100vw),
   and its height stops below the site header. */
html[data-ui="v2"] #chat-assistant{
  --rased-g:24px;                       /* gutter from the screen edge */
  --rased-b:24px;                       /* launcher's bottom offset */
  --rased-s:48px;                       /* launcher size */
  position:fixed;z-index:var(--z-launcher, 30);
  inset-inline-start:var(--rased-g);inset-inline-end:auto;inset-block-end:var(--rased-b);
}
@media (max-width:768px){
  html[data-ui="v2"] #chat-assistant{
    --rased-g:12px;
    --rased-b:calc(var(--fx-tabbar-h) + env(safe-area-inset-bottom) + 12px);
    --rased-s:44px;
  }
}
html[data-ui="v2"] #chat-assistant .chat-launcher{inline-size:var(--rased-s);block-size:var(--rased-s)}
html[data-ui="v2"] #chat-assistant .chat-panel{
  position:fixed;
  inset-inline-start:var(--rased-g);inset-inline-end:auto;
  inset-block-start:auto;inset-block-end:calc(var(--rased-b) + var(--rased-s) + 12px);
  inline-size:min(400px, calc(100% - 2 * var(--rased-g)));max-inline-size:none;
  block-size:min(600px, calc(100dvh - var(--fx-header-h) - var(--rased-b) - var(--rased-s) - 28px));
}

/* -- panel ---------------------------------------------------------------- */
html[data-ui="v2"] #chat-assistant .chat-panel{
  background:var(--fx-surface);color:var(--fx-text);
  border:1px solid var(--fx-border);border-radius:var(--fx-radius-xl);
  box-shadow:var(--fx-shadow-lg);overflow:hidden;
}
/* Open grows out of the launcher, close collapses back into it: the script
   sets --fx-morph-x/-y (launcher corner minus panel corner) and -sx/-sy (size
   ratios) right before each run; the defaults are a plain scale-fade. */
html[data-ui="v2"] #chat-assistant .chat-panel:not([hidden]){
  animation:fx-rased-open var(--fx-dur-base) var(--fx-ease-out) both;
  transform-origin:top left;
}
html[data-ui="v2"] #chat-assistant .chat-panel.is-measuring{animation:none;visibility:hidden}
@keyframes fx-rased-open{
  from{opacity:0;transform:translate(var(--fx-morph-x, 0px), var(--fx-morph-y, 8px)) scale(var(--fx-morph-sx, .97), var(--fx-morph-sy, .97))}
  45%{opacity:1}
}
/* closing collapses back into the launcher, quicker than the open
   (chat-assistant.js adds .is-closing on v2 and hides on animationend) */
html[data-ui="v2"] #chat-assistant .chat-panel.is-closing:not([hidden]){
  /* ease-in-out, not ease-in: an ease-in this steep only reaches the launcher in
     the very last instant, so the panel faded out while still well above it */
  animation:fx-rased-close var(--fx-dur-fast) var(--fx-ease-in-out) both;pointer-events:none;
}
@keyframes fx-rased-close{
  70%{opacity:1}
  to{opacity:0;transform:translate(var(--fx-morph-x, 0px), var(--fx-morph-y, 8px)) scale(var(--fx-morph-sx, .96), var(--fx-morph-sy, .96))}
}

/* -- header --------------------------------------------------------------- */
html[data-ui="v2"] #chat-assistant .chat-panel-header{
  position:relative;display:flex;align-items:center;gap:var(--fx-space-3);
  min-block-size:64px;padding:var(--fx-space-3) var(--fx-space-4);
  background:var(--fx-surface);color:var(--fx-text);
  border-block-end:1px solid var(--fx-border);border-image:none;
}
html[data-ui="v2"] #chat-assistant .chat-panel-header::before{
  content:"";position:absolute;inset-inline:0;inset-block-start:0;block-size:3px;
  background:var(--fx-gradient-brand);
}
html[data-ui="v2"] #chat-assistant .chat-avatar{
  inline-size:38px;block-size:38px;border-radius:var(--fx-radius-md);
  background:var(--fx-gradient-brand);color:var(--fx-text-inverse);box-shadow:var(--fx-shadow-xs);
}
html[data-ui="v2"] #chat-assistant .chat-title h2{
  margin:0;font-size:var(--fx-text-base);font-weight:var(--fx-weight-bold);color:var(--fx-text);
}
html[data-ui="v2"] #chat-assistant .chat-live{
  display:inline-flex;align-items:center;gap:6px;
  font-size:var(--fx-text-2xs);color:var(--fx-text-muted);
}
html[data-ui="v2"] #chat-assistant .chat-live-dot{inline-size:7px;block-size:7px;background:var(--fx-accent);box-shadow:0 0 0 0 color-mix(in srgb,var(--fx-accent) 55%,transparent);animation:fx-rased-live 2.4s ease-out infinite}
@keyframes fx-rased-live{70%{box-shadow:0 0 0 7px color-mix(in srgb,var(--fx-accent) 0%,transparent)}100%{box-shadow:0 0 0 0 transparent}}
html[data-ui="v2"] #chat-assistant .chat-icon-btn{
  inline-size:34px;block-size:34px;border-radius:var(--fx-radius-md);
  background:transparent;color:var(--fx-text-muted);
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out),color var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] #chat-assistant .chat-icon-btn:hover{background:var(--fx-surface-sunken);color:var(--fx-text)}
html[data-ui="v2"] #chat-assistant .chat-icon-btn:focus-visible{outline:none;box-shadow:var(--fx-ring)}

/* -- transcript ----------------------------------------------------------- */
html[data-ui="v2"] #chat-assistant .chat-messages{
  background:var(--fx-surface-sunken);
  padding:var(--fx-space-4);gap:var(--fx-space-3);
}
html[data-ui="v2"] #chat-assistant .chat-welcome{
  margin:auto;display:grid;justify-items:center;gap:var(--fx-space-2);
  max-inline-size:20rem;text-align:center;
  color:var(--fx-text-muted);font-size:var(--fx-text-sm);line-height:var(--fx-leading-body);
}
html[data-ui="v2"] #chat-assistant .chat-welcome-art{
  display:grid;place-items:center;inline-size:56px;block-size:56px;border-radius:50%;
  margin-block-end:var(--fx-space-2);
  background:var(--fx-gradient-brand);color:var(--fx-text-inverse);
  box-shadow:0 8px 24px color-mix(in srgb, var(--fx-primary) 30%, transparent);
}
html[data-ui="v2"] #chat-assistant .chat-welcome-title{
  margin:0;font-size:var(--fx-text-lg);font-weight:var(--fx-weight-bold);color:var(--fx-text);
}

/* messages: appended once each, so a short entrance never replays */
html[data-ui="v2"] #chat-assistant .chat-msg{
  max-inline-size:86%;
  animation:fx-rased-msg var(--fx-dur-base) var(--fx-ease-out) both;
}
@keyframes fx-rased-msg{from{opacity:0;transform:translateY(6px)}}
html[data-ui="v2"] #chat-assistant .chat-msg-body,
html[data-ui="v2"] #chat-assistant .chat-msg-user p{
  padding:var(--fx-space-3) var(--fx-space-4);
  font-size:var(--fx-text-sm);line-height:var(--fx-leading-body);
}
html[data-ui="v2"] #chat-assistant .chat-msg-user p{
  background:var(--fx-primary);color:var(--fx-text-inverse);
  border-radius:var(--fx-radius-lg);border-end-end-radius:4px;
  border-start-end-radius:var(--fx-radius-lg);
}
/* the assistant speaks with a small brand mark beside its bubble */
html[data-ui="v2"] #chat-assistant .chat-msg-assistant{
  display:grid;grid-template-columns:26px minmax(0,1fr);column-gap:var(--fx-space-2);align-items:end;
}
html[data-ui="v2"] #chat-assistant .chat-msg-assistant::before{
  content:"";inline-size:26px;block-size:26px;border-radius:50%;
  background:var(--fx-gradient-brand);box-shadow:var(--fx-shadow-xs);
}
html[data-ui="v2"] #chat-assistant .chat-msg-assistant .chat-msg-body{
  grid-column:2;
  background:var(--fx-surface);color:var(--fx-text);
  border:1px solid var(--fx-border);border-radius:var(--fx-radius-lg);
  border-end-start-radius:4px;border-start-start-radius:var(--fx-radius-lg);
  box-shadow:var(--fx-shadow-xs);
}
html[data-ui="v2"] #chat-assistant .chat-msg-body p{margin:0 0 var(--fx-space-2)}
html[data-ui="v2"] #chat-assistant .chat-msg-body p:last-child{margin-block-end:0}
html[data-ui="v2"] #chat-assistant .chat-msg-body ul{
  margin:var(--fx-space-1) 0 var(--fx-space-2);padding:0;list-style:none;display:grid;gap:6px;
}
html[data-ui="v2"] #chat-assistant .chat-msg-body li{
  position:relative;margin:0;padding-inline-start:16px;
}
html[data-ui="v2"] #chat-assistant .chat-msg-body li::before{
  content:"";position:absolute;inset-inline-start:2px;inset-block-start:.7em;
  inline-size:6px;block-size:6px;border-radius:50%;background:var(--fx-accent);
}
html[data-ui="v2"] #chat-assistant .chat-msg-body strong{color:var(--fx-primary);font-weight:var(--fx-weight-bold)}
html[data-ui="v2"] #chat-assistant .chat-msg-body a{
  color:var(--fx-link);font-weight:var(--fx-weight-semibold);
  text-decoration:underline;text-decoration-color:color-mix(in srgb, currentColor 35%, transparent);
  text-underline-offset:3px;
}
html[data-ui="v2"] #chat-assistant .chat-msg-body a:hover{color:var(--fx-link-hover);text-decoration-color:currentColor}
html[data-ui="v2"] #chat-assistant .chat-msg-body bdi{font-variant-numeric:tabular-nums}

/* thinking: three dots that rise in turn (still under reduced motion) */
html[data-ui="v2"] #chat-assistant .chat-typing .chat-dots{
  display:flex;gap:5px;align-items:center;min-block-size:20px;
  padding:var(--fx-space-3) var(--fx-space-4);
}
html[data-ui="v2"] #chat-assistant .chat-dots span{
  inline-size:7px;block-size:7px;border-radius:50%;background:var(--fx-primary);
  animation:fx-rased-dot 1.2s var(--fx-ease-in-out, ease-in-out) infinite;
}
html[data-ui="v2"] #chat-assistant .chat-dots span:nth-child(2){animation-delay:.15s}
html[data-ui="v2"] #chat-assistant .chat-dots span:nth-child(3){animation-delay:.3s}
@keyframes fx-rased-dot{0%,80%,100%{transform:translateY(0);opacity:.35}40%{transform:translateY(-4px);opacity:1}}

/* an error line: small, centred, with a mark */
html[data-ui="v2"] #chat-assistant .chat-msg-status{
  margin:0 auto;display:inline-flex;align-items:center;gap:8px;max-inline-size:92%;
  padding:var(--fx-space-2) var(--fx-space-3);border-radius:var(--fx-radius-md);
  font-size:var(--fx-text-xs);text-align:start;
  animation:fx-rased-msg var(--fx-dur-base) var(--fx-ease-out) both;
}
html[data-ui="v2"] #chat-assistant .chat-msg-status-error{
  background:var(--fx-danger-bg);color:var(--fx-danger);border:1px solid var(--fx-danger-border);
}
html[data-ui="v2"] #chat-assistant .chat-msg-status-error::before{
  content:"!";flex:none;display:grid;place-items:center;inline-size:18px;block-size:18px;border-radius:50%;
  background:var(--fx-danger);color:var(--fx-text-inverse);font-size:11px;font-weight:var(--fx-weight-bold);
}

/* -- composer ------------------------------------------------------------- */
html[data-ui="v2"] #chat-assistant .chat-form{
  display:grid;gap:var(--fx-space-2);
  padding:var(--fx-space-3);background:var(--fx-surface);border-block-start:1px solid var(--fx-border);
}
/* the chips live in the welcome state, under its text */
html[data-ui="v2"] #chat-assistant .chat-suggestions{
  display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin:var(--fx-space-2) 0 0;
}
html[data-ui="v2"] #chat-assistant .chat-suggestions[hidden]{display:none}
html[data-ui="v2"] #chat-assistant .chat-chip{
  padding:6px 12px;border:1px solid var(--fx-info-border);border-radius:var(--fx-radius-pill);
  background:var(--fx-primary-soft);color:var(--fx-primary);
  font:inherit;font-size:var(--fx-text-xs);font-weight:var(--fx-weight-medium);cursor:pointer;
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out),border-color var(--fx-dur-fast) var(--fx-ease-out),transform var(--fx-dur-instant) var(--fx-ease-out);
}
html[data-ui="v2"] #chat-assistant .chat-chip:hover{background:var(--fx-primary-soft-hover);border-color:var(--fx-primary)}
html[data-ui="v2"] #chat-assistant .chat-chip:active{transform:scale(var(--fx-press-scale))}
html[data-ui="v2"] #chat-assistant .chat-chip:focus-visible{outline:none;box-shadow:var(--fx-ring)}
/* one ring for the whole pill, none on the textarea inside it */
html[data-ui="v2"] #chat-assistant .chat-composer{
  display:flex;align-items:flex-end;gap:var(--fx-space-2);padding:5px;
  border:1px solid var(--fx-border-strong);border-radius:22px;background:var(--fx-surface);
  transition:border-color var(--fx-dur-fast) var(--fx-ease-out),box-shadow var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] #chat-assistant .chat-composer:focus-within{border-color:var(--fx-primary);box-shadow:var(--fx-ring)}
html[data-ui="v2"] #chat-assistant .chat-composer textarea,
html[data-ui="v2"] #chat-assistant .chat-composer textarea:focus,
html[data-ui="v2"] #chat-assistant .chat-composer textarea:focus-visible{
  flex:1;min-block-size:38px;max-block-size:120px;resize:none;
  padding:8px 12px;border:0;outline:none;box-shadow:none;background:transparent;
  color:var(--fx-text);font:inherit;font-size:var(--fx-text-sm);line-height:1.5;
}
html[data-ui="v2"] #chat-assistant .chat-composer textarea::placeholder{color:var(--fx-text-subtle)}
html[data-ui="v2"] #chat-assistant .chat-composer textarea:disabled{opacity:.6}
/* send: a round icon button; its text stays as the accessible name */
html[data-ui="v2"] #chat-assistant .chat-send{
  position:relative;flex:none;display:grid;place-items:center;
  inline-size:38px;block-size:38px;padding:0;border:0;border-radius:50%;
  background:var(--fx-primary);color:var(--fx-text-inverse);cursor:pointer;
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out),opacity var(--fx-dur-fast) var(--fx-ease-out),transform var(--fx-dur-instant) var(--fx-ease-out);
}
html[data-ui="v2"] #chat-assistant .chat-send > span{
  position:absolute;inline-size:1px;block-size:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap;
}
html[data-ui="v2"] #chat-assistant .chat-send:hover:not(:disabled){background:var(--fx-primary-hover);transform:none}
html[data-ui="v2"] #chat-assistant .chat-send:not(:disabled):active{transform:scale(var(--fx-press-scale))}
html[data-ui="v2"] #chat-assistant .chat-send:focus-visible{outline:none;box-shadow:var(--fx-ring)}
html[data-ui="v2"] #chat-assistant .chat-send:disabled,
html[data-ui="v2"] #chat-assistant .chat-form:has(#chat-input:placeholder-shown) .chat-send{opacity:.45;cursor:default}

/* dark: the transcript sits a step below the panel surface */
html[data-ui="v2"].dark #chat-assistant .chat-messages{background:var(--fx-bg)}

@media (prefers-reduced-motion:reduce){
  html[data-ui="v2"] #chat-assistant .chat-panel:not([hidden]){animation:none}
  html[data-ui="v2"] #chat-assistant .chat-dots span{animation:none;opacity:.6}
  html[data-ui="v2"] #chat-assistant .chat-live-dot{animation:none}
}

/* The launcher sits in the reading-start corner, so its hover/focus label
   opens toward the page (app.css placed it past the start edge, off-screen). */
html[data-ui="v2"] #chat-assistant .chat-launcher:is(:hover,:focus-visible) .chat-launcher-label{
  inset-inline-end:auto;inset-inline-start:calc(100% + 10px);
}
