/* Oraakkeli Web's styles: the sign-in and error pages (TODO.md T10), the
   chat page (T11) and the admin page (T12). Plain CSS, a few variables, no framework: short enough to
   read in one sitting. No style is set inline in the pages: the
   Content-Security-Policy allows only this file (main._SECURITY_HEADERS). */

:root {
  --bg:       #f6f7f9;
  --surface:  #ffffff;
  --border:   #dcdfe4;
  --text:     #1f2328;
  --muted:    #59636e;
  --accent:   #0f6cbd;
  --accent-2: #115ea3;
  --error:    #b42318;
  --error-bg: #fdeceb;
  --radius:   0.5rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* `hidden` must win over the display rules below. */
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.spacer { flex: 1; }

/* The sign-in link and every button look alike; .ghost is the quiet kind. */
.button,
button {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0.375rem;
  font: inherit;
  color: #fff;
  background: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.button:hover,
button:hover { background: var(--accent-2); }
button:disabled { opacity: 0.5; cursor: default; }
button.ghost,
.button.ghost {
  color: var(--text);
  background: transparent;
  border: 1px solid var(--border);
  padding: 0.3rem 0.75rem;
}
button.ghost:hover,
.button.ghost:hover { background: var(--bg); }

/* --------------------------------------------- the sign-in and error pages */
.page {
  max-width: 40rem;
  margin: 4rem auto;
  padding: 0 1rem;
}

/* ------------------------------------------------------------- the chat page */
/* The page is the window's height: the transcript scrolls between the bar
   and the question box, which stay put. */
body.chat {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.chat-width {
  width: 100%;
  max-width: 48rem;
  margin-left: auto;
  margin-right: auto;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar form { margin: 0; }
.brand { font-weight: 650; font-size: 1.1rem; }
.who { color: var(--muted); }

/* The sites, a fold-out under the bar. */
.sites { position: relative; }
.sites summary { cursor: pointer; color: var(--muted); }
.sites-panel {
  position: absolute;
  right: 0;
  z-index: 1;
  width: 22rem;
  margin-top: 0.5rem;
  padding: 0.25rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.08);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.welcome {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.welcome h2 { margin-top: 0; font-size: 1.2rem; }
.warning { color: var(--error); }

/* An Admin's demo (T62): under the bar, on every load, never missed. */
.demo-banner {
  margin: 0;
  padding: 0.5rem 1rem;
  color: var(--error);
  background: var(--error-bg);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.msg { margin: 1rem auto; }
.msg-role {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.msg-body {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
}
/* The user's question exactly as typed, its line breaks included. */
.msg.user .msg-body { white-space: pre-wrap; background: #eef4fb; }
.msg.error .msg-body { color: var(--error); background: var(--error-bg); border-color: #f3c7c3; }

/* A caret while the answer is still coming. */
.msg-body.streaming::after {
  content: "▍";
  animation: blink 1s steps(1) infinite;
  color: var(--muted);
}
@keyframes blink { 50% { opacity: 0; } }

/* The answer's Markdown (markdown.js). */
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown h3, .markdown h4, .markdown h5, .markdown h6 { margin: 1rem 0 0.5rem; font-size: 1rem; }
.markdown h3 { font-size: 1.1rem; }
.markdown p { margin: 0.5rem 0; }
.markdown ul, .markdown ol { margin: 0.5rem 0; padding-left: 1.5rem; }
.markdown code {
  font-family: ui-monospace, monospace;
  font-size: 0.9em;
  background: var(--bg);
  padding: 0.1em 0.3em;
  border-radius: 0.25rem;
}
.markdown pre {
  overflow-x: auto;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 0.375rem;
}
.markdown pre code { padding: 0; background: none; }
.markdown hr { border: none; border-top: 1px solid var(--border); }
a.cite { text-decoration: none; font-size: 0.85em; vertical-align: super; }

/* The agent's steps (TODO.md T57), a fold-out above the answer's text: open
   while it works, folded by chat.js once the answer starts. Small and muted
   either way: they explain the answer, they are not it. */
.steps {
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.steps summary, .other-sources summary { cursor: pointer; }
.steps ul { margin: 0.25rem 0; padding-left: 1.5rem; overflow-wrap: anywhere; }
/* The model's own sentence, apart from the wording of its tool calls. */
.steps li.commentary { font-style: italic; }

.sources {
  margin-top: 0.5rem;
  font-size: 0.9rem;
}
.sources h3 { margin: 0; font-size: 0.85rem; color: var(--muted); }
.sources ol { margin: 0.25rem 0; padding-left: 2rem; }
/* The documents the agent looked at without citing: folded, and quieter. */
.other-sources { font-size: 0.85rem; color: var(--muted); }
.no-sources, .answer-note { margin: 0.5rem 0 0; font-size: 0.85rem; color: var(--muted); }
/* What made the answer: the mode, the model, its reasoning effort (D57). */
.answer-note { font-size: 0.75rem; }

.conversation-divider {
  margin: 1.5rem auto;
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
}

/* The documents while a first question is typed (T79), built by chat.js in
   #preview between the transcript and the question box. #preview itself has
   no box of its own, so empty it takes no room. Shown, the panel is a flex
   item of body.chat like the box under it: the transcript above gives up
   the room and the question box stays where it is, so nothing moves under
   the cursor while someone types. A long list scrolls within its own
   height rather than squeezing the transcript away on a small window. */
.preview-bar {
  max-height: 40vh;
  overflow-y: auto;
  padding: 0.5rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.9rem;
}
.preview-bar h2 { margin: 0; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.preview-bar ul { margin: 0.25rem 0 0; padding: 0; list-style: none; }
.preview-bar li + li { margin-top: 0.35rem; }
.preview-detail, .preview-waiting { font-size: 0.8rem; color: var(--muted); }
.preview-waiting { margin: 0.25rem 0 0; }

.composer {
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.composer-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 12rem;
  padding: 0.5rem 0.75rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
}
/* The options under the question: the mode switch (T57). */
.composer-options {
  display: flex;
  gap: 1rem;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
}
/* Radio buttons drawn as one switch: each mode a segment, the chosen one
   filled. The inputs stay in the page, unseen, so the keyboard works as on
   any radio group (Tab to it, arrows to change) and the focus ring shows on
   the segment. */
.mode-switch { display: flex; align-items: center; }
.mode-switch > span { margin-right: 0.5rem; }
.mode-switch label { position: relative; cursor: pointer; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch label span {
  display: block;
  padding: 0.15rem 0.75rem;
  border: 1px solid var(--border);
  margin-left: -1px;
  background: var(--surface);
}
.mode-switch label:first-of-type span { margin-left: 0; border-radius: 0.375rem 0 0 0.375rem; }
.mode-switch label:last-of-type span { border-radius: 0 0.375rem 0.375rem 0; }
.mode-switch input:checked + span {
  position: relative;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}
.mode-switch input:focus-visible + span { outline: 2px solid var(--accent-2); outline-offset: 2px; }

/* ------------------------------------------------------------ the admin page */
/* An ordinary page that scrolls as a whole: panels for the index and its
   update (admin.js fills them), then the server's three lists. */
.section-name { color: var(--muted); }
.small { font-size: 0.8rem; }

.admin-page {
  max-width: 76rem;
  margin: 0 auto;
  padding: 1rem;
}
.panel {
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1.1rem; }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.update-state:empty, #update-error:empty { display: none; }

/* A finished run's report (sync_report.js). */
.report {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border-radius: 0.375rem;
}
.report h3 { margin: 0; font-size: 0.85rem; color: var(--muted); }
.report .headline { margin: 0.25rem 0; font-weight: 600; }
.report ul { margin: 0.25rem 0; padding-left: 1.25rem; }
.report-warnings li { color: var(--error); overflow-wrap: anywhere; }

/* The lists scroll sideways on a narrow screen rather than squeeze. */
.table-wrap { overflow-x: auto; }
table.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
table.list th,
table.list td {
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
table.list th { font-weight: 600; color: var(--muted); white-space: nowrap; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; }
/* The API's own English messages: long, unbroken, and secondary. */
table.list .message { max-width: 28rem; overflow-wrap: anywhere; color: var(--muted); }

/* The modes' settings (T57): a row's controls, and what a save answered. */
.mode-row select { font: inherit; }
.mode-row .mode-save { padding: 0.3rem 0.75rem; }
.mode-state { max-width: 22rem; margin-top: 0.25rem; overflow-wrap: anywhere; color: var(--muted); }
.mode-state:empty { display: none; }
.mode-state.warning { color: var(--error); }

/* The demo's sites (T62): a checkbox per site, and what is in force. */
.site-choices { list-style: none; margin: 0.5rem 0; padding: 0; }
.site-choices li { margin: 0.2rem 0; }
.demo-in-force { font-weight: 600; }
#demo-state:empty { display: none; }
