* { box-sizing: border-box; }

[hidden] { display: none !important; }

:root {
  --green: #1faa4b;
  --green-dark: #178a3c;
  --blue: #1565c0;
  --blue-dark: #0f4f99;
  --ink: #1b1b1b;
  --muted: #666;
  --line: #e2e2e2;
  --bg: #f6f7f6;
}

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

.topbar {
  padding: 14px 20px;
  background: #262626;
  color: #fff;
  text-align: center;
}

.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; }

section { max-width: 1100px; margin: 0 auto; padding: 18px 20px 40px; }

/* --- hero --- */

.hero {
  display: flex;
  gap: 14px;
  margin-bottom: 18px;
}

.hero-btn {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 22px 16px;
  color: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.hero-offer { background: var(--green); }
.hero-offer:hover { background: var(--green-dark); }
.hero-need { background: var(--blue); }
.hero-need:hover { background: var(--blue-dark); }

.hero-title { font-size: 19px; font-weight: 700; }
.hero-sub { font-size: 14px; opacity: .9; }

/* --- flash --- */

.flash {
  background: #e6f6ea;
  border: 1px solid var(--green);
  color: #14602c;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-weight: 600;
}

/* --- filters --- */

.filters-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.filters-bar label { font-size: 12px; color: var(--muted); display: block; }
.filters-bar select, .filters-bar input {
  display: block;
  margin-top: 3px;
  padding: 7px 8px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}
.filters-bar input { width: 140px; }
.filters-bar #filter-radius { width: 100px; }

.geo-wrap { display: flex; gap: 6px; align-items: center; }
.geo-wrap input { flex: 1; }

.geo-btn {
  background: #eef4fb;
  color: var(--blue);
  border: 1px solid var(--blue);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 3px;
}
.geo-btn:hover { background: #dce9f8; }
.geo-btn:disabled { opacity: .6; cursor: wait; }

.geo-btn-wide {
  display: block;
  width: 100%;
  margin: -8px 0 14px;
  font-weight: 600;
}

/* Paikkakuntaehdotin: neljä riviä näkyvissä, loput rullaamalla. */
.suggest {
  position: absolute;
  z-index: 800;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 7px;
  box-shadow: 0 6px 18px rgba(0,0,0,.18);
  max-height: 154px;
  overflow-y: auto;
}
.suggest-item {
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 400;
  color: var(--ink);
  cursor: pointer;
}
.suggest-item:hover, .suggest-item.is-active { background: #eef4fb; }

.type-chips { display: flex; gap: 6px; margin-left: auto; }

.filter-block { width: 100%; }
.filter-label { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }
.mat-filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.map-expand {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 600;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

body.map-fullscreen { overflow: hidden; }
body.map-fullscreen .map-col {
  position: fixed;
  inset: 0;
  z-index: 1000;
  margin: 0;
  background: #fff;
}
body.map-fullscreen #map {
  height: 100%;
  border-radius: 0;
  border: 0;
}

.chip {
  background: #efefef;
  color: #444;
  border: 0;
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 13px;
  cursor: pointer;
}
.chip.is-active { background: #262626; color: #fff; }

/* --- home grid: feed + map --- */

.home-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  align-items: start;
}

.feed h2 { font-size: 15px; margin: 4px 0 8px; }

.feed-list { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.feed-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 13.5px;
}
.feed-item:hover { border-color: #bbb; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.feed-item strong { font-size: 14.5px; }
.feed-item span { color: var(--muted); }

.feed-empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }

.map-col { position: relative; }

#map {
  height: 520px;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  /* Oma pinontakonteksti, etteivät Leafletin painikkeet nouse ponnahdusikkunoiden päälle. */
  position: relative;
  z-index: 0;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,.25);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; }
.dot-offer { background: var(--green); }
.dot-need { background: var(--blue); }

/* --- form popup --- */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0,0,0,.45);
  overflow-y: auto;
  padding: 28px 14px;
}

.modal {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
  position: relative;
  padding: 22px 22px 26px !important;
  margin: 0 auto;
}

/* --- form view --- */

#view-form, #view-matches { max-width: 560px; }

.back {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 10px;
}
.back:hover { color: var(--ink); }

#view-form h2, #view-matches h2 { margin: 0 0 4px; font-size: 22px; }
.form-lead { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

form label { display: block; font-size: 13px; color: #555; margin-bottom: 14px; font-weight: 600; }
form input, form select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 7px;
  font-size: 15px;
  font-weight: 400;
  background: #fff;
}

/* Ei nuolinäppäimiä numerokenttiin. */
input[type="number"] { appearance: textfield; -moz-appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.optional { font-weight: 400; color: #999; }

/* Materiaalivalinta: napautettavat sirut, useita voi valita kerralla. */
.mat-group {
  border: 0;
  padding: 0;
  margin: 0 0 14px;
}
.mat-group legend {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  padding: 0;
  margin-bottom: 8px;
}
.mat-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.mat-chip { position: relative; margin: 0; }
.mat-chip input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.mat-chip span {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid #ccc;
  border-radius: 999px;
  background: #fff;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  user-select: none;
}
.mat-chip input:checked + span {
  background: #262626;
  border-color: #262626;
  color: #fff;
}
.mat-chip input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }

/* Määrä materiaaleittain: rivi per valittu materiaali. */
.vol-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-weight: 400; }
.vol-name { flex: 0 0 110px; font-size: 14px; color: var(--ink); }
.vol-row .suffix-wrap { flex: 1; }
.vol-row input { margin-top: 0; }
.vol-hint { color: #999; font-size: 14px; font-weight: 400; }

.suffix-wrap { position: relative; display: block; }
.suffix-wrap .suffix {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #999;
  font-weight: 400;
  margin-top: 2px;
}

.field-error {
  color: #c0392b;
  font-size: 13px;
  margin: -8px 0 12px;
}

.mini-map-wrap { margin-bottom: 14px; }
.mini-map-label { font-size: 12px; color: #999; display: block; margin-bottom: 4px; }
#form-map {
  height: 200px;
  border-radius: 8px;
  border: 1px solid var(--line);
}

.when {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px 12px;
  margin: 0 0 14px;
  background: #fff;
}
.when legend { font-size: 13px; font-weight: 600; color: #555; padding: 0 4px; }
.when .radio { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-weight: 400; font-size: 15px; color: var(--ink); }
.when .radio input[type="radio"] { width: auto; margin: 0; }
.when .radio input[type="date"] { margin: 0; width: auto; flex: 1; }
.when .radio input[type="date"]:disabled { background: #f2f2f2; color: #aaa; }

.submit {
  width: 100%;
  border: 0;
  border-radius: 9px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  cursor: pointer;
  background: #262626;
}
.submit-offer { background: var(--green); }
.submit-offer:hover { background: var(--green-dark); }
.submit-need { background: var(--blue); }
.submit-need:hover { background: var(--blue-dark); }

/* --- matches --- */

.matches-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }

.match-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.match-item strong { font-size: 16px; }
.match-meta { color: var(--muted); font-size: 13.5px; white-space: pre-wrap; }
.match-actions { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }

.action {
  display: inline-block;
  text-align: center;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 7px;
  font-weight: 700;
  font-size: 14px;
  border: 0;
  cursor: pointer;
}
.action.call { background: var(--green); color: #fff; flex: 1; }
.action.call:hover { background: var(--green-dark); }
.action.sms { background: #eef4fb; color: var(--blue); border: 1px solid var(--blue); flex: 1; }
.action.sms:hover { background: #dcE9f8; }
.action.edit { background: #efefef; color: var(--ink); }
.action.edit:hover { background: #e4e4e4; }
.action.delete { background: none; color: #c0392b; font-weight: 400; font-size: 13px; margin-top: 8px; }

/* --- listing card modal --- */

.card-overlay[hidden] { display: none; }

.card-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  position: relative;
  width: 100%;
  max-width: 340px;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card h3 { margin: 6px 0 2px; font-size: 20px; }

.close {
  position: absolute;
  top: 8px;
  right: 12px;
  border: 0;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: #888;
  cursor: pointer;
}

.tag {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  color: #fff;
}
.tag-tarjoan { background: var(--green); }
.tag-tarvitsen { background: var(--blue); }

.card-line { margin: 0; color: var(--muted); font-size: 14px; }
.card-note { margin: 2px 0; font-size: 14px; font-style: italic; }
.card .action { margin-top: 4px; }

/* --- mobile --- */

@media (max-width: 760px) {
  section { padding: 14px 12px 30px; }
  .hero { flex-direction: column; }
  .home-grid { grid-template-columns: 1fr; }
  .map-col { order: -1; }
  #map { height: 46vh; }
  .type-chips { margin-left: 0; }
}
