:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-soft: #273449;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --origin: #f43f5e;
  --sidebar-width: 380px;
  --topbar-height: 104px;
}

* {
  box-sizing: border-box;
}

/* display を指定した要素でも hidden 属性を効かせる。
   これが無いと読み込みオーバーレイが消えず、地図のクリックを奪ってしまう。 */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    system-ui,
    -apple-system,
    'Hiragino Kaku Gothic ProN',
    'Noto Sans JP',
    Meiryo,
    sans-serif;
  font-size: 14px;
  display: flex;
  flex-direction: column;
}

/* ---------- ヘッダ ---------- */

.topbar {
  flex: 0 0 auto;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: 'title search' 'hint hint';
  gap: 4px 20px;
  align-items: center;
}

.topbar h1 {
  grid-area: title;
  margin: 0;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.search {
  grid-area: search;
  display: flex;
  gap: 8px;
}

.hint {
  grid-area: hint;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.hint code {
  background: var(--panel-soft);
  padding: 1px 5px;
  border-radius: 4px;
}

input,
select,
button {
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--border);
}

input,
select {
  background: var(--bg);
  color: var(--text);
  padding: 7px 10px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

#url-input {
  flex: 1;
  min-width: 0;
}

button {
  background: var(--panel-soft);
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
}

button:hover:not(:disabled) {
  background: #334155;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

#load-button,
#origin-form button {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #04222f;
  font-weight: 600;
}

#load-button:hover:not(:disabled),
#origin-form button:hover:not(:disabled) {
  background: var(--accent);
}

button[aria-pressed='true'] {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #04222f;
}

/* ---------- レイアウト ---------- */

.layout {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--bg);
}

.panel {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.origin-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.origin-actions button {
  flex: 1;
}

.origin-address {
  display: flex;
  gap: 8px;
}

.origin-address input {
  flex: 1;
  min-width: 0;
}

.status {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.status.error {
  color: #fda4af;
}

.list-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.list-controls label {
  font-size: 12px;
  color: var(--muted);
}

.list-controls select {
  flex: 1;
}

/* ---------- 物件リスト ---------- */

.property-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.property-list li {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.property-list li:hover {
  background: var(--panel);
}

.property-list li.active {
  background: var(--panel-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.row-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.kind {
  font-weight: 600;
  color: var(--accent);
  font-size: 12px;
}

.price {
  font-weight: 700;
  white-space: nowrap;
}

.address {
  margin: 4px 0 0;
  line-height: 1.4;
}

.meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
}

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--panel-soft);
  font-size: 11px;
  white-space: nowrap;
}

.badge.distance {
  background: #0c4a6e;
  color: #bae6fd;
}

.badge.approx {
  background: #422006;
  color: #fed7aa;
}

.unmapped ul {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
}

.unmapped summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- 地図 ---------- */

.map-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: #1e293b;
}

.map-wrap.picking {
  cursor: crosshair;
}

.map-wrap.picking #map {
  cursor: crosshair;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(15, 23, 42, 0.78);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* マーカー（価格ラベル付き） */

.price-marker {
  background: transparent;
  border: 0;
}

.price-pin {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--accent-strong);
  color: #04222f;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid #075985;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -120%);
}

/* 丁目レベルまでしか特定できなかった物件は破線にして区別する。 */
.price-pin.approx {
  background: #fbbf24;
  border-color: #b45309;
  border-style: dashed;
  color: #422006;
}

.price-pin.active {
  background: #fff;
  border-color: var(--accent);
  outline: 2px solid var(--accent);
}

.origin-pin {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--origin);
  border: 3px solid #fff;
  box-shadow: 0 0 0 3px rgba(244, 63, 94, 0.35);
}

.leaflet-popup-content {
  margin: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
  min-width: 200px;
}

.leaflet-popup-content dl {
  margin: 6px 0 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
}

.leaflet-popup-content dt {
  color: #475569;
  font-size: 11px;
}

.leaflet-popup-content dd {
  margin: 0;
}

.leaflet-popup-content .popup-title {
  font-weight: 700;
}

.leaflet-popup-content .popup-thumb {
  display: block;
  width: 100%;
  max-height: 140px;
  object-fit: cover;
  border-radius: 6px;
  margin-top: 6px;
}

.leaflet-popup-content a {
  color: #0369a1;
}

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr;
    grid-template-areas: 'title' 'search' 'hint';
  }

  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex: 1 1 auto;
    border-right: 0;
    border-top: 1px solid var(--border);
    order: 2;
  }

  .map-wrap {
    order: 1;
    flex: 0 0 45vh;
  }
}
