/* The whole site's styling.
 *
 * Tokens and names are lifted from backend/app/templates/admin/base.html so
 * the public site and the console look like one product. Dark mode follows
 * the operating system and has no toggle, for the same reason it does there:
 * a toggle is a preference to store, and this site stores nothing it does
 * not have to.
 */

:root { --bg:#fff; --fg:#15181d; --muted:#6b7280; --line:#e4e7ec; --card:#f7f8fa;
        --accent:#1f6f4a; --live:#2ea062; --warn:#c04b4b; --amber:#b5820a;
        --faint:#9aa1ad; }
@media (prefers-color-scheme: dark) {
  :root { --bg:#15181d; --fg:#e9ecf1; --muted:#98a1b0; --line:#2a2f38; --card:#1c2027;
          --accent:#43b07f; --live:#45c187; --warn:#e2726f; --amber:#d8a33c;
          --faint:#79818f; } }

* { box-sizing: border-box; }

/* 100dvh, not 100vh: on iOS Safari the address bar is counted in vh, so a
   full-height chat column would sit permanently under the browser chrome. */
html, body { height: 100%; }
body { margin:0; background:var(--bg); color:var(--fg);
  font:15px/1.6 system-ui,-apple-system,"Segoe UI",sans-serif;
  display:flex; flex-direction:column; min-height:100dvh; }

header { border-bottom:1px solid var(--line); padding:12px 20px; flex:0 0 auto; }
header .brand { color:var(--fg); text-decoration:none; font-weight:600; font-size:15px; }

main { width:100%; max-width:720px; margin:0 auto; padding:28px 20px 40px; flex:1 1 auto; }


h1 { font-size:22px; margin:0 0 4px; }
.sub { color:var(--muted); margin:0 0 24px; }
a { color:var(--accent); }
.muted { color:var(--muted); }
.small { font-size:13px; }

/* -- the picker, and any list of tappable cards -------------------------- */

.picker { list-style:none; margin:0; padding:0; display:grid; gap:12px; }

.card { background:var(--card); border:1px solid var(--line); border-radius:10px;
  padding:16px; }

/* A whole card as one hit target. Two lines, not a link inside a box: on a
   phone the box is the thing people aim at. */
a.tap { display:flex; flex-direction:column; gap:3px; text-decoration:none;
  color:var(--fg); }
a.tap .name { font-weight:600; color:var(--accent); }
a.tap:hover { border-color:var(--accent); }
a.tap:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }

/* -- buttons ------------------------------------------------------------- */

.btn { font:inherit; padding:7px 13px; border-radius:7px; cursor:pointer;
  border:1px solid var(--line); background:var(--bg); color:var(--fg);
  text-decoration:none; display:inline-block; }
.btn.primary { background:var(--accent); border-color:var(--accent); color:#fff; }
.btn:disabled { opacity:.55; cursor:not-allowed; }

.sr-only { position:absolute; width:1px; height:1px; padding:0; margin:-1px;
  overflow:hidden; clip:rect(0 0 0 0); white-space:nowrap; border:0; }

/* -- chat ---------------------------------------------------------------- */

/* The chat page is a column that fills the viewport: the message list
   scrolls, the composer stays put. Without this the whole page scrolls and
   the input walks off the bottom of a phone screen as the thread grows. */
main.chat { display:flex; flex-direction:column; min-height:0; padding-bottom:20px; }

.chat-head { display:flex; align-items:flex-start; justify-content:space-between;
  gap:16px; }
.chat-head .sub { margin-bottom:16px; }

.messages { flex:1 1 auto; overflow-y:auto; min-height:220px;
  display:flex; flex-direction:column; gap:12px; padding:4px 0 16px; }

.msg { max-width:85%; padding:10px 14px; border-radius:14px;
  overflow-wrap:anywhere; }
/* The visitor's own text keeps the line breaks they typed. An answer does
   not: it arrives as markdown and is rendered into real elements, so
   pre-wrap here would add a blank line either side of every paragraph. */
.msg.user .text { white-space:pre-wrap; }

/* Rendered markdown. First and last child lose their margin so a bubble
   hugs its content instead of carrying paragraph padding. */
.msg p, .msg ul { margin:0 0 9px; }
.msg > .text > :last-child { margin-bottom:0; }
.msg ul { padding-left:20px; }
.msg li { margin:2px 0; }
.msg li > ul { margin:4px 0 2px; }
.msg strong { font-weight:600; }
.msg.user { align-self:flex-end; background:var(--accent); color:#fff;
  border-bottom-right-radius:5px; }
.msg.assistant { align-self:flex-start; background:var(--card);
  border:1px solid var(--line); border-bottom-left-radius:5px; }
.msg.pending { color:var(--muted); font-style:italic; }
/* A rate limit or an outage reads as a message, because that is how the API
   reports it - but it should not look like an answer. */
.msg.degraded { border-color:var(--amber); color:var(--muted); }

.sources { margin-top:7px; line-height:1.5; }
.sources a { color:var(--accent); }

.composer { display:flex; gap:8px; align-items:flex-end;
  border-top:1px solid var(--line); padding-top:12px; }
.composer textarea { flex:1 1 auto; font:inherit; resize:none; overflow-y:auto;
  padding:9px 12px; border-radius:10px; border:1px solid var(--line);
  background:var(--bg); color:var(--fg); line-height:1.5; max-height:140px; }
.composer textarea:focus { outline:none; border-color:var(--accent); }
.composer .btn { flex:0 0 auto; }

/* Quieter than .muted on purpose: it must stay readable without competing
   with the answer above it. Overrides the .muted .small it carries. */
.disclaimer { margin:10px 0 0; font-size:11.5px; line-height:1.45;
              color:var(--faint); }

@media (max-width:560px) {
  .msg { max-width:92%; }
  .chat-head { flex-direction:column; gap:8px; }
}

/* -- the admin console --------------------------------------------------
 *
 * Reuses the tokens above rather than defining its own: one visitor-facing
 * site and one console, two audiences, one product. It is a page of text
 * with no JavaScript at all - the only reason it needs rules of its own is
 * that a transcript wants more width than a masjid page does.
 */

header { display:flex; align-items:center; gap:12px; }
header .spacer { flex:1; }
header .admin-tag { font-size:11px; text-transform:uppercase; letter-spacing:.06em;
  color:var(--muted); border:1px solid var(--line); border-radius:99px;
  padding:1px 8px; }

main.wide { max-width:860px; }

.err { background:var(--warn); color:#fff; padding:9px 13px; border-radius:8px;
  margin:0 0 16px; }
.bad { color:var(--warn); }
code { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:.92em; }

.signin { display:grid; gap:4px; max-width:320px; }
.signin label { display:block; margin-bottom:10px; }
.signin label span { display:block; font-size:12px; color:var(--muted);
  margin-bottom:3px; }
.signin input { width:100%; padding:8px 10px; border-radius:7px; font:inherit;
  border:1px solid var(--line); background:var(--bg); color:var(--fg); }
.signin input:focus { outline:none; border-color:var(--accent); }

.range { display:flex; gap:12px; align-items:baseline; margin:0 0 18px; }
.range a { color:var(--muted); text-decoration:none; }
.range a.on, .range a:hover { color:var(--accent); }

/* auto-fit rather than a fixed count: the strip gains a column when there
   are turns the chatbot refused, and must not reflow to one per line. */
.totals { list-style:none; margin:0 0 10px; padding:16px;
  display:grid; grid-template-columns:repeat(auto-fit,minmax(90px,1fr)); gap:12px; }
.totals b { display:block; font-size:19px; font-variant-numeric:tabular-nums; }
.totals span { font-size:12px; color:var(--muted); }

.convo { margin-top:16px; padding:0; overflow:hidden; }
.convo-head { display:flex; flex-wrap:wrap; gap:4px 10px; align-items:baseline;
  padding:12px 16px; border-bottom:1px solid var(--line); }

.turn { padding:14px 16px; }
.turn + .turn { border-top:1px solid var(--line); }
.turn p { margin:0 0 6px; }
.turn .q { font-weight:600; }
.turn .a { white-space:pre-wrap; }
.turn .searched { margin-top:-3px; font-style:italic; }
.turn .meta { margin-bottom:0; font-variant-numeric:tabular-nums; }
/* A turn the chatbot could not answer is a fact about the service, not an
   answer, and is marked the same way the chat window marks one. */
.turn.degraded { border-left:3px solid var(--amber); }

@media (max-width:560px) {
  .totals { grid-template-columns:repeat(auto-fit,minmax(80px,1fr)); }
}
