:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #24292f;
  --sub: #6b7280;
  --accent: #2563eb;
  --ok: #16a34a;
  --cond: #d97706;
  --ng: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Hiragino Sans", "Noto Sans JP", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
.hidden { display: none !important; }

/* ---------- ヘッダー ---------- */
#topbar {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.search-box { flex: 1; min-width: 260px; display: flex; gap: 6px; }
#kw { flex: 1; min-width: 180px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
#aiSearchBtn {
  white-space: nowrap; border: 1px solid var(--accent); background: #eff6ff; color: var(--accent);
  border-radius: 8px; padding: 8px 14px; font-size: 13px; cursor: pointer; font-weight: 600;
}
#aiSearchBtn:hover { background: var(--accent); color: #fff; }
.ai-note {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: 8px 12px; font-size: 13px; margin-bottom: 10px;
}
.ai-note .ai-hint { display: block; color: var(--sub); font-size: 11px; margin-top: 3px; }
.topbar-controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.topbar-controls label { display: flex; flex-direction: column; font-size: 10px; color: var(--sub); gap: 2px; }
.topbar-controls select { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.view-toggle { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.view-toggle button { border: 0; background: var(--panel); padding: 8px 16px; cursor: pointer; font-size: 13px; }
.view-toggle button.active { background: var(--accent); color: #fff; }

/* ---------- レイアウト ---------- */
#layout { display: flex; min-height: calc(100vh - 57px); }
#sidebar {
  width: 280px; flex-shrink: 0; background: var(--panel);
  border-right: 1px solid var(--border); padding: 14px; overflow-y: auto;
  height: calc(100vh - 57px); position: sticky; top: 57px;
}
#main { flex: 1; padding: 14px 18px; min-width: 0; }

.filter-block { margin-bottom: 20px; }
.filter-block h3 { font-size: 13px; margin: 0 0 8px; }
.filter-block .hint { font-weight: 400; font-size: 11px; color: var(--sub); }
.filter-block label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 8px; }
.filter-block select { width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; margin-top: 2px; font-size: 13px; }
.filter-block .check { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }

.small-btn {
  border: 1px solid var(--border); background: var(--panel); border-radius: 6px;
  padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.small-btn:hover { background: #f0f2f5; }

.reset-btn {
  width: 100%; margin-bottom: 14px; padding: 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; background: #f7f8fa;
  font-size: 12px; color: var(--sub);
}
.reset-btn:hover { background: #eef1f5; color: var(--text); }

/* ---------- 都道府県セレクタ ---------- */
.pref-picker { position: relative; margin-top: 2px; }
.pp-btn {
  width: 100%; text-align: left; padding: 6px 8px; font-size: 13px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 6px; background: var(--panel); color: var(--sub);
}
.pp-btn.pp-selected { color: var(--text); font-weight: 600; border-color: var(--accent); }
.pp-btn::after { content: "▾"; float: right; color: var(--sub); }
.pp-panel {
  position: absolute; z-index: 60; top: calc(100% + 2px); left: 0; width: 220px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px;
}
.pp-search {
  width: 100%; padding: 5px 7px; font-size: 12px; margin-bottom: 4px;
  border: 1px solid var(--border); border-radius: 6px;
}
.pp-list { max-height: 240px; overflow-y: auto; }
.pp-item {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 5px 7px; font-size: 13px; cursor: pointer; border-radius: 5px; color: var(--text);
}
.pp-item:hover { background: #eef2ff; }
.pp-item.pp-cur { background: #e0e7ff; font-weight: 600; }
.pp-item.pp-empty { color: var(--sub); border-bottom: 1px solid var(--border); border-radius: 0; margin-bottom: 3px; }
.pp-none { padding: 8px; font-size: 12px; color: var(--sub); }
#topbar .pp-btn { min-width: 110px; padding: 5px 8px; }
#topbar .pp-panel { width: 200px; }

/* ---------- タグ検索 ---------- */
.tag-row {
  border: 1px dashed var(--border); border-radius: 8px; padding: 6px;
  margin-bottom: 4px; display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  cursor: pointer; min-height: 34px;
}
.tag-row.active { border-color: var(--accent); background: #eff6ff; }
.tag-row .row-label { font-size: 10px; color: var(--sub); }
.and-sep { text-align: center; font-size: 10px; color: var(--sub); margin: 2px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  background: #e0e7ff; border-radius: 999px; padding: 3px 10px; font-size: 12px;
}
.chip .x { cursor: pointer; color: var(--sub); font-weight: 700; }
.chip.or-label::before { content: "or "; color: var(--sub); font-size: 10px; }

#tagPicker { margin-top: 10px; }
.picker-group h4 { font-size: 11px; color: var(--sub); margin: 10px 0 4px; }
.picker-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.pick-chip {
  border: 1px solid var(--border); background: var(--panel); border-radius: 999px;
  padding: 3px 9px; font-size: 12px; cursor: pointer; color: var(--text);
}
.pick-chip:hover { border-color: var(--accent); }
.pick-chip.used { background: #e0e7ff; border-color: var(--accent); }
.pick-chip .cnt { color: var(--sub); font-size: 10px; margin-left: 3px; }
.pick-chip:disabled { opacity: .35; cursor: default; }

/* ---------- ギャラリー ---------- */
#resultBar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; color: var(--sub); font-size: 13px; }
#gallery { display: flex; flex-wrap: wrap; gap: 8px; }
.gcard {
  position: relative; border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: #ddd; flex-grow: 1;
}
.gcard img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gcard.ng img { filter: saturate(.25) brightness(.85); }
.gcard .badges { position: absolute; top: 6px; left: 6px; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.badge { font-size: 10px; padding: 2px 7px; border-radius: 999px; color: #fff; font-weight: 600; }
.badge.cond { background: var(--cond); }
.badge.ng { background: var(--ng); }
.badge.info { background: rgba(0,0,0,.55); }
.gcard .hover-bar {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 24px 8px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.65));
  color: #fff; font-size: 11px; display: flex; justify-content: space-between; align-items: flex-end;
  opacity: 0; transition: opacity .15s;
}
.gcard:hover .hover-bar { opacity: 1; }
.good-btn { border: 0; background: rgba(255,255,255,.25); color: #fff; border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px; }
.good-btn.on { background: #f43f5e; }

/* 物件カード */
.pcard {
  width: 250px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
}
.pcard .cover { width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block; background: #ddd; }
.pcard .p-body { padding: 8px 10px; }
.pcard .p-name { font-weight: 600; font-size: 13px; }
.pcard .p-sub { color: var(--sub); font-size: 11px; margin-top: 2px; }

#emptyMsg { color: var(--sub); padding: 40px; text-align: center; }
#loadMore { text-align: center; padding: 16px; }

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15,18,25,.75); z-index: 100;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.overlay-inner {
  background: var(--panel); border-radius: 14px; max-width: 1200px; width: 100%;
  max-height: 92vh; overflow-y: auto; padding: 18px;
}
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(280px, 1fr); gap: 18px; }
.detail-grid .main-img { width: 100%; border-radius: 10px; background: #eee; }
.meta-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.meta-table th { text-align: left; color: var(--sub); font-weight: 500; padding: 4px 8px 4px 0; white-space: nowrap; vertical-align: top; width: 90px; }
.meta-table td { padding: 4px 0; }
.perm-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.perm-table td, .perm-table th { padding: 3px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.light { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; }
.light.ok { background: var(--ok); }
.light.cond { background: var(--cond); }
.light.ng { background: var(--ng); }
.light.unknown { background: #9ca3af; }
.reason-box { background: #fef3c7; border: 1px solid #fcd34d; border-radius: 8px; padding: 8px 10px; font-size: 12px; margin: 8px 0; }
.reason-box.ng { background: #fee2e2; border-color: #fca5a5; }
.siblings { display: flex; gap: 6px; overflow-x: auto; margin-top: 10px; padding-bottom: 4px; }
.siblings img { height: 64px; border-radius: 6px; cursor: pointer; flex-shrink: 0; opacity: .8; }
.siblings img.current { outline: 2px solid var(--accent); opacity: 1; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.primary-btn {
  border: 0; background: var(--accent); color: #fff; border-radius: 8px;
  padding: 9px 16px; font-size: 13px; cursor: pointer; font-weight: 600;
}
.primary-btn:disabled { background: #9ca3af; cursor: default; }
.close-x { float: right; border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--sub); }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.place-group h4 { font-size: 13px; margin: 16px 0 6px; }
.place-group .grid { display: flex; flex-wrap: wrap; gap: 6px; }
.place-group img { height: 110px; border-radius: 8px; cursor: pointer; }

/* ---------- モーダル ---------- */
.modal { background: var(--panel); border-radius: 14px; max-width: 460px; width: 100%; padding: 20px; }
.modal h3 { margin: 0 0 12px; font-size: 15px; }
.modal label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 10px; }
.modal select { width: 100%; padding: 8px; border: 1px solid var(--border); border-radius: 8px; margin-top: 3px; font-size: 13px; }
.credit-box {
  background: #f0f2f5; border-radius: 8px; padding: 10px; font-size: 12px; margin: 10px 0;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---------- トースト ---------- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2937; color: #fff; border-radius: 10px; padding: 10px 18px;
  font-size: 13px; z-index: 300; max-width: 80vw;
}

@media (max-width: 800px) {
  #sidebar { display: none; }
  .detail-grid { grid-template-columns: 1fr; }
}
