/* Lilla hjärnan – gränssnitt
   Färger och mått styrs av variablerna nedan. Byt --accent mot den exakta
   röda nyansen i er grafiska profil om den skiljer sig från #990000. */

:root {
  color-scheme: light dark;

  --bg: #f4f4f6;
  --surface: #ffffff;
  --text: #1c1b1f;
  --muted: #58545e;
  --line: #dddbe1;
  --field-line: #7d7984;

  --accent: #990000;
  --accent-hover: #750000;
  --on-accent: #ffffff;
  --accent-ink: #990000;
  --accent-soft: #f6ebeb;

  --danger-ink: #b3261e;
  --danger-solid: #b3261e;
  --danger-solid-hover: #8f1e18;

  --ok-bg: #e8f3ea;  --ok-ink: #14532d;  --ok-line: #9ccaa8;
  --err-bg: #fbeceb; --err-ink: #7f1d1d; --err-line: #e3aaa6;

  --focus: #0b57d0;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141316;
    --surface: #1d1c20;
    --text: #ebe9ee;
    --muted: #b0acb6;
    --line: #34323a;
    --field-line: #8b8793;

    --accent: #b02a2a;
    --accent-hover: #c63a3a;
    --accent-ink: #ff9f9f;
    --accent-soft: #2c1c1e;

    --danger-ink: #ff9f9f;
    --danger-solid: #c0392b;
    --danger-solid-hover: #d44a3b;

    --ok-bg: #15281b;  --ok-ink: #a5e0b8;  --ok-line: #2f6a44;
    --err-bg: #2f1819; --err-ink: #ffb4b4; --err-line: #7a3535;

    --focus: #8ab4ff;
  }
}

/* ---------- Bas ---------- */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 1.0625rem/1.6 var(--font);
}

h1, h2 { line-height: 1.2; letter-spacing: -0.01em; margin: 0 0 .75rem; }
h1 { font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem); font-weight: 700; }
h2 { font-size: 1.25rem; font-weight: 650; }
p { margin: 0 0 1rem; }

a { color: var(--accent-ink); text-underline-offset: .2em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.muted { color: var(--muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: .5rem; top: -4rem; z-index: 10;
  background: var(--surface); color: var(--text); padding: .6rem 1rem;
  border: 2px solid var(--focus); border-radius: var(--radius);
}
.skip-link:focus { top: .5rem; }

/* ---------- Sidhuvud ---------- */
.site-header {
  background: var(--surface);
  border-top: 4px solid var(--accent);
  border-bottom: 1px solid var(--line);
}
.site-header__inner {
  max-width: 64rem; margin-inline: auto; padding: .6rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  min-height: 4rem;
}
.brand { display: flex; align-items: center; gap: .7rem; color: var(--text); text-decoration: none; min-width: 0; }
.brand__logo { height: 2.5rem; width: auto; display: block; }
.brand__name { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; }

.header-actions { display: flex; align-items: center; gap: .6rem; }

.user-menu { position: relative; }
.user-menu summary {
  list-style: none; cursor: pointer; display: flex; align-items: center; gap: .5rem;
  min-height: 2.75rem; padding: .15rem .4rem; border-radius: 999px;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after {
  content: ""; width: .45rem; height: .45rem; margin-left: .15rem;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-.1rem) rotate(45deg);
}
.user-menu[open] summary::after { transform: translateY(.1rem) rotate(225deg); }
.avatar {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); font-weight: 700;
}
.user-menu__name { max-width: 10rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 40em) {
  .user-menu__name {
    position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0);
  }
}
.user-menu__panel {
  position: absolute; right: 0; top: calc(100% + .4rem); z-index: 5; min-width: 15rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .5rem; box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
.user-menu__who { margin: 0; padding: .5rem .75rem; color: var(--muted); font-size: .95rem; border-bottom: 1px solid var(--line); }
.user-menu__panel a {
  display: block; padding: .7rem .75rem; min-height: 2.75rem; border-radius: 6px;
  color: var(--text); text-decoration: none;
}
.user-menu__panel a:hover { background: var(--accent-soft); color: var(--accent-ink); }

/* ---------- Layout ---------- */
.page { max-width: 64rem; margin-inline: auto; padding: 1.5rem 1rem 4rem; }
.page--narrow { max-width: 40rem; }
@media (min-width: 40em) { .page { padding-top: 2.5rem; } }

.page-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .25rem 1rem; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.page-head__count { margin: 0; color: var(--muted); }

.backlink { margin-bottom: .75rem; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; }
@media (min-width: 40em) { .panel { padding: 1.75rem; } }

/* ---------- Knappar ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 2.75rem; padding: .55rem 1.15rem;
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius);
}
.btn--small { min-height: 2.5rem; padding: .4rem .95rem; }
.btn--primary { background: var(--accent); color: var(--on-accent); }
.btn--primary:hover { background: var(--accent-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--field-line); }
.btn--secondary:hover { background: var(--accent-soft); }
.btn--danger { background: transparent; color: var(--danger-ink); border-color: var(--danger-ink); }
.btn--danger:hover { background: var(--err-bg); }
.btn--danger-solid { background: var(--danger-solid); color: #fff; }
.btn--danger-solid:hover { background: var(--danger-solid-hover); }

/* ---------- Meddelanden ---------- */
.notice { border: 1px solid; border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1.25rem; transition: opacity .3s; }
.notice > :last-child { margin-bottom: 0; }
.notice ul { margin: .25rem 0 0; padding-left: 1.25rem; }
.notice--ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok-line); }
.notice--error { background: var(--err-bg); color: var(--err-ink); border-color: var(--err-line); }
.notice--error a { color: inherit; }
.notice.is-leaving { opacity: 0; }

/* ---------- Formulär ---------- */
.field { margin-bottom: 1.25rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; }
.hint { font-weight: 400; color: var(--muted); font-size: .95rem; margin-left: .35rem; }

input[type="text"], input[type="email"], input[type="tel"], input[type="password"], input[type="search"], textarea {
  display: block; width: 100%; min-height: 3rem; padding: .65rem .8rem;
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--field-line); border-radius: var(--radius);
}
textarea { resize: vertical; min-height: 7rem; }
input::placeholder { color: var(--muted); opacity: 1; }
input:user-invalid, input[aria-invalid="true"] { border-color: var(--danger-ink); border-width: 2px; }
.field__error { color: var(--danger-ink); margin: .35rem 0 0; font-weight: 600; }

.form-actions, .actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.form-actions .btn { flex: 1 1 auto; }
.actions { margin-top: 1.25rem; }
@media (min-width: 40em) { .form-actions .btn { flex: 0 0 auto; } }

/* ---------- Sök och A–Ö ---------- */
.search { display: flex; gap: .5rem; }
.search input { flex: 1; min-width: 0; }
.clear-search { margin: .6rem 0 0; }

.letters { margin: 1.25rem 0 .5rem; }
.letters ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.letters a {
  display: grid; place-items: center; min-width: 2.75rem; height: 2.75rem; padding-inline: .4rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--text); font-weight: 650; text-decoration: none;
}
.letters a:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

.letter-group { margin-top: 2rem; }
.letter-group__letter {
  font-size: 2.25rem; line-height: 1; font-weight: 700; color: var(--accent-ink);
  margin: 0 0 .5rem; padding-bottom: .5rem; border-bottom: 2px solid var(--accent);
  scroll-margin-top: 1rem;
}
.name-list { list-style: none; margin: 0; padding: 0; columns: 16rem auto; column-gap: 2rem; }
.name-list li { break-inside: avoid; }
.name-list a {
  display: block; min-height: 2.75rem; padding: .7rem .5rem;
  border-bottom: 1px solid var(--line); color: var(--text); text-decoration: none;
}
.name-list a:hover { background: var(--accent-soft); color: var(--accent-ink); }
.name-list strong { font-weight: 650; }

@media (min-width: 48em) {
  .letter-group { display: grid; grid-template-columns: 5rem 1fr; column-gap: 1.5rem; }
  .letter-group__letter { position: sticky; top: 1rem; align-self: start; font-size: 3rem; margin: 0; padding: 0; border-bottom: 0; }
}

.empty { text-align: center; padding: 3rem 1rem; }
.empty p { color: var(--muted); }

/* ---------- Detaljsida ---------- */
.facts { margin: 0; }
.facts > div { padding: .9rem 0; border-bottom: 1px solid var(--line); }
.facts > div:first-child { padding-top: 0; }
.facts > div:last-child { padding-bottom: 0; border-bottom: 0; }
.facts dt { color: var(--muted); font-size: .95rem; margin-bottom: .15rem; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
@media (min-width: 40em) {
  .facts > div { display: grid; grid-template-columns: 11rem 1fr; gap: 1rem; }
  .facts dt { margin: 0; padding-top: .15rem; }
}

.danger-zone { margin-top: 2.5rem; padding-top: 1.5rem; border-top: 1px solid var(--line); }
.danger-zone p { color: var(--muted); }

/* ---------- Dialog ---------- */
.dialog {
  padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text); width: min(28rem, calc(100vw - 2rem));
}
.dialog::backdrop { background: rgb(20 18 22 / .6); }
.dialog__body { padding: 1.5rem; }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .75rem; margin-top: 1.5rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Till toppen ---------- */
.to-top {
  position: fixed; z-index: 4;
  right: max(1rem, env(safe-area-inset-right)); bottom: max(1rem, env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: .5rem; min-height: 2.75rem; padding: .5rem 1rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--field-line); border-radius: 999px;
  font-weight: 600; text-decoration: none; box-shadow: 0 4px 14px rgb(0 0 0 / .15);
}
.to-top[hidden] { display: none; }
.to-top:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.to-top__icon {
  width: .55rem; height: .55rem; border-left: 2px solid currentColor; border-top: 2px solid currentColor;
  transform: translateY(.12rem) rotate(45deg);
}

/* ---------- Bästa träff ---------- */
.best-hits { margin-top: 1.5rem; padding: 1rem 1.25rem 1.25rem; background: var(--accent-soft); border: 1px solid var(--line); border-radius: var(--radius); }
.best-hits h2 { margin-bottom: .25rem; }
.best-hits__list { list-style: none; margin: 0; padding: 0; }
.best-hits__list a { display: block; padding: .6rem 0; min-height: 2.75rem; font-size: 1.3rem; color: var(--accent-ink); }
.others-title { margin-top: 2.25rem; }
