:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --line: #e3e6ec;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --good: #2f9e44;
  --bad: #e03131;
  --t-used: #1971c2;
  --t-pre: #9c36b5;
  --t-new: #2f9e44;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 30, 50, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1e2128;
    --text: #e6e8ee;
    --muted: #9aa1b2;
    --line: #2f343e;
    --accent: #ff8a3d;
    --accent-soft: #3a2618;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
h3 { margin: 0 0 12px; font-size: 16px; }
h4 { margin: 16px 0 4px; font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.up { color: var(--bad); }
.down { color: var(--good); }

/* 頂部 */
.topbar { background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; }
.brand { font-weight: 700; font-size: 18px; color: var(--accent); text-decoration: none; white-space: nowrap; }
#nav { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
#nav a { padding: 8px 12px; border-radius: 8px; color: var(--text); text-decoration: none; white-space: nowrap; }
#nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding-top: 16px; padding-bottom: 48px; }
.tab { display: none; }
.tab.active { display: block; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.notice { background: var(--accent-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; font-size: 14px; }

/* 表單 */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { padding: 0; flex: 1; accent-color: var(--accent); background: none; border: none; }
.grid-filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span2 { grid-column: span 2; }
.row { display: flex; align-items: center; gap: 8px; }
.row.gap { gap: 8px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.kv { display: flex; justify-content: space-between; font-size: 14px; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; border-radius: 8px; padding: 8px 14px;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.danger { border-color: var(--bad); color: var(--bad); background: transparent; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--muted); padding: 4px; }
.icon-btn.on { color: var(--accent); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 999px; padding: 3px 12px; cursor: pointer; font: inherit; font-size: 14px; }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.filters { display: flex; flex-direction: column; gap: 10px; }
.searchbar { display: flex; gap: 8px; flex-wrap: wrap; }
.searchbar input { flex: 1; min-width: 200px; }
.searchbar .btn { text-decoration: none; white-space: nowrap; }
.frow { display: grid; grid-template-columns: 72px 1fr; gap: 8px; align-items: baseline; padding-top: 10px; border-top: 1px dashed var(--line); }
.flabel { font-size: 13px; color: var(--muted); font-weight: 600; }
.end-row { display: flex; justify-content: space-between; align-items: center; }
.filters:not(.expanded) .frow.more { display: none; }
a.card { color: inherit; text-decoration: none; }
.table a { color: var(--t-used); text-decoration: none; }
.table a:hover { text-decoration: underline; }
.bar-row[data-c] { cursor: pointer; }
.bar-row[data-c]:hover span:first-child { color: var(--accent); }

/* 物件卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .15s; }
.card:hover { transform: translateY(-2px); }
.card-img { height: 120px; display: flex; align-items: flex-start; justify-content: space-between; padding: 10px; font-size: 13px; }
.card-img.t-中古屋 { background: linear-gradient(135deg, #d0ebff, #a5d8ff); }
.card-img.t-預售屋 { background: linear-gradient(135deg, #f3d9fa, #e599f7); }
.card-img.t-新成屋 { background: linear-gradient(135deg, #d3f9d8, #8ce99a); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; color: #fff; }
.badge.t-中古屋 { background: var(--t-used); }
.badge.t-預售屋 { background: var(--t-pre); }
.badge.t-新成屋 { background: var(--t-new); }
.badge.cut { background: var(--bad); }
.gmap { display: inline-flex; align-items: center; gap: 2px; font: inherit; font-size: 12px; white-space: nowrap; color: var(--t-used) !important; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; margin-left: 6px; cursor: pointer; text-decoration: none !important; vertical-align: middle; }
.gmap:hover { border-color: var(--t-used); }
.card-foot { margin-top: auto; padding-top: 6px; }
.more-wrap { text-align: center; margin-top: 16px; }
.proj-card { cursor: default; }
.proj-card:hover { transform: none; }
.proj-card .btn { text-decoration: none; }
.notice a, .source-box a { color: var(--t-used); }
.source-box { border-left: 4px solid var(--t-used); }
.ref-list { margin: 4px 0 0; padding-left: 20px; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-title { font-weight: 600; }
.price { color: var(--accent); font-size: 22px; font-weight: 700; }
.price small { font-size: 13px; font-weight: 400; color: var(--muted); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* 統計 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 22px; font-weight: 700; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.hl .value { color: var(--accent); }

/* 長條圖 */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 70px 1fr 56px; align-items: center; gap: 8px; font-size: 14px; }
.bar-track { background: var(--bg); border-radius: 4px; height: 18px; overflow: hidden; }
.bar { height: 100%; background: var(--accent); border-radius: 4px; opacity: .8; }
.bar-row.sel .bar { opacity: 1; }
.bar-row.sel { font-weight: 700; }

/* 表格 */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; white-space: nowrap; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; }
.table th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--panel); }
.table td.l { text-align: left; }

/* 房貸 */
.calc-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.calc-layout output { min-width: 40px; text-align: right; color: var(--text); font-weight: 600; }
.chart svg { width: 100%; height: auto; max-height: 260px; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.chart .grid { stroke: var(--line); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .area { fill: var(--accent); opacity: .12; }
.chart .today { stroke: var(--text); stroke-dasharray: 4 3; }

/* 我的房子 */
.toolbar { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.toolbar .stats { flex: 1; margin-bottom: 16px; }
.home-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.home-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.home-head h3 { margin: 0; }
.progress { height: 10px; background: var(--bg); border-radius: 5px; overflow: hidden; margin: 6px 0 4px; }
.progress > div { height: 100%; background: var(--good); }
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.home-grid .label { font-size: 13px; color: var(--muted); }
.home-grid .value { font-size: 18px; font-weight: 700; }
details summary { cursor: pointer; color: var(--accent); margin-top: 8px; }
.event-list { font-size: 14px; margin: 8px 0; padding-left: 20px; }

/* 對話框 */
.dialog { border: none; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--panel); color: var(--text); }
.dialog::backdrop { background: rgba(0, 0, 0, .45); }
.dialog > div, .dialog > form { padding: 20px; }
.event-row { display: grid; grid-template-columns: 100px 1fr 1fr 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.detail-grid .label { font-size: 13px; color: var(--muted); }
.compare { background: var(--bg); border-radius: 8px; padding: 12px; font-size: 14px; }

/* 匯入實價登錄 */
.import { display: flex; flex-direction: column; gap: 8px; border-style: dashed; }
.import.drag { border-color: var(--accent); background: var(--accent-soft); }
.import.busy { opacity: .6; pointer-events: none; }
.import-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.import label.btn { display: inline-flex; flex-direction: row; color: #fff; font-size: 13px; }
.import ol { margin: 8px 0; padding-left: 20px; line-height: 1.8; }
.import a { color: var(--t-used); }
.imp-log { font-size: 13px; }
.imp-log:empty { display: none; }
.imp-log div { padding: 2px 0; }

/* 實價地圖頁 */
.map-body { height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.map-page { flex: 1; display: grid; grid-template-columns: 380px 1fr; min-height: 0; }
.map-side { overflow-y: auto; padding: 12px 16px; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 12px; }
.map-side .filters { gap: 8px; }
.map-side .frow { grid-template-columns: 60px 1fr; padding-top: 8px; }
#bigmap { height: 100%; min-height: 300px; background: var(--bg); }
.stats.compact { margin: 0; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats.compact .stat { padding: 8px 10px; box-shadow: none; }
.stats.compact .value { font-size: 18px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 13px; }
.lg { display: inline-flex; align-items: center; gap: 4px; }
.lg i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.lg i.lg-star { width: auto; height: auto; background: none; color: var(--accent); font-style: normal; }
.m-list { display: flex; flex-direction: column; }
.m-item { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; padding: 8px 6px; border-bottom: 1px solid var(--line); cursor: pointer; font-size: 14px; border-radius: 6px; }
.m-item:hover, .m-item.on { background: var(--accent-soft); }
.m-item i { width: 12px; height: 12px; border-radius: 50%; }

/* 物件詳細頁 */
.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.detail-head h2 { margin: 8px 0 4px; font-size: 22px; }
.detail-price { text-align: right; }
.detail-price .btn { text-decoration: none; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.calc-layout > *, .detail-layout > * { min-width: 0; }
.map-box { height: 340px; border-radius: 8px; overflow: hidden; background: var(--bg); }
.star-pin { color: #fff; background: var(--accent); border: 2px solid #fff; border-radius: 50%; display: flex !important; align-items: center; justify-content: center; font-size: 16px; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.mini-list { display: flex; flex-direction: column; gap: 10px; }
/* 周邊機能 */
.am-summary { background: var(--bg); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; margin-bottom: 12px; }
.am-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.am-row { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.am-head { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; margin-bottom: 4px; }
.am-head span:last-child { font-weight: 400; font-size: 13px; white-space: nowrap; }
.am-row ul { list-style: none; margin: 0; padding: 0; }
.am-row li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; }
.am-row li span { font-size: 12px; white-space: nowrap; }
.proj-pin { font-size: 18px; display: flex !important; align-items: center; justify-content: center; background: #fff; border: 2px solid var(--t-used); border-radius: 8px; box-shadow: 0 1px 4px rgba(0, 0, 0, .4); }
.lg i.lg-proj { width: auto; height: auto; background: none; font-style: normal; }
.am-pin { font-size: 18px; display: flex !important; align-items: center; justify-content: center; background: #fff; border-radius: 50%; box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.mini { display: block; padding: 10px; border: 1px solid var(--line); border-radius: 8px; color: inherit; text-decoration: none; }
.mini:hover { border-color: var(--accent); }
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }

@media (max-width: 760px) {
  .detail-layout { grid-template-columns: 1fr; }
  .map-body { height: auto; overflow: visible; }
  .map-page { grid-template-columns: 1fr; }
  #bigmap { height: 60vh; order: -1; }
  .map-side { border-right: none; }
  .detail-price { text-align: left; }
  .calc-layout { grid-template-columns: 1fr; }
  .brand { font-size: 16px; }
  #nav a { padding: 8px 8px; }
  .detail-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .event-row { grid-template-columns: 1fr 1fr; }
}
