/* legi-som-v2 — shared design tokens and chrome.
 *
 * Used by both static/index.html and static/chats.html. Page-specific
 * layout (e.g. the chat thread on /, the chat-list on /chats) stays
 * inline in each page's own <style> block.
 *
 * Adapted from the v1 shared.css at ../legi-som/sivilombudet/static/shared.css.
 */

/* ── Tokens ──────────────────────────────────────────────── */

:root {
  /* Burgundy palette — body sits on the burgundy; surfaces are
     translucent white tints on top of it; text is white at varying
     opacities. Inputs are light surfaces (handled in step 9). */
  --bg: #7a1f4d;
  --fg: rgba(255, 255, 255, 0.9);
  --muted: rgba(255, 255, 255, 0.6);
  --faint: rgba(255, 255, 255, 0.45);
  --surface: rgba(255, 255, 255, 0.07);
  --surface-strong: rgba(255, 255, 255, 0.12);
  --border: rgba(255, 255, 255, 0.15);
  --border-strong: rgba(255, 255, 255, 0.25);
  --user-bg: rgba(255, 255, 255, 0.12);
  --agent-bg: rgba(255, 255, 255, 0.07);
  --tool-bg: rgba(0, 0, 0, 0.18);
  --tool-fg: rgba(255, 255, 255, 0.75);
  --error: #fca5a5;
  --error-bg: rgba(180, 83, 83, 0.25);
  --error-border: rgba(180, 83, 83, 0.4);
  /* Contrast token for dark-on-light interactive surfaces (input
     pill in step 9, modal body in step 8). */
  --on-light-fg: #1a1a1a;
}

/* ── Reset + body typography ─────────────────────────────── */

* { box-sizing: border-box; }

/* NB: pages own their own body layout (flex column on /, plain block
   on /chats). Shared rules cover only typography + color. */
body {
  font: 16px/1.55 'Archivo', -apple-system, BlinkMacSystemFont,
        "Segoe UI", system-ui, sans-serif;
  color: var(--fg);
  background: var(--bg);
  margin: 0;
}

/* Utility for ad-hoc Playfair use (e.g. answer h1/h2 once markdown
   rendering lands in step 5). The wordmark and page-title classes
   below already set Playfair directly. */
.serif {
  font-family: 'Playfair Display', Georgia, "Times New Roman", serif;
}

/* ── Header chrome ───────────────────────────────────────── */

header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
header .left { min-width: 0; }
header a {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
}
header a:hover { color: var(--fg); }

/* The LEGI wordmark sits in the header on every page, faded by
   default so it reads as a brand mark not a page title. */
.wordmark {
  font-family: 'Playfair Display', Georgia, "Times New Roman", serif;
  font-size: 28px;
  line-height: 1.6;
  font-weight: 400;
  color: var(--muted);
  text-decoration: none;
  margin: 0;
  transition: color 0.2s ease;
}
.wordmark:hover { color: var(--fg); }

/* The actual page title sits in <main>, not the header — so the
   wordmark isn't competing for emphasis with the page name. */
.page-title {
  font-family: 'Playfair Display', Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 500;
  color: var(--fg);
  margin: 0 0 24px 0;
  letter-spacing: 0.01em;
}

/* ── Markdown rendering inside agent answer bubbles ──────── */
/* Applied to .answer-text (whose innerHTML is set by marked.parse).
   Adapted from v1's rules; weights slightly more restrained. */

.answer-text { color: var(--fg); }

.answer-text > :first-child { margin-top: 0; }
.answer-text > :last-child  { margin-bottom: 0; }

.answer-text h1, .answer-text h2 {
  font-family: 'Playfair Display', Georgia, "Times New Roman", serif;
  font-weight: 600;
  color: var(--fg);
  line-height: 1.3;
}
.answer-text h1 { font-size: 24px; margin: 1.1em 0 0.4em; }
.answer-text h2 { font-size: 20px; margin: 1.0em 0 0.35em; }
.answer-text h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--fg);
  margin: 1.0em 0 0.3em;
  line-height: 1.4;
}

.answer-text p {
  margin: 0 0 0.7em;
  line-height: 1.6;
}

.answer-text ul, .answer-text ol {
  margin: 0 0 0.7em;
  padding-left: 1.4em;
}
.answer-text li { margin-bottom: 0.25em; line-height: 1.5; }
/* marked wraps <li> contents in <p> when items have blank lines or
   nested blocks. Strip the paragraph margins so list items read
   tight; nested lists collapse their own outer margins too. */
.answer-text li > p { margin: 0; }
.answer-text li > p + p { margin-top: 0.4em; }
.answer-text li > ul, .answer-text li > ol { margin: 0.25em 0 0.25em; }

.answer-text strong { font-weight: 600; color: rgba(255, 255, 255, 1); }
.answer-text em { font-style: italic; }

.answer-text code {
  background: var(--surface-strong);
  color: var(--fg);
  padding: 1px 6px;
  border-radius: 4px;
  font: 14px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
}
.answer-text pre {
  background: var(--tool-bg);
  color: var(--tool-fg);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 0 0 0.7em;
  /* Restore pre's whitespace handling — we override .segment *
     to white-space: normal in index.html to kill phantom newlines
     from HTML template literals, and that override would otherwise
     beat <pre>'s default. */
  white-space: pre;
}
.answer-text pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}

.answer-text hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 1em 0;
}

.answer-text blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 0.4em 0 0.4em 1em;
  margin: 0.7em 0;
  color: var(--muted);
  font-style: italic;
}

.answer-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.85em 0;
  font-size: 14px;
}
.answer-text th, .answer-text td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.answer-text th {
  background: var(--surface-strong);
  font-weight: 600;
  color: var(--fg);
}
.answer-text tr:hover td { background: var(--surface); }

.answer-text a {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}
.answer-text a:hover { text-decoration-color: var(--fg); }

/* ── Profile dropdown (top-right of every page) ──────────── */

.profile-container {
  position: relative;
}

.user-menu-button {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface-strong);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  color: var(--muted);
  flex-shrink: 0;
  padding: 0;
}
.user-menu-button:hover {
  background: rgba(255, 255, 255, 0.3);
  color: var(--fg);
}
.user-menu-button svg {
  width: 18px;
  height: 18px;
}

.profile-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: white;
  color: var(--on-light-fg);
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s, transform 0.15s, visibility 0.15s;
  z-index: 1000;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.profile-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.dropdown-item {
  display: block;
  padding: 10px 14px;
  font: inherit;
  font-size: 13px;
  color: var(--on-light-fg);
  cursor: pointer;
  transition: background 0.15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover {
  background: #f5f5f5;
}

/* ── Modal (About, etc) ──────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(26, 26, 26, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  backdrop-filter: blur(2px);
  padding: 20px;
}
.modal-overlay.show {
  opacity: 1;
  pointer-events: auto;
}
.modal {
  background: #f5f5f5;
  color: var(--on-light-fg);
  border-radius: 12px;
  padding: 28px;
  width: 480px;
  max-width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15),
              0 8px 20px rgba(0, 0, 0, 0.1);
  position: relative;
}
.modal-title {
  font-family: 'Playfair Display', Georgia, "Times New Roman", serif;
  font-size: 20px;
  font-weight: 600;
  margin: 0 0 20px;
  color: var(--on-light-fg);
}
.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: #999;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close-btn:hover {
  background: rgba(0, 0, 0, 0.05);
  color: #666;
}
.modal-section {
  margin-bottom: 16px;
}
.modal-section:last-child {
  margin-bottom: 0;
}
.modal-section h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--on-light-fg);
  margin: 0 0 6px;
}
.modal-section p {
  font-size: 14px;
  color: #555;
  line-height: 1.55;
  margin: 0;
}

/* Feedback-modal-only bits (textarea + submit). */
.modal textarea.feedback-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d8d8d8;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  color: var(--on-light-fg);
  resize: vertical;
  min-height: 100px;
  background: white;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.modal textarea.feedback-textarea:focus {
  border-color: var(--bg);
  box-shadow: 0 0 0 2px rgba(122, 31, 77, 0.12);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
}
.modal-actions .btn-primary {
  padding: 8px 16px;
  background: var(--bg);
  color: white;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}
.modal-actions .btn-primary:hover { background: #5a1739; }
.modal-actions .btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* ── Input pill (search / follow-up) ─────────────────────── */
/* Reusable rounded floating-pill input. Light-on-burgundy at rest,
   pure white + deeper shadow on focus. The textarea inside auto-
   resizes via JS (autoResize() on input). */

.input-pill {
  background: #f5f5f5;
  border-radius: 24px;
  padding: 10px 12px 10px 20px;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: background 0.3s cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.input-pill:focus-within {
  background: white;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
}
.input-pill textarea {
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  resize: none;
  font: inherit;
  /* 16px (not 15px) suppresses iOS Safari's "zoom to focused input"
     behaviour — Safari auto-zooms to readable text size if it's < 16px,
     which made the whole page jump on focus. */
  font-size: 16px;
  color: var(--on-light-fg);
  line-height: 1.4;
  max-height: 200px;
  padding: 6px 0;
  /* The autoResize() handler in index.html keeps the textarea height
     in lockstep with its scrollHeight, so the only time a scrollbar
     is meaningful is when content exceeds max-height. Default
     `overflow: hidden` avoids a stray scrollbar on single-line
     content where scrollHeight and clientHeight can disagree by a
     sub-pixel; autoResize() flips it to `auto` once we hit the cap. */
  overflow-y: hidden;
}
.input-pill textarea::placeholder { color: #999; }

/* Round icon button (send / stop) sitting on the right of the pill. */
.pill-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
  background: #e0e0e0;
  color: #999;
  padding: 0;
}
/* `display: flex` above beats the `hidden` HTML attribute (which
   sets display: none). Re-honour it so the Stop button stays
   genuinely hidden on the empty state. */
.pill-btn[hidden] { display: none; }
.pill-btn:hover:not(:disabled) {
  background: #d0d0d0;
  color: #555;
}
.pill-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.pill-btn svg {
  width: 16px;
  height: 16px;
}
/* When the pill is focused, the active send button darkens to give a
   strong "press me" affordance — matches v1. */
.input-pill:focus-within .pill-btn:not(:disabled):not(.pill-btn-stop) {
  background: var(--on-light-fg);
  color: white;
}
.input-pill:focus-within .pill-btn:not(:disabled):not(.pill-btn-stop):hover {
  background: #333;
}
/* Stop variant always reads loud, even when the pill isn't focused. */
.pill-btn-stop {
  background: var(--error-bg);
  color: var(--error);
}
.pill-btn-stop:hover:not(:disabled) {
  background: rgba(180, 83, 83, 0.5);
  color: white;
}

/* ── Footer ──────────────────────────────────────────────── */
/* Small centred line at the bottom of every page. Pages own
   whether they push it down (chats.html lets <main> grow naturally;
   index.html uses a flex column where the footer sits below the form). */

footer {
  padding: 18px 20px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 12px;
  color: var(--faint);
}
footer .row {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  justify-content: center;
  gap: 24px;
  flex-wrap: wrap;
}
footer p { margin: 0; }
