/*
  app.css — the layout of the two pages: login and chat.

  Every value comes from tokens.css. Sections:
    1. Shared: the brand name
    2. Login page  (body.page-login)
    3. Chat page   (body.page-chat): header, messages, prompt bar
    4. Answer text: what the Markdown in an answer turns into
    5. Admin page  (body.page-admin): system prompt, costs table
*/

/* ── 1. Shared ───────────────────────────────────────────────────────── */

.brand {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  text-decoration: none;
}

/* ── 2. Login page ───────────────────────────────────────────────────── */

/* The form sits in the middle of the screen. */
.page-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.login {
  width: 100%;
  max-width: var(--form-max);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.login .brand { margin-bottom: var(--sp-4); text-align: center; }

.login-error {
  margin: 0;
  color: var(--error);
  font-size: var(--fs-sm);
}

.login-switch {
  margin: var(--sp-2) 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-align: center;
}

/* ── 3. Chat page ────────────────────────────────────────────────────── */

/* A column the full height of the screen: header, messages, prompt bar.
   The page itself scrolls (no inner scroll box), and the prompt bar sticks
   to the bottom edge while the messages scroll under it. */
.page-chat {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.chat-header,
.chat,
.prompt,
.admin {
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding-left: var(--sp-4);
  padding-right: var(--sp-4);
}

/* Header: brand on the left, the account links on the right. */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: var(--sp-4);
  padding-bottom: var(--sp-4);
}

.chat-header nav {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  color: var(--muted);
  font-size: var(--fs-sm);
}

/* Links in the header look like the text buttons beside them. */
.chat-header nav a { text-decoration: none; }
.chat-header nav a:hover { color: var(--text); }

/* Messages: takes all the room between header and prompt bar. */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  padding-top: var(--sp-4);
  padding-bottom: var(--sp-4);
}

/* Shown in the middle while the conversation is empty. */
.chat-empty {
  margin: auto;
  color: var(--muted);
}

.bubble {
  max-width: var(--bubble-max);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  overflow-wrap: anywhere;
}

/* The visitor's question: right side, on the grey surface, kept as typed. */
.bubble.user {
  align-self: flex-end;
  background: var(--surface);
  border-top-right-radius: 0;
  white-space: pre-wrap;
}

/* The model's answer: left side, no background, so long text reads like a page. */
.bubble.assistant {
  align-self: flex-start;
  padding-left: 0;
  padding-right: 0;
}

/* While waiting for the first word. */
.bubble.waiting { color: var(--muted); }

.bubble.error { color: var(--error); }

/* Prompt bar: sticks to the bottom of the screen. */
.prompt {
  position: sticky;
  bottom: 0;
  z-index: var(--z-bar);
  padding-bottom: var(--sp-4);
  background: var(--bg);
}

/* The box around the text field. (No send button: Enter sends.) */
.prompt-box {
  display: flex;
  padding: var(--sp-2);
  border: var(--line) solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg);
  transition: border-color var(--t-fast);
}
.prompt-box:focus-within { border-color: var(--accent); }

/* The field itself has no frame of its own; the box above is the frame. */
.prompt-box textarea {
  flex: 1;
  max-height: var(--input-max-h);
  padding: var(--sp-2);
  border: none;
  background: none;
  line-height: var(--lh-normal);
  resize: none;
}
.prompt-box textarea:hover,
.prompt-box textarea:focus { background: none; }

.prompt-hint {
  margin: var(--sp-2) 0 0;
  color: var(--muted);
  font-size: var(--fs-sm);
  text-align: center;
}

/* ── 4. Answer text ──────────────────────────────────────────────────── */
/* public/js/markdown.js turns the answer into these elements. One gap
   between any two blocks, so the spacing is the same everywhere. */

.md > * { margin: 0; }
.md > * + * { margin-top: var(--sp-3); }

.md h1, .md h2, .md h3 {
  font-size: var(--fs-md);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

.md ul, .md ol { padding-left: var(--sp-4); }
.md li + li { margin-top: var(--sp-1); }

.md code {
  padding: 0 var(--sp-1);
  border-radius: var(--r-sm);
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

.md pre {
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  background: var(--surface);
  overflow-x: auto;
}
.md pre code { padding: 0; background: none; }

/* ── 5. Admin page ───────────────────────────────────────────────────── */

.admin {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  padding-top: var(--sp-4);
  padding-bottom: var(--sp-5);
}

.admin-section h2 {
  margin: 0;
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
}

.admin-note {
  margin: var(--sp-2) 0 var(--sp-3);
  color: var(--muted);
  font-size: var(--fs-sm);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.admin-form textarea {
  height: var(--editor-h);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  line-height: var(--lh-normal);
  resize: vertical;
}

/* Save button, then the status, then the character count on the right. */
.admin-row {
  display: flex;
  flex-wrap: wrap;           /* on a phone the count moves under the button */
  align-items: center;
  gap: var(--sp-3);
}

.admin-status {
  color: var(--muted);
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.admin-status.is-error { color: var(--error); }
.admin-count { margin-left: auto; }

/* The costs table scrolls sideways on a narrow phone instead of squeezing. */
.admin-table-wrap { overflow-x: auto; }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;   /* digits line up in columns */
}

.admin-table th,
.admin-table td {
  padding: var(--sp-2) var(--sp-3);
  border-bottom: var(--line) solid var(--border);
  text-align: right;
  white-space: nowrap;
}
/* The day column reads left to right; the numbers line up on the right. */
.admin-table th:first-child,
.admin-table td:first-child { text-align: left; padding-left: 0; }
.admin-table th:last-child,
.admin-table td:last-child { padding-right: 0; }

.admin-table thead th {
  color: var(--muted);
  font-weight: var(--fw-normal);
}

.admin-table tfoot th {
  border-bottom: none;
  font-weight: var(--fw-bold);
}

.admin-table td.admin-empty {
  color: var(--muted);
  text-align: left;
}
