/* Arendalsuka-guiden — visual language
   Signature: a printed festival-program feel — a small monospace
   "wayfinding" line in the header, echoed as a quiet accent spine on
   assistant replies, as if someone had marked up a paper program.
   Serif is used once (the title) for an editorial, unbranded voice;
   everything else is plain system sans so the content stays legible. */

* { box-sizing: border-box; margin: 0; }

:root {
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: ui-serif, Georgia, "Iowan Old Style", "Times New Roman", serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Roboto Mono", Menlo, Consolas, monospace;

  --bg: #f0f1ec;
  --surface: #ffffff;
  --ink: #191d1b;
  --muted: #666f6b;
  --border: #dee1d9;

  --accent: #21605a;
  --accent-strong: #164945;
  --accent-ink: #ffffff;
  --user-bubble: #e3e8e1;

  --error-bg: #fbeaea;
  --error-border: #e3b4b4;
  --error-ink: #7a2020;

  --radius: 16px;
  --radius-sm: 10px;
  --radius-pill: 999px;
  --maxw: 720px;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181a;
    --surface: #1b2224;
    --ink: #e9eded;
    --muted: #97a19c;
    --border: #2b3436;

    --accent: #4fa79e;
    --accent-strong: #6bc0b6;
    --accent-ink: #05201d;
    --user-bubble: #24312e;

    --error-bg: #3a2222;
    --error-border: #6b3535;
    --error-ink: #f3b8b8;
  }
}

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- header ---------- */

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  padding: 0.9rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

h1 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.tagline {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.15rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  padding-bottom: 0.2rem;
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  white-space: nowrap;
  transition: color 0.15s, border-color 0.15s;
}

.ghost-btn:hover:not(:disabled) { background: transparent; color: var(--accent); border-color: var(--accent); }
.ghost-btn[hidden] { display: none; }

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

main#chat {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  margin: auto 0;
  text-align: center;
  padding: 1.5rem 0.5rem;
}

.empty-heading {
  font-family: var(--font-display);
  font-size: 1.2rem;
  margin-bottom: 0.4rem;
}

.empty-body {
  color: var(--muted);
  font-size: 0.9rem;
  max-width: 46ch;
  margin: 0 auto 1.25rem;
  line-height: 1.5;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.chip {
  font: inherit;
  font-size: 0.85rem;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.chip:hover { border-color: var(--accent); color: var(--accent); }

.msg {
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  max-width: 85%;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
}

.msg.user {
  background: var(--user-bubble);
  align-self: flex-end;
}

.msg.assistant {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  align-self: flex-start;
}

.msg.assistant a { color: var(--accent); }

/* Assistant replies (and the reveal analysis) are rendered from a small Markdown subset
   — see public/markdown.js. Normal flow instead of pre-wrap now that they contain block elements. */
.msg.assistant { white-space: normal; }

.msg.assistant > :first-child,
#revealBody > :first-child { margin-top: 0; }
.msg.assistant > :last-child,
#revealBody > :last-child { margin-bottom: 0; }

.msg.assistant p,
#revealBody p { margin: 0.5rem 0; }

.msg.assistant ul,
#revealBody ul { margin: 0.5rem 0; padding-left: 1.2rem; }

.msg.assistant li,
#revealBody li { margin: 0.2rem 0; }

.msg.assistant li::marker,
#revealBody li::marker { color: var(--accent); }

.msg.assistant h3,
#revealBody h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ink);
  margin: 0.8rem 0 0.35rem;
}

.msg.assistant strong,
#revealBody strong { font-weight: 600; }

/* ---------- event cards ---------- */

.msg-prose:not(:empty) { margin-bottom: 0.6rem; }

.msg-cards { display: flex; flex-direction: column; gap: 0.5rem; }

.event-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.8rem;
}

.event-card__title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; margin: 0; }
.event-card__title a { color: var(--ink); text-decoration: none; }
.event-card__title a:hover { color: var(--accent); text-decoration: underline; }

.event-card__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.6rem;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.event-card__chip {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  white-space: nowrap;
}

.event-card__chip--live {
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.event-card__chip--live::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
}

.event-card__abstract {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0.4rem 0 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.event-card__tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.4rem; }

.event-card__tag {
  font-size: 0.7rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 0.05rem 0.45rem;
}

.event-card__speakers { font-size: 0.78rem; color: var(--muted); margin: 0.4rem 0 0; }

.msg.error {
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  align-self: center;
  color: var(--error-ink);
  text-align: center;
}

/* ---------- progress line ---------- */

/* While the model searches, the pending bubble narrates it — monospace, like the header's
   wayfinding line, so it reads as machinery rather than as part of the answer. Server-supplied
   labels arrive as {type:'status'} on the chat stream (see src/routes/chat.ts). */
.msg-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* Sits under whatever the model has already written (it can keep searching mid-answer). */
.msg-prose:not(:empty) ~ .msg-status,
.msg-cards:not(:empty) ~ .msg-status { margin-top: 0.55rem; }

.msg-status__label:empty { display: none; }

/* typing indicator */

.typing {
  display: inline-flex;
  gap: 0.28rem;
  padding: 0.15rem 0;
}

.typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.6;
}

@media (prefers-reduced-motion: no-preference) {
  .typing span { animation: typingBounce 1.1s infinite ease-in-out; }
  .typing span:nth-child(2) { animation-delay: 0.15s; }
  .typing span:nth-child(3) { animation-delay: 0.3s; }

  @keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
  }
}

/* ---------- composer ---------- */

form#composer {
  display: flex;
  gap: 0.5rem;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0.75rem 1.25rem;
  flex: 0 0 auto;
}

#input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  background: var(--surface);
  color: var(--ink);
  min-width: 0;
}

#input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
#input:disabled { opacity: 0.6; }

button {
  font: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 0.75rem 1.25rem;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: background 0.15s;
}

button:hover:not(:disabled) { background: var(--accent-strong); }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

#reveal {
  margin: 0 auto 0.75rem;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  flex: 0 0 auto;
}

/* ---------- footer (persistent AI disclosure) ---------- */

footer {
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 0.6rem 1rem calc(0.9rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex: 0 0 auto;
}

footer .disclosure { margin: 0; }

footer .credit {
  margin: 0.45rem 0 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-size: 0.72rem;
}

footer .credit a { display: inline-flex; line-height: 0; }

.footer-logo { height: 22px; width: auto; display: block; opacity: 0.9; }

@media (prefers-color-scheme: dark) {
  /* The wordmark is dark ink; invert + hue-rotate keeps it legible on the dark footer
     while roughly preserving the blue window-mark. */
  .footer-logo { filter: invert(1) hue-rotate(180deg); opacity: 0.85; }
}

/* ---------- reveal dialog ---------- */

dialog {
  border: 0;
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: min(92vw, 640px);
  background: var(--surface);
  color: var(--ink);
}

dialog::backdrop { background: rgb(0 0 0 / 0.35); }

dialog h2 { font-family: var(--font-display); font-size: 1.15rem; margin-bottom: 0.75rem; }
dialog h3 { font-size: 0.85rem; color: var(--muted); margin: 1rem 0 0.4rem; text-transform: uppercase; letter-spacing: 0.04em; }
dialog #closeReveal { margin-top: 1rem; }

dialog pre {
  white-space: pre-wrap;
  background: var(--bg);
  color: var(--ink);
  padding: 1rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  max-height: 40vh;
  overflow: auto;
}

/* ---------- mode toggle ---------- */

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  cursor: pointer;
  flex: 0 0 auto;
}

.toggle[hidden] { display: none; }

.toggle input { display: none; }

.toggle .track {
  width: 38px;
  height: 22px;
  border-radius: var(--radius-pill);
  background: var(--border);
  position: relative;
  transition: background 0.15s;
}

.toggle .thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--surface);
  transition: left 0.15s;
}

.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track .thumb { left: 18px; }
.toggle input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- responsive ---------- */

@media (min-width: 640px) {
  .site-header { padding: 1.1rem 1.5rem; }
  h1 { font-size: 1.5rem; }
  main#chat { padding: 1.5rem; }
  form#composer { padding: 0.85rem 1.5rem; }
}

@media (max-width: 639px) {
  .msg { max-width: 92%; }
}
