:root {
  --bg: #f5f3ee;
  --card: #ffffff;
  --ink: #1d2421;
  --muted: #6b726e;
  --line: #e3dfd6;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --warn: #b5541c;
  --warn-soft: #fbeee4;
  --danger: #b3261e;
  --star: #e0a21b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 2px 8px rgba(30, 30, 20, .05);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
a { color: var(--accent); }
img { max-width: 100%; }

/* ---- ヘッダー・タブ ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(245, 243, 238, .92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand img { width: 28px; height: 28px; border-radius: 7px; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; text-align: center; padding: 14px 0; text-decoration: none;
  color: var(--muted); font-size: 14px; font-weight: 600;
}
.tabbar a.active { color: var(--accent); box-shadow: inset 0 3px 0 var(--accent); }
/* 下のタブは画面幅に関係なく常に画面下に固定する。広い画面ではタブを中央の幅に並べる */
@media (min-width: 760px) {
  .tabbar { justify-content: center; }
  .tabbar a { max-width: 144px; }
}

main { max-width: 720px; margin: 0 auto; padding: 12px; }
.pad { padding: 24px; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---- ボタン・入力 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { color: var(--danger); border-color: #efc9c5; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }

input, select, textarea {
  font: inherit; font-size: 16px; /* iOS のズーム防止 */
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink);
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---- カード ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.section-title { font-size: 13px; font-weight: 700; color: var(--muted); margin: 20px 4px 8px; letter-spacing: .02em; }

/* ---- 一覧 ---- */
.toolbar { display: grid; gap: 8px; margin-bottom: 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--card); font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer;
}
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip .n { opacity: .7; margin-left: 4px; font-weight: 500; }

.plist { display: grid; gap: 10px; }
.pcard {
  display: grid; grid-template-columns: 96px 1fr; gap: 12px;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 10px; color: inherit; text-decoration: none; position: relative;
}
.pcard.dim { opacity: .55; }
.thumb {
  width: 96px; height: 96px; border-radius: 8px; object-fit: cover; background: #ebe7de;
  display: flex; align-items: center; justify-content: center; color: #b4ad9f; font-size: 28px;
}
.pcard .name { font-weight: 700; font-size: 15px; line-height: 1.35; margin: 2px 0 4px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.price { font-size: 20px; font-weight: 800; letter-spacing: -.01em; }
.price small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.specs { font-size: 13px; color: var(--muted); margin-top: 2px; }
.initial { font-size: 12px; font-weight: 700; color: var(--accent); }
.price-inline { font-size: 15px; font-weight: 800; color: var(--accent); margin-left: 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 12px; }
.badge { display: inline-block; white-space: nowrap; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 700; background: #efece5; color: var(--muted); }
.badge.site { background: #eef0f6; color: #445; }
.badge.gone { background: var(--warn-soft); color: var(--warn); }
.st { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.st-candidate { background: #efece5; color: #625b4e; }
.st-contacted { background: #e5eef9; color: #29548c; }
.st-viewing   { background: #fff2d6; color: #8a5a00; }
.st-viewed    { background: #ece6f7; color: #5b3f8f; }
.st-applied   { background: var(--accent-soft); color: var(--accent); }
.st-rejected  { background: #f1f1f1; color: #888; }
.rates { display: inline-flex; gap: 8px; color: var(--muted); }
.rates b { color: var(--star); font-weight: 700; }

/* ---- 詳細 ---- */
.hero { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius); background: #ebe7de; display: block; margin-bottom: 12px; }
.detail-title { font-size: 20px; margin: 4px 0 6px; line-height: 1.35; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.fact { background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.fact .k { font-size: 11px; color: var(--muted); font-weight: 600; }
.fact .v { font-size: 15px; font-weight: 700; margin-top: 2px; word-break: break-all; }
.fact.wide { grid-column: span 3; }
.kv { display: grid; grid-template-columns: 6em 1fr; gap: 6px 10px; font-size: 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

.stars { display: inline-flex; gap: 2px; }
.stars button {
  border: 0; background: none; font-size: 28px; line-height: 1; padding: 2px; cursor: pointer; color: #d9d4c8;
}
.stars button.on { color: var(--star); }
.rate-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 0; }
.rate-row + .rate-row { border-top: 1px solid var(--line); }

.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment:last-of-type { border-bottom: 0; }
.comment .who { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.comment .body { white-space: pre-wrap; margin-top: 4px; line-height: 1.5; }
.linkbtn { border: 0; background: none; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0; }

.notice { padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; line-height: 1.5; }
.notice.warn { background: var(--warn-soft); color: #6e3510; }
.notice.ok { background: var(--accent-soft); color: #134a3d; }
.notice ul { margin: 4px 0 0; padding-left: 1.2em; }

details.paste > summary { cursor: pointer; font-weight: 600; font-size: 14px; color: var(--accent); padding: 4px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* 比較 */
.pcard.picking { padding-left: 40px; }
.pcard.picked { outline: 2px solid var(--accent); }
.pick {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px; border-radius: 6px; border: 2px solid var(--line); background: var(--card);
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: var(--accent-ink);
}
.pcard.picked .pick { background: var(--accent); border-color: var(--accent); }
.comparebar {
  position: fixed; left: 0; right: 0; bottom: calc(49px + env(safe-area-inset-bottom)); z-index: 9;
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -2px 8px rgba(0, 0, 0, .06);
  font-size: 14px; font-weight: 700;
}
.comparebar span { flex: 1; }
.comparebar small { font-weight: 500; color: var(--muted); margin-left: 4px; }
.plist:has(+ .comparebar) { margin-bottom: 64px; }
@media (min-width: 760px) {
  .comparebar { bottom: calc(57px + env(safe-area-inset-bottom)); max-width: 696px; margin: 0 auto; border: 1px solid var(--line); border-radius: var(--radius); }
}
.compare-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table.compare { border-collapse: collapse; font-size: 13px; min-width: 100%; }
table.compare th, table.compare td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.compare td { min-width: 120px; }
table.compare thead th { font-size: 14px; min-width: 120px; }
table.compare tbody th, table.compare thead th:first-child {
  position: sticky; left: 0; background: var(--card); color: var(--muted); font-weight: 600; white-space: nowrap; z-index: 1;
}
table.compare td.best { background: var(--accent-soft); color: var(--accent); font-weight: 800; }

/* 希望条件 */
.badge.miss { background: #fdecd8; color: #9a4b00; }
label.check { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.check input { width: auto; }

/* 内見チェックリスト */
.check-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.check-row:last-of-type { border-bottom: 0; }
.check-row .ci { font-size: 14px; font-weight: 600; }
.check-row .marks { display: inline-flex; gap: 4px; }
.check-row .cnote { grid-column: 1 / -1; padding: 6px 10px; font-size: 13px; display: none; }
.check-row.has-note .cnote { display: block; }
.check-row.has-note .note-toggle { visibility: hidden; }
.note-toggle { margin-left: 4px; }
.card-summary { cursor: pointer; font-size: 16px; font-weight: 700; }
details[open] > .card-summary { margin-bottom: 8px; }
.mk {
  width: 38px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  font-size: 16px; font-weight: 800; color: var(--muted); cursor: pointer;
}
.mk-good.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.mk-fair.on { background: #e9b949; border-color: #e9b949; color: #fff; }
.mk-bad.on { background: var(--warn); border-color: var(--warn); color: #fff; }

/* 写真 */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; align-items: start; }
.ph { position: relative; }
.ph img { width: 100%; aspect-ratio: 1; height: auto; object-fit: cover; border-radius: 8px; display: block; background: #ebe7de; }
.ph-del {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, .55); color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
}
label.btn { display: inline-flex; align-items: center; cursor: pointer; }
label.btn.busy { opacity: .6; pointer-events: none; }

/* 内見の予定 */
.badge.viewing { background: var(--accent-soft); color: var(--accent); }
.sched { display: grid; grid-template-columns: 7.5em 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.sched:last-of-type { border-bottom: 0; }
.sched .when { font-weight: 800; color: var(--accent); font-size: 14px; }
.sched .name { font-weight: 700; }

/* 地図 */
.map { height: calc(100vh - 220px); min-height: 360px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 0; }
.pin {
  display: inline-block; transform: translate(-50%, -100%); white-space: nowrap;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 800; padding: 3px 8px; border-radius: 999px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35); border: 2px solid #fff;
}
.pin.dim { background: #8c8f8b; }
.pop { font-size: 13px; line-height: 1.6; }
.pop-img { display: block; width: 100%; height: 130px; object-fit: cover; border-radius: 8px; margin-bottom: 6px; background: #ebe7de; }
.pop + .pop { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 6px; }

/* 掲載サイト（まとめた物件） */
.compare-wrap.flat { box-shadow: none; border: 1px solid var(--line); }
table.listings { border-collapse: collapse; font-size: 13px; min-width: 100%; }
table.listings th, table.listings td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.listings th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.listings tr:last-child td { border-bottom: 0; }
.nowrap { white-space: nowrap; }
.notice .btn-sm { margin-left: 4px; }

/* 「新」「更新」の目印 */
.badge.fresh { background: var(--accent); color: #fff; }
.badge.fresh.upd { background: #3d6fb6; }
.fresh-row { justify-content: space-between; margin-top: 8px; color: var(--muted); }

/* ゴミ箱 */
.trash-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.trash-row:last-child { border-bottom: 0; }
.trash-row .name { font-weight: 700; }

/* 駅ごとの徒歩分数 */
.specs.stations { font-size: 12px; }
.st-focus { color: var(--accent); }
table.compare td { white-space: pre-line; }

/* 更新のお知らせ */
#updateBar {
  position: fixed; top: 8px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 2px 10px rgba(0, 0, 0, .15);
  font-size: 14px; font-weight: 700; white-space: nowrap;
}
.btn.disabled { opacity: .5; pointer-events: none; }

/* 物件を探すサイトの一覧 */
.site-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.site-row:last-child { border-bottom: 0; }
.site-row .name { font-weight: 700; }
.badge.site-ok { background: var(--accent-soft); color: var(--accent); }
.badge.site-paste { background: var(--warn-soft); color: var(--warn); }

/* 用語の説明 */
[hidden] { display: none !important; }
dl.glossary { margin: 0; }
dl.glossary .term { padding: 10px 0; border-bottom: 1px solid var(--line); }
dl.glossary .term:last-child { border-bottom: 0; }
dl.glossary dt { font-weight: 700; }
dl.glossary dd { margin: 4px 0 0; font-size: 14px; }

/* ログイン・ユーザー管理 */
body.auth-only .tabbar, body.auth-only #topAdd { display: none; }
.auth-card { max-width: 420px; margin: 24px auto; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.user-row:last-child { border-bottom: 0; }
.user-row .name { font-weight: 700; }
.selectable { user-select: all; font-family: ui-monospace, Menlo, Consolas, monospace; }
