/* ==========================================================================
   VBFA15 Husbyggnads- och VA-teknik — läsdelen
   Ljus "papper"-yta, tegelröd accent, seriftext för läsning och
   systemsans för allt gränssnitt. Inga webbfonter (ingen CLS, inga requests).
   ========================================================================== */

:root {
  --paper: #fbf8f5;
  --card: #ffffff;
  --ink: #23201d;
  --ink-soft: #4a433c;
  --muted: #756a60;
  --line: #e7dfd5;
  --line-soft: #f1eae1;
  --accent: #a8432c;
  --accent-dark: #8a3623;
  --accent-tint: #fbeeea;
  --accent-tint-2: #f6e2db;
  --ok: #2f6f4f;
  --ok-tint: #e8f2ec;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --shadow: 0 1px 2px rgba(35, 32, 29, .05), 0 8px 24px -16px rgba(35, 32, 29, .18);
  --radius: 12px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
}

a { color: var(--accent-dark); }
a:hover { color: var(--accent); }

[hidden] { display: none !important; }

/* ------------------------------- topbar --------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: center;
  padding: 10px 20px;
  background: rgba(251, 248, 245, .94);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }

.brand .glyph {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 21px;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.06rem;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand .sub {
  margin: 1px 0 0;
  font-size: .78rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-right { display: flex; align-items: center; gap: 12px; justify-self: end; }

.hub-back {
  font-size: .82rem;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}
.hub-back:hover { color: var(--accent); }

.tabs {
  grid-column: 1 / -1;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .9rem;
  font-weight: 550;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { background: var(--line-soft); color: var(--ink); }
.tab.active { background: var(--accent-tint); color: var(--accent-dark); }

.nav-toggle {
  display: none;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font-size: 1rem;
  width: 38px; height: 38px;
  border-radius: 9px;
  cursor: pointer;
}

/* --------------------------------- layout -------------------------------- */

main { padding: 0 20px 64px; }

.view { display: none; }
.view.active { display: block; }

.read-layout {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  gap: 36px;
  max-width: 1240px;
  margin: 0 auto;
  align-items: start;
}

/* --------------------------------- sidebar ------------------------------- */

.toc {
  position: sticky;
  top: 108px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  padding: 18px 4px 24px 0;
  scrollbar-width: thin;
}

.part-switch { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }

.part-btn {
  appearance: none;
  text-align: left;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 10px;
  padding: 9px 11px;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  align-items: baseline;
}
.part-btn:hover { border-color: var(--accent-tint-2); }
.part-btn .pt { font-size: .88rem; font-weight: 600; }
.part-btn .ph { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.part-btn .pm { grid-column: 1 / -1; font-size: .74rem; color: var(--muted); }
.part-btn.active { background: var(--accent-tint); border-color: var(--accent-tint-2); }
.part-btn.active .pt { color: var(--accent-dark); }
.part-btn.empty { opacity: .72; }

.toc-search { position: relative; margin-bottom: 14px; }
.toc-search input {
  width: 100%;
  font: inherit;
  font-size: .88rem;
  padding: 9px 30px 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
}
.toc-search input:focus { outline: 2px solid var(--accent-tint-2); border-color: var(--accent); }
.toc-search .clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted);
  font-size: 1rem; cursor: pointer; padding: 4px 6px; line-height: 1;
}

.toc-head {
  font-size: .7rem;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px 2px;
}

.toc ol { list-style: none; margin: 0; padding: 0; }

.ch-row {
  display: grid;
  grid-template-columns: 1.6rem 1fr auto;
  gap: 8px;
  align-items: baseline;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: .9rem;
  color: var(--ink-soft);
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
}
.ch-row:hover { background: var(--line-soft); color: var(--ink); }
.ch-row .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: .8rem; }
.ch-row .t { font-weight: 500; }
.ch-row .p { font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.ch-row.active { background: var(--accent-tint); color: var(--accent-dark); }
.ch-row.active .t { font-weight: 650; }
.ch-row.done .p { color: var(--ok); }

.toc .sec-list { margin: 2px 0 10px 2.4rem; display: none; }
.toc li.open .sec-list { display: block; }

.sec-link {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  border-left: 2px solid var(--line);
  background: transparent;
  font: inherit;
  font-size: .83rem;
  color: var(--muted);
  padding: 5px 8px 5px 11px;
  cursor: pointer;
}
.sec-link:hover { color: var(--ink); border-left-color: var(--accent-tint-2); }
.sec-link.current { color: var(--accent-dark); border-left-color: var(--accent); font-weight: 550; }
.sec-link.read::after { content: " ✓"; color: var(--ok); }

.hits { margin: 0; padding: 0; list-style: none; }
.hit {
  display: block; width: 100%; text-align: left;
  appearance: none; border: 0; background: transparent; font: inherit;
  padding: 8px; border-radius: 8px; cursor: pointer; color: var(--ink-soft);
}
.hit:hover { background: var(--line-soft); }
.hit .hk { display: block; font-size: .72rem; color: var(--muted); }
.hit .hs { display: block; font-size: .87rem; font-weight: 550; }
.hit mark { background: var(--accent-tint-2); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ------------------------------- reading pane --------------------------- */

.doc { min-width: 0; padding: 22px 0 0; }

.doc-head { margin-bottom: 26px; }

.crumb {
  font-size: .76rem;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 6px;
}

.doc-head h2 {
  font-family: var(--serif);
  font-size: clamp(1.7rem, 1.2rem + 1.8vw, 2.3rem);
  line-height: 1.12;
  letter-spacing: -.015em;
  margin: 0 0 10px;
  font-weight: 700;
}

.doc-head .lead { margin: 0; color: var(--muted); font-size: .92rem; }

.bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 14px; max-width: 340px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .25s ease; }

article.chapter { max-width: 68ch; }

article.chapter section { margin: 0 0 40px; scroll-margin-top: 118px; }

.sec-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 6px;
  margin-bottom: 16px;
}

.sec-head h3 {
  font-family: var(--serif);
  font-size: 1.32rem;
  line-height: 1.22;
  letter-spacing: -.01em;
  margin: 0;
  font-weight: 700;
}

.read-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: .75rem;
  padding: 4px 10px;
  border-radius: 99px;
  cursor: pointer;
  white-space: nowrap;
  flex: 0 0 auto;
}
.read-btn:hover { border-color: var(--accent-tint-2); color: var(--ink); }
.read-btn[aria-pressed="true"] { background: var(--ok-tint); border-color: #cfe3d7; color: var(--ok); }

/* brödtext */
article.chapter p,
article.chapter li,
article.chapter dd,
article.chapter dt {
  font-family: var(--serif);
  font-size: 1.0625rem;
  line-height: 1.62;
  color: var(--ink);
}

article.chapter p { margin: 0 0 14px; }

article.chapter h4 {
  font-family: var(--sans);
  font-size: .82rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--accent-dark);
  margin: 26px 0 10px;
  font-weight: 650;
}

article.chapter ul,
article.chapter ol { margin: 0 0 16px; padding-left: 1.35em; }
article.chapter li { margin-bottom: 6px; }
article.chapter li::marker { color: var(--accent); }

article.chapter dl { margin: 0 0 16px; }
article.chapter dt { font-weight: 700; margin-top: 10px; }
article.chapter dd { margin: 2px 0 0; padding-left: 1em; border-left: 2px solid var(--line); }

article.chapter strong { font-weight: 700; }
article.chapter code {
  font-family: var(--mono);
  font-size: .9em;
  background: var(--line-soft);
  padding: 1px 5px;
  border-radius: 5px;
}

/* tabeller */
.table-wrap { overflow-x: auto; margin: 0 0 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
article.chapter table { border-collapse: collapse; width: 100%; font-family: var(--sans); font-size: .88rem; }
article.chapter th,
article.chapter td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; line-height: 1.45; }
article.chapter thead th { background: var(--accent-tint); color: var(--accent-dark); font-size: .78rem; letter-spacing: .03em; text-transform: uppercase; font-weight: 650; border-bottom: 1px solid var(--line); }
article.chapter tbody tr:last-child td { border-bottom: 0; }
article.chapter tbody tr:nth-child(even) td { background: #fdfbf9; }

/* figurer */
article.chapter figure {
  margin: 24px 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
article.chapter figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: zoom-in;
  background: #fff;
}
article.chapter figcaption {
  font-family: var(--sans);
  font-size: .82rem;
  line-height: 1.5;
  color: var(--muted);
  margin-top: 10px;
  padding: 0 2px;
}

/* rutor */
.callout, .note {
  margin: 20px 0;
  padding: 12px 16px;
  border-radius: 10px;
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.55;
}
.callout { background: var(--accent-tint); border-left: 3px solid var(--accent); color: #4a1f14; }
.note { background: #f4f2ee; border-left: 3px solid #c9beb1; color: var(--ink-soft); font-size: .95rem; }
.callout p:last-child, .note p:last-child { margin-bottom: 0; }
.callout p, .note p { font-size: inherit; }

/* kapitelfot */
.doc-foot {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--line);
  padding-top: 18px;
  margin-top: 8px;
  max-width: 68ch;
}
.step {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  max-width: 46%;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.step:hover { border-color: var(--accent-tint-2); }
.step:disabled { opacity: .4; cursor: default; }
.step .sl { display: block; font-size: .7rem; color: var(--muted); }

/* tom del */
.empty-part {
  max-width: 62ch;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow);
}
.empty-part h3 { font-family: var(--serif); font-size: 1.3rem; margin: 0 0 10px; }
.empty-part p { font-family: var(--serif); font-size: 1.02rem; line-height: 1.6; color: var(--ink-soft); margin: 0 0 12px; }
.empty-part ul { font-family: var(--serif); margin: 0 0 4px; padding-left: 1.3em; color: var(--ink-soft); }

/* ------------------------------- min status ----------------------------- */

.status-wrap { max-width: 900px; margin: 24px auto 0; }
.status-wrap h2 { font-family: var(--serif); font-size: 1.8rem; margin: 0 0 6px; }
.status-wrap .lead { color: var(--muted); margin: 0 0 24px; font-size: .94rem; }

.stat-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 26px; }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 18px; min-width: 132px; box-shadow: var(--shadow);
}
.stat b { display: block; font-family: var(--serif); font-size: 1.7rem; line-height: 1; }
.stat span { font-size: .78rem; color: var(--muted); }

.prog-list { display: grid; gap: 8px; }
.prog-item {
  display: grid;
  grid-template-columns: 1.8rem 1fr 7rem 3.6rem;
  gap: 12px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  text-align: left;
  appearance: none;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}
.prog-item:hover { border-color: var(--accent-tint-2); }
.prog-item .n { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.prog-item .t { font-weight: 550; font-size: .92rem; }
.prog-item .v { font-size: .78rem; color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------- lightbox ------------------------------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(30, 26, 23, .82);
  cursor: zoom-out;
}
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
.lightbox .lb-cap {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 24px;
  color: #f3ece6;
  font-size: .85rem;
  text-align: center;
  background: linear-gradient(transparent, rgba(20, 17, 15, .85));
}

/* -------------------------------- footer -------------------------------- */

.footnote {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  color: var(--muted);
  font-size: .8rem;
  line-height: 1.55;
  border-top: 1px solid var(--line);
}

/* ------------------------------ responsivt ------------------------------ */

@media (max-width: 900px) {
  .read-layout { grid-template-columns: 1fr; gap: 0; }
  .nav-toggle { display: block; }
  .toc {
    position: static;
    max-height: none;
    overflow: visible;
    display: none;
    padding: 14px 0 6px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 12px;
  }
  .toc.open { display: block; }
  .topbar { grid-template-columns: 1fr auto auto; padding: 8px 14px; }
  main { padding: 0 14px 48px; }
  article.chapter section { scroll-margin-top: 150px; }
  .prog-item { grid-template-columns: 1.6rem 1fr 4.5rem; }
  .prog-item .v { display: none; }
}

/* kontowidgeten (e-postfält + knapp) får egen rad när headern blir trång */
@media (max-width: 680px) {
  .topbar { grid-template-columns: 1fr auto; row-gap: 6px; }
  .brand h1 { font-size: .98rem; }
  .top-right {
    grid-column: 1 / -1;
    justify-self: start;
    justify-content: space-between;
    width: 100%;
    flex-wrap: wrap;
  }
  .top-right .kb-acc-form input { max-width: 42vw; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .bar > i { transition: none; }
}

/* --------------------------------- print -------------------------------- */

@media print {
  .topbar, .toc, .doc-foot, .read-btn, .nav-toggle, .footnote { display: none !important; }
  body { background: #fff; }
  main { padding: 0; }
  .read-layout { display: block; }
  article.chapter { max-width: none; }
  article.chapter section { break-inside: auto; }
  article.chapter figure { break-inside: avoid; box-shadow: none; }
}
