/* Vessakartta — modern, minimal, monochrome UI.
   Semantic colors are reserved for map pins and attribute badges. */

:root {
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #ffffff;
  --surface-2: #f4f4f6;
  --text: #141417;
  --text-2: #74747c;
  --line: rgba(20, 20, 23, 0.08);
  --ink: #141417;      /* CTA + active chip */
  --on-ink: #ffffff;
  --star: #f5b301;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.05), 0 10px 32px rgba(0, 0, 0, 0.10);
  --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 14px rgba(0, 0, 0, 0.08);
  --radius: 22px;
  --blur: saturate(180%) blur(20px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: rgba(23, 23, 26, 0.80);
    --surface-solid: #17171a;
    --surface-2: #232327;
    --text: #f4f4f6;
    --text-2: #9a9aa2;
    --line: rgba(255, 255, 255, 0.10);
    --ink: #f4f4f6;
    --on-ink: #141417;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5), 0 14px 40px rgba(0, 0, 0, 0.55);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", sans-serif;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

#map {
  position: fixed;
  inset: 0;
  background: var(--surface-2);
}

/* The basemap (CARTO Voyager) is light in both schemes for readability;
   match the tile background so loading edges don't flash dark. */
.leaflet-container { background: #d5e8eb; }

/* ---------- Filter bar ---------- */

#filterbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  display: flex;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#filterbar::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow-2);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.chip svg {
  width: 20px;
  height: 20px;
}

.chip-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: #0a84ff;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.chip-badge[hidden] { display: none; }

.chip:active { transform: scale(0.96); }

.chip.on {
  background: var(--ink);
  border-color: transparent;
  color: var(--on-ink);
}

.chip:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ---------- Filters panel ---------- */

#filters-panel {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 14px;
  z-index: 1250;
  width: min(80vw, 280px);
  padding: 14px 18px 10px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

#filters-panel[hidden] { display: none; }

#filters-panel h3 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

#filters-panel label {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
}

#filters-panel label + label {
  border-top: 1px solid var(--line);
}

#filters-panel input[type="checkbox"] {
  width: 19px;
  height: 19px;
  accent-color: var(--ink);
}

#filters-panel .row-icon {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  color: var(--text-2);
}

#filters-panel .lang-row select {
  margin-inline-start: auto;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

/* ---------- Nearest-toilet button (lives in the toolbar row) ---------- */

#nearest-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-2);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  transition: transform 0.1s ease;
}

#nearest-chip:active { transform: scale(0.96); }
#nearest-chip[hidden] { display: none; }

#nearest-chip svg {
  width: 17px;
  height: 17px;
  color: #30c15b;
}

/* ---------- Status pill ---------- */

#status {
  position: fixed;
  top: calc(64px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  padding: 9px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  font-weight: 500;
  max-width: min(90vw, 420px);
  text-align: center;
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

/* ---------- Bottom card ---------- */

#card {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  width: min(92vw, 420px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

#card .card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

#card .card-header .spacer { flex: 1; }

#card .card-kicker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#card .card-kicker svg,
#card .icon-btn svg {
  width: 15px;
  height: 15px;
}

#card .icon-btn {
  border: none;
  background: none;
  font-size: 17px;
  cursor: pointer;
  padding: 2px 4px;
  color: var(--text-2);
}

#card h3 {
  margin: 8px 0 2px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#card .distance {
  margin: 0 0 10px;
  font-size: 14px;
  color: var(--text-2);
}

#card .hours {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: -4px 0 10px;
  font-size: 12.5px;
  color: var(--text-2);
}

#card .hours svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
}

#card .actions {
  display: flex;
  gap: 10px;
  margin-top: 14px;
}

#card .actions button,
#card .actions a,
.modal-card .actions button {
  flex: 1;
  padding: 12px 0;
  border-radius: 14px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

#card .actions button:active,
#card .actions a:active,
.modal-card .actions button:active { transform: scale(0.97); }

.btn-secondary {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
}

.btn-primary {
  border: 1px solid transparent;
  background: var(--ink);
  color: var(--on-ink);
}

/* ---------- Badges ---------- */

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
}

.badge-free { background: rgba(52, 199, 89, 0.14); color: #248a48; }
.badge-paid { background: rgba(255, 149, 0, 0.14); color: #b06c00; }
.badge-open { background: rgba(52, 199, 89, 0.14); color: #248a48; }
.badge-maybe-closed { background: rgba(255, 59, 48, 0.12); color: #b3261e; }
.badge-accessible { background: rgba(0, 122, 255, 0.12); color: #0a66d0; }
.badge-changing { background: rgba(175, 82, 222, 0.12); color: #9440c4; }
.badge-user { background: rgba(90, 200, 250, 0.16); color: #0a7ea8; }
.badge-rating { background: rgba(245, 179, 1, 0.16); color: #93700a; }

@media (prefers-color-scheme: dark) {
  .badge-free { color: #4cd964; }
  .badge-paid { color: #ffb340; }
  .badge-open { color: #4cd964; }
  .badge-maybe-closed { color: #ff7a70; }
  .badge-accessible { color: #64a8ff; }
  .badge-changing { color: #cd8cf0; }
  .badge-user { color: #6fd0ff; }
  .badge-rating { color: #ffd60a; }
}

/* ---------- Rating stars ---------- */

.stars {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-top: 10px;
}

.stars-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-inline-end: 8px;
}

.star-btn {
  border: none;
  background: none;
  font-size: 21px;
  line-height: 1;
  padding: 2px;
  cursor: pointer;
  color: var(--star);
  transition: transform 0.1s ease;
}

.star-btn:active { transform: scale(1.2); }

/* ---------- List panel ---------- */

#list {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: min(100vw, 480px);
  max-height: 58vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}

#list[hidden],
#card[hidden],
#status[hidden] {
  display: none;
}

#list::before {
  content: "";
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

#list header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 18px 10px;
}

#list h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

#list-close {
  border: none;
  background: none;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-2);
  padding: 4px;
}

#list-items {
  margin: 0;
  padding: 0 10px;
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

#list-items li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 8px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}

#list-items .row-main {
  flex: 1;
  min-width: 0;
}

#list-items .row-name {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#list-items .row-distance {
  font-size: 13px;
  color: var(--text-2);
  margin: 2px 0 5px;
}

#list-items .row-btn {
  border: none;
  background: none;
  font-size: 17px;
  cursor: pointer;
  padding: 6px;
  color: var(--text-2);
  text-decoration: none;
}

/* Favourite hearts: outlined and muted when off, filled and red when on,
   in the card and in the list alike. */
.fav-btn svg {
  width: 19px;
  height: 19px;
  display: block;
}

/* Both selectors carry an id so they outrank the #card / #list-items rules
   that set the default muted colour. */
#card .icon-btn.fav-btn.on,
#list-items .row-btn.fav-btn.on { color: #ff375f; }

.fav-btn:active { transform: scale(1.15); }

#list .empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-2);
  font-size: 14px;
}

#list footer {
  padding: 10px 18px calc(14px + env(safe-area-inset-bottom));
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-2);
  border-top: 1px solid var(--line);
}

#app-version {
  opacity: 0.7;
  white-space: nowrap;
}

/* ---------- Add-toilet modal ---------- */

#add-modal {
  position: fixed;
  inset: 0;
  z-index: 1300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

#add-modal[hidden] { display: none; }

.modal-card {
  width: min(92vw, 360px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  box-shadow: var(--shadow-1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-2);
}

.modal-card label.check {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}

.modal-card input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--ink);
}

.modal-card input[type="text"],
.modal-card select {
  padding: 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}

.modal-card input[type="text"]:focus,
.modal-card select:focus {
  outline: none;
  border-color: var(--text-2);
}

.modal-card .actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

/* ---------- Map pins ----------
   Fixed high-contrast colors on purpose: pins must pop against both the
   light and the dark basemap, so they don't follow the UI theme vars.
   Teardrop shape: the container rotates -45deg so its sharp corner points
   straight down at the exact location (the icon counter-rotates). The
   marker's iconAnchor in app.js sits on that tip. */

.cluster {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--ink);
  color: var(--on-ink);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  background: #ffffff;
  color: #17181c;
  border: 2px solid rgba(255, 255, 255, 0.95);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 5px 12px rgba(0, 0, 0, 0.3);
}

.pin svg {
  width: 19px;
  height: 19px;
  transform: rotate(45deg);
}

.pin-nearest { background: #30c15b; color: #ffffff; }
.pin-fav { background: #ff375f; color: #ffffff; }
.pin-user { background: #5ac8fa; color: #0c2e40; }

/* The nearest pin is larger and pulses so it can't drown in a cluster. */
.pin-xl {
  width: 46px;
  height: 46px;
  position: relative;
}

.pin-xl svg {
  width: 25px;
  height: 25px;
}

.pin-xl::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50% 50% 50% 0;
  border: 3px solid rgba(48, 193, 91, 0.55);
  animation: nearest-pulse 2s ease-out infinite;
  pointer-events: none;
}

@keyframes nearest-pulse {
  0% { transform: scale(0.85); opacity: 0.9; }
  70% { transform: scale(1.25); opacity: 0; }
  100% { transform: scale(1.25); opacity: 0; }
}
