:root {
  --bg: #e9edf1;          /* talviasfaltti */
  --surface: #ffffff;
  --ink: #15212c;
  --muted: #5b6874;
  --line: #d3dae1;
  --sign: #0a5ca8;        /* tienviitan sininen */
  --sign-ink: #ffffff;
  --head: #0a5ca8;        /* yläpalkki */
  --on-free: #ffffff;     /* teksti vihreällä pohjalla */
  --free: #1b7f4f;
  --busy: #b06a00;
  --off: #8a939b;
  --warn-bg: #fff4e0;
  --warn-ink: #7a4a00;
  --focus: #ffb000;
  --radius-sm: 6px;
  --radius-lg: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #10171e; --surface: #18222c; --ink: #e6ebf0; --muted: #98a5b1; --line: #2a3743;
    --sign: #5aa7ec; --sign-ink: #08182a; --head: #0e3d6b; --free: #3fbf80; --on-free: #06190f;
    --busy: #e2a03a; --off: #6d7883;
    --warn-bg: #3a2c12; --warn-ink: #f2c97c; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 400 16px/1.45 "Barlow", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--sign); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------- yläpalkki: tienviitta ---------- */
.top {
  background: var(--head);
  color: #fff;
  padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.mark {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 2px solid currentColor; border-radius: 7px;
}
.top h1 {
  margin: 0; font: 700 1.5rem/1 "Barlow Semi Condensed", sans-serif; letter-spacing: .01em;
}
.topright { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.viewswitch { color: inherit; font-size: .9rem; font-weight: 500; text-underline-offset: 3px; }
.fresh { margin: 0; font-size: .9rem; opacity: .9; display: inline-flex; align-items: center; gap: 7px; }
.fresh.live { opacity: 1; font-weight: 500; }
.fresh.live::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: #7dffb5;
  box-shadow: 0 0 0 3px rgba(125,255,181,.25);
}

/* ---------- päävalikko (kaikilla sivuilla) ---------- */
.brand { color: inherit; text-decoration: none; }
.brandname { font: 700 1.5rem/1 "Barlow Semi Condensed", sans-serif; letter-spacing: .01em; }
.mainnav { display: flex; gap: 4px; flex-wrap: wrap; margin-right: auto; margin-left: 12px; }
.mainnav a {
  color: inherit; text-decoration: none; font-weight: 500; font-size: .98rem;
  padding: 8px 12px; border-radius: 8px; min-height: 40px; display: inline-flex; align-items: center;
}
.mainnav a:hover { background: rgba(255,255,255,.12); }
.mainnav a[aria-current="page"] { background: rgba(255,255,255,.2); font-weight: 600; }
@media (max-width: 640px) {
  .mainnav { order: 3; width: calc(100% + 16px); margin: 0 -8px; gap: 0; flex-wrap: nowrap; }
  .mainnav a { padding: 6px 9px; font-size: .95rem; white-space: nowrap; }
}
@media (max-width: 380px) {
  .mainnav a { padding: 6px 7px; font-size: .9rem; }
}

/* ---------- asettelu ---------- */
.layout { display: grid; grid-template-columns: 1fr; }
.panel { padding: 16px; max-width: 760px; width: 100%; margin: 0 auto; }
.mapwrap { display: none; }
@media (min-width: 1100px) {
  .layout { grid-template-columns: minmax(560px, 720px) 1fr; height: calc(100vh - 58px); }
  .panel { overflow-y: auto; margin: 0; max-width: none; padding: 20px 24px; }
  .mapwrap { display: block; position: relative; border-left: 1px solid var(--line); }
  #map { position: absolute; inset: 0; }
}
.nomap .mapwrap { display: none !important; }
@media (min-width: 1100px) { .nomap .layout { grid-template-columns: minmax(560px, 760px); justify-content: center; } }

/* ---------- haku ---------- */
.search {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 14px; display: grid; gap: 14px;
}
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.grow { flex: 1 1 200px; }
.field { display: grid; gap: 4px; }
.lbl { font-size: .85rem; color: var(--muted); font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.lbl output { color: var(--ink); font-weight: 600; }
select {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 10px; min-height: 42px; width: 100%;
}
/* Paikkakunta: kirjoitettava kenttä + oma sijainti */
.placebox { display: flex; gap: 6px; }
.combo { position: relative; flex: 1 1 auto; min-width: 0; }
.combo-chev { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.placemenu {
  position: absolute; z-index: 1100; left: 0; right: 0; top: calc(100% + 4px); margin: 0; padding: 4px;
  list-style: none; max-height: min(340px, 60vh); overflow-y: auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.placemenu[hidden] { display: none; }
.placemenu li {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 9px 10px; border-radius: 5px; cursor: pointer; min-height: 40px;
}
.placemenu li small { color: var(--muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.placemenu li[aria-selected] { background: var(--sign); color: var(--sign-ink); }
.placemenu li[aria-selected] small { color: inherit; opacity: .85; }
.placemenu li:hover:not([aria-selected]):not(.none) { background: var(--bg); }
.placemenu li.none { color: var(--muted); cursor: default; }
.placebox input {
  width: 100%; padding-right: 32px; min-width: 0; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 9px 10px; min-height: 42px;
}
.locbtn {
  display: inline-flex; align-items: center; gap: 6px; flex: none; min-height: 42px; padding: 0 12px;
  font: 600 .92rem "Barlow", sans-serif; color: var(--sign); background: var(--surface);
  border: 1.5px solid var(--sign); border-radius: var(--radius-sm); cursor: pointer;
}
.locbtn:hover { background: color-mix(in srgb, var(--surface) 88%, var(--sign)); }
.locbtn[aria-pressed="true"] { background: var(--sign); border-color: var(--sign); color: var(--sign-ink); }
.placeerr { margin: 4px 0 0; font-size: .85rem; color: var(--busy); }
.placeerr:empty { display: none; }
@media (max-width: 360px) { .locbtn span { display: none; } .locbtn { padding: 0 11px; } }
.tag.area { background: var(--sign); color: var(--sign-ink); font-weight: 600; }
.fact.area { font-weight: 600; color: var(--sign); }
input[type="range"] { width: 100%; accent-color: var(--sign); min-height: 28px; }

.seg { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg legend { margin-bottom: 4px; padding: 0; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span {
  display: grid; gap: 1px; padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); text-align: center; align-content: center; min-height: 44px; height: 100%;
}
.seg b { font-weight: 600; font-size: .98rem; }
.seg small { color: var(--muted); font-size: .8rem; }
.seg input:checked + span { background: var(--sign); border-color: var(--sign); color: var(--sign-ink); }
.seg input:checked + span small { color: inherit; opacity: .85; }
.seg input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }

.opts { justify-content: space-between; align-items: center; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; min-height: 36px; }
.check input { width: 18px; height: 18px; accent-color: var(--sign); }
.sort { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.sort button {
  font: 500 .9rem "Barlow", sans-serif; border: 0; background: var(--bg); color: var(--ink);
  padding: 8px 12px; cursor: pointer; min-height: 36px;
}
.sort button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

/* ---------- tulokset ---------- */
.summary { margin: 18px 2px 8px; color: var(--muted); font-size: .95rem; }
.summary strong { color: var(--ink); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; background: var(--line);
        border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.list:empty { display: none; }

.st {
  background: var(--surface); display: grid; gap: 4px 14px; padding: 14px;
  grid-template-columns: 92px 1fr auto; align-items: start; cursor: pointer;
}
.st:hover { background: color-mix(in srgb, var(--surface) 92%, var(--sign)); }
.st.sel { box-shadow: inset 4px 0 0 var(--sign); }
.price { display: grid; line-height: 1; }
.price .eur {
  font: 700 1.9rem/1 "Barlow Semi Condensed", sans-serif; font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.price .eur small { font-size: .55em; font-weight: 600; margin-left: 1px; }
.price .kwh { font-size: .82rem; color: var(--muted); margin-top: 5px; font-variant-numeric: tabular-nums; }
.price.none .eur { color: var(--off); font-size: 1.1rem; font-weight: 600; line-height: 1.15; }

.info { min-width: 0; }
.info h3 { margin: 0; font-size: 1.03rem; font-weight: 600; line-height: 1.25; }
.info .op { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 6px; margin-top: 6px; }
.tag { font-size: .78rem; padding: 2px 7px; border-radius: 4px; background: var(--bg); color: var(--ink); }
.note { margin: 6px 0 0; font-size: .82rem; color: var(--muted); }
.warn { margin: 7px 0 0; font-size: .82rem; background: var(--warn-bg); color: var(--warn-ink);
        padding: 4px 8px; border-radius: 4px; }

.side { text-align: right; display: grid; gap: 4px; justify-items: end; }
.free { font-weight: 600; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.free::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: currentColor; }
.free.ok { color: var(--free); } .free.busy { color: var(--busy); } .free.off { color: var(--off); }
.dist { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.go { font-size: .88rem; font-weight: 500; text-decoration: none; padding: 4px 0; }
.go:hover { text-decoration: underline; }

.divider { background: var(--bg); padding: 12px 14px 8px; color: var(--muted); font-size: .9rem; }
.empty { background: var(--surface); padding: 24px 16px; }
.empty p { margin: 0 0 6px; }

.foot { color: var(--muted); font-size: .82rem; margin: 18px 2px 30px; max-width: 70ch; }
.foot p { margin: 0 0 6px; }

@media (max-width: 520px) {
  .st { grid-template-columns: 78px 1fr; }
  .side { grid-column: 2; text-align: left; justify-items: start; grid-auto-flow: column; justify-content: start; gap: 12px; align-items: center; }
  .price .eur { font-size: 1.6rem; }
  .seg b { font-size: .9rem; }
  .seg span { padding: 8px; }
  .search { padding: 12px; gap: 12px; }
  .panel { padding: 12px; }
  .opts { flex-wrap: nowrap; }
}

/* ---------- kartta ---------- */
.pin {
  /* MapLibre sijoittaa merkin itse (anchor: center), joten transformia ei saa asettaa tässä */
  background: var(--sign); color: var(--sign-ink); border: 2px solid #fff; border-radius: 6px;
  font: 700 12px/1 "Barlow Semi Condensed", sans-serif; padding: 4px 5px; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,.35); display: inline-block; cursor: pointer; margin: 0;
  -webkit-appearance: none; appearance: none;
}
.pin:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.maplibregl-ctrl-attrib { font-size: 11px; }
.pin.none { background: var(--off); color: #fff; }
.pin.sel { background: var(--ink); }

/* Tilamuutos: rivi välähtää kerran, kun vapaiden määrä muuttuu */
@keyframes changed { from { background: color-mix(in srgb, var(--surface) 70%, var(--free)); } to { background: var(--surface); } }
.st.changed { animation: changed 2.4s ease-out; }
.st.changed .free { animation: pop .5s ease-out; }
@keyframes pop { 40% { transform: scale(1.12); } }

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

/* ---------- alapalkki ---------- */
.sitefoot {
  border-top: 1px solid var(--line); background: var(--surface); color: var(--muted);
  padding: 18px 16px 22px; font-size: .88rem; text-align: center;
}
.sitefoot nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 20px; margin-bottom: 8px; }
.sitefoot nav a { color: var(--ink); text-decoration: none; font-weight: 500; padding: 6px 0; }
.sitefoot nav a:hover { text-decoration: underline; color: var(--sign); }
.sitefoot p { margin: 0; }
.sitefoot p a { color: var(--muted); }
.sitefoot.in-panel { margin: 26px -16px -16px; }
@media (min-width: 1100px) { .sitefoot.in-panel { margin: 26px -24px -20px; } }
@media (max-width: 1099px) { .v2 .sitefoot.in-panel { margin-bottom: -84px; padding-bottom: 96px; } }
@media (max-width: 520px) { .sitefoot.in-panel { margin: 26px -12px -12px; } }
