/* DALA MESH
   Ett typsnitt (Archivo), en accentfärg (Falu rödfärg), linjer i stället för kort.
   Mellanrum enligt 4/8-skala. */

:root {
  --paper: #fbfaf7;
  --paper-2: #f2efe8;
  --ink: #16181a;
  --ink-2: #3d4246;
  --muted: #5d6266;
  --rule: #d9d4ca;
  --rule-strong: #16181a;
  --accent: #9b2c20;          /* Falu rödfärg */
  --accent-hover: #7a2017;
  --on-accent: #ffffff;
  --code-bg: #f2efe8;

  --st-ok: #1b7a4e;
  --st-recent: #a86a00;
  --st-old: #8c9296;

  --t-repeater: #9b2c20;
  --t-room: #2c5aa0;
  --t-companion: #1b7a4e;
  --t-sensor: #7a4c96;

  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px; --s9: 96px;
  --wrap: 1120px;
  --header-h: 56px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121416; --paper-2: #1a1d20; --ink: #ecebe7; --ink-2: #c8c9c5; --muted: #9ba1a5;
    --rule: #2d3236; --rule-strong: #ecebe7; --accent: #e36a5a; --accent-hover: #f08576; --on-accent: #1a0b08;
    --code-bg: #1d2124; --st-ok: #46c98a; --st-recent: #e0a93e; --st-old: #6f777b;
    --t-repeater: #e36a5a; --t-room: #79a7ee; --t-companion: #46c98a; --t-sensor: #c09ae0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121416; --paper-2: #1a1d20; --ink: #ecebe7; --ink-2: #c8c9c5; --muted: #9ba1a5;
  --rule: #2d3236; --rule-strong: #ecebe7; --accent: #e36a5a; --accent-hover: #f08576; --on-accent: #1a0b08;
  --code-bg: #1d2124; --st-ok: #46c98a; --st-recent: #e0a93e; --st-old: #6f777b;
  --t-repeater: #e36a5a; --t-room: #79a7ee; --t-companion: #46c98a; --t-sensor: #c09ae0;
  color-scheme: dark;
}

/* ---------- Bas ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 1.0625rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased; overflow-x: hidden;
}
img, svg { max-width: 100%; }
h1, h2, h3 { font-stretch: 87.5%; line-height: 1.15; margin: 0 0 var(--s3); text-wrap: balance; }
h1 { font-size: clamp(2.5rem, 7vw, 4rem); font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 1.375rem; font-weight: 700; }
h3 { font-size: 1.125rem; font-weight: 700; margin-top: var(--s6); }
p { margin: 0 0 var(--s4); }
ul, ol { padding-left: 1.25rem; margin: 0 0 var(--s4); }
li { margin-bottom: var(--s2); }
a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); text-decoration-thickness: 2px; }
strong { font-weight: 650; }
code, .mono { font-family: var(--mono); font-size: .9em; }
:not(pre) > code { background: var(--code-bg); padding: .1em .35em; border-radius: 3px; overflow-wrap: anywhere; }
pre {
  font: .875rem/1.6 var(--mono); background: var(--code-bg); color: var(--ink);
  border-left: 3px solid var(--rule-strong); padding: var(--s4); overflow-x: auto; margin: 0 0 var(--s5);
}
pre .c { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; z-index: 100; background: var(--ink); color: var(--paper); padding: var(--s3) var(--s4); }
.skip:focus { left: var(--s4); top: var(--s2); }
.muted { color: var(--muted); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.wrap { width: min(100% - 32px, var(--wrap)); margin-inline: auto; }

/* ---------- Sidhuvud ---------- */
.site-header { border-bottom: 1px solid var(--rule); background: var(--paper); position: sticky; top: 0; z-index: 50; }
.nav { display: flex; align-items: center; gap: var(--s5); min-height: var(--header-h); }
.brand { display: inline-flex; align-items: center; gap: var(--s2); color: var(--ink); text-decoration: none; font-weight: 800; font-stretch: 87.5%; font-size: 1.125rem; }
.brand:hover { color: var(--ink); }
.brand img { width: 24px; height: 24px; }
.nav-links { display: flex; gap: var(--s1); list-style: none; margin: 0 0 0 auto; padding: 0; }
.nav-links li { margin: 0; }
.nav-links a {
  display: flex; align-items: center; min-height: 44px; padding: 0 var(--s3);
  color: var(--ink-2); text-decoration: none; font-weight: 500; border-bottom: 2px solid transparent;
}
.nav-links a:hover { color: var(--ink); }
.nav-links a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }
.theme-btn {
  width: 44px; height: 44px; display: grid; place-items: center; flex: none;
  background: none; border: 0; color: var(--ink-2); cursor: pointer; border-radius: 4px;
}
.theme-btn:hover { color: var(--ink); background: var(--paper-2); }
.theme-btn svg { width: 20px; height: 20px; }

@media (max-width: 640px) {
  .nav { flex-wrap: wrap; gap: 0; }
  .brand { min-height: 48px; }
  .theme-btn { margin-left: auto; }
  .nav-links { order: 3; width: 100%; margin: 0 0 0 calc(-1 * var(--s3)); }
  .site-header { position: static; }
}

/* ---------- Knappar ---------- */
.btn {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s5);
  border: 1.5px solid var(--ink); border-radius: 3px; background: var(--ink); color: var(--paper);
  font: 600 1rem/1 var(--font); text-decoration: none; cursor: pointer;
  transition: background-color .15s ease, color .15s ease;
}
.btn:hover { background: var(--accent); border-color: var(--accent); color: var(--on-accent); text-decoration: none; }
.btn-secondary { background: transparent; color: var(--ink); }
.btn-secondary:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s5); }

/* ---------- Startsida: intro ---------- */
.intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 420px); gap: var(--s8); align-items: center; padding: var(--s8) 0; }
.intro .lede { font-size: clamp(1.125rem, 2.2vw, 1.3rem); line-height: 1.5; color: var(--ink-2); max-width: 34em; }
.summary { color: var(--muted); font-size: .95rem; min-height: 1.6em; }
.summary b { color: var(--ink); font-weight: 650; font-variant-numeric: tabular-nums; }

.netfig { margin: 0; }
.netfig svg { display: block; width: 100%; height: auto; aspect-ratio: 1; }
.netfig .ring { fill: none; stroke: var(--rule); }
.netfig .near { stroke: var(--ink); stroke-opacity: .14; stroke-width: 1; }
.netfig .near.real { stroke-opacity: .45; stroke-width: 1.25; }
.netfig .node { fill: var(--ink); }
.netfig .node.ok { fill: var(--accent); }
.netfig .center { fill: none; stroke: var(--ink); stroke-width: 1.5; }
.netfig text { font: 500 11px var(--font); fill: var(--muted); }
.netfig figcaption { font-size: .85rem; color: var(--muted); margin-top: var(--s2); border-top: 1px solid var(--rule); padding-top: var(--s2); }

@media (max-width: 860px) {
  .intro { grid-template-columns: 1fr; gap: var(--s6); padding: var(--s7) 0 var(--s6); }
  .netfig { max-width: 360px; }
}

/* ---------- Sektioner: rubrik vänster, innehåll höger ---------- */
.row { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: var(--s6); padding: var(--s7) 0; border-top: 1px solid var(--rule); }
.row > header h2 { position: sticky; top: calc(var(--header-h) + var(--s4)); }
.row .body { max-width: 720px; min-width: 0; }
.row .body > :last-child { margin-bottom: 0; }
@media (max-width: 760px) {
  .row { grid-template-columns: 1fr; gap: var(--s2); padding: var(--s6) 0; }
  .row > header h2 { position: static; }
}

/* ---------- Radioinställningar ---------- */
.settings { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 2px solid var(--rule-strong); margin: 0 0 var(--s5); }
.settings div { padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--rule); }
.settings dt { font-size: .85rem; color: var(--muted); }
.settings dd { margin: 0; font: 600 1.5rem/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.settings dd small { font-size: .6em; font-weight: 400; color: var(--muted); }
@media (max-width: 560px) { .settings { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.cmd { display: flex; align-items: stretch; max-width: 100%; border: 1px solid var(--rule); border-radius: 3px; background: var(--code-bg); margin-bottom: var(--s4); }
.cmd code { flex: 1; min-width: 0; padding: var(--s3) var(--s4); background: none; font-size: .95rem; overflow-wrap: anywhere; }
.copy {
  flex: none; min-width: 88px; border: 0; border-left: 1px solid var(--rule); background: transparent; color: var(--ink);
  font: 600 .9rem var(--font); cursor: pointer; padding: 0 var(--s4);
}
.copy:hover { background: var(--paper); }

/* ---------- Tabeller ---------- */
.table-scroll { overflow-x: auto; margin: 0 0 var(--s5); }
table { width: 100%; border-collapse: collapse; font-size: .975rem; }
th, td { text-align: left; padding: var(--s3) var(--s4) var(--s3) 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
thead th { font-weight: 600; font-size: .85rem; color: var(--muted); border-bottom: 2px solid var(--rule-strong); }
td.num, th.num { text-align: right; padding-right: 0; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody th { font-weight: 600; }
td code { white-space: nowrap; overflow-wrap: normal; }

/* Status: färg + text, aldrig bara färg */
.st { display: inline-flex; align-items: center; gap: var(--s2); white-space: nowrap; }
.st::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--st-old); flex: none; }
.st.ok::before { background: var(--st-ok); }
.st.recent::before { background: var(--st-recent); }

/* ---------- Notiser ---------- */
.note { border-left: 3px solid var(--accent); padding: var(--s1) 0 var(--s1) var(--s4); margin: var(--s5) 0; color: var(--ink-2); }
.note p:last-child { margin: 0; }

/* ---------- Guide ---------- */
.page-title { padding: var(--s8) 0 var(--s6); }
.page-title p { font-size: 1.15rem; color: var(--ink-2); max-width: 38em; margin: 0; }
.guide { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: var(--s7); padding-bottom: var(--s9); border-top: 1px solid var(--rule); }
.toc { position: sticky; top: calc(var(--header-h) + var(--s5)); align-self: start; padding-top: var(--s6); font-size: .95rem; }
.toc ol { margin: 0; padding-left: 1.4rem; }
.toc li { margin-bottom: var(--s1); color: var(--muted); }
.toc a { color: var(--ink-2); text-decoration: none; display: inline-block; padding: var(--s1) 0; }
.toc a:hover, .toc a.active { color: var(--accent); }
.toc a.active { font-weight: 600; }
.steps { max-width: 720px; min-width: 0; }
.step { padding: var(--s6) 0; border-bottom: 1px solid var(--rule); scroll-margin-top: calc(var(--header-h) + var(--s4)); }
.step:last-child { border-bottom: 0; }
.step h2 { font-size: clamp(1.4rem, 3vw, 1.75rem); }
.step h2 .n { color: var(--muted); font-weight: 500; margin-right: var(--s2); font-variant-numeric: tabular-nums; }
@media (max-width: 860px) {
  .guide { grid-template-columns: 1fr; gap: 0; }
  .toc { position: static; padding: var(--s5) 0; border-bottom: 1px solid var(--rule); }
  .toc ol { columns: 2; column-gap: var(--s5); }
}

details { border-bottom: 1px solid var(--rule); }
details:first-of-type { border-top: 1px solid var(--rule); }
summary { cursor: pointer; padding: var(--s3) 0; font-weight: 600; min-height: 44px; display: list-item; }
summary:hover { color: var(--accent); }
details > div { padding: 0 0 var(--s4); color: var(--ink-2); }
details > div p:last-child { margin: 0; }

/* ---------- Karta ---------- */
.map-page { display: grid; grid-template-columns: minmax(0, 1fr) 360px; height: calc(100dvh - var(--header-h) - 1px); }
#map { height: 100%; width: 100%; background: var(--paper-2); }
.panel { border-left: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; background: var(--paper); }
.panel-head { padding: var(--s4); border-bottom: 1px solid var(--rule); }
.panel-head h1 { font-size: 1.5rem; margin-bottom: var(--s1); }
.panel-head .summary { margin: 0 0 var(--s3); }
fieldset { border: 0; margin: 0 0 var(--s3); padding: 0; min-width: 0; }
legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: var(--s1); }
.checks { display: flex; flex-wrap: wrap; gap: 0 var(--s4); }
.checks label { display: inline-flex; align-items: center; gap: var(--s2); min-height: 36px; cursor: pointer; font-size: .95rem; }
.checks input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.sq { width: 12px; height: 12px; display: inline-block; opacity: .75; flex: none; }
.line { width: 16px; height: 2px; background: var(--ink); opacity: .6; display: inline-block; }
.checks input:disabled + * , .checks input:disabled ~ * { opacity: .45; }
.checks label:has(input:disabled) { cursor: not-allowed; color: var(--muted); }
.coverage-legend { display: flex; flex-wrap: wrap; gap: 2px var(--s3); margin-top: var(--s2); font-size: .8rem; color: var(--ink-2); }
.coverage-legend .leg { display: inline-flex; align-items: center; gap: var(--s2); }
.layers-note { font-size: .85rem; margin: var(--s1) 0 0; }
.field-row { display: flex; gap: var(--s2); }
.field { display: flex; flex-direction: column; gap: var(--s1); font-size: .85rem; color: var(--muted); }
.field:first-child { flex: 1; min-width: 0; }
.field input, .field select {
  height: 44px; border: 1px solid var(--rule); border-radius: 3px; background: var(--paper); color: var(--ink);
  padding: 0 var(--s3); font: 400 1rem var(--font);
}
.field input:focus, .field select:focus { border-color: var(--ink); outline: 2px solid var(--accent); outline-offset: 0; }
.node-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.node-list li { margin: 0; border-bottom: 1px solid var(--rule); }
.node-list button {
  width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s3); align-items: center;
  text-align: left; border: 0; background: none; color: var(--ink); padding: var(--s3) var(--s4); cursor: pointer; font: inherit;
}
.node-list button:hover { background: var(--paper-2); }
.node-list .nm { font-weight: 600; font-size: .975rem; overflow-wrap: anywhere; }
.node-list .meta { font-size: .85rem; color: var(--muted); }
.node-list .ago { font-size: .85rem; color: var(--ink-2); text-align: right; }
.panel-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--rule); font-size: .85rem; color: var(--muted); }
.panel-foot p { margin: 0; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); margin-top: var(--s1); }
.empty { padding: var(--s6) var(--s4); color: var(--muted); }

@media (max-width: 900px) {
  .map-page { grid-template-columns: 1fr; grid-template-rows: 60vh auto; height: auto; }
  .panel { border-left: 0; border-top: 1px solid var(--rule); }
  .node-list { overflow: visible; }
}

/* Leaflet */
.leaflet-container { font-family: var(--font); background: var(--paper-2); }
.map-dark .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.5); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--paper); color: var(--ink); border-radius: 3px; box-shadow: 0 2px 12px rgba(0,0,0,.18); }
.leaflet-popup-content { margin: var(--s4); font-size: .9rem; line-height: 1.5; min-width: 220px; }
.leaflet-popup-content h2 { font-size: 1.05rem; margin: 0 0 var(--s1); padding-right: var(--s5); }
.leaflet-popup-content p { margin: 0; }
.leaflet-popup-content dl { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s3); margin: var(--s3) 0 0; }
.leaflet-popup-content dt { color: var(--muted); }
.leaflet-popup-content dd { margin: 0; }
.leaflet-popup-content .warn { margin-top: var(--s3); padding-top: var(--s2); border-top: 1px solid var(--rule); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); width: 32px; height: 32px; font-size: 20px; }
.leaflet-bar a, .leaflet-bar a:hover { background: var(--paper); color: var(--ink); border-color: var(--rule); width: 36px; height: 36px; line-height: 36px; }
.leaflet-control-attribution { background: var(--paper) !important; color: var(--muted); }
.leaflet-control-attribution a { color: var(--ink-2); }
.center-mark { width: 14px; height: 14px; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper); }

/* ---------- Sidfot ---------- */
.site-footer { border-top: 1px solid var(--rule); padding: var(--s6) 0 var(--s7); font-size: .95rem; color: var(--muted); }
.site-footer .wrap { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s4) var(--s6); }
.site-footer ul { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); list-style: none; margin: 0; padding: 0; }
.site-footer li { margin: 0; }
.site-footer a { color: var(--ink-2); }
.site-footer p { margin: 0; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
