/* Ask: floating chat widget + #ask teaser. Shared look (.card, .btn, .chip, inputs, tables, .sec-head) comes from styles.css. */

/* ---- floating button: above the back-to-top button (44px at 16px) and the mobile result bar (sim.js .sim-bar, ~56px) ---- */
.ask-fab { position: fixed; right: var(--space-4); bottom: calc(var(--space-4) + 44px + 12px); z-index: 60; display: inline-flex; align-items: center; gap: var(--space-2);
  min-height: 48px; padding: 0 var(--space-5) 0 var(--space-4); border-radius: 999px; border: 0; cursor: pointer; font: inherit; font-weight: 650;
  background: var(--accent); color: var(--accent-fg); box-shadow: var(--shadow-lg); }
.ask-fab:hover { filter: brightness(1.08); }
.ask-fab:focus-visible { outline: 2px solid var(--fg); outline-offset: 3px; }
.ask-fab[hidden] { display: none; }
.ask-fab-dot { position: absolute; top: 4px; right: 4px; width: 14px; height: 14px; border-radius: 50%; background: var(--good); border: 2px solid var(--surface); }
.ask-fab-dot[hidden] { display: none; }
@media (max-width: 960px) { .ask-fab { bottom: calc(var(--space-7) + 24px + 44px + 12px); } }

/* ---- widget ---- */
.ask-widget { position: fixed; right: var(--space-4); bottom: var(--space-4); z-index: 70; width: 380px; height: min(560px, calc(100dvh - 2 * var(--space-4)));
  display: flex; flex-direction: column; background: var(--surface); color: var(--fg); border: 1px solid var(--border-strong); border-radius: 16px;
  box-shadow: var(--shadow-lg); overflow: hidden; }
.ask-widget[hidden] { display: none; }
.ask-head { display: flex; align-items: center; gap: var(--space-1); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); background: var(--surface-2); }
.ask-head-txt { flex: 1; min-width: 0; }
.ask-head h2 { margin: 0; font-size: var(--fs-base); line-height: 1.25; }
.ask-badge { padding: var(--space-2) var(--space-4); font-size: var(--fs-xs); color: var(--good); font-weight: 600; line-height: 1.3; border-bottom: 1px solid var(--border); }
.ask-hbtn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.5rem; line-height: 1; cursor: pointer; flex: none; }
.ask-hbtn:hover { background: var(--border); color: var(--fg); }
.ask-hbtn:focus-visible, .ask-widget .btn:focus-visible, .ask-widget .chip:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.ask-log { flex: 1; min-height: 0; overflow-y: auto; padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-3); overscroll-behavior: contain; }
.ask-empty[hidden] { display: none; }
.ask-empty-h { margin: 0 0 var(--space-1); font-weight: 650; }
.ask-can, .ask-cant { margin: 0 0 var(--space-1); font-size: var(--fs-sm); line-height: 1.5; }
.ask-cant { color: var(--muted); }
.ask-starters { display: flex; flex-direction: column; gap: var(--space-3); margin-top: var(--space-3); }
.ask-sgroup { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.ask-sg-l { font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ask-chip { min-height: 40px; height: auto; padding-top: var(--space-2); padding-bottom: var(--space-2); text-align: left; line-height: 1.35; white-space: normal; }
.ask-chip:disabled { opacity: .5; cursor: not-allowed; }

/* ---- messages ---- */
.ask-msg { padding: var(--space-3) var(--space-4); border-radius: var(--radius); border: 1px solid var(--border); max-width: 100%;
  line-height: 1.55; overflow-wrap: anywhere; font-size: var(--fs-sm); }
.ask-msg > :first-child { margin-top: 0; }
.ask-msg > :last-child { margin-bottom: 0; }
.ask-user { align-self: flex-end; max-width: 88%; background: var(--accent); color: var(--accent-fg); border-color: var(--accent); border-bottom-right-radius: var(--radius-sm); }
.ask-bot { align-self: stretch; background: var(--surface); }
.ask-loading { color: var(--muted); }
.ask-error { background: var(--surface); color: var(--bad); border-color: var(--bad); display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-3); }
.ask-limit { color: var(--fg); border-color: var(--border-strong); background: var(--surface-2); }
.ask-err-t { line-height: 1.5; }

.ask-msg p { margin: 0 0 var(--space-2); }
.ask-msg ul, .ask-msg ol { margin: 0 0 var(--space-2); padding-left: var(--space-5); }
.ask-msg h3, .ask-msg h4, .ask-msg h5, .ask-msg h6 { font-size: var(--fs-sm); margin: var(--space-3) 0 var(--space-2); }
.ask-msg code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.ask-msg pre { font-family: var(--mono); font-size: var(--fs-xs); background: var(--surface-2); padding: var(--space-2); border-radius: var(--radius-sm); overflow-x: auto; margin: var(--space-1) 0; }
.ask-msg pre code { background: none; padding: 0; }
.ask-msg em:only-child { color: var(--muted); font-size: var(--fs-xs); }
.ask-tablewrap { margin: 0 0 var(--space-3); }
.ask-msg table { font-size: var(--fs-xs); }
.ask-msg table td, .ask-msg table th { white-space: nowrap; }

/* result card */
.ask-card { background: var(--surface-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius-sm); padding: var(--space-3) var(--space-4); margin-bottom: var(--space-3); }
.ask-card-top { display: flex; align-items: baseline; gap: var(--space-2); flex-wrap: wrap; }
.ask-card-fig { font-size: var(--fs-xl); font-weight: 750; font-variant-numeric: tabular-nums; line-height: 1.2; }
.ask-card-unit { font-size: var(--fs-xs); color: var(--muted); }
.ask-card-place { font-weight: 650; margin-top: 2px; }
.ask-card-sub { font-size: var(--fs-xs); color: var(--muted); margin-top: 2px; }
.ask-text > :last-child { margin-bottom: var(--space-2); }

.ask-assume { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); margin: var(--space-2) 0 var(--space-3); }
.ask-assume-l { width: 100%; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ask-tag { font-size: var(--fs-xs); padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--fg); }
.ask-sim { margin-bottom: var(--space-2); min-height: 40px; }

.ask-calls { margin-top: var(--space-2); font-size: var(--fs-xs); color: var(--muted); }
.ask-calls summary { cursor: pointer; min-height: 32px; display: flex; align-items: center; }
.ask-calls ol { margin: var(--space-1) 0 0; padding-left: var(--space-5); }
.ask-actions { margin-top: var(--space-2); display: flex; gap: var(--space-2); }
.ask-followups { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-2); }
.ask-stopped { margin: var(--space-2) 0 0; }

.ask-progress { display: flex; align-items: center; gap: var(--space-2); color: var(--muted); font-size: var(--fs-sm); }
.ask-streaming .ask-progress { margin-bottom: var(--space-2); }
.ask-body:empty { display: none; }
.ask-dots { display: inline-flex; gap: 3px; }
.ask-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: ask-bounce 1s infinite; }
.ask-dots i:nth-child(2) { animation-delay: .15s; }
.ask-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes ask-bounce { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ask-dots i { animation: none; opacity: .6; } }

/* ---- input ---- */
.ask-form { border-top: 1px solid var(--border); padding: var(--space-3) var(--space-4) var(--space-3); display: flex; flex-direction: column; gap: var(--space-2); background: var(--surface); }
.ask-row { display: flex; gap: var(--space-2); align-items: flex-end; }
.ask-input { flex: 1; min-height: 44px; max-height: 120px; resize: none; font-size: 16px; }
.ask-send, .ask-stop { min-height: 44px; padding: 0 var(--space-4); }
.ask-form .check { margin: 0; font-size: var(--fs-sm); }
.ask-ctx-prev { background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); }
.ask-note { margin: 0; font-size: var(--fs-xs); color: var(--muted); line-height: 1.4; }

/* ---- teaser in #ask ---- */
.ask-teaser { display: flex; flex-direction: column; gap: var(--space-4); align-items: flex-start; }
.ask-teaser .ask-starters { margin-top: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4); width: 100%; }

/* ---- phones: full-screen sheet; height follows the visual viewport so the input stays above the keyboard ---- */
@media (max-width: 560px) {
  .ask-widget { inset: 0 auto auto 0; width: 100%; height: var(--ask-vh, 100dvh); max-height: 100dvh; border: 0; border-radius: 0; z-index: 80; }
  .ask-hbtn { width: 48px; height: 48px; }
  .ask-head { padding-top: calc(var(--space-2) + env(safe-area-inset-top)); }
  .ask-form { padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom)); }
  .ask-chip { min-height: 48px; }
  .ask-send, .ask-stop, .ask-input { min-height: 48px; }
  .ask-widget .btn.sm { min-height: 44px; }
  .ask-widget .ask-ctx { min-height: 44px; display: flex; align-items: center; }
  html.ask-is-open { overflow: hidden; }
}
