/* ==========================================================================
   koulu — tool.css
   Lookup app (app.html) + school detail page (school.html).
   Panel, ring, rows-list, components-list, leaflet overrides, tabs, badges.
   ========================================================================== */

/* ============== APP — MAIN LAYOUT ============== */
.app-body { display: grid; grid-template-rows: auto 1fr auto; min-height: 100vh; background: var(--cream); }
.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 440px;
  min-height: 0;
}
#map-wrap { position: relative; min-height: 0; }
#map { width: 100%; height: 100%; background: #ddd5c2; }
#map-hint {
  position: absolute;
  bottom: 14px; left: 14px;
  background: rgba(255,255,255,.95);
  border: 1px solid var(--cream-3);
  border-radius: var(--radius-pill);
  padding: 7px 14px;
  font-size: 12px; color: var(--ink-muted);
  z-index: 500; pointer-events: none;
  box-shadow: 0 2px 8px rgba(0,0,0,.06);
}

#panel {
  background: #fff;
  border-left: 1px solid var(--cream-3);
  padding: 24px 28px;
  overflow-y: auto;
}
.panel-state { display: flex; flex-direction: column; gap: 18px; }
.panel-state.hidden { display: none; }
.panel-state h2 {
  font-size: clamp(28px, 3.5vw, 36px);
  line-height: 1.05;
  letter-spacing: -0.02em;
  margin: 0;
}
.panel-state p { margin: 0; }
.bullet-list { margin: 4px 0 0; padding-left: 0; list-style: none; display: grid; gap: 6px; font-size: 14.5px; }
.bullet-list li { padding-left: 18px; position: relative; }
.bullet-list li::before {
  content: ""; position: absolute; left: 0; top: 9px;
  width: 8px; height: 1px; background: var(--accent);
}
.bullet-list strong { color: var(--ink); font-weight: 600; }

.block { display: flex; flex-direction: column; gap: 10px; }
.block + .block { padding-top: 18px; border-top: 1px dotted var(--cream-3); }
.block__h {
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-muted); margin: 0;
}
.block__sub {
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.10em;
  color: var(--ink-muted); margin: 12px 0 6px;
}

.addr-hd { gap: 2px; padding-bottom: 6px; }
.addr-hd h2 {
  font-size: 26px; letter-spacing: -0.01em;
  margin: 0;
}
.mono--coord { font-size: 11.5px; color: var(--ink-muted); margin: 0; }

/* ============== FIT RING ============== */
.fit-row { display: flex; align-items: center; gap: 18px; }
.ring {
  --pct: 0;
  width: 76px; height: 76px; flex-shrink: 0;
  border-radius: 50%;
  background: conic-gradient(var(--accent) 0deg, var(--accent) calc(var(--pct) * 3.6deg), var(--cream-2) calc(var(--pct) * 3.6deg));
  position: relative;
  display: flex; align-items: center; justify-content: center;
}
.ring::before { content: ""; position: absolute; inset: 6px; background: #fff; border-radius: 50%; }
.ring__v {
  position: relative; z-index: 1;
  font-family: "Instrument Serif", serif;
  font-size: 30px; font-weight: 500;
}
.fit-meta { flex: 1; }
.fit-meta .lbl {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--ink-muted); margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.fit-meta .h { font-size: 17px; line-height: 1.25; }

/* Confidence chip next to a /100 label — plain text, no background blob */
.signal-count {
  display: inline; font-size: 11px; letter-spacing: 0;
  text-transform: none; color: var(--ink-muted);
}
.signal-count::before { content: "· "; }
.signal-count[hidden] { display: none; }
.signal-count[data-level="low"] { color: #9a6b1f; }
.signal-count[data-level="med"] { color: var(--ink-2); }
.signal-count[data-level="hi"]  { color: var(--accent-2, #3a5530); }

/* Low-confidence ring — striped to signal that the number is one signal,
   not a full verdict. */
.ring.is-low-confidence {
  background: repeating-conic-gradient(
    var(--ink-muted) 0deg,
    var(--ink-muted) calc(var(--pct) * 3.6deg / 8),
    transparent calc(var(--pct) * 3.6deg / 8),
    transparent calc(var(--pct) * 3.6deg / 4),
    var(--cream-2) calc(var(--pct) * 3.6deg),
    var(--cream-2) 360deg
  );
}
.ring.is-low-confidence .ring__v { color: var(--ink-muted); }

.components-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.components-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  font-size: 12.5px;
}
.components-list .bar {
  grid-column: 1 / -1;
  height: 4px; background: var(--cream-2);
  border-radius: 2px; overflow: hidden;
}
.components-list .bar > span { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ============== ROWS LIST (services, lukios, catchments) ============== */
.rows-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.rows-list li {
  padding: 11px 14px;
  background: var(--cream);
  border: 1px solid var(--cream-3);
  border-radius: var(--radius-r);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
}
.rows-list li.empty {
  background: transparent;
  border: 1px dashed var(--cream-3);
  color: var(--ink-muted);
  justify-content: center;
}
/* Small in-list scope heading — used in the area-context block to split rows
   that vary per postcode from rows that are city-wide. */
.rows-list .rows-list__scope {
  background: transparent; border: 0;
  padding: 10px 2px 4px; margin-top: 4px;
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.10em;
  color: var(--ink-muted); font-weight: 600;
  display: block;
}
.rows-list .rows-list__scope:first-child { margin-top: 0; padding-top: 4px; }
.rows-list .role,
.rows-list .kind {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-muted); margin-bottom: 2px;
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.rows-list .school-name { font-weight: 500; letter-spacing: -0.005em; }
.rows-list .school-link {
  color: var(--ink);
  text-decoration: none;
  font-weight: 600;
}
.rows-list .school-link:hover { color: var(--accent); text-decoration: underline; }
.leaflet-popup .school-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}
.leaflet-popup .school-link:hover { text-decoration: underline; }
.rows-list .dist {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px; color: var(--ink-muted); white-space: nowrap;
}

/* ============== TIER & METRIC LABELS (lukio rows) ==============
   All numbers / labels render as plain typography: a small uppercase chip
   would read as decorative noise next to so many other numbers. The colour
   carries the tier signal without a box. */
.tier {
  display: inline; font-size: 10px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-muted);
  margin-right: 4px;
}
.tier--hi  { color: var(--tier-hi-fg); }
.tier--mid { color: var(--tier-mid-fg); }
.tier--lo  { color: var(--tier-lo-fg); }
.tier--na  { color: var(--ink-muted); }

.year-tag {
  display: inline; font-family: "JetBrains Mono", monospace;
  font-size: 10.5px; color: var(--accent); margin-left: 4px;
}
.year-tag--old { color: var(--ink-muted); }

.trend {
  display: inline; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px; margin-left: 6px;
}
.trend--up   { color: var(--tier-hi-fg); }
.trend--down { color: var(--tier-lo-fg); }

.demand-badge, .matric-badge {
  display: inline; font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 10.5px; color: var(--ink-2); margin-left: 6px;
  letter-spacing: 0;
}
.matric-badge { color: var(--accent-2); }

.spark {
  vertical-align: -3px;
  margin-left: 6px;
  opacity: 0.85;
}
.spark:hover { opacity: 1; }

.lukio-note {
  font-size: 11.5px;
  line-height: 1.45;
}

.disclaimer {
  font-size: 11px;
  color: var(--ink-muted);
  line-height: 1.5;
  margin: 0;
}

/* ============== TABS (area + services block) ============== */
.tabbed { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabbed button {
  border: 1px solid var(--cream-3); background: #fff; color: var(--ink-2);
  border-radius: 999px; padding: 5px 11px; font: inherit; font-size: 11.5px; cursor: pointer;
}
.tabbed button[aria-pressed="true"] { background: var(--ink); color: var(--cream); border-color: var(--ink); }
.tab-panel[hidden] { display: none; }

/* ============== LEAFLET MAP POLYGONS ============== */
.leaflet-container { font-family: inherit; }
.catchment-poly       { stroke: #4a6a3a; stroke-opacity: 0.7;  fill: #4a6a3a; fill-opacity: 0.06; stroke-width: 1.2; }
.catchment-poly--upper{ stroke: #a85a2a; fill: #a85a2a; }
.catchment-poly--esi  { stroke: #2f4527; fill: #dee6d2; }
.catchment-poly--espoo{ stroke: #315f7d; fill: #d8e8ee; }
.catchment-poly--pupil{ stroke: #315f7d; fill: #d8e8ee; }
.catchment-poly--hit  { fill-opacity: 0.22; stroke-width: 2.4; stroke-opacity: 1; }
/* Non-matching polygons fade out once a hit is highlighted, so the user can
   see at a glance which polygons govern their address. */
.catchment-poly--faded { stroke-opacity: 0.18; fill-opacity: 0.02; stroke-width: 0.8; }

/* ============== SCHOOL PAGE ============== */
.school-page { max-width: 980px; margin: 0 auto; padding: 32px 28px 96px; }
.crumb { font-family: "JetBrains Mono", monospace; font-size: 12px; color: var(--ink-muted); margin-bottom: 12px; }
.crumb a { color: var(--ink-muted); text-decoration: none; }
.crumb a:hover { color: var(--accent); }
.sch-hd h1 { font-family: "Instrument Serif", serif; font-size: clamp(36px, 5.5vw, 64px); line-height: 1.02; letter-spacing: -0.025em; font-weight: 400; margin: 0 0 8px; }
.sch-hd .meta { font-family: "JetBrains Mono", monospace; font-size: 13px; color: var(--ink-muted); }
.sch-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 28px; margin-top: 32px; }
.sch-card { background: #fff; border: 1px solid var(--cream-3); border-radius: var(--radius-card); padding: 24px; }
.sch-card h2 { font-family: "Instrument Serif", serif; font-size: 22px; font-weight: 400; letter-spacing: -0.015em; margin: 0 0 14px; }
.sch-card h2 .it { font-style: italic; color: var(--accent); }
.sch-card p { margin: 0 0 10px; font-size: 14.5px; color: var(--ink-2); line-height: 1.6; }
.demand-summary { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }
.demand-summary .ring { width: 88px; height: 88px; }
.demand-summary .ring__v { font-size: 32px; }
.demand-summary .of { font-size: 12px; color: var(--ink-muted); display: block; margin-top: -4px; }
.cutoff-line { display: grid; grid-template-columns: 60px 1fr auto; gap: 12px; align-items: baseline; padding: 8px 0; border-bottom: 1px dotted var(--cream-3); font-size: 14px; }
.cutoff-line:last-child { border: 0; }
.cutoff-line .yr { font-family: "JetBrains Mono", monospace; color: var(--ink-muted); }
.cutoff-line .val { font-family: "JetBrains Mono", monospace; font-weight: 600; }
.cutoff-line .bar { background: var(--cream-2); height: 6px; border-radius: 3px; overflow: hidden; }
.cutoff-line .bar > span { display: block; height: 100%; background: var(--accent); }
.lines-list { list-style: none; padding: 0; margin: 0; }
.lines-list li { display: grid; grid-template-columns: 1fr auto; gap: 14px; padding: 9px 0; border-bottom: 1px dotted var(--cream-3); font-size: 14px; align-items: center; }
.lines-list li:last-child { border: 0; }
.lines-list .line-name { color: var(--ink); line-height: 1.3; }
.lines-list .line-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.lines-list .line-kind { font-family: "Instrument Serif", serif; font-size: 11.5px; color: var(--ink-muted); font-style: italic; }
.lines-list .v { font-family: "JetBrains Mono", monospace; font-size: 13.5px; color: var(--ink); }
.lines-list .v strong { font-weight: 600; }
.lines-list .v .unit { color: var(--ink-muted); font-size: 11.5px; margin-left: 2px; }
.programs-sub { margin-bottom: 14px; }
.programs-sub:last-child { margin-bottom: 0; }
.programs-sub h3 { font-family: "Instrument Serif", serif; font-size: 14px; font-weight: 400; color: var(--ink-2); margin: 0 0 6px 0; letter-spacing: 0.02em; }
.programs-list { list-style: none; padding: 0; margin: 0; }
.programs-list li { padding: 5px 0; border-bottom: 1px dotted var(--cream-3); font-size: 13.5px; color: var(--ink); }
.programs-list li:last-child { border: 0; }
.programs-list--lang li { display: flex; gap: 10px; align-items: baseline; }
.programs-list .kieli-lvl { font-family: "JetBrains Mono", monospace; font-size: 11px; background: var(--cream-2); color: var(--ink-2); padding: 1px 6px; border-radius: 3px; min-width: 22px; text-align: center; }
#sch-map { height: 280px; border-radius: var(--radius-card); border: 1px solid var(--cream-3); }
.compare-list li {
  display: grid; grid-template-columns: 1fr auto auto; gap: 14px;
  padding: 10px 0; border-bottom: 1px dotted var(--cream-3); font-size: 14px;
}
.compare-list li:last-child { border: 0; }
.compare-list .nm { font-family: "Instrument Serif", serif; font-size: 17px; }
.compare-list .stat { font-family: "JetBrains Mono", monospace; color: var(--ink-muted); font-size: 12.5px; }
.compare-list .stat strong { color: var(--ink); font-size: 13.5px; }
.compare-list a { text-decoration: none; color: inherit; }
.compare-list li:hover { background: var(--cream); cursor: pointer; }

/* ============== RESPONSIVE ============== */
@media (max-width: 900px) {
  .app-main { grid-template-columns: 1fr; grid-template-rows: 50vh auto; }
  #panel { border-left: none; border-top: 1px solid var(--cream-3); }
  .knav--app { flex-wrap: wrap; padding: 12px 16px; }
  .knav--app .search-pill--nav { flex-basis: 100%; }
}
@media (max-width: 760px) {
  .sch-grid { grid-template-columns: 1fr; }
}
