:root {
  --bg: #f7f5f2;
  --panel-bg: #ffffff;
  --border: #e2ddd5;
  --text: #2b2823;
  --text-muted: #6b665e;
  --accent: #0f7a8c;
  --accent-contrast: #ffffff;
  --header-h: 56px;
  --footer-h: 40px;
  font-family: "Hiragino Sans", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  flex: 0 0 var(--header-h);
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 24px; color: var(--accent); }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-ja { font-weight: 700; font-size: 16px; }
.brand-en { font-size: 11px; color: var(--text-muted); }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}
.icon-btn:hover { background: var(--bg); }

.filter-toggle { display: none; }

/* Body layout */
.app-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  position: relative;
}

.filter-panel {
  flex: 0 0 300px;
  width: 300px;
  overflow-y: auto;
  background: var(--panel-bg);
  border-right: 1px solid var(--border);
  padding: 16px;
  z-index: 10;
}

.filter-group { margin-bottom: 18px; }
.filter-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

select, input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* Dual-handle pH range: two native <input type="range"> stacked on one
   track. Each input is transparent except its own thumb (pointer-events
   is disabled on the input and re-enabled only on the thumb), so clicks
   pass through to whichever handle is underneath. */
.dual-range {
  position: relative;
  height: 20px;
}

.dual-range-track,
.dual-range-fill {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: 4px;
  border-radius: 2px;
}
.dual-range-track { left: 0; right: 0; background: var(--border); }
.dual-range-fill { background: var(--accent); }

.dual-range input[type="range"] {
  position: absolute;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track { background: transparent; }
.dual-range input[type="range"]::-moz-range-track { background: transparent; border: none; }

.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}
.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--panel-bg);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
  cursor: pointer;
}

#phMin { z-index: 3; }
#phMax { z-index: 4; }

.text-btn {
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--accent);
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  width: 100%;
}
.text-btn:hover { background: var(--bg); }

.legend { border-top: 1px solid var(--border); padding-top: 14px; margin-bottom: 14px; }
.legend-title { font-size: 12px; font-weight: 600; color: var(--text-muted); margin: 0 0 8px; }
.legend ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.swatch {
  width: 12px; height: 12px; border-radius: 50%;
  display: inline-block; flex: 0 0 auto;
  border: 1px solid rgba(0,0,0,0.15);
}

.result-count { font-size: 12px; color: var(--text-muted); margin: 0; }

/* Map */
#map {
  flex: 1 1 auto;
  min-width: 0;
}

.leaflet-popup-content, .leaflet-container {
  font-family: inherit;
}

/* Onsen marker popup */
.leaflet-popup-content { margin: 12px 14px; }

.onsen-popup .popup-category {
  font-weight: 700;
  font-size: 13px;
  margin: 0 0 4px;
}
.onsen-popup .popup-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 4px;
}
.onsen-popup .popup-ph {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 8px;
}
.onsen-popup .popup-rph { margin-left: 6px; }
.onsen-popup .popup-table {
  border-collapse: collapse;
  font-size: 12px;
}
.onsen-popup .popup-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 500;
  padding: 2px 8px 2px 0;
  white-space: nowrap;
  vertical-align: top;
}
.onsen-popup .popup-table td {
  padding: 2px 0;
  word-break: break-word;
}

/* Footer */
.app-footer {
  flex: 0 0 auto;
  min-height: var(--footer-h);
  display: flex;
  align-items: center;
  padding: 6px 16px;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
}
.app-footer a { color: var(--accent); }

/* Mobile */
@media (max-width: 760px) {
  .filter-toggle { display: inline-flex; align-items: center; justify-content: center; }

  .filter-panel {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,0.15);
  }
  .filter-panel.open { transform: translateX(0); }
}
