/* Design tokens */
:root {
  --paper: #FAFAFA;
  --paper-soft: #F2F2F2;
  --ink: #151513;
  --ink-2: #2B2B2B;
  --muted: #6B6860;
  --hair: #E4E4E4;
  --hair-strong: #C8C8C8;
  --focus: #FFE7A3;

  --font-display: ui-serif, Georgia, serif;
  --font-body:    system-ui, sans-serif;
  --font-mono:    ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--paper); color: var(--ink); }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 48px 56px 64px;
}

/* ---------- MASTHEAD ---------- */
.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 48px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 32px;
}
.masthead-left {
  display: flex;
  align-items: flex-end;
  gap: 24px;
}
.masthead-stat { text-align: right; }
.masthead-stat .stat-value { font-size: 48px; }
.masthead-mark {
  width: 80px;
  height: 80px;
  flex-shrink: 0;
  display: block;
}
.title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 72px;
  line-height: 0.95;
  letter-spacing: -0.01em;
  margin: 0;
}
.meta-line {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-align: right;
  max-width: 320px;
  line-height: 1.6;
  white-space: nowrap;
}

/* ---------- TWO-COLUMN LAYOUT ---------- */
.layout {
  display: flex;
  flex-direction: column;
  gap: 40px;
}

@media (min-width: 1024px) {
  .layout {
    flex-direction: row;
    gap: 56px;
    align-items: flex-start;
  }
  .map-col {
    flex: 0 0 44%;
    position: sticky;
    top: 32px;
  }
  .content-col {
    flex: 1 1 0;
    min-width: 0;
  }
}

/* ---------- INTRO ---------- */
.intro-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 32px;
  margin-bottom: 32px;
}
.intro p {
  font-family: var(--font-display);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink-2);
  margin: 0;
  text-wrap: pretty;
}

/* ---------- STATS ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0;
  border-top: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  margin-bottom: 36px;
}
.stat {
  padding: 14px 18px 12px;
  border-right: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
}
.stat:nth-child(2n) { border-right: none; }
.stat:nth-last-child(-n+2) { border-bottom: none; }
.stat-value {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 28px;
  line-height: 1;
  letter-spacing: -0.01em;
  color: var(--ink);
  font-variant-numeric: lining-nums;
}
.stat-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 8px;
}
.stat-sub {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-style: italic;
}

/* ---------- SECTION HEADS ---------- */
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink);
  margin-bottom: 24px;
}
.section-label {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.005em;
}
.section-hint {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  min-height: 16px;
}
.muted { color: var(--muted); }

/* ---------- MAP ---------- */
.map-wrap {
  position: relative;
  padding: 8px 0;
}
.norge-map,
.norge-map svg {
  width: 100%;
  height: auto;
  display: block;
}

/* SVG municipality interactivity.
   vector-effect: non-scaling-stroke bypasses the viewBox coordinate transform so
   stroke-width values are in CSS pixels, not SVG user units. Without this the
   strokes scale down with the viewBox (11379 → ~470 px, factor ~0.04) and become
   sub-pixel hairlines that are nearly invisible on high-DPI displays. */
.muni {
  fill: transparent;
  stroke: var(--hair-strong);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
  cursor: default;
  transition: stroke 80ms, stroke-width 80ms;
}
.muni.visited {
  fill: var(--ink-2);
  cursor: pointer;
}
.muni:hover,
.muni.touch-pending { fill: url(#muni-hover); }
.muni.visited:hover,
.muni.visited.touch-pending { fill: url(#muni-hover-v); stroke: var(--ink-2); }
.muni.tiny { stroke-width: 2; }
.muni.tiny.visited { fill: var(--ink-2); stroke: var(--ink-2); }
.muni.tiny:hover { stroke: var(--ink); stroke-width: 3; }

/* Tooltip */
.hover-tip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-display);
  font-size: 14px;
  line-height: 1;
  padding: 6px 10px;
  white-space: nowrap;
  z-index: 10;
  transform: translate(14px, -50%);
}
.hover-tip-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  color: var(--hair-strong);
  margin-left: 4px;
}

/* Legend */
.legend {
  display: flex;
  justify-content: center;
  gap: 32px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.06em;
  padding-top: 8px;
  flex-wrap: wrap;
  row-gap: 6px;
}
.legend-item { display: inline-flex; align-items: center; gap: 8px; }
.sw { display: inline-block; width: 14px; height: 10px; }
.sw-vis { background: var(--ink-2); }
.sw-unv { background: var(--paper); border: 1px solid var(--hair-strong); }
.sw-dot {
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 50%;
  width: 8px;
  height: 8px;
}

/* ---------- LOG ---------- */
.log-section { margin-bottom: 48px; }
.log-head,
.log-row {
  display: grid;
  grid-template-columns: 90px 1.4fr 1.6fr 80px 1fr;
  align-items: center;
  gap: 16px;
  padding: 0 4px;
}
.log-head {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  height: 28px;
  border-bottom: 1px solid var(--hair-strong);
}
.log-row {
  height: 36px;
  border-bottom: 1px solid var(--hair);
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  transition: background 160ms;
  text-decoration: none;
}
.log-row.focused { background: var(--focus); }
.log-row:hover { background: var(--paper-soft); }
a.log-row { cursor: pointer; }
a.log-row .col-muni { text-decoration: underline; }

/* Layout only — applies to both header and data cells */
.col-date { white-space: nowrap; }
.col-elev { text-align: right; }
.col-peak,
.col-fylke { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Data-row rendering — scoped so headers stay consistent */
.log-row .col-date { font-family: var(--font-mono); font-size: 13px; color: var(--muted); }
.log-row .col-muni { font-weight: 500; }
.log-row .col-peak { font-style: italic; color: var(--ink-2); }
.log-row .col-elev { font-variant-numeric: tabular-nums; }
.log-row .col-fylke { color: var(--muted); }
.col-elev .unit { color: var(--muted); }

/* ---------- FOOTER ---------- */
.foot {
  margin-top: 48px;
  padding: 16px 56px 32px;
  border-top: 1px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.foot a { color: inherit; }

/* ---------- VISIT PAGE ---------- */
.visit-page {
  max-width: 740px;
}
.visit-nav {
  margin-bottom: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.visit-nav-mark {
  width: 32px;
  height: 32px;
  display: block;
  opacity: 0.5;
}
.back-link {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }
.visit-header {
  border-bottom: 1px solid var(--ink);
  padding-bottom: 20px;
  margin-bottom: 32px;
}
.visit-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 52px;
  line-height: 1;
  letter-spacing: -0.01em;
  margin: 8px 0 12px;
}
.visit-meta {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--muted);
  display: flex;
  gap: 24px;
}
.visit-body {
  font-family: var(--font-display);
  font-size: 18px;
  line-height: 1.6;
  color: var(--ink-2);
  margin-bottom: 40px;
}
.visit-body p { margin: 0 0 1em; }
.visit-body h2 {
  font-weight: 500;
  font-size: 24px;
  margin: 1.5em 0 0.5em;
}
.visit-body a { color: var(--ink); }
.visit-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 48px;
}
.gallery-item {
  margin: 0;
}
.gallery-item img {
  width: 100%;
  height: auto;
  display: block;
}
.gallery-item figcaption {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
  letter-spacing: 0.04em;
}

/* ---------- ADMIN NAV ---------- */
.admin-nav {
  background: var(--paper-soft);
  border-bottom: 1px solid var(--hair-strong);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
}
.admin-nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 56px;
  height: 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
}
.admin-nav-links { display: flex; gap: 24px; align-items: center; }
.admin-nav a { color: var(--muted); text-decoration: none; }
.admin-nav a:hover { color: var(--ink); }
.admin-nav-mark { width: 20px; height: 20px; display: block; }

/* ---------- ADMIN FORMS ---------- */
.admin-page { max-width: 900px; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; }
.login-box input {
  display: block;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  outline: none;
}
.login-box .btn { display: block; width: 100%; padding: 10px; text-align: center; }
.login-note { margin-top: 20px; font-size: 12px; color: var(--muted); line-height: 1.5; }

/* Field: label wrapping a <span> header + input/textarea */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}
.field > input,
.field > textarea {
  padding: 8px 10px;
  font-family: var(--font-body);
  font-size: 14px;
  border: 1px solid var(--hair-strong);
  background: var(--paper);
  color: var(--ink);
  outline: none;
}
.field > input[type="date"],
.field > input[type="number"] { font-family: var(--font-mono); }
.field > input[type="file"]   { padding: 0; border: none; background: none; font-family: var(--font-mono); font-size: 12px; }
.field > textarea { font-family: var(--font-mono); font-size: 13px; line-height: 1.6; resize: vertical; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 9px 20px;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  border: none;
  cursor: pointer;
  text-decoration: none;
}
.btn-ghost {
  background: none;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  border: none;
  cursor: pointer;
  padding: 0;
}

/* Form utilities */
.form-error { color: #c0392b; font-family: var(--font-mono); font-size: 12px; margin: 0 0 20px; }
.form-meta  { font-family: var(--font-mono); font-size: 11px; color: var(--muted); margin-bottom: 20px; }
.form-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.form-grid .field.full { grid-column: 1 / -1; }
.danger-zone { margin-top: 56px; padding-top: 24px; border-top: 1px solid var(--hair); }

/* Image grid in visit edit */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.img-card { border: 1px solid var(--hair); padding: 10px; }
.img-card img { width: 100%; height: 120px; object-fit: cover; display: block; margin-bottom: 8px; }
.img-card-name { font-family: var(--font-mono); font-size: 10px; color: var(--muted); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Admin visits list: extra "edit" column */
.log-cols-admin { grid-template-columns: 110px 1.2fr 1.4fr 70px 1fr 80px; }
.log-row.admin  { height: auto; padding: 8px 4px; }
.col-action     { text-align: right; }

/* Dashboard */
.dash-4col  { grid-template-columns: repeat(4, 1fr); margin-bottom: 48px; }
.dash-4col .stat:nth-child(2n) { border-right: 1px solid var(--hair); }
.dash-4col .stat:nth-child(4n) { border-right: none; }
.dash-4col .stat               { border-bottom: none; }
.dash-grid  { display: grid; grid-template-columns: 1fr 1fr; gap: 48px; }
.dash-chart { display: flex; align-items: flex-end; gap: 3px; height: 80px; border-bottom: 1px solid var(--hair); margin-bottom: 4px; }
.dash-chart-bar   { flex: 1; background: var(--ink-2); min-width: 4px; }
.dash-chart-dates { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 10px; color: var(--muted); margin-bottom: 48px; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.dash-table th { text-align: left; padding: 6px 4px; font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--hair-strong); font-weight: normal; }
.dash-table td { padding: 7px 4px; border-bottom: 1px solid var(--hair); }
.dash-table td:first-child { color: var(--ink-2); font-family: var(--font-mono); }
.dash-table th:not(:first-child),
.dash-table td:not(:first-child) { text-align: right; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 860px) {
  .admin-nav-inner { padding: 0 20px; }
  .page { padding: 32px 20px 48px; }
  .foot { padding: 16px 20px 32px; }
  .title { font-size: 44px; }
  .masthead-mark { width: 56px; height: 56px; }
  .masthead {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
    padding-bottom: 14px;
  }
  .meta-line { text-align: left; }
  .masthead-stat { text-align: left; }
  .intro-row { flex-direction: column; gap: 8px; }
  .log-head,
  .log-row { grid-template-columns: 90px 1fr 80px; gap: 10px; }
  .col-peak, .col-fylke { display: none; }
  .visit-title { font-size: 36px; }
}
