:root {
  --ink: #17242c;
  --ink-soft: #4a5b66;
  --bg: #f3f6f8;
  --surface: #ffffff;
  --line: #d3dde3;
  --lake: #1f5a80;
  --lake-deep: #154361;
  --lake-wash: #e2edf4;
  --pine: #2d6a4f;
  --brick: #a3402a;
  --brick-wash: #f7e6e1;
  --focus: #e0a526;

  --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", sans-serif;
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: 2.441rem;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e5edf2;
    --ink-soft: #a3b4bf;
    --bg: #0f1b22;
    --surface: #16252e;
    --line: #2b3e4a;
    --lake: #7db7dc;
    --lake-deep: #a6cfea;
    --lake-wash: #1b3444;
    --pine: #7cc4a2;
    --brick: #f09a85;
    --brick-wash: #3a2420;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
}

a { color: var(--lake); text-underline-offset: 0.15em; }
a:hover { color: var(--lake-deep); }

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

h1, h2, h3 { line-height: 1.2; margin: 0; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap;
}

.page {
  width: 100%;
  max-width: 52rem;
  margin: 0 auto;
  padding: 0 1rem;
}
.narrow { max-width: 40rem; padding-top: 2rem; }

/* ---------- Sidhuvud ---------- */

.masthead {
  background: var(--lake-deep);
  color: #fff;
  padding: 1.25rem 0 2rem;
}
@media (prefers-color-scheme: dark) {
  .masthead { background: #12313f; }
}
.masthead-note {
  display: inline-block;
  margin: 0 0 1.5rem;
  padding: 0.15rem 0.6rem;
  font-size: var(--step--1);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.85);
}
.brand { margin: 0; font-size: var(--step-3); font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; }
.brand a { color: inherit; text-decoration: none; }
.brand a:hover { text-decoration: underline; text-decoration-thickness: 2px; }
.tagline { margin: 0.5rem 0 0; font-size: var(--step-1); color: rgba(255, 255, 255, 0.85); max-width: 36rem; }

/* Undersidor: samma huvud, mindre */
.masthead.compact { padding: 0.75rem 0; }
.masthead.compact .page {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 1rem;
}
.masthead.compact .brand { order: -1; font-size: var(--step-1); }
.masthead.compact .masthead-note { margin: 0; }

.lead { font-size: var(--step-1); color: var(--ink-soft); }

/* ---------- Bläddra i tiden ---------- */

.period {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 0 0.25rem;
}
.period-label { text-align: center; }
.period-range { margin: 0; font-size: var(--step-1); font-weight: 700; }
.period-label a { font-size: var(--step--1); }
.period-btn { font-size: var(--step-0); padding: 0.5rem 0.9rem; }
.btn.is-disabled,
.btn.is-disabled:hover {
  color: var(--ink-soft);
  background: transparent;
  border-color: var(--line);
  opacity: 0.55;
  cursor: default;
}

/* ---------- Filter ---------- */

.filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem 0 0.5rem;
}
.chip {
  font: inherit;
  font-size: var(--step--1);
  padding: 0.35rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
.chip:hover { border-color: var(--lake); }
.chip[aria-pressed="true"] {
  background: var(--lake);
  border-color: var(--lake);
  color: var(--surface);
  font-weight: 700;
}

/* ---------- Tidslinje ---------- */

.timeline {
  list-style: none;
  margin: 1rem 0 3rem;
  padding: 0;
}

.day {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 1rem;
  padding: 1rem 0;
  border-top: 1px solid var(--line);
}
.day:first-child { border-top: 0; }

.day-date { padding-top: 0.35rem; }
.dnum {
  display: block;
  font-size: 2.75rem;
  font-weight: 700;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.dname { display: block; color: var(--ink-soft); margin-top: 0.35rem; }
.today-tag {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: var(--step--1);
  font-weight: 700;
  color: var(--pine);
}

.day.past .dnum,
.day.past .unit { color: var(--ink-soft); }
.day.past .dnum { font-weight: 400; }
.day.today .dnum { color: var(--pine); }

.meetings { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }

.meetings .meeting > a {
  display: grid;
  grid-template-columns: 3.5rem 1fr;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--lake);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
}
.meetings .meeting > a:hover { border-color: var(--lake); background: var(--lake-wash); }
.day.past .meetings .meeting > a { border-left-color: var(--line); }
.meetings .meeting.cancelled > a { border-left-color: var(--brick); }
.meeting.cancelled .unit { text-decoration: line-through; text-decoration-thickness: 1px; }

.time { font-variant-numeric: tabular-nums; color: var(--ink-soft); }
.what { display: flex; flex-wrap: wrap; gap: 0.25rem 0.6rem; align-items: baseline; }
.unit { font-size: var(--step-1); font-weight: 700; }

.tag {
  display: inline-block;
  font-size: var(--step--1);
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  background: var(--lake-wash);
  color: var(--ink);
}
.tag-cancel { background: var(--brick-wash); color: var(--brick); font-weight: 700; }

.now-line {
  position: relative;
  margin: 0.5rem 0;
  padding: 0.5rem 0;
  color: var(--pine);
  font-weight: 700;
}
.now-line::before {
  content: "";
  position: absolute;
  left: 0; right: 0; top: 50%;
  border-top: 2px solid var(--pine);
}
.now-line span {
  position: relative;
  background: var(--bg);
  padding-right: 0.75rem;
}

.empty {
  margin: 2rem 0;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--ink-soft);
}

.site-footer {
  margin-top: 1rem;
  padding: 1.5rem 0 2.5rem;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: var(--step--1);
}
.site-footer p { margin: 0 0 0.5rem; max-width: 40rem; }

/* ---------- Mötessidan ---------- */

.crumb { margin: 1.5rem 0 1rem; }

.meeting-head { padding-bottom: 1.5rem; border-bottom: 2px solid var(--ink); }
.meeting-head h1 { font-size: var(--step-3); letter-spacing: -0.01em; }
.when { font-size: var(--step-1); margin: 0.5rem 0 0; }
.where { margin: 0.15rem 0 0; color: var(--ink-soft); }
.head-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 1.25rem 0 0; }
.hint { color: var(--ink-soft); font-size: var(--step--1); }

.section-title { font-size: var(--step-1); margin: 2rem 0 0.5rem; }

.agenda { list-style: none; margin: 0 0 4rem; padding: 0; }

.topic {
  display: grid;
  grid-template-columns: 2.75rem 1fr;
  gap: 0.75rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--line);
}
.num {
  font-size: var(--step-2);
  font-weight: 700;
  line-height: 1.1;
  color: var(--lake);
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.topic h3 { font-size: var(--step-1); }
.topic.no-docs h3 { font-weight: 400; }
.topic.no-docs .num { color: var(--ink-soft); }
.case { margin: 0.25rem 0 0; color: var(--ink-soft); font-size: var(--step--1); }

.docs { list-style: none; margin: 0.85rem 0 0; padding: 0; display: grid; gap: 0.4rem; }

.doc {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  padding: 0.6rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.doc.active { border-color: var(--lake); box-shadow: inset 4px 0 0 var(--lake); }
.doc-info { flex: 1 1 18rem; min-width: 0; }
.doc-name { font-weight: 700; text-decoration: none; overflow-wrap: anywhere; }
.doc-name:hover { text-decoration: underline; }
.doc-meta { display: block; color: var(--ink-soft); font-size: var(--step--1); }
.doc-actions { display: flex; gap: 0.4rem; }

.topic-zip { margin: 0.6rem 0 0; font-size: var(--step--1); }

.btn {
  display: inline-flex;
  align-items: center;
  font: inherit;
  font-size: var(--step--1);
  font-weight: 700;
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--lake);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--lake); background: var(--lake-wash); color: var(--lake-deep); }
.btn-primary { background: var(--lake); border-color: var(--lake); color: var(--surface); font-size: var(--step-0); padding: 0.55rem 1rem; }
.btn-primary:hover { background: var(--lake-deep); color: var(--surface); }

.err-title { font-size: var(--step-2); margin-top: 1rem; }

/* ---------- Visare bredvid dagordningen ---------- */

.viewer { display: none; }

@media (min-width: 1100px) {
  /* Sidhuvudet ligger kvar överst, dagordning och handling delar resten av höjden. */
  body.viewer-open {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
  }
  body.viewer-open .site-footer { display: none; }
  body.viewer-open .split {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(28rem, 40%) 1fr;
  }
  body.viewer-open .agenda-page {
    max-width: none;
    height: 100%;
    overflow-y: auto;
    padding: 0 1.5rem;
  }
  body.viewer-open .viewer {
    position: relative;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-left: 1px solid var(--line);
    background: var(--surface);
  }
  .viewer-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--line);
  }
  .viewer-title {
    flex: 1;
    margin: 0;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .viewer-actions { display: flex; gap: 0.4rem; }
  .viewer iframe { flex: 1; width: 100%; border: 0; background: #525659; }
  .viewer-loading {
    position: absolute;
    left: 50%;
    top: 45%;
    transform: translateX(-50%);
  }
}

/* ---------- Laddar ---------- */

.loading-bar {
  position: fixed;
  top: 0; left: 0;
  z-index: 50;
  height: 3px;
  width: 0;
  background: var(--focus);
  opacity: 0;
  pointer-events: none;
}
.is-loading .loading-bar { opacity: 1; width: 85%; }

.loading-note,
.viewer-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  padding: 0.5rem 0.9rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: var(--step--1);
  font-weight: 700;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.loading-note {
  position: fixed;
  z-index: 50;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
/* Visas bara om sidan dröjer – snabba klick ska inte blinka. */
.is-loading .loading-note { opacity: 1; visibility: visible; transition: opacity 0.2s 0.35s, visibility 0s 0.35s; }

.spinner {
  width: 1rem;
  height: 1rem;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  flex: none;
}
.viewer-loading[hidden] { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .is-loading .loading-bar { transition: width 8s cubic-bezier(0.1, 0.7, 0.2, 1); }
  .spinner { animation: spin 0.8s linear infinite; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { border-right-color: currentColor; opacity: 0.6; }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .masthead { padding: 1rem 0 1.5rem; }
  .brand, .meeting-head h1 { font-size: 1.95rem; }
  .masthead.compact .brand { font-size: var(--step-1); }
  .masthead-note { margin-bottom: 1rem; }
  .period { gap: 0.5rem; }
  .period-btn { padding: 0.45rem 0.6rem; }
  .period-range { font-size: var(--step-0); }
  .day { grid-template-columns: 1fr; gap: 0.5rem; }
  .day-date { display: flex; align-items: baseline; gap: 0.6rem; padding-top: 0; }
  .dnum { font-size: 2rem; }
  .dname, .today-tag { margin-top: 0; }
  .topic { grid-template-columns: 2rem 1fr; }
  .num { font-size: var(--step-1); }
}

@media (prefers-reduced-motion: no-preference) {
  .meetings .meeting > a, .btn, .chip { transition: background-color 0.12s, border-color 0.12s; }
}

@media (min-width: 1100px) {
  body.viewer-open .masthead .page { max-width: none; padding: 0 1.5rem; }
}
