/* Help assistant: chat panel beside the notifications bell + on-page walkthrough.
 * Loaded after controls.css (base.html). Colours follow the site's accent and
 * dark-mode variables; nothing here depends on the page it is shown on. */

#ac-assist-btn.active { color: rgb(var(--accent-rgb, 59, 130, 246)); }

/* Header mascot: same white line weight as the bell and search icons, motion kept
 * to a slow blink and a tiny antenna bob so it never competes with them. */
.header .nav-icon .ac-buddy { color: rgba(255, 255, 255, 0.9); display: block; overflow: visible; }
.header .nav-icon:hover .ac-buddy { color: #fff; }
#ac-assist-btn.active .ac-buddy { color: rgb(var(--accent-rgb, 59, 130, 246)); }
.ac-buddy-eye { transform-box: fill-box; transform-origin: center; animation: ac-buddy-blink 5.5s infinite; }
.ac-buddy-tip { animation: ac-buddy-bob 3.2s ease-in-out infinite; }
.ac-buddy-body { transform-box: view-box; transform-origin: 50% 100%; }
#ac-assist-btn:hover .ac-buddy-body { animation: ac-buddy-wiggle .7s ease-in-out 1; }
.ac-buddy-smile { transition: transform .25s ease; transform-box: fill-box; transform-origin: center; }
#ac-assist-btn:hover .ac-buddy-smile { transform: scale(1.25, 1.15); }
@keyframes ac-buddy-blink { 0%, 93%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes ac-buddy-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(.7px); } }
@keyframes ac-buddy-wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-7deg); } 60% { transform: rotate(6deg); } }
@media (prefers-reduced-motion: reduce) { .ac-buddy-eye, .ac-buddy-tip, #ac-assist-btn:hover .ac-buddy-body { animation: none; } }

#ac-assist-panel {
  --ac-a: rgb(var(--accent-rgb, 59, 130, 246));
  --ac-a-soft: rgba(var(--accent-rgb, 59, 130, 246), .10);
  --ac-a-line: rgba(var(--accent-rgb, 59, 130, 246), .28);
  --ac-ink: var(--bs-body-color, #212529);
  --ac-muted: var(--bs-secondary-color, #6c757d);
  --ac-card: var(--bs-body-bg, #fff);
  --ac-line: var(--bs-border-color, #dee2e6);
  --ac-bot: rgba(var(--accent-rgb, 59, 130, 246), .07);
  display: none;
  flex-direction: column;
  position: fixed;
  top: 60px;
  inset-inline-end: 8px;
  width: 410px;
  max-width: calc(100vw - 16px);
  height: min(640px, calc(100vh - 76px));
  background: var(--ac-card);
  color: var(--ac-ink);
  border: 1px solid var(--ac-line);
  border-radius: 14px;
  box-shadow: 0 14px 44px rgba(15, 23, 42, .24);
  z-index: 9999;
  overflow: hidden;
  text-align: start;
  font-size: .9rem;
}

body.dark-mode #ac-assist-panel {
  --ac-a: rgb(var(--dark-accent-rgb, 96, 165, 250));
  --ac-a-soft: rgba(var(--dark-accent-rgb, 96, 165, 250), .16);
  --ac-a-line: rgba(var(--dark-accent-rgb, 96, 165, 250), .34);
  --ac-ink: var(--dark-text-primary, #f2f2f7);
  --ac-muted: var(--dark-text-secondary, #aeaeb2);
  --ac-card: var(--dark-bg-card, #2c2c2e);
  --ac-line: rgba(255, 255, 255, .12);
  --ac-bot: rgba(255, 255, 255, .07);
}

#ac-assist-panel * { box-sizing: border-box; }

.ac-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--ac-line);
}
.ac-head-title { font-weight: 700; font-size: .98rem; flex: 1; min-width: 0; }
.ac-quota {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .76rem; color: var(--ac-muted);
  padding: 3px 9px; border-radius: 999px; background: var(--ac-a-soft);
  white-space: nowrap;
}
.ac-quota b { color: var(--ac-a); font-weight: 800; font-variant-numeric: tabular-nums; }
.ac-quota.ac-quota-low b { color: #d97706; }
.ac-quota.ac-quota-empty b { color: #dc2626; }
.ac-close {
  border: 0; background: transparent; color: var(--ac-muted); font-size: 1.2rem; line-height: 1;
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer;
}
.ac-close:hover { background: var(--ac-a-soft); color: var(--ac-ink); }
.ac-min { font-size: 1rem; }
.ac-head .ac-min + .ac-close { margin-inline-start: -6px; }

.ac-list { flex: 1; overflow-y: auto; padding: 12px 14px 6px; display: flex; flex-direction: column; gap: 8px; }
.ac-loading { text-align: center; color: var(--ac-muted); padding: 24px 0; }
.ac-day {
  align-self: center; font-size: .7rem; color: var(--ac-muted); letter-spacing: .02em;
  padding: 2px 10px; border-radius: 999px; background: var(--ac-a-soft); margin: 6px 0 2px;
}
.ac-more {
  align-self: center; border: 1px solid var(--ac-line); background: transparent; color: var(--ac-a);
  font-size: .78rem; font-weight: 600; padding: 4px 12px; border-radius: 999px; cursor: pointer;
}
.ac-more:hover { background: var(--ac-a-soft); }

.ac-msg { display: flex; flex-direction: column; max-width: 92%; }
.ac-msg-user { align-self: flex-end; align-items: flex-end; }
.ac-msg-bot { align-self: flex-start; align-items: flex-start; }
.ac-bubble {
  padding: 9px 12px; border-radius: 14px; line-height: 1.5; word-break: break-word;
  background: var(--ac-bot); border: 1px solid transparent;
}
.ac-msg-user .ac-bubble { background: var(--ac-a); color: #fff; border-end-end-radius: 4px; }
.ac-msg-bot .ac-bubble { border-end-start-radius: 4px; }
.ac-bubble-muted { background: transparent; border-color: var(--ac-line); color: var(--ac-muted); }
.ac-user-text { white-space: pre-wrap; }
.ac-meta { font-size: .66rem; color: var(--ac-muted); margin: 2px 4px 0; }
.ac-rich-p { margin: 0 0 6px; }
.ac-rich-p:last-child { margin-bottom: 0; }
.ac-rich-list { margin: 2px 0 6px; padding-inline-start: 1.25rem; }
.ac-rich-list li { margin: 2px 0; }
.ac-bubble strong { font-weight: 700; }

.ac-show-btn {
  margin-top: 8px; display: inline-flex; align-items: center; gap: 4px;
  border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .82rem;
  background: var(--ac-a); color: #fff; cursor: pointer;
}
.ac-show-btn:hover { filter: brightness(1.08); }

.ac-welcome { border: 1px dashed var(--ac-a-line); border-radius: 12px; padding: 14px; background: var(--ac-a-soft); }
.ac-welcome-title { font-weight: 700; margin-bottom: 4px; }
.ac-welcome-text { color: var(--ac-muted); font-size: .84rem; margin-bottom: 10px; }
.ac-chips { display: flex; flex-direction: column; gap: 6px; }
.ac-chip {
  text-align: start; border: 1px solid var(--ac-a-line); background: var(--ac-card); color: var(--ac-ink);
  border-radius: 10px; padding: 7px 10px; font-size: .82rem; cursor: pointer;
}
.ac-chip:hover { background: var(--ac-a-soft); }

.ac-dots i {
  display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%;
  background: var(--ac-muted); animation: ac-bounce 1.1s infinite ease-in-out;
}
.ac-dots i:nth-child(2) { animation-delay: .15s; }
.ac-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ac-bounce { 0%, 80%, 100% { opacity: .25; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.ac-banner { margin: 0 14px 6px; padding: 8px 10px; border-radius: 10px; font-size: .8rem; }
.ac-banner-info { background: var(--ac-a-soft); }
.ac-banner-warn { background: rgba(245, 158, 11, .16); color: var(--ac-ink); }

.ac-form { display: flex; align-items: flex-end; gap: 8px; padding: 8px 14px 12px; position: relative; }
.ac-form textarea {
  flex: 1; resize: none; min-height: 40px; max-height: 110px; padding: 9px 12px; line-height: 1.4;
  border: 1px solid var(--ac-line); border-radius: 12px; background: var(--ac-card); color: var(--ac-ink); font: inherit;
  overflow-y: hidden; scrollbar-width: thin;
}
.ac-form textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ac-form textarea:focus { outline: 2px solid var(--ac-a-line); border-color: var(--ac-a); }
.ac-form textarea:disabled { opacity: .55; }
.ac-send {
  width: 40px; height: 40px; flex: none; border: 0; border-radius: 12px; cursor: pointer;
  background: var(--ac-a); color: #fff; display: inline-flex; align-items: center; justify-content: center;
}
.ac-send:disabled { opacity: .4; cursor: default; }
html[dir="rtl"] .ac-send i, #ac-assist-panel.ac-rtl .ac-send i { transform: scaleX(-1); }
.ac-count { position: absolute; top: -9px; inset-inline-end: 66px; font-size: .68rem; color: var(--ac-muted); background: var(--ac-card); padding: 0 4px; }
.ac-count.ac-count-over { color: #dc2626; font-weight: 700; }
.ac-foot { padding: 2px 14px 10px; font-size: .68rem; color: var(--ac-muted); line-height: 1.35; }

/* Minimised: just a pill, so the page (and a walkthrough) is fully usable. */
.ac-pill {
  position: fixed; z-index: 9998; display: none; align-items: center; gap: 8px;
  inset-inline-end: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  border: 0; border-radius: 999px; padding: 10px 16px; font-weight: 700; font-size: .85rem; cursor: pointer;
  background: rgb(var(--accent-rgb, 59, 130, 246)); color: #fff; box-shadow: 0 8px 24px rgba(15, 23, 42, .3);
}
body.dark-mode .ac-pill { background: rgb(var(--dark-accent-rgb, 96, 165, 250)); color: #0b1220; }
.ac-pill.show { display: inline-flex; }

/* Phones: a bottom sheet (never taller than 70% of what is really visible),
   kept above the browser's bottom bar and the keyboard (see fitViewport in JS). */
@media (max-width: 575px) {
  .ac-head { flex-wrap: wrap; row-gap: 6px; }
  .ac-quota { order: 3; flex-basis: 100%; justify-content: center; }
  #ac-assist-panel {
    top: auto; bottom: 0; inset-inline-start: 0; inset-inline-end: 0; width: auto; max-width: none;
    height: min(62vh, 520px); height: min(62dvh, 520px);
    border-radius: 18px 18px 0 0; border-width: 1px 0 0;
    box-shadow: 0 -10px 36px rgba(15, 23, 42, .28);
  }
  .ac-form { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .ac-form textarea { font-size: 16px; } /* iOS zooms the page for smaller inputs */
  .ac-head { padding: 10px 12px; }
}

/* ------------------------------------------------------------ walkthrough */
.ac-guide-layer { position: fixed; inset: 0; z-index: 100000; pointer-events: none; display: none; }
.ac-guide-ring {
  position: fixed; display: none; border-radius: 12px; pointer-events: none;
  border: 3px solid rgb(var(--accent-rgb, 59, 130, 246));
  box-shadow: 0 0 0 9999px rgba(15, 23, 42, .42), 0 0 0 6px rgba(var(--accent-rgb, 59, 130, 246), .35);
  animation: ac-pulse 1.5s ease-in-out infinite;
  transition: left .18s ease, top .18s ease, width .18s ease, height .18s ease;
}
@keyframes ac-pulse {
  0%, 100% { border-color: rgb(var(--accent-rgb, 59, 130, 246)); }
  50% { border-color: #fff; }
}
.ac-guide-tip {
  position: fixed; display: none; pointer-events: auto; width: 290px; max-width: calc(100vw - 16px);
  background: #fff; color: #172033; border-radius: 12px; padding: 12px 14px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, .38); border: 1px solid rgba(15, 23, 42, .08);
  text-align: start; font-size: .9rem; line-height: 1.45;
}
body.dark-mode .ac-guide-tip { background: var(--dark-bg-card, #2c2c2e); color: var(--dark-text-primary, #f2f2f7); border-color: rgba(255, 255, 255, .14); }
.ac-guide-count { font-size: .7rem; font-weight: 800; letter-spacing: .04em; color: rgb(var(--accent-rgb, 59, 130, 246)); margin-bottom: 3px; }
body.dark-mode .ac-guide-count { color: rgb(var(--dark-accent-rgb, 96, 165, 250)); }
.ac-guide-note { font-weight: 700; font-size: .98rem; }
.ac-guide-hint { margin-top: 4px; font-size: .8rem; opacity: .75; }
.ac-guide-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.ac-guide-btn { border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: .8rem; cursor: pointer; }
.ac-guide-btn-main { background: rgb(var(--accent-rgb, 59, 130, 246)); color: #fff; }
body.dark-mode .ac-guide-btn-main { background: rgb(var(--dark-accent-rgb, 96, 165, 250)); color: #0b1220; }
.ac-guide-btn-ghost { background: transparent; color: inherit; opacity: .7; }
.ac-guide-btn-ghost:hover { opacity: 1; }
.ac-guide-actions { flex-wrap: wrap; }
.ac-guide-toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 100001;
  background: #16a34a; color: #fff; font-weight: 700; padding: 9px 20px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
@media (prefers-reduced-motion: reduce) {
  .ac-guide-ring { animation: none; transition: none; }
  .ac-dots i { animation: none; opacity: .6; }
}
