/* "Ask Waypoint", the chat box (issue 197). Only on a page built or served with --chat-url (web/chat_build.py).
   Uses the page's own colours and typefaces from style.css. The look is web/design/final.html (Dev, 2026-11-17):
   a plain box, a short answer with its sources, one line of small print. No avatar, no greeting, no glow.
   Where it sits: beside the plan in #side from 1041px; below that, a bar fixed to the bottom of the screen that
   opens it. On a page with no #side it sits above the footer, as it always did. */
.chat { margin-top: 28px; margin-bottom: 8px; }
.chat-card { background: var(--card); border-radius: var(--radius); padding: 24px; }
.chat-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.chat h2 { font-family: var(--display); font-size: 1.15rem; font-weight: 600; margin: 0 0 12px; }
.chat p { margin: 6px 0; }
.chat-open, .chat-close { display: none; font: inherit; cursor: pointer; }
.chat-log { margin: 4px 0 16px; display: flex; flex-direction: column; gap: 12px; }
.chat-turn { overflow-wrap: anywhere; }
/* the student's words: a quiet block on the right. The answer: plain text on the panel, nothing around it. */
.chat-turn.you { background: var(--wash); border-radius: 10px; padding: 8px 12px; align-self: flex-end; max-width: 90%; }
.chat-turn.refused { border-left: 2px solid var(--warn); padding-left: 12px; }
.chat .chat-who { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* "Sources" comes after the answer's text and is shown, small */
.chat-turn .chat-text ~ .chat-who { position: static; width: auto; height: auto; margin: 8px 0 0; overflow: visible; clip: auto;
  font-size: 0.8rem; font-weight: 400; color: var(--fine); }
.chat .chat-text { white-space: pre-wrap; margin: 0; }
.chat-sources { margin: 2px 0 0; padding-left: 18px; font-size: 0.85rem; color: var(--fine); }
.chat-sources a { color: var(--soft); }
.chat-ask { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
#chat-input { display: block; font: inherit; width: 100%; min-height: 48px; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; background: transparent; color: var(--ink); resize: vertical; }
#chat-input::placeholder { color: var(--fine); }
#chat-input:focus-visible, .chat-open:focus-visible, .chat-close:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.chat-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 8px; }
.chat-status.chat-problem { color: var(--danger); }
.chat .chat-fine { font-size: 0.8rem; color: var(--fine); margin: 12px 0 0; }
/* What the chat reads and what leaves the device: after the box, small, always there to read */
.chat-about { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.chat-about .quiet { font-size: 0.8rem; color: var(--fine); }
.chat-switch { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 0.9rem; }
.chat-switch input { width: 20px; height: 20px; margin: 0; flex: none; accent-color: var(--accent); }
.chat-switch label { cursor: pointer; }
.chat .chat-save { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }
.chat .chat-save .chat-status { display: block; overflow-wrap: anywhere; }

/* Beside the plan */
#side .chat { margin: 0; }

/* A phone, on a page with the column: a bar at the bottom that opens the chat as a sheet */
@media (max-width: 1040px) {
  #side:not(:empty) { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; }
  #side .chat-open { display: block; width: 100%; min-height: 64px; padding: 0 20px; text-align: left; color: var(--fine);
    background: var(--card); border: 0; border-top: 1px solid var(--line); font-size: 1rem; }
  #side .chat-card { display: none; }
  #side .chat.open .chat-open { display: none; }
  #side .chat.open .chat-card { display: block; max-height: 85vh; overflow-y: auto; border-radius: var(--radius) var(--radius) 0 0;
    border-top: 1px solid var(--line); padding: 20px; }
  #side .chat.open .chat-close { display: inline-block; background: none; border: 0; color: var(--ink); text-decoration: underline;
    text-underline-offset: 3px; padding: 4px 0; }
  .chat-turn.you { max-width: 100%; }
}
@media (max-width: 600px) {
  .chat-card { padding: 16px; }
}
@media print { .chat, #side { display: none; } }
