/* Ask PI (OneStop batch 4, R3): the chat of Client\Apps\AskPi (AskPiChat, AskPiAnswerCard, AskPiTrendChart, the log).
   Prefix ap-. Colours: the tokens of app.css only (light and dark), the brand gold (--brand-gold) for the ask button.
   Layouts: two columns from 1100 px (the chat, the history on the right), one below; checked at 360, 768 and 1280 px. */

.ap-page {
  /* The anchor of the hidden labels (.ap-sr is absolute): without it they sit against the window, far below, and the window
     scrolls as well as the page (owner: "two scrolls") */
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  /* The whole width of the page (the owner, 2026-11-06: every app uses the page width; 1440 px before) */
  width: 100%;
}
@media (min-width: 1100px) {
  .ap-page { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  /* One scroll only (owner: "two scroll on that page"): the panel sits in the page, it does not scroll by itself */
  .ap-side { position: static; max-height: none; overflow: visible; }
}
.ap-main { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.ap-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- Introduction and examples ---- */
.ap-intro { display: flex; flex-direction: column; gap: 14px; padding: 18px 20px; }
.ap-intro-head { display: flex; align-items: flex-start; gap: 14px; }
.ap-intro-head .spacer { flex: 1; }
.ap-intro h2 { margin: 2px 0 4px; font-size: 1.35rem; font-weight: 900; }
.ap-intro-text { margin: 0; color: var(--muted); max-width: 70ch; }
.ap-intro-icon, .ap-setup-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: var(--gold-soft);
  color: var(--gold-text);
}
.ap-facts-row { display: flex; flex-wrap: wrap; gap: 8px 16px; color: var(--muted); font-size: 0.84rem; }
.ap-facts-row > span { display: inline-flex; align-items: center; gap: 5px; }
.ap-examples-label { color: var(--muted); font-size: 0.78rem; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; }
.ap-examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.ap-example {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.88rem;
  line-height: 1.35;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.ap-example .mud-icon-root { flex: none; margin-top: 1px; color: var(--gold-text); }
.ap-example:hover:not(:disabled) { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.ap-example:disabled { cursor: default; opacity: 0.55; }

.ap-loading { gap: 10px; }
.ap-skeleton {
  height: 14px;
  width: 55%;
  margin: 6px 0;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--chip) 0%, var(--chip-hover) 50%, var(--chip) 100%);
  background-size: 200% 100%;
  animation: ap-shimmer 1.4s infinite linear;
}
.ap-skeleton.wide { width: 85%; height: 18px; }
@keyframes ap-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* Not set up, Development */
.ap-setup { display: flex; align-items: flex-start; gap: 14px; padding: 18px 20px; border-left: 5px solid var(--brand-gold); }
.ap-setup h2 { margin: 2px 0 6px; font-size: 1.1rem; }
.ap-setup p { margin: 4px 0; }
.ap-dev {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--info-soft);
  color: var(--info);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ---- The conversation ---- */
.ap-conversation { display: flex; flex-direction: column; gap: 22px; }
.ap-turn { display: flex; flex-direction: column; gap: 10px; scroll-margin-top: 12px; }
.ap-question { align-self: flex-end; max-width: min(78%, 720px); }
.ap-question-text {
  padding: 10px 14px;
  border-radius: 16px 16px 4px 16px;
  background: var(--os-accent);
  color: var(--os-on-accent);
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.ap-question-meta { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; color: var(--faint); font-size: 0.76rem; }
.ap-question-meta > span { display: inline-flex; align-items: center; gap: 3px; }

.ap-answer { display: flex; align-items: flex-start; gap: 10px; }
.ap-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--os-accent);
  color: var(--os-on-accent);
}
.ap-answer-body {
  flex: 1;
  min-width: 0;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.ap-text { margin: 0; font-size: 1.02rem; line-height: 1.55; white-space: pre-line; overflow-wrap: anywhere; }

/* While it runs */
.ap-steps { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.ap-steps li { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.ap-steps li.done .mud-icon-root { color: var(--good); }
.ap-steps li.current { color: var(--text); font-weight: 600; }
.ap-running-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; }
.ap-stop { display: inline-flex; align-items: center; gap: 5px; }
.ap-spinner {
  display: inline-block;
  flex: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--chip-hover);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: ap-spin 0.8s linear infinite;
}
.ap-spinner.light { border-color: rgba(46, 46, 46, 0.25); border-top-color: #2e2e2e; }
@keyframes ap-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .ap-spinner { animation-duration: 2.4s; }
  .ap-skeleton { animation: none; }
  .ap-example { transition: none; }
}

/* Status, warning */
.ap-status {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 8px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--chip-text);
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}
.ap-status.good { background: var(--good-soft); color: var(--good-text); }
.ap-status.warn { background: var(--warn-soft); color: var(--warn); }
.ap-status.bad { background: var(--bad-soft); color: var(--bad); }
.ap-log-table .ap-status { margin-bottom: 0; }
.ap-warning {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin: 10px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--note-soft);
  color: var(--warn);
  font-size: 0.86rem;
  font-weight: 600;
}

/* ---- How it was computed ---- */
.ap-how, .ap-trend-box, .ap-matches { margin-top: 14px; }
.ap-how-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.ap-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
.ap-card { min-width: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--head-bg); }
.ap-card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px; }
.ap-card-kind { font-size: 0.82rem; font-weight: 900; }
.ap-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--gold-soft);
  color: var(--gold-text);
  font-size: 0.74rem;
  font-weight: 800;
}
.ap-chip.bad { background: var(--bad-soft); color: var(--bad); }
.ap-card-value { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; margin: 6px 0 8px; }
.ap-card-value b { font-size: 1.75rem; font-weight: 900; line-height: 1.1; font-variant-numeric: tabular-nums; }
.ap-card-value > span { color: var(--muted); font-weight: 700; }
.ap-card-sub { flex-basis: 100%; font-size: 0.82rem; }
.ap-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 10px; margin: 0; font-size: 0.82rem; }
.ap-facts dt { color: var(--muted); font-weight: 700; }
.ap-facts dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.ap-source { font-weight: 700; }
.ap-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: 4px;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--code-bg);
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.78rem;
}
.ap-path { color: var(--muted); font-family: Consolas, "Cascadia Mono", monospace; font-size: 0.76rem; }

/* The trend */
.ap-trend { position: relative; margin: 0; padding: 8px 0 0 56px; }
.ap-trend svg { display: block; width: 100%; height: 150px; overflow: visible; }
.ap-trend-grid { stroke: var(--rule); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ap-trend-area { fill: var(--accent-soft); opacity: 0.85; }
.ap-trend-line { fill: none; stroke: var(--accent); stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.ap-trend-dot { fill: transparent; }
.ap-trend-dot:hover { fill: var(--brand-gold); }
.ap-trend-y {
  position: absolute;
  top: 8px;
  left: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 52px;
  height: 150px;
  color: var(--muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.ap-trend-x { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; color: var(--muted); font-size: 0.74rem; }
.ap-trend-units { font-weight: 800; }

/* Closest matches, usage */
.ap-matches ul { display: flex; flex-direction: column; gap: 4px; margin: 0; padding-left: 18px; font-size: 0.88rem; }
.ap-usage {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 14px;
  padding-top: 10px;
  border-top: 1px solid var(--rule);
  color: var(--faint);
  font-size: 0.76rem;
}
.ap-usage > span { display: inline-flex; align-items: center; gap: 4px; }
.ap-cost { color: var(--muted); font-weight: 800; }

/* ---- The question box ---- */
.ap-ask {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.ap-ask.sticky { position: sticky; bottom: 8px; z-index: 3; }
.ap-ask:focus-within { border-color: var(--accent); }
.ap-input {
  flex: 1;
  min-width: 0;
  padding: 10px 8px;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}
.ap-input::placeholder { color: var(--faint); }
.ap-scope {
  max-width: 190px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--field);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
}
.ap-send {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--os-accent-fill);
  color: var(--os-on-accent-fill);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
}
.ap-send:hover:not(:disabled) { background: var(--os-accent-fill-hover); }
.ap-send:disabled { cursor: not-allowed; opacity: 0.5; }
.ap-ask-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 16px; padding: 0 6px; }
.ap-example:focus-visible, .ap-send:focus-visible, .ap-scope:focus-visible, .ap-history-item:focus-visible, .ap-log-row:focus-visible {
  outline: 2px solid var(--brand-gold);
  outline-offset: 2px;
}

/* ---- History ---- */
.ap-side { min-width: 0; padding: 14px; }
.ap-side-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.ap-side-head h2 { margin: 0; font-size: 1rem; font-weight: 800; }
.ap-history { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; }
.ap-history-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 2px 8px;
  width: 100%;
  padding: 8px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.ap-history-item:hover { background: var(--accent-soft); }
.ap-history-text { display: -webkit-box; overflow: hidden; font-size: 0.86rem; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.ap-history-meta { grid-column: 2; color: var(--faint); font-size: 0.74rem; }
.ap-dot { width: 9px; height: 9px; margin-top: 5px; border-radius: 50%; background: var(--faint); }
.ap-dot.good { background: var(--good); }
.ap-dot.warn { background: var(--warn); }
.ap-dot.bad { background: var(--bad); }
.ap-dot.running { background: var(--brand-gold); }

/* ---- Log ---- */
.ap-log { display: flex; flex-direction: column; gap: 14px; width: 100%; }
.ap-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.ap-log-table { padding: 0; overflow-x: auto; }
.ap-log-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ap-log-table .nowrap { white-space: nowrap; }
.ap-log-row { cursor: pointer; }
.ap-log-row:hover { background: var(--accent-soft); }
.ap-log-question { min-width: 220px; max-width: 460px; overflow-wrap: anywhere; }
.ap-opened .ap-turn { margin-top: 4px; }

/* ---- Phones ---- */
@media (max-width: 600px) {
  .ap-intro { padding: 14px; }
  .ap-intro h2 { font-size: 1.15rem; }
  .ap-intro-head .m2-guide-button { display: none; }
  .ap-examples { grid-template-columns: minmax(0, 1fr); }
  .ap-question { max-width: 92%; }
  .ap-avatar { display: none; }
  .ap-answer-body { padding: 12px; border-radius: 12px; }
  .ap-cards { grid-template-columns: minmax(0, 1fr); }
  .ap-card-value b { font-size: 1.45rem; }
  .ap-trend { padding-left: 44px; }
  .ap-trend-y { width: 40px; }
  .ap-ask { flex-wrap: wrap; }
  .ap-ask.sticky { position: static; }
  .ap-scope { flex: 1 1 100%; max-width: none; }
  .ap-send-text { display: none; }
  .ap-send { padding: 10px 12px; }
}

/* Conversations (V1.26): the list like a chat's, the one on screen marked, rename and remove on the right */
.ap-new {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid var(--accent, #a88d60);
  border-radius: 999px; background: transparent; color: inherit; font: inherit; font-size: 0.82rem; font-weight: 700; cursor: pointer;
}
.ap-new:hover:not(:disabled) { background: var(--accent-soft); }
.ap-new:disabled { opacity: 0.5; cursor: default; }
.ap-new:focus-visible, .ap-conv-action:focus-visible { outline: 2px solid var(--accent, #a88d60); outline-offset: 2px; }
.ap-conv { position: relative; display: flex; align-items: stretch; border-radius: 8px; }
.ap-conv.current { background: var(--accent-soft); }
.ap-conv .ap-history-item { grid-template-columns: minmax(0, 1fr); flex: 1 1 auto; min-width: 0; }
.ap-conv .ap-history-meta { grid-column: 1; }
.ap-conv-actions { display: flex; align-items: center; gap: 0; padding-right: 4px; opacity: 0; }
.ap-conv:hover .ap-conv-actions, .ap-conv:focus-within .ap-conv-actions { opacity: 1; }
.ap-conv-action { display: inline-flex; padding: 4px; border: 0; border-radius: 6px; background: transparent; color: var(--faint); cursor: pointer; }
.ap-conv-action:hover { background: var(--accent-soft); color: inherit; }
@media (hover: none) { .ap-conv-actions { opacity: 1; } }

/* V1.26 (owner's remarks): the model choice as a
   quiet line under the question box, the tables of answers */
.ap-ask-foot { flex-wrap: wrap; align-items: center; gap: 4px 16px; }
.ap-model { display: inline-flex; align-items: center; gap: 4px; color: var(--faint); font-size: 0.78rem; }
.ap-model select {
  max-width: 190px; padding: 1px 2px; border: 0; border-bottom: 1px dotted var(--border); border-radius: 0; background: transparent;
  color: var(--muted); font: inherit; cursor: pointer;
}
.ap-model select:hover:not(:disabled) { color: inherit; border-bottom-color: currentColor; }
.ap-model select:focus-visible { outline: 2px solid var(--accent, #a88d60); outline-offset: 2px; }
.ap-scope:disabled { opacity: 0.75; cursor: not-allowed; }
.ap-table-wrap { max-width: 100%; margin: 4px 0; overflow-x: auto; }
.ap-table { border-collapse: collapse; font-size: 0.95rem; }
.ap-table th, .ap-table td { padding: 6px 14px; border-bottom: 1px solid var(--border); text-align: left; }
.ap-table th { color: var(--muted); font-size: 0.8rem; font-weight: 800; letter-spacing: 0.3px; text-transform: uppercase; white-space: nowrap; }
.ap-table td:not(:first-child), .ap-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.ap-more { width: 100%; margin-top: 6px; padding: 6px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font: inherit; font-size: 0.82rem; cursor: pointer; }
.ap-more:hover { background: var(--accent-soft); color: inherit; }
