/* Core One — Ask AI panel (public/askai.js).
   Colours come from the theme tokens only, so dark mode follows on its own. Every side is
   written as a logical property (inline-start / inline-end), so Arabic mirrors without a
   rule in rtl.css — keep it that way, and gen-rtl.mjs never needs to read this file. */

/* ---------- the top-bar button ---------- */
.topbar .askai-btn {
  flex: none; display: inline-flex; align-items: center; gap: 6px; height: 32px;
  padding-block: 0; padding-inline: 10px 12px; margin-inline-end: 8px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .06);
  color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.topbar .askai-btn:hover { border-color: rgba(255, 255, 255, .36); background: rgba(255, 255, 255, .1); }
.topbar .askai-btn.on { border-color: color-mix(in srgb, var(--signal, #3cd95d) 60%, transparent); background: rgba(255, 255, 255, .12); }
.askai-spark {
  font-size: 14px; line-height: 1; color: var(--signal, #3cd95d);
  text-shadow: 0 0 10px color-mix(in srgb, var(--signal, #3cd95d) 55%, transparent);
}
@media (max-width: 1100px) { .topbar .askai-btn .askai-lbl { display: none; } .topbar .askai-btn { padding-inline: 9px; } }

/* ---------- the panel ---------- */
.askai {
  position: fixed; inset-block: 0; inset-inline-end: 0; z-index: 95;
  width: min(420px, 100vw); display: flex; flex-direction: column;
  background: var(--paper); border-inline-start: 1px solid var(--line);
  box-shadow: var(--e3); animation: askai-in .22s var(--ease);
}
@keyframes askai-in { from { opacity: 0; translate: 24px 0; } }
:root[dir="rtl"] .askai { animation-name: askai-in-rtl; }
@keyframes askai-in-rtl { from { opacity: 0; translate: -24px 0; } }
/* On a wide screen the page makes room instead of hiding under the panel. */
@media (min-width: 1280px) { body.askai-open #app { padding-inline-end: 420px; } }

.askai-head {
  display: flex; align-items: center; gap: 10px; flex: none;
  padding-block: 12px; padding-inline: 16px 10px; min-height: 54px;
  background: var(--night, #0d0032); color: #fff;
}
.askai-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--royal, #1e56d5), var(--electric, #216ffb));
  color: #fff; font-size: 15px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .14) inset;
}
.askai-title { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
.askai-title b { font-size: 15px; font-weight: 650; }
.askai-title span { font-size: 12px; color: rgba(255, 255, 255, .66); }
.askai-icon {
  width: 32px; height: 32px; border-radius: 9px; border: 0; background: none; flex: none;
  display: grid; place-items: center; color: rgba(255, 255, 255, .74);
}
.askai-icon:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.askai-icon:focus-visible { outline: 2px solid var(--signal, #3cd95d); outline-offset: 1px; }
.askai-icon svg { width: 18px; height: 18px; }

.askai-stream { flex: 1; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }

/* empty state */
.askai-empty { margin: auto 0; padding: 12px 4px 4px; text-align: center; }
.askai-orb {
  width: 54px; height: 54px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center;
  font-size: 24px; color: #fff; background: var(--hero, linear-gradient(180deg, #0d0032, #1e56d5));
  box-shadow: 0 10px 30px -10px color-mix(in srgb, var(--royal, #1e56d5) 70%, transparent);
}
.askai-empty h3 { font-size: 17px; margin-bottom: 6px; color: var(--ink); }
.askai-empty p { color: var(--muted); font-size: 13px; max-width: 300px; margin: 0 auto 16px; }
.askai-sugs { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.askai-sug {
  text-align: start; padding: 10px 12px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--raised); color: var(--ink-2); font-size: 13.5px; font-weight: 500;
  transition: border-color .15s var(--ease), background .15s var(--ease), color .15s var(--ease);
}
.askai-sug:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); color: var(--ink); }

/* messages */
.askai-msg { display: flex; gap: 8px; align-items: flex-start; max-width: 100%; }
.askai-msg.me { justify-content: flex-end; }
.askai-msg.me .askai-bubble {
  max-width: 86%; background: var(--accent); color: #fff; padding: 9px 13px;
  border-radius: 16px; border-end-end-radius: 5px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.askai-av {
  width: 24px; height: 24px; border-radius: 7px; flex: none; display: grid; place-items: center; margin-top: 2px;
  font-size: 12px; color: #fff; background: linear-gradient(135deg, var(--royal, #1e56d5), var(--electric, #216ffb));
}
.askai-msg.ai .askai-bubble { flex: 1; min-width: 0; color: var(--ink); font-size: 14px; line-height: 1.55; overflow-wrap: anywhere; }
.askai-md p { margin: 0 0 8px; }
.askai-md p:last-child, .askai-md ul:last-child, .askai-md ol:last-child { margin-bottom: 0; }
.askai-md ul, .askai-md ol { margin: 0 0 8px; padding-inline-start: 20px; }
.askai-md li { margin: 2px 0; }
.askai-md b { font-weight: 650; }
.askai-md code { font-size: 12.5px; background: var(--line-2); padding: 1px 5px; border-radius: 5px; }
.askai-src {
  margin-top: 8px; font-size: 12px; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap;
  padding-top: 7px; border-top: 1px dashed var(--line);
}
.askai-src > span:first-child { font-weight: 600; }
.askai-msg.err .askai-bubble {
  padding: 10px 12px; border-radius: var(--r-sm); font-size: 13.5px;
  background: color-mix(in srgb, var(--danger) 9%, var(--paper)); color: var(--ink);
  border: 1px solid color-mix(in srgb, var(--danger) 30%, var(--line));
}
.askai-retry {
  margin-top: 8px; border: 1px solid var(--line); background: var(--paper); color: var(--ink);
  border-radius: 999px; padding: 4px 12px; font-size: 12.5px; font-weight: 600;
}
.askai-msg.wait .askai-bubble { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; padding-top: 3px; }
.askai-secs { font-variant-numeric: tabular-nums; color: var(--faint); }
.askai-dots { display: inline-flex; gap: 4px; }
.askai-dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent);
  animation: askai-dot 1.1s infinite ease-in-out both;
}
.askai-dots i:nth-child(2) { animation-delay: .15s; }
.askai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes askai-dot { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* composer */
.askai-compose { flex: none; padding: 10px 14px 12px; border-top: 1px solid var(--line); background: var(--paper); }
.askai-ctx {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; min-width: 0;
}
.askai-ctx-k { color: var(--muted); font-weight: 600; flex: none; }
.askai-ctx-v {
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 2px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink, var(--accent)); font-weight: 600;
}
.askai-box {
  display: flex; align-items: flex-end; gap: 8px; padding-block: 6px; padding-inline: 12px 6px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--raised);
  transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
.askai-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
.askai-box textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: none; color: var(--ink);
  font-size: 14px; line-height: 1.45; padding: 6px 0; max-height: 160px; unicode-bidi: plaintext;
}
.askai-send {
  width: 34px; height: 34px; border-radius: 10px; border: 0; flex: none; display: grid; place-items: center;
  background: var(--signal, #3cd95d); color: var(--signal-ink, #0d0032);
}
.askai-send:hover { background: var(--signal-hi, #55e273); }
.askai-send svg { width: 18px; height: 18px; }
.askai-foot { margin-top: 7px; font-size: 11.5px; color: var(--faint); text-align: center; }

/* ---------- phone: a full-screen sheet over the tab bar ---------- */
@media (max-width: 760px) {
  .askai { width: 100vw; inset-block-start: 0; border-inline-start: 0; z-index: 260; }
  .askai-head { padding-top: env(safe-area-inset-top); }
  .askai-compose { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  /* The phone bar drops its spacer, so the button pushes itself to the far edge. */
  .topbar .askai-btn { margin-inline-start: auto; margin-inline-end: 2px; }
}
@media (prefers-reduced-motion: reduce) { .askai, .askai-dots i { animation: none; } }
