/* معمار: the assistant's launcher and panel (chat.js). Bottom right corner on every screen; a full screen sheet on phones
   and in short windows. Tokens come from styles.css, with fallbacks so a page without it still reads. */
.mm{--mm-ink:var(--ink,#1b1b17);--mm-paper:var(--paper,#eae3d4);--mm-card:var(--card,#fbf8f0);--mm-surface:var(--surface,#fffdf7);
  --mm-muted:var(--muted,#5e5d56);--mm-line:var(--line,#1b1b171f);--mm-soft:var(--line-soft,#1b1b1714);--mm-gold:var(--yellow,#f4c542);
  --mm-gold-ink:var(--gold-ink,#6f5200);--mm-wash:var(--surface-muted,#f2ede1);font-family:var(--font-body,Tahoma,sans-serif);
  /* a field's edge at 3:1 on the surface (WCAG 1.4.11): the text box and the suggestion chips read as controls */
  --mm-field:#8f8c82;
  /* the launcher's bottom: the corner, or above the owner page's total bar (--mm-lift, measured in chat.js) */
  --mm-b:max(1.25rem,env(safe-area-inset-bottom),calc(var(--mm-lift,0px) + .75rem))}
.mm .i{width:1.15em;height:1.15em;flex:none}
.mm .sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}

/* launcher: under toasts and the undo snack (z 40), over the total bar (z 30) */
.mm-launch{position:fixed;right:max(1.25rem,env(safe-area-inset-right));bottom:var(--mm-b);z-index:35;width:3.75rem;height:3.75rem;
  padding:0;border:0;border-radius:50%;background:var(--mm-ink);color:var(--mm-paper);cursor:pointer;box-shadow:0 10px 30px #19191438,0 2px 6px #19191426;
  transition:transform .25s var(--ease,ease),box-shadow .25s}
.mm-launch:hover{transform:translateY(-2px) scale(1.04);box-shadow:0 14px 36px #19191440,0 2px 6px #19191426}
.mm-launch:focus-visible{outline:3px solid var(--mm-gold-ink);outline-offset:3px}
.mm-av{display:block;border-radius:50%;overflow:hidden;background:var(--mm-ink)}
.mm-launch .mm-av{position:absolute;inset:0;transition:opacity .2s,transform .3s var(--ease,ease)}
.mm-av img{width:100%;height:100%;display:block}
/* the launcher's mark: a gold chat bubble on ink; the panel's avatar: the monogram م in the display face (no image, no motion) */
.mm-mark{display:grid;place-items:center;color:var(--mm-gold)}
.mm-mark .i{width:1.75rem;height:1.75rem}
.mm-mono{display:grid;place-items:center;color:var(--mm-gold);font-family:var(--font-display,inherit);font-weight:800;font-size:1.4rem;line-height:1;padding-bottom:.15rem}
.mm-x{position:absolute;inset:0;display:grid;place-items:center;opacity:0;transform:rotate(-45deg);transition:opacity .2s,transform .3s var(--ease,ease)}
.mm-x .i{width:1.5rem;height:1.5rem}
.mm.open .mm-launch .mm-av{opacity:0;transform:scale(.6)}
.mm.open .mm-x{opacity:1;transform:none}
.mm-tip{position:absolute;right:calc(100% + .7rem);top:50%;transform:translate(.4rem,-50%);opacity:0;pointer-events:none;white-space:nowrap;
  padding:.35rem .8rem;border-radius:999px;background:var(--mm-ink);color:var(--mm-paper);font-size:.82rem;font-weight:700;box-shadow:0 6px 18px #1919142e;transition:opacity .2s,transform .2s}
.mm-launch:hover .mm-tip,.mm-launch:focus-visible .mm-tip{opacity:1;transform:translate(0,-50%)}
/* until the first open the label stays in view (a dark circle alone does not say «ask a question»), and a tap on it opens */
.mm.hint .mm-tip{opacity:1;transform:translate(0,-50%);pointer-events:auto}
.mm.open .mm-tip{display:none}
@media (hover:none){.mm:not(.hint) .mm-tip{display:none}}

/* panel */
.mm-panel{position:fixed;right:max(1.25rem,env(safe-area-inset-right));bottom:calc(var(--mm-b) + 4.6rem);z-index:46;
  width:min(25rem,calc(100vw - 2rem));height:min(40rem,calc(100dvh - var(--mm-b) - 6.1rem));display:flex;flex-direction:column;overflow:hidden;
  border-radius:1.25rem;background:var(--mm-surface);color:var(--mm-ink);border:1px solid var(--mm-line);box-shadow:0 24px 70px #19191433,0 4px 14px #1919141f;
  transform-origin:bottom right;animation:mm-in .28s var(--ease,ease) both}
.mm-panel[hidden]{display:none}
@keyframes mm-in{from{opacity:0;transform:translateY(.6rem) scale(.97)}to{opacity:1;transform:none}}
.mm-head{display:flex;align-items:center;gap:.7rem;padding:.75rem .8rem .75rem 1rem;border-bottom:1px solid var(--mm-soft);background:var(--mm-card)}
.mm-head .mm-av{width:2.5rem;height:2.5rem;flex:none}
.mm-who{display:grid;line-height:1.3;margin-inline-end:auto;min-width:0}
.mm-who h2{margin:0;font-size:1.02rem;line-height:1.3;font-family:var(--font-display,inherit)}
.mm-who h2:focus{outline:none}
.mm-who small{color:var(--mm-muted);font-size:.76rem}
.mm-icon{width:2.5rem;height:2.5rem;display:grid;place-items:center;border:0;border-radius:.7rem;background:transparent;color:var(--mm-muted);cursor:pointer}
.mm-icon:hover:not(:disabled){background:var(--mm-wash);color:var(--mm-ink)}
.mm-icon:disabled{opacity:.35;cursor:default}
/* a gap between «new chat» and «close», so a slip of the thumb does not clear the conversation */
.mm-icon[data-act=new]{margin-inline-end:.5rem}
.mm-icon:focus-visible,.mm-chip:focus-visible,.mm-send:focus-visible,.mm-copy:focus-visible,.mm-retry:focus-visible,.mm-cite:focus-visible,.mm-src a:focus-visible,
.mm-jump:focus-visible,.mm-undo button:focus-visible,.mm-table:focus-visible,.mm-quote pre:focus-visible,.mm-quote a:focus-visible,.mm-ctx a:focus-visible{outline:2px solid var(--mm-gold-ink);outline-offset:2px}
.mm-ctx{display:flex;align-items:flex-start;gap:.45rem;margin:0;padding:.5rem 1rem;font-size:.78rem;line-height:1.55;color:var(--mm-muted);background:var(--mm-wash);border-bottom:1px solid var(--mm-soft)}
.mm-ctx .i{margin-top:.15rem}
.mm-ctx bdi{color:var(--mm-ink);font-weight:700}
.mm-ctx a{color:var(--mm-gold-ink);font-weight:700;text-underline-offset:2px}
.mm-undo{display:flex;align-items:center;justify-content:space-between;gap:.6rem;padding-block:.35rem;padding-inline:1rem .6rem;background:var(--mm-ink);color:var(--mm-paper);font-size:.84rem}
.mm-undo[hidden]{display:none}
.mm-undo button{display:inline-flex;align-items:center;gap:.3rem;padding:.3rem .85rem;border:0;border-radius:999px;background:var(--mm-gold);color:var(--mm-ink);font:inherit;font-weight:700;cursor:pointer}

/* conversation: no smooth scrolling, the view is placed by chat.js while an answer streams */
.mm-body{position:relative;flex:1;min-height:0;display:flex;flex-direction:column}
.mm-log{position:relative;flex:1;overflow-y:auto;overscroll-behavior:contain;padding:1rem;display:flex;flex-direction:column;gap:.75rem}
.mm-jump{position:absolute;bottom:.6rem;left:50%;transform:translateX(-50%);display:inline-flex;align-items:center;gap:.35rem;padding:.35rem .9rem;
  border-radius:999px;border:1px solid var(--mm-field);background:var(--mm-surface);color:var(--mm-ink);font:inherit;font-size:.8rem;font-weight:700;box-shadow:0 6px 18px #1919142e;cursor:pointer}
.mm-jump[hidden]{display:none}
.mm-msg{display:flex;flex-direction:column;max-width:88%;position:relative}
.mm-msg.me{align-self:flex-end}
.mm-msg.bot,.mm-msg.err{align-self:flex-start}
.mm-msg.bot:has(.mm-table){max-width:100%;align-self:stretch}
.mm-msg.note{align-self:center;max-width:100%}
.mm-b{padding:.6rem .85rem;border-radius:1rem;font-size:.92rem;line-height:1.75;overflow-wrap:anywhere}
.mm-msg.me .mm-b{background:var(--mm-ink);color:var(--mm-paper);border-start-end-radius:.3rem}
.mm-msg.bot .mm-b,.mm-msg.err .mm-b{background:var(--mm-card);border:1px solid var(--mm-soft);border-start-start-radius:.3rem}
.mm-msg.err .mm-b{border-color:#a3362a40;background:var(--danger-wash,#f6e1dc)}
.mm-msg.note .mm-b{padding:.25rem .8rem;border-radius:999px;background:var(--mm-wash);color:var(--mm-muted);font-size:.78rem;text-align:center}
.mm-b :where(p,h4,ul,ol,pre,blockquote,.mm-table){margin:0}
.mm-b>*+*{margin-top:.5rem}
.mm-b :where(ul,ol){padding-inline-start:1.3rem}.mm-b li+li{margin-top:.2rem}
.mm-b h4{font-size:.95rem}
.mm-b code{font-family:var(--font-mono,monospace);font-size:.85em;background:var(--mm-wash);padding:0 .25rem;border-radius:.3rem}
.mm-b pre{padding:.5rem .7rem;border-radius:.5rem;background:var(--mm-wash);white-space:pre-wrap;font-size:.82rem;line-height:1.6}
.mm-b pre code{background:none;padding:0}
.mm-b blockquote{padding:.1rem .8rem;border-inline-start:3px solid var(--mm-gold);color:var(--ink-2,#3d3c35)}
.mm-b a{color:var(--mm-gold-ink);font-weight:700;text-underline-offset:2px}
.mm-b .mm-flag{color:var(--mm-muted);font-size:.82rem}
.mm-b .mm-flag.err{color:var(--danger,#a3362a);font-weight:700}
/* tables keep whole words and numbers: too wide, they scroll sideways, with a shade on the side that has more */
.mm-table{overflow-x:auto;border-radius:.35rem;
  background:linear-gradient(to right,var(--mm-card) 40%,#fbf8f000) left/1.5rem 100% no-repeat local,linear-gradient(to left,var(--mm-card) 40%,#fbf8f000) right/1.5rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%,#1b1b1733,#1b1b1700) left/.7rem 100% no-repeat scroll,radial-gradient(farthest-side at 100% 50%,#1b1b1733,#1b1b1700) right/.7rem 100% no-repeat scroll}
.mm-table table{border-collapse:collapse;font-size:.82rem;min-width:100%}
.mm-table th,.mm-table td{border:1px solid var(--mm-soft);padding:.3rem .5rem;text-align:start;vertical-align:top;overflow-wrap:normal;word-break:normal}
.mm-table th{background:var(--mm-wash);font-weight:700;white-space:nowrap}
.mm-table td{min-width:4.5rem}
.mm-src{display:flex;flex-wrap:wrap;align-items:center;gap:.35rem;margin-top:.45rem;font-size:.78rem;color:var(--mm-muted)}
.mm-src>span{display:inline-flex;align-items:center;gap:.3rem;font-weight:700}
.mm-cite,.mm-src a{padding:.15rem .6rem;border-radius:999px;border:1px solid var(--mm-field);background:var(--mm-surface);color:var(--mm-gold-ink);font:inherit;font-weight:700;text-decoration:none;cursor:pointer}
.mm-cite:hover,.mm-src a:hover,.mm-cite[aria-expanded=true]{background:var(--yellow-wash,#f4c54240);border-color:var(--mm-gold-ink)}
.mm-quote{margin-top:.4rem;padding:.6rem .75rem;border-radius:.8rem;border:1px solid var(--mm-soft);background:var(--mm-wash);font-size:.82rem;line-height:1.7}
.mm-quote[hidden]{display:none}
.mm-quote p{margin:0}.mm-quote .mm-quote-h{font-weight:700}
.mm-quote pre{margin:.35rem 0;max-height:14rem;overflow:auto;padding:.5rem .65rem;border-radius:.5rem;background:var(--mm-surface);white-space:pre-wrap;font-family:inherit;font-size:.82rem;line-height:1.8}
.mm-quote a{display:inline-flex;align-items:center;gap:.3rem;min-height:2rem;color:var(--mm-gold-ink);font-weight:700}
.mm-copy{position:absolute;bottom:-.55rem;left:.3rem;width:1.9rem;height:1.9rem;display:grid;place-items:center;border-radius:50%;border:1px solid var(--mm-line);
  background:var(--mm-surface);color:var(--mm-muted);cursor:pointer;opacity:0;transition:opacity .15s}
.mm-msg:hover .mm-copy,.mm-copy:focus-visible,.mm-copy.done{opacity:1}
.mm-copy.done{color:var(--ok,#3f6b46)}
@media (hover:none){.mm-copy{opacity:.85}}
.mm-msg.bot:has(.mm-copy){margin-bottom:.4rem}
.mm-clip{position:fixed;top:0;left:0;width:1px;height:1px;opacity:0}
.mm-wait{display:flex;align-items:center;gap:.55rem;color:var(--mm-muted);font-size:.85rem}
.mm-dots{display:inline-flex;gap:.22rem}
.mm-dots i{width:.38rem;height:.38rem;border-radius:50%;background:var(--mm-gold-ink);opacity:.35;animation:mm-dot 1.1s infinite}
.mm-dots i:nth-child(2){animation-delay:.15s}.mm-dots i:nth-child(3){animation-delay:.3s}
@keyframes mm-dot{0%,80%,100%{opacity:.25;transform:translateY(0)}40%{opacity:1;transform:translateY(-3px)}}
.mm-retry{margin-top:.5rem;display:inline-flex;align-items:center;gap:.35rem;padding:.35rem .8rem;border-radius:999px;border:1px solid var(--mm-field);background:var(--mm-surface);color:var(--mm-ink);font:inherit;font-size:.82rem;font-weight:700;cursor:pointer}

/* first open */
.mm-hello{display:grid;gap:.75rem}
.mm-hello p{margin:0;padding:.75rem .9rem;border-radius:1rem;background:var(--mm-card);border:1px solid var(--mm-soft);font-size:.92rem;line-height:1.75}
.mm-chips{display:flex;flex-wrap:wrap;gap:.45rem}
.mm-chip{padding:.45rem .85rem;border-radius:999px;border:1px solid var(--mm-field);background:var(--mm-wash);color:var(--mm-ink);font:inherit;font-size:.84rem;
  text-align:start;cursor:pointer;transition:background .15s,border-color .15s}
.mm-chip:hover{background:var(--yellow-wash,#f4c54240);border-color:var(--mm-gold-ink)}

/* composer: one round button sends, and stops an answer while it streams */
.mm-form{display:flex;align-items:flex-end;gap:.5rem;padding:.65rem .75rem;border-top:1px solid var(--mm-soft);background:var(--mm-surface)}
.mm-form textarea{flex:1;resize:none;min-height:2.75rem;max-height:8.25rem;padding:.6rem .85rem;border:1px solid var(--mm-field);border-radius:1rem;background:var(--mm-card);
  color:var(--mm-ink);font:inherit;font-size:16px;line-height:1.5}
.mm-form textarea:focus{outline:2px solid var(--mm-gold-ink);outline-offset:1px}
.mm-send{width:2.75rem;height:2.75rem;flex:none;display:grid;place-items:center;border:0;border-radius:50%;background:var(--mm-gold);color:var(--mm-ink);cursor:pointer;transition:transform .15s,opacity .15s}
.mm-send:not(.stop) .i{transform:scaleX(-1)}
.mm-send.stop{background:var(--mm-ink);color:var(--mm-paper)}
.mm-send:hover:not([aria-disabled=true]){transform:scale(1.06)}
.mm-send[aria-disabled=true]{opacity:.4;cursor:default}

/* phones, and windows too short for a floating panel (a phone held sideways): a full screen sheet */
@media (max-width:600px),(max-height:500px){
  .mm-panel{inset:0;width:100%;height:100dvh;border-radius:0;border:0;padding-bottom:env(safe-area-inset-bottom)}
  .mm.open .mm-launch{display:none}
  html.mm-lock,html.mm-lock body{overflow:hidden}
  .mm-msg{max-width:92%}
}
@media (max-height:500px){

  .mm-head{padding-block:.35rem}
  .mm-ctx{padding-block:.3rem}
}
/* touch: 44 px targets and larger small print, for the older owners this site serves */
@media (max-width:600px),(pointer:coarse){
  .mm-icon{width:2.75rem;height:2.75rem}
  .mm-chip,.mm-retry,.mm-jump,.mm-undo button{min-height:2.75rem}
  .mm-copy{width:2.5rem;height:2.5rem;bottom:-.85rem}
  .mm-msg.bot:has(.mm-copy){margin-bottom:.75rem}
  .mm-cite,.mm-src a{min-height:2rem;padding:.3rem .7rem;font-size:.8rem}
  .mm-ctx,.mm-src{font-size:.8rem}
}
@media (prefers-reduced-motion:reduce){.mm-panel,.mm-launch,.mm-launch .mm-av,.mm-x,.mm-tip{animation:none;transition:none}.mm-dots i{animation:none;opacity:.7}}
@media print{.mm{display:none}}
