/* AI assistant: floating button + chat panel (assistant.js). BBB palette from
   styles.css: navy fills, line icons, 8px corners, no new accent colours. */

/* Same look as the menu button (.fab): light circle, navy line icon. */

.assistant-panel {
  position: fixed;
  z-index: 9;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(400px, 42vw);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--fg);
  border-left: 1px solid var(--btn-border);
  box-shadow: -2px 0 12px rgba(0, 16, 51, 0.12);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) 0;
  box-sizing: border-box;
  /* Body text is 2px smaller than the page (15px -> 13px) so more fits. */
  font-size: 13px;
  --as-small: 11px;           /* tables, footers, notes: 2px down, floor 11px */
  --as-input: 14px;
}
.assistant-panel[hidden] { display: none; }

/* Desktop: the report gets narrower instead of hiding behind the panel. */
@media (min-width: 769px) {
  body.assistant-open .report { right: min(400px, 42vw); }
  body.assistant-open .dock { right: calc(min(400px, 42vw) + 10px); }
}

/* Phone: a bottom sheet over the report. */
@media (max-width: 768px) {
  .assistant-panel {
    font-size: 13px;          /* phone floor for body text */
    --as-small: 12px;
    --as-input: 16px;         /* below 16px iOS zooms into the field */
    top: auto;
    left: 0;
    width: auto;
    height: 90vh;
    height: 90dvh;
    border-left: 0;
    border-top: 1px solid var(--btn-border);
    border-radius: 8px 8px 0 0;
    box-shadow: 0 -4px 16px rgba(0, 16, 51, 0.18);
    padding-left: env(safe-area-inset-left);
  }
  body.assistant-open .dock { display: none; }
}

.as-head {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 14px 12px 10px 16px;
  border-bottom: 1px solid var(--btn-border);
}
.as-title { flex: 1; min-width: 0; }
.as-title h2 { margin: 0; font-size: 14px; font-weight: 600; color: var(--ink); }
.as-context { margin: 2px 0 0; font-size: var(--as-small); color: var(--muted); opacity: 0.8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.as-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.as-icon:hover { background: var(--hover); }
.as-icon.is-on { background: var(--hover); }
.as-icon:focus-visible, .as-send:focus-visible, .as-starter:focus-visible, .assistant-fab:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.as-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.as-empty p { margin: 0 0 12px; color: var(--muted); }
.as-starters { display: flex; flex-direction: column; gap: 8px; }
.as-starter {
  text-align: left;
  padding: 10px 12px;
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.as-starter:hover { background: var(--hover); }

.as-msg { max-width: 100%; overflow-wrap: anywhere; }
.as-user {
  align-self: flex-end;
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 8px 8px 2px 8px;
  background: var(--accent);
  color: #FFFFFF;
  white-space: pre-wrap;
}
.as-bot { align-self: stretch; }
.as-bot p { margin: 0 0 8px; }
.as-bot ul, .as-bot ol { margin: 0 0 8px; padding-left: 20px; }
.as-bot code { font-size: 12px; padding: 1px 4px; border-radius: 4px; background: var(--hover); }
.as-error { color: var(--muted); padding: 8px 12px; border: 1px solid var(--btn-border); border-radius: 8px; }

/* Tables wrap to the panel instead of scrolling sideways. */
.as-list { container-type: inline-size; }
.as-table { margin: 0 0 8px; max-width: 100%; }
.as-table table { width: 100%; border-collapse: collapse; font-size: var(--as-small); line-height: 1.3; }
.as-table th, .as-table td { padding: 4px 6px; border-bottom: 1px solid var(--btn-border); text-align: left; vertical-align: top; white-space: normal; overflow-wrap: anywhere; }
.as-table th { font-weight: 600; color: var(--ink); font-size: var(--as-small); }
.as-table td:not(:first-child), .as-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: normal; word-break: normal; }

/* Narrow panel and many columns: each row becomes a small labelled card. */
@container (max-width: 460px) {
  .as-table.as-wide thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .as-table.as-wide table, .as-table.as-wide tbody, .as-table.as-wide tr, .as-table.as-wide td { display: block; width: 100%; box-sizing: border-box; }
  .as-table.as-wide tr { padding: 6px 0; border-bottom: 1px solid var(--btn-border); }
  .as-table.as-wide td { display: flex; justify-content: space-between; gap: 12px; padding: 1px 0; border: 0; text-align: right; }
  .as-table.as-wide td::before { content: attr(data-label); flex: none; max-width: 45%; color: var(--muted); text-align: left; }
  .as-table.as-wide td:first-child { font-weight: 600; color: var(--ink); justify-content: flex-start; text-align: left; }
  .as-table.as-wide td:first-child::before { display: none; }
}

.as-queued { opacity: 0.85; border: 1px dashed rgba(255, 255, 255, 0.6); display: flex; flex-direction: column; gap: 4px; }
.as-q-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--as-small); opacity: 0.85; }
.as-q-cancel { display: inline-flex; padding: 2px; border: 0; border-radius: 4px; background: transparent; color: inherit; cursor: pointer; }
.as-q-cancel:hover { background: rgba(255, 255, 255, 0.2); }
.as-q-cancel:focus-visible { outline: 2px solid #FFFFFF; }


.as-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: var(--as-small); }
.as-dax-toggle {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 0; border: 0; background: transparent;
  color: var(--muted); font: inherit; cursor: pointer;
}
.as-dax-toggle::before { content: ""; width: 6px; height: 6px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); transition: transform 0.15s; }
.as-dax-toggle[aria-expanded="true"]::before { transform: rotate(45deg); }
.as-dax-toggle:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.as-rate { display: flex; gap: 2px; margin-left: auto; }
.as-rate .as-icon { width: 28px; height: 28px; opacity: 0.65; }
.as-rate .as-icon.is-on, .as-rate .as-icon:hover { opacity: 1; }
/* The whole explanation sits in one rounded frame, like the Query box inside it. */
.as-dax-body { margin: 4px 0 6px; padding: 4px 12px 10px; border: 1px solid var(--btn-border); border-radius: 8px; background: var(--hover); font-size: var(--as-small); }
.as-dax-body[hidden] { display: none; }
.as-dax-body .as-q:first-child { margin-top: 4px; padding-top: 0; border-top: 0; }
.as-dax-body .as-q pre { background: var(--surface); border: 1px solid var(--btn-border); }
.as-q { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--btn-border); }
.as-q-title { margin: 0 0 4px; font-weight: 600; color: var(--fg); }
.as-q-res .as-table { margin: 0 0 2px; }
.as-q-res .as-table table { font-size: var(--as-small); }
.as-q-res .as-table th, .as-q-res .as-table td { text-align: left; }
.as-q-dax { margin-top: 4px; }
.as-q-dax summary { cursor: pointer; color: var(--muted); }
.as-q-dax pre { margin-top: 4px; }
.as-q-meta { margin: 0 0 4px; color: var(--muted); }
.as-q pre {
  margin: 0;
  padding: 8px;
  border-radius: 6px;
  background: var(--hover);
  white-space: pre-wrap;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.as-q-err { margin: 4px 0 0; color: var(--muted); }

.as-thinking { padding: 4px 0; }
.as-dots { display: inline-flex; gap: 4px; }
.as-dots i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink); opacity: 0.35;
  animation: as-blink 1.2s infinite ease-in-out;
}
.as-dots i:nth-child(2) { animation-delay: 0.2s; }
.as-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes as-blink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { .as-dots i { animation: none; opacity: 0.6; } }

.as-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 6px 16px;
  border-top: 1px solid var(--btn-border);
}
.as-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  box-sizing: border-box;
  height: 40px;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: var(--as-input);  /* 16px on phones stops iOS zooming into the field */
  line-height: 1.35;
}
.as-input:focus { outline: none; border-color: var(--ink); }
.as-send {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #FFFFFF;
  cursor: pointer;
}
.as-send:hover { background: var(--accent-hover); }
.as-send:disabled { opacity: 0.5; cursor: default; }
.as-note { margin: 0; padding: 0 16px 10px; font-size: var(--as-small); color: var(--muted); opacity: 0.75; }

.as-new:disabled { opacity: 0.45; cursor: default; }
.as-mic:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* Voice mode (voice.js): mic button next to Send (same size) and a slim status strip above the form. */
.as-mic {
  flex: none;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--btn-border);
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.as-mic[hidden] { display: none; }
.as-mic:hover:not(:disabled) { background: var(--hover); }
.as-mic:disabled { opacity: 0.5; cursor: default; }
.as-mic.is-live { background: var(--accent); border-color: var(--accent); color: #fff; }
.as-mic.is-live:hover { background: var(--accent-hover); }
.as-pending { opacity: 0.7; }
.vo-bar { padding: 6px 16px; border-top: 1px solid var(--btn-border); background: var(--surface); }
.vo-bar[hidden] { display: none; }
.vo-bar { display: flex; align-items: center; gap: 10px; }
.vo-status { margin: 0; font-size: 0.75rem; font-weight: 600; color: var(--ink); flex: 1; }
.vo-keep { flex: none; font: inherit; font-size: 0.75rem; font-weight: 600; padding: 4px 12px; border-radius: 6px; border: 0; background: var(--accent); color: #fff; cursor: pointer; }
.vo-keep:hover { background: var(--accent-hover); }
.vo-keep[hidden] { display: none; }
.as-mic.is-live.is-muted, .as-mic.is-live.is-muted:hover { background: transparent; border-color: var(--btn-border); color: var(--muted); }
.as-send.is-stop { background: var(--accent); }
