:root {
  --bg: #f4f5f7; --card: #fff; --text: #1d2330; --sub: #5d6575; --line: #e2e5ea;
  --accent: #2f6fde; --accent-soft: #e6eefc; --good: #1f9d63; --warn: #d98a00; --bad: #c8463d;
  --heart: #e0457b; --radius: 14px; --shadow: 0 1px 3px rgba(20, 30, 50, .08), 0 4px 14px rgba(20, 30, 50, .05);
  --tabbar: 64px; --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --card: #1c2029; --text: #e8ebf1; --sub: #9aa3b2; --line: #2b313d;
    --accent: #6c9cf0; --accent-soft: #23314d; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
.app { max-width: 880px; margin: 0 auto; padding-bottom: calc(var(--tabbar) + var(--safe-b) + 16px); min-height: 100vh; }

/* ヘッダー */
.header { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); padding: 10px 14px 8px; border-bottom: 1px solid var(--line); }
.header-row { display: flex; align-items: center; gap: 10px; }
.title { font-weight: 700; font-size: 17px; flex: 1; white-space: nowrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 10px; border-radius: 99px;
  background: var(--card); border: 1px solid var(--line); color: var(--sub); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sub); }
.dot.on { background: var(--good); } .dot.busy { background: var(--accent); animation: pulse 1.2s infinite; }
.dot.off { background: var(--bad); }
@keyframes pulse { 50% { opacity: .3; } }
.fetch-btn { border: 0; background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 99px; font-weight: 600;
  font-size: 14px; white-space: nowrap; }
.fetch-btn:disabled { opacity: .55; }
.progress { margin-top: 8px; font-size: 12px; color: var(--sub); }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }
.since { margin: 10px 14px 0; padding: 10px 12px; background: var(--accent-soft); border-radius: 12px; font-size: 14px; }

/* 絞り込み */
.toolbar { padding: 10px 14px 4px; display: grid; gap: 8px; }
.toolbar > * { min-width: 0; }
html, body { overflow-x: hidden; }
.search { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); padding: 5px 12px; border-radius: 99px;
  font-size: 13px; color: var(--sub); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
select.chip { appearance: none; padding-right: 26px;
  background-image: linear-gradient(45deg, transparent 50%, var(--sub) 50%), linear-gradient(135deg, var(--sub) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; background-repeat: no-repeat; }
.count { padding: 2px 14px 6px; font-size: 13px; color: var(--sub); overflow-wrap: anywhere; }
.header-row { min-width: 0; } .title { overflow: hidden; text-overflow: ellipsis; }

/* カード */
.list { display: grid; gap: 12px; padding: 4px 14px 14px; }
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; } }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  display: flex; flex-direction: column; border: 1px solid var(--line); }
.card.out { opacity: .6; }
.card-media { position: relative; aspect-ratio: 16 / 9; background: var(--line); cursor: pointer; overflow: hidden; }
.card-media img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.score { position: absolute; left: 10px; top: 10px; min-width: 46px; height: 46px; border-radius: 50%; display: grid;
  place-items: center; font-weight: 800; font-size: 17px; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.heart { position: absolute; right: 10px; top: 10px; width: 42px; height: 42px; border-radius: 50%; border: 0;
  background: rgba(255,255,255,.92); font-size: 21px; display: grid; place-items: center; color: #999; }
.heart.on { color: var(--heart); }
.badges { position: absolute; left: 10px; bottom: 10px; display: flex; gap: 4px; flex-wrap: wrap; }
.badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #fff; color: var(--text); }
.badge.new { background: #ff6a3d; color: #fff; } .badge.drop { background: var(--good); color: #fff; }
.badge.relist { background: #8656d8; color: #fff; } .badge.check { background: var(--warn); color: #fff; }
.badge.out { background: var(--bad); color: #fff; } .badge.status { background: var(--accent); color: #fff; }
.card-body { padding: 10px 12px 12px; cursor: pointer; display: grid; gap: 4px; }
.price { font-size: 20px; font-weight: 800; }
.price small { font-size: 12px; font-weight: 500; color: var(--sub); margin-left: 4px; }
.name { font-weight: 600; }
.meta { font-size: 13px; color: var(--sub); }
.minibars { display: flex; gap: 3px; margin-top: 4px; }
.minibars > span { flex: 1; height: 5px; border-radius: 3px; background: var(--line); overflow: hidden; }
.minibars > span > i { display: block; height: 100%; background: var(--accent); }
.card-foot { display: flex; align-items: center; justify-content: space-between; padding: 0 12px 10px; font-size: 12px; color: var(--sub); }
.compare-check { display: inline-flex; gap: 6px; align-items: center; }
.flagline { color: var(--heart); }

/* 下のタブ */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--tabbar) + var(--safe-b));
  padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; }
.tabbar > div { display: flex; width: 100%; max-width: 880px; }
.tab { flex: 1; border: 0; background: none; display: grid; place-items: center; gap: 0; font-size: 11px; color: var(--sub); padding: 6px 0; position: relative; }
.tab b { font-size: 20px; font-weight: 400; line-height: 1.1; }
.tab.on { color: var(--accent); font-weight: 700; }
.tab .num { position: absolute; top: 4px; left: 55%; background: var(--bad); color: #fff; font-size: 10px; border-radius: 99px; padding: 0 5px; }

/* 詳細などの全画面シート */
.sheet { position: fixed; inset: 0; z-index: 50; background: var(--bg); overflow-y: auto; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(24px); opacity: .4; } }
.sheet-head { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.sheet-head .t { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 14px; }
.sheet-body { max-width: 880px; margin: 0 auto; padding: 0 0 40px; }
.gallery { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: 4px; background: #000; }
.gallery figure { flex: none; width: 100%; margin: 0; scroll-snap-align: center; position: relative; aspect-ratio: 4 / 3; }
.gallery img { width: 100%; height: 100%; object-fit: contain; }
.gallery figcaption { position: absolute; bottom: 6px; left: 8px; font-size: 12px; color: #fff; background: rgba(0,0,0,.5); padding: 1px 8px; border-radius: 99px; }
.section { background: var(--card); margin: 12px 12px 0; border-radius: var(--radius); padding: 14px; border: 1px solid var(--line); }
.section h3 { margin: 0 0 10px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 7.5em 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--sub); } .kv dd { margin: 0; }
.part { display: grid; grid-template-columns: 7.5em 1fr 4.5em; align-items: center; gap: 8px; margin: 8px 0 2px; font-size: 14px; }
.part .bar { height: 8px; margin: 0; }
.part-reason { font-size: 12px; color: var(--sub); margin: 0 0 6px 0; }
.notes { margin: 0; padding-left: 1.2em; font-size: 14px; }
.notes.bad li { color: var(--bad); } .notes.warn li { color: var(--warn); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 12px; font-size: 14px; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 700; }
.btn.danger { color: var(--bad); }
textarea, input[type=text], input[type=email], input[type=password], input[type=number], input[type=datetime-local], select.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--bg); }
textarea { min-height: 80px; resize: vertical; }
.hint { font-size: 12px; color: var(--sub); }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple th, table.simple td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; vertical-align: top; }
table.simple th { color: var(--sub); font-weight: 500; }

/* 比較 */
.compare-bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + var(--safe-b) + 10px); z-index: 25;
  background: var(--text); color: var(--bg); border-radius: 99px; padding: 8px 8px 8px 16px; display: flex; gap: 10px; align-items: center; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.compare-bar button { border: 0; border-radius: 99px; padding: 6px 14px; background: var(--accent); color: #fff; font-weight: 700; }
.compare-wrap { overflow-x: auto; }
.compare { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.compare th, .compare td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: top; text-align: left; min-width: 150px; }
.compare th:first-child { position: sticky; left: 0; background: var(--card); min-width: 90px; color: var(--sub); font-weight: 500; }
.compare img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 8px; }
.best { color: var(--good); font-weight: 700; }

/* 地図 */
.map { height: calc(100vh - 140px - var(--tabbar)); margin: 0; }
.legend { display: flex; gap: 10px; padding: 8px 14px; font-size: 12px; color: var(--sub); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }

/* 設定 */
.subtabs { display: flex; gap: 6px; padding: 10px 14px; overflow-x: auto; }
.field { display: grid; gap: 4px; margin: 12px 0; }
.field-row { display: flex; align-items: center; gap: 10px; }
.field-row input[type=range] { flex: 1; accent-color: var(--accent); }
.field-row .val { min-width: 4.5em; text-align: right; font-weight: 700; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.draft-bar { position: sticky; top: 56px; z-index: 15; margin: 8px 12px 0; padding: 10px 12px; border-radius: 12px;
  background: #fff4d6; color: #6b4b00; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
@media (prefers-color-scheme: dark) { .draft-bar { background: #3b3014; color: #ffd98a; } }
.draft-bar .grow { flex: 1; }
.rankdiff { font-size: 13px; margin-top: 6px; }
.up { color: var(--good); } .down { color: var(--bad); }

/* その他 */
.center { display: grid; place-items: center; min-height: 70vh; padding: 24px; text-align: center; }
.login { width: min(380px, 100%); display: grid; gap: 10px; text-align: left; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar) + var(--safe-b) + 64px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.empty { padding: 40px 20px; text-align: center; color: var(--sub); }
.banner { margin: 10px 14px 0; padding: 10px 12px; border-radius: 12px; font-size: 13px; background: #fde8e6; color: #8a2a22; }
@media (prefers-color-scheme: dark) { .banner { background: #3d1e1b; color: #ffb4ab; } }
.review-item { display: grid; grid-template-columns: 88px 1fr; gap: 10px; align-items: start; }
.review-item img { width: 88px; height: 66px; object-fit: cover; border-radius: 8px; background: var(--line); }
.stations-table input, .stations-table select { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--bg); width: 4.5em; }
.stations-table input.wide { width: 100%; min-width: 10em; }

/* 表で表示 */
.table-wrap { overflow-x: auto; margin: 4px 14px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.ptable { width: 100%; border-collapse: collapse; font-size: 13px; }
.ptable th { position: sticky; top: 0; background: var(--card); text-align: left; font-weight: 500; color: var(--sub); padding: 8px 6px;
  border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
.ptable th.sortable { cursor: pointer; } .ptable th.sortable:hover, .ptable th.on { color: var(--accent); }
.ptable td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.ptable td.tname { white-space: normal; min-width: 180px; max-width: 320px; }
.ptable td.num { text-align: right; }
.ptable tbody tr { cursor: pointer; } .ptable tbody tr:hover { background: var(--accent-soft); }
.ptable tr.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.ptable tr.out { opacity: .55; }
.tscore { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; color: #fff; font-weight: 800; }
.theart { border: 0; background: none; font-size: 18px; color: #aaa; } .theart.on { color: var(--heart); }
.tthumb { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; display: block; background: var(--line); }

/* PCなど幅の広い画面：タブを左に縦に並べ、詳細は右側に開く（一覧を見たまま切り替えられる） */
@media (min-width: 1100px) {
  :root { --rail: 92px; --panel: min(720px, 46vw); }
  .app { max-width: none; margin: 0; padding: 0 0 24px var(--rail); }
  .app.has-detail { padding-right: var(--panel); }
  .tabbar { top: 0; bottom: 0; left: 0; right: auto; width: var(--rail); height: auto; padding: 12px 0; border-top: 0; border-right: 1px solid var(--line); }
  .tabbar > div { flex-direction: column; gap: 4px; }
  .tab { flex: none; padding: 12px 0; font-size: 12px; }
  .tab b { font-size: 24px; }
  .sheet.side { left: auto; width: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(20, 30, 50, .08); animation: side .16s ease-out; }
  @keyframes side { from { transform: translateX(24px); opacity: .4; } }
  .list { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
  .compare-bar { bottom: 20px; left: calc(50% + var(--rail) / 2); }
  .toast { bottom: 24px; }
  .map { height: calc(100vh - 150px); }
  .toolbar { grid-template-columns: minmax(240px, 360px) 1fr; align-items: center; }
  .chips { flex-wrap: wrap; overflow: visible; }
  .section { margin-left: 14px; margin-right: 14px; }
  .app.has-detail .toolbar { grid-template-columns: 1fr; }
  .app.has-detail .tthumb { width: 48px; height: 34px; }
}

/* 地図のピン（点数入りの丸） */
.pin { width: 100%; height: 100%; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 13px;
  border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, .35); cursor: pointer; }
.pin.fav { border: 3px solid #e0457b; font-size: 15px; }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; line-height: 1.5; }

/* 建物ごと（試作）：1枚のカードに同じ建物の部屋を並べる */
.bldg .card-media { aspect-ratio: 21 / 9; }
.bldg .rooms { border-top: 1px solid var(--line); }
.bldg .room { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 8px; padding: 7px 12px;
  border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; }
.bldg .room:last-child { border-bottom: 0; }
.bldg .room:hover { background: rgba(47, 111, 222, .05); }
.bldg .room.out { opacity: .55; }
.bldg .room-spec .badge { margin-left: 4px; font-size: 10px; }
.bldg .room-price { font-weight: 700; white-space: nowrap; }
