/* Script assistant: the panel inside the task dialog, and the admin spend page.
   Logical properties throughout so nothing needs mirroring for RTL. */

/* ── Panel ────────────────────────────────────────────────────────────────── */
.ai-panel {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.ai-head { display: flex; align-items: center; gap: 0.5rem; }

.ai-title {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}
.ai-title .icon { color: var(--mms-primary); }

.ai-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }

.ai-action {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-full);
  padding-block: 0.34rem;
  padding-inline: 0.75rem;
  font: inherit;
  font-size: 0.83rem;
  cursor: pointer;
  transition: background var(--dur-tap) var(--ease-out-quart),
              border-color var(--dur-tap) var(--ease-out-quart),
              transform var(--dur-tap) var(--ease-out-quart);
}
.ai-action:hover:not(:disabled) {
  background: var(--mms-primary-soft);
  border-color: var(--mms-primary);
}
.ai-action:active:not(:disabled) { transform: scale(0.97); }
.ai-action:disabled { opacity: 0.5; cursor: default; }

.ai-thread {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-block-size: 340px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.ai-thread:empty { display: none; }

.ai-msg {
  border-radius: var(--r-md);
  padding: 0.55rem 0.7rem;
  font-size: 0.88rem;
  line-height: 1.75;
  animation: ai-in var(--dur-base) var(--ease-out-quart) both;
}

@keyframes ai-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

.ai-user {
  align-self: flex-start;
  background: var(--mms-primary);
  color: var(--on-primary);
  max-inline-size: 85%;
  font-size: 0.84rem;
}

.ai-assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}
.ai-assistant.is-error { border-color: var(--mms-danger); color: var(--mms-danger); }

/* The model returns plain text with its own line breaks; honour them instead
   of parsing markdown we would then have to sanitize. */
.ai-body { white-space: pre-wrap; overflow-wrap: anywhere; }

.ai-tag {
  display: inline-block;
  margin-block-end: 0.3rem;
  font-size: 0.7rem;
  color: var(--mms-primary);
  background: var(--mms-primary-soft);
  border-radius: var(--r-full);
  padding-block: 0.1rem;
  padding-inline: 0.45rem;
}

.ai-tools {
  display: flex;
  gap: 0.25rem;
  margin-block-start: 0.4rem;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out-quart);
}
.ai-msg:hover .ai-tools,
.ai-msg:focus-within .ai-tools { opacity: 1; }
.is-streaming .ai-tools { display: none; }

/* Caret while the answer is still arriving - the one signal that the panel is
   working, without a spinner competing with text that is already readable. */
.is-streaming .ai-body::after {
  content: '';
  display: inline-block;
  inline-size: 2px;
  block-size: 1em;
  vertical-align: text-bottom;
  margin-inline-start: 2px;
  background: var(--mms-primary);
  animation: ai-caret 900ms steps(2, start) infinite;
}
@keyframes ai-caret { 50% { opacity: 0; } }

.ai-compose { display: flex; gap: 0.35rem; }

@media (prefers-reduced-motion: reduce) {
  .ai-msg { animation: none; }
  .is-streaming .ai-body::after { animation: none; }
  .ai-thread { scroll-behavior: auto; }
}

/* Coarse pointers have no hover, so the tools would never appear. */
@media (pointer: coarse) {
  .ai-tools { opacity: 1; }
}

/* ── Admin spend page ─────────────────────────────────────────────────────── */
.aiu-spark {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  block-size: 70px;
  margin-block-start: 0.75rem;
}
.aiu-spark-bar {
  flex: 1;
  min-block-size: 2px;
  background: var(--mms-primary);
  border-radius: 2px 2px 0 0;
  opacity: 0.85;
  transition: opacity var(--dur-fast) var(--ease-out-quart);
}
.aiu-spark-bar:hover { opacity: 1; }
.aiu-spark-bar.is-empty { background: var(--border); }

.aiu-table { inline-size: 100%; border-collapse: collapse; font-size: 0.85rem; }
.aiu-table th,
.aiu-table td {
  text-align: start;
  padding: 0.45rem 0.5rem;
  border-block-end: 1px solid var(--border);
  white-space: nowrap;
}
.aiu-table th { color: var(--text-2); font-weight: 600; }
.aiu-table td.num { font-variant-numeric: tabular-nums; }
.aiu-fail { color: var(--mms-danger); }

.aiu-scroll { overflow-x: auto; }
