/* All colors and sizes live in :root so the look can be re-skinned later
   without touching templates. */
:root {
  --bg: #fafaf8;
  --surface: #ffffff;
  --text: #1f2a2e;
  --text-muted: #5d6b70;
  --border: #e2e5e3;
  --accent: #0f6e56;

  --cell-great: #1d9e75;    /* deep green */
  --cell-good: #9fe1cb;     /* light green */
  --cell-decent: #aab0b1;   /* neutral grey — distinct from green & yellow */
  --cell-marginal: #fac775; /* yellow */
  --cell-bad: #f0a8a8;
  --cell-no-data: #ececea;

  /* certainty hatching: darker, denser lines = less certain */
  --hatch-color: rgba(38, 48, 52, 0.30);

  /* avalanche danger scale (NVE / varsom): ? = not evaluated, 1..5 */
  --aval-na: #dbe9f1;
  --aval-1: #6abf69;
  --aval-2: #ffcf33;
  --aval-3: #ff8c1a;
  --aval-4: #e8483f;
  --aval-5: #1a1a1a;

  --radius: 6px;
  --cell-h: 30px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

main { max-width: 880px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }

.site-header {
  max-width: 880px; margin: 0 auto; padding: 1rem;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 0.6rem 1rem;
}
.logo { font-size: 1.15rem; font-weight: 600; letter-spacing: 0.02em; }
.logo-dot { color: var(--accent); font-weight: 400; }

.activity-nav { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.activity-btn {
  font-size: 0.85rem; padding: 0.3rem 0.7rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.activity-btn:hover { border-color: var(--accent); }
.activity-btn.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

/* ----- the grid ----- */
.grid {
  display: grid;
  grid-template-columns: minmax(90px, 130px) repeat(var(--ndays), minmax(22px, 1fr));
  grid-auto-rows: var(--cell-h);   /* fixed row height: spacing stays uniform */
  gap: 3px;
  overflow-x: auto;
}
.day-head {
  text-align: center; font-size: 0.7rem; color: var(--text-muted);
  display: flex; flex-direction: column; line-height: 1.2;
}
.day-head .dow { font-size: 0.6rem; text-transform: uppercase; }
.day-head.today { color: var(--accent); font-weight: 600; }
.day-head.weekend { font-weight: 700; }
.day-head.weekend .dow { font-weight: 700; }
.place-name {
  align-self: center; font-size: 0.85rem; color: var(--text-muted);
  line-height: 1.1;   /* keep a two-line name within one row height */
}

.cell {
  height: var(--cell-h); border: none; border-radius: 4px; padding: 0;
  cursor: pointer; position: relative; overflow: hidden;
}
.cell:hover { outline: 2px solid var(--accent); }
.cell.no-data { background-color: var(--cell-no-data); cursor: default; }
.cell.no-data:hover { outline: none; }
/* band fill is background-COLOR so the hatch background-image is not reset */
.cell.great { background-color: var(--cell-great); }
.cell.good { background-color: var(--cell-good); }
.cell.decent { background-color: var(--cell-decent); }
.cell.marginal { background-color: var(--cell-marginal); }
.cell.bad { background-color: var(--cell-bad); }

/* certainty hatch overlay (applies to cells and legend swatches). hatch-0 is
   no overlay; hatch-2 is denser than hatch-1. */
/* Certainty marker: a small top-right corner triangle, all in the lean colour
   (--hatch-color, set per-cell inline); gaps are transparent so the band fill
   shows through. The triangle is identical in both levels; uncertain adds one
   thick line further in. less certain (hatch-1) = triangle; uncertain
   (hatch-2) = triangle + thick line. */
.hatch-1::after, .hatch-2::after {
  content: ""; position: absolute; top: 0; right: 0;
  width: 16px; height: 16px;
  clip-path: polygon(0 0, 100% 0, 100% 100%);   /* top-right triangle */
}
/* note: inside this triangle the gradient only spans 0-50% (the hypotenuse is at
   50%); anything past 50% is clipped away, so keep the line within 0-50%. */
.hatch-1::after {
  background-image: linear-gradient(to bottom left,
    var(--hatch-color) 0 30%, transparent 30%);
}
.hatch-2::after {
  background-image: linear-gradient(to bottom left,
    var(--hatch-color) 0 30%, transparent 30% 37%,
    var(--hatch-color) 37% 50%, transparent 50%);
}

/* avalanche danger marker: small square in the top-left corner, inside the cell.
   `.aval-swatch` is the same chip for the legend. Colour rules come after both
   base classes so aval-4/5's white text wins over the default. */
.aval {
  position: absolute; top: 1px; left: 1px;
  width: 14px; height: 14px; border-radius: 3px;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 700; line-height: 1;
  color: #1f2a2e; pointer-events: none;
}
.aval-swatch {
  display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 3px; vertical-align: text-bottom;
  margin-right: 4px; font-size: 9px; font-weight: 700; font-style: normal;
  color: #1f2a2e;
}
.aval-na { background: var(--aval-na); color: #35505c; }
.aval-1 { background: var(--aval-1); }
.aval-2 { background: var(--aval-2); }
.aval-3 { background: var(--aval-3); }
.aval-4 { background: var(--aval-4); color: #fff; }
.aval-5 { background: var(--aval-5); color: #fff; }
.legend-aval { margin-top: -0.8rem; }

.legend {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1.2rem;
  margin: 0.8rem 0 1.5rem; font-size: 0.75rem; color: var(--text-muted);
}
.swatch {
  display: inline-block; width: 11px; height: 11px; border-radius: 3px;
  vertical-align: -1px; margin-right: 4px;
}
.swatch.great { background-color: var(--cell-great); }
.swatch.good { background-color: var(--cell-good); }
.swatch.decent { background-color: var(--cell-decent); }
.swatch.marginal { background-color: var(--cell-marginal); }
.swatch.bad { background-color: var(--cell-bad); }
.swatch.no-data { background-color: var(--cell-no-data); }
.legend-hatch { margin-top: -0.8rem; }
.legend-hint { opacity: 0.8; }
/* bigger swatches so the corner flag is legible; neutral marker colour here */
.legend-hatch .swatch {
  width: 18px; height: 18px; vertical-align: -4px;
  position: relative; overflow: hidden; --hatch-color: var(--text-muted);
}

/* grid recolours in place during tuning: dim only, never resize */
#grid-wrap.updating { opacity: 0.7; transition: opacity 0.1s; }

/* ----- detail panel ----- */
.detail-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.2rem; margin-top: 0.5rem;
  min-height: 110px;   /* reserve space so loading doesn't jump the layout */
}
.detail-panel.loading { opacity: 0.55; }   /* keep old content while reloading */
.detail-head { display: flex; justify-content: space-between; flex-wrap: wrap;
  gap: 0.3rem; margin-bottom: 0.8rem; }
.detail-score { color: var(--text-muted); font-size: 0.85rem; }

.metric-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.metric { background: var(--bg); border-radius: var(--radius); padding: 8px 10px; }
.metric-label { font-size: 0.7rem; color: var(--text-muted); }
.metric-uncert { float: right; opacity: 0.6; font-weight: 400; }
.metric-value { font-size: 1.05rem; font-weight: 600; margin: 2px 0 4px; }
.metric-bar { height: 3px; background: var(--border); border-radius: 2px; }
.metric-bar i { display: block; height: 100%; background: var(--accent);
  border-radius: 2px; }
.metric-note { font-size: 0.7rem; color: #a32d2d; }

.detail-note, .detail-links { font-size: 0.8rem; color: var(--text-muted);
  margin: 0.8rem 0 0; }
.detail-links a, .site-footer a { color: var(--accent); }

.empty-note { color: var(--text-muted); font-size: 0.9rem; }
code { background: var(--border); padding: 0 4px; border-radius: 3px; }

.site-footer {
  max-width: 880px; margin: 0 auto; padding: 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem; color: var(--text-muted);
}

/* ----- login page ----- */
.login-box { max-width: 300px; margin: 18vh auto; display: flex;
  flex-direction: column; gap: 1rem; }
.login-box form { display: flex; flex-direction: column; gap: 0.6rem; }
.login-box label { font-size: 0.85rem; color: var(--text-muted); }
.login-box input {
  font: inherit; padding: 0.5rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--surface);
}
.login-box button {
  font: inherit; padding: 0.5rem; border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff; cursor: pointer;
}
.login-error { color: #a32d2d; font-size: 0.85rem; margin: 0; }

/* ----- interactive tuning ("Fikle med innstillinger"), at the page bottom ----- */
.tuning { margin-top: 2rem; }
.tuning-toggle {
  font: inherit; font-size: 0.85rem; padding: 0.4rem 0.8rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
}
.tuning-toggle:hover { border-color: var(--accent); }
.tuning-panel {
  margin-top: 0.8rem; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; background: var(--surface);
}
.tuning-actions { display: flex; gap: 0.5rem; margin-bottom: 0.9rem; }
.tuning-actions button {
  font: inherit; font-size: 0.78rem; padding: 0.3rem 0.7rem;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer;
}
.tuning-actions button:hover { border-color: var(--accent); }

#settings-body {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.8rem;
}
.ctl-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0.6rem 0.7rem; background: var(--bg);
}
.ctl-card-h {
  font-size: 0.8rem; font-weight: 600; margin-bottom: 0.5rem;
  text-transform: capitalize;
}
.ctl-active {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.74rem; font-weight: 600; margin-bottom: 0.35rem;
}
.ctl-gate {
  display: flex; align-items: center; gap: 0.35rem;
  font-size: 0.72rem; color: var(--text-muted); margin-bottom: 0.5rem;
}
.ctl-card.inactive { opacity: 0.55; }   /* parameter switched off for this activity */
.ctl-card.inactive .ctl-card-h { text-decoration: line-through; }
.ctl { margin: 0.45rem 0; }
.ctl-head { display: flex; justify-content: space-between; font-size: 0.72rem; }
.ctl-label { color: var(--text-muted); }
.ctl-val { font-weight: 600; }
.ctl-track { position: relative; margin-top: 0.15rem; }
.ctl-track input[type="range"] { width: 100%; margin: 0; }
.ctl-tick {                       /* marker showing the default value */
  position: absolute; top: 50%; width: 2px; height: 13px;
  background: var(--accent); opacity: 0.55;
  transform: translate(-1px, -50%); pointer-events: none;
}
.ctl-def { font-size: 0.63rem; color: var(--text-muted); opacity: 0.75; }
.tuning-yaml {
  width: 100%; height: 200px; margin-top: 0.9rem; padding: 0.5rem;
  font-family: ui-monospace, monospace; font-size: 0.72rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); resize: vertical;
}
