/* Bjart. Fargene er samlet her, så utseendet er lett å justere. */
:root {
  --bg: #f6f4fb;
  --surface: #ffffff;
  --text: #1d1a26;
  --muted: #6b6680;
  --line: #e3dfee;
  --brand: #e2473b;       /* Bjarts chili-rød */
  --brand-ink: #ffffff;
  --brand-soft: #fde9e6;
  --user: #2d2640;
  --user-ink: #ffffff;
  --bot: #ffffff;
  --code-bg: #f1eef8;
  --danger: #b42318;
  --radius: 18px;
  --shadow: 0 1px 2px rgba(20, 14, 40, .06), 0 4px 16px rgba(20, 14, 40, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121d;
    --surface: #1f1a2b;
    --text: #ece8f6;
    --muted: #a19bb5;
    --line: #2f2940;
    --brand: #ff5a4c;
    --brand-ink: #ffffff;
    --brand-soft: #3a1f22;
    --user: #3a3150;
    --user-ink: #ffffff;
    --bot: #1f1a2b;
    --code-bg: #2a2438;
    --danger: #ff8a80;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ------------------------------------------------ innlogging */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border-radius: 24px; padding: 32px 24px;
  box-shadow: var(--shadow); text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-logo { margin: 0 auto; }
.login-card h1 { margin: 0; font-size: 28px; }
.tagline { margin: 0 0 8px; color: var(--muted); }
.login-card input {
  font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text);
}
.login-card button {
  padding: 12px; border: 0; border-radius: 12px; background: var(--brand); color: var(--brand-ink); font-weight: 600;
}
.login-error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 14px; }

/* ------------------------------------------------ topp */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .name { font-weight: 700; font-size: 18px; line-height: 1.1; }
.brand .sub { color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; }
.ghost {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 7px 14px;
}
.ghost.small { color: var(--muted); }
.banner { margin: 12px auto 0; max-width: 760px; padding: 10px 14px; border-radius: 12px; background: var(--brand-soft); color: var(--text); font-size: 14px; width: calc(100% - 32px); }

/* ------------------------------------------------ chat */
.chat { max-width: 760px; margin: 0 auto; padding: 16px 16px 180px; }
.empty { text-align: center; padding: 6vh 8px 0; }
.empty h2 { margin: 12px 0 6px; font-size: 22px; }
.empty p { color: var(--muted); max-width: 460px; margin: 0 auto 18px; }
.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.examples button {
  border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 8px 14px; font-size: 14px;
}

.messages { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; align-items: flex-start; }
.msg.user { justify-content: flex-end; }
.msg .bubble { max-width: min(100%, 680px); border-radius: var(--radius); padding: 10px 14px; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); color: var(--user-ink); border-bottom-right-radius: 6px; max-width: 85%; }
.msg.user .text { white-space: pre-wrap; }
.msg.assistant .bubble { background: var(--bot); box-shadow: var(--shadow); border-top-left-radius: 6px; flex: 1; min-width: 0; }
.msg.error .bubble { color: var(--danger); }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; background: url(bjart.svg) center/cover; margin-top: 2px; }

.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.thumbs img { max-width: 220px; max-height: 220px; border-radius: 10px; display: block; }
.img-tag { font-size: 13px; opacity: .8; margin-bottom: 4px; }

.msg.thinking .md::after {
  content: "Bjart tenker …"; color: var(--muted); font-style: italic;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: .4; } }

/* Markdown og matte i svarene */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 10px; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: 3px 0; }
.md h3, .md h4, .md h5, .md h6 { margin: 14px 0 6px; font-size: 1.02em; }
.md strong { font-weight: 700; }
.md code { background: var(--code-bg); border-radius: 6px; padding: 1px 5px; font-size: .92em; }
.md pre { background: var(--code-bg); border-radius: 10px; padding: 10px 12px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.md .math-block { overflow-x: auto; overflow-y: hidden; margin: 6px 0 10px; padding: 2px 0; }
.md .katex { font-size: 1.08em; }
.md .katex-display { margin: 0; }

/* ------------------------------------------------ skrivefelt */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 75%, transparent);
}
.composer .row, .previews, .fine { max-width: 760px; margin: 0 auto; }
.composer .row {
  display: flex; align-items: flex-end; gap: 6px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 24px; padding: 6px; box-shadow: var(--shadow);
}
.composer textarea {
  flex: 1; min-width: 0; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; padding: 8px 6px; max-height: 200px;
}
.icon, .send {
  flex: none; width: 40px; height: 40px; border-radius: 50%; border: 0; display: grid; place-items: center;
}
.icon { background: transparent; color: var(--muted); }
.send { background: var(--brand); color: var(--brand-ink); }
.send.stop { background: var(--text); color: var(--bg); }
.previews { display: flex; gap: 8px; margin-bottom: 8px; }
.preview { position: relative; }
.preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }
.preview .remove {
  position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 1;
}
.fine { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; color: var(--muted); padding: 6px 8px 0; }

@media (max-width: 520px) {
  .brand .sub { display: none; }
  .fine { flex-direction: column; gap: 0; }
  .thumbs img { max-width: 160px; }
}
