:root {
  --ink: #0f172a; --mut: #64748b; --line: #e2e8f0; --bg: #f1f5f9;
  --brand: #0f766e; --brand-2: #115e59; --gold: #d97706; --card: #ffffff;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; color: var(--ink);
  font-family: -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); display: flex; flex-direction: column;
}
button { font: inherit; cursor: pointer; }
a { color: var(--brand); }

/* header */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; background: linear-gradient(90deg, #0f766e, #134e4a);
  color: #fff; box-shadow: 0 1px 8px rgba(0,0,0,.18); z-index: 30;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand .logo { font-size: 24px; }
.brand b { font-size: 18px; letter-spacing: .5px; display: block; }
.brand small { opacity: .85; font-size: 11px; }
.top-actions { display: flex; gap: 8px; }
.btn {
  border: 1px solid rgba(255,255,255,.4); background: rgba(255,255,255,.12); color: #fff;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; transition: .15s;
}
.btn:hover { background: rgba(255,255,255,.24); }
.btn.primary { background: var(--gold); border-color: var(--gold); }
.btn.primary:hover { background: #b45309; }
.btn.danger { background: #b91c1c; border-color: #b91c1c; }

/* layout */
.layout { flex: 1; display: flex; min-height: 0; }
.side {
  width: 340px; min-width: 300px; background: var(--bg);
  display: flex; flex-direction: column; border-right: 1px solid var(--line); z-index: 20;
}
.filters { padding: 10px; display: flex; flex-direction: column; gap: 8px; background: #fff; border-bottom: 1px solid var(--line); }
.filters input[type=search], .filters select, .filters input[type=text] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff;
}
.filters input:focus, .filters select:focus { outline: 2px solid #99f6e4; border-color: var(--brand); }
.frow { display: flex; gap: 8px; }
.frow > * { flex: 1; min-width: 0; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; color: var(--mut);
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.fstat { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: var(--mut); }
.mini { border: 0; background: none; color: var(--brand); font-size: 12.5px; text-decoration: underline; }

.cards { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--mut); text-align: center; padding: 40px 0; font-size: 14px; }
.card {
  display: flex; background: var(--card); border-radius: 12px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(15,23,42,.08); border: 1px solid var(--line); cursor: pointer;
  transition: .15s; flex: none;
}
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(15,23,42,.12); }
.card.active { outline: 2px solid var(--brand); }
.card-band { width: 6px; flex: none; }
.card-band.b1 { background: #0e9f6e; } .card-band.b2 { background: #3b82f6; }
.card-band.b3 { background: #f59e0b; } .card-band.b4 { background: #ef4444; }
.card-main { padding: 10px 12px; flex: 1; min-width: 0; }
.card-title { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.card-name { font-weight: 700; font-size: 15px; }
.tag { font-size: 10px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.tag.demo, .hero-tag.demo { background: #fef3c7; color: #92400e; }
.tag.own, .hero-tag.own { background: #d1fae5; color: #065f46; }
.card-sub { font-size: 12px; color: var(--mut); margin: 2px 0 6px; }
.card-price { font-size: 17px; font-weight: 800; color: var(--brand-2); }
.card-psf { font-size: 12px; color: var(--mut); font-weight: 500; margin-left: 4px; }
.card-meta { font-size: 12.5px; color: #334155; margin-top: 2px; }
.card-mtr { font-size: 12px; color: #475569; margin-top: 4px; background: #f8fafc; border-radius: 6px; padding: 3px 6px; display: inline-block; }

/* map */
.mapwrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.panel {
  position: absolute; background: rgba(255,255,255,.95); backdrop-filter: blur(6px);
  border-radius: 12px; padding: 10px 12px; box-shadow: 0 2px 12px rgba(0,0,0,.15); z-index: 10;
}
.panel.tl { top: 10px; left: 10px; display: flex; flex-direction: column; gap: 10px; }
.grp { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.grp > b { font-size: 12px; color: var(--mut); text-transform: uppercase; letter-spacing: .5px; }
.grp label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.seg { display: flex; gap: 4px; }
.seg button {
  border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 4px 10px; font-size: 12.5px;
}
.seg button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.legend {
  position: absolute; bottom: 10px; left: 10px; z-index: 10;
  background: rgba(255,255,255,.95); border-radius: 10px; padding: 6px 10px;
  font-size: 11.5px; color: #334155; display: flex; gap: 6px; align-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* price markers */
.phk-marker {
  border: 0; padding: 3px 7px; border-radius: 7px 7px 7px 2px; font-size: 11.5px; font-weight: 700;
  color: #fff; transform-origin: bottom; box-shadow: 0 2px 6px rgba(0,0,0,.3); white-space: nowrap;
  transition: transform .12s;
}
.phk-marker.b1 { background: #0e9f6e; } .phk-marker.b2 { background: #3b82f6; }
.phk-marker.b3 { background: #f59e0b; } .phk-marker.b4 { background: #ef4444; }
.phk-marker.own { outline: 2px solid #10b981; }
.phk-marker:hover, .phk-marker.active { transform: scale(1.18); z-index: 5; }

/* drawer */
.drawer {
  position: fixed; top: 0; right: -420px; width: 400px; max-width: 96vw; height: 100%;
  background: #fff; z-index: 40; box-shadow: -6px 0 24px rgba(0,0,0,.2);
  transition: right .25s ease; overflow-y: auto;
}
.drawer.open { right: 0; }
.drawer-close {
  position: absolute; top: 10px; right: 10px; z-index: 2; border: 0; background: rgba(255,255,255,.85);
  border-radius: 50%; width: 32px; height: 32px; font-size: 15px;
}
.hero { color: #fff; padding: 46px 18px 18px; position: relative; }
.hero h2 { margin: 4px 0 2px; font-size: 24px; }
.hero-sub { font-size: 13px; opacity: .92; }
.hero-tag { position: absolute; top: 12px; left: 14px; border-radius: 6px; padding: 2px 8px; font-size: 11px; font-weight: 700; }
.grad-0 { background: linear-gradient(135deg,#0f766e,#2dd4bf); }
.grad-1 { background: linear-gradient(135deg,#1e3a8a,#60a5fa); }
.grad-2 { background: linear-gradient(135deg,#7c2d12,#f59e0b); }
.grad-3 { background: linear-gradient(135deg,#581c87,#a78bfa); }
.grad-4 { background: linear-gradient(135deg,#164e63,#22d3ee); }
.grad-5 { background: linear-gradient(135deg,#831843,#fb7185); }
.d-body { padding: 14px 16px 26px; display: flex; flex-direction: column; gap: 14px; }
.d-price { display: flex; align-items: baseline; gap: 10px; }
.d-big { font-size: 28px; font-weight: 900; color: var(--brand-2); }
.d-psf { font-weight: 700; padding: 2px 8px; border-radius: 6px; color: #fff; }
.d-psf small { font-weight: 400; }
.d-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.cell { background: #f8fafc; border-radius: 8px; padding: 7px 8px; min-width: 0; }
.cell small { display: block; color: var(--mut); font-size: 10.5px; }
.cell b { font-size: 13px; }
.d-body h4 { margin: 0 0 6px; font-size: 14px; }
.d-mtr, .d-schools, .d-commute, .d-agent { font-size: 13px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.d-schools ol { margin: 0; padding-left: 18px; }
.d-schools li { margin: 3px 0; }
.d-schools small { color: var(--mut); margin-left: 4px; }
.d-src { font-size: 10.5px; color: var(--mut); margin: 6px 0 0; }
.hint { font-size: 11.5px; color: var(--mut); }
.commute-res { font-size: 13.5px; font-weight: 700; color: var(--brand-2); min-height: 18px; }
.d-agent .btn { margin: 6px 6px 0 0; background: #f0fdfa; border-color: #99f6e4; color: var(--brand-2); }
.d-agent .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.d-agent .btn.danger { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }
.d-export { display: flex; gap: 8px; }
.d-export .btn, .drawer .d-export { color: var(--brand-2); background: #f0fdfa; border-color: #99f6e4; }

/* modals */
.modal {
  position: fixed; inset: 0; background: rgba(15,23,42,.55); display: none;
  align-items: center; justify-content: center; z-index: 60; padding: 16px;
}
.modal.open { display: flex; }
.modal-card {
  background: #fff; border-radius: 14px; padding: 18px; max-height: 92vh; overflow-y: auto;
  width: 480px; max-width: 96vw; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal-card.wide { width: 760px; }
.modal h3 { margin: 0 0 10px; font-size: 17px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { font-size: 12px; color: var(--mut); display: flex; flex-direction: column; gap: 4px; }
.form label.wide { grid-column: 1 / -1; }
.form input {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13.5px;
}
.pt-label { font-size: 13px; color: var(--brand-2); font-weight: 600; }
.modal .btn { background: #f0fdfa; border-color: #99f6e4; color: var(--brand-2); }
.modal .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }

/* market modal */
.mkt-body { font-size: 13px; }
.mkt-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; margin-bottom: 8px; }
.mkt-big { font-size: 34px; font-weight: 900; color: var(--brand-2); }
.mkt-sub { color: var(--mut); margin-left: 6px; font-size: 12px; }
.mkt-mom { font-weight: 700; }
.mkt-mom.up { color: #dc2626; } .mkt-mom.down { color: #059669; }
.mkt-src { width: 100%; font-size: 11.5px; color: var(--mut); }
.mkt-sec { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.mkt-sec h4 { margin: 0 0 8px; font-size: 14px; }
.mkt-range { display: flex; gap: 6px; margin-bottom: 6px; }
.mkt-range button { border: 1px solid var(--line); background: #fff; border-radius: 7px; padding: 3px 12px; font-size: 12px; }
.mkt-range button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.mkt-chart svg { width: 100%; height: auto; }
.mkt-legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11.5px; color: #334155; margin-top: 4px; }
.mkt-legend i { width: 10px; height: 3px; display: inline-block; margin-right: 4px; vertical-align: middle; border-radius: 2px; }
.mkt-foot { font-size: 11px; color: var(--mut); border-top: 1px solid var(--line); padding-top: 8px; }
.mkt-err { color: var(--mut); }

/* footer */
.foot { background: #0f172a; color: #cbd5e1; font-size: 12px; padding: 10px 14px; z-index: 30; }
.foot details { margin-bottom: 4px; }
.foot summary { cursor: pointer; }
.foot p { margin: 8px 0 4px; color: #94a3b8; font-size: 11.5px; line-height: 1.6; }
.attr a { color: #5eead4; }

/* responsive */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .side { width: 100%; min-width: 0; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .cards { flex: 1; }
  .mapwrap { flex: 1; min-height: 46vh; }
  .drawer { top: auto; bottom: 0; right: 0; left: 0; width: 100%; height: 78vh; border-radius: 16px 16px 0 0; transform: translateY(105%); transition: transform .25s ease; right: auto; }
  .drawer.open { transform: translateY(0); right: auto; }
  .panel.tl { top: 8px; left: 8px; padding: 8px; gap: 6px; font-size: 12px; }
  .d-grid { grid-template-columns: repeat(2, 1fr); }
  .form { grid-template-columns: 1fr; }
}

/* ---- first-hand edition ----------------------------------------------------*/
.card-band.b0, .phk-marker.b0 { background: #64748b; }
.tag.selling, .hero-tag.selling { background: #d1fae5; color: #065f46; }
.tag.sold_out, .hero-tag.sold_out { background: #e2e8f0; color: #475569; }
.tag.no_price_list, .hero-tag.no_price_list { background: #fef3c7; color: #92400e; }

.hero-img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
}
.hero.has-cover h2, .hero.has-cover .hero-sub, .hero.has-cover .hero-tag {
  position: relative; z-index: 2;
}
.hero.has-cover::before {
  content: ""; position: absolute; inset: 0; z-index: 1;
  background: linear-gradient(180deg, rgba(15,23,42,.55) 0%, rgba(15,23,42,.15) 45%, rgba(15,23,42,.78) 100%);
}
.hero.has-cover h2, .hero.has-cover .hero-sub { text-shadow: 0 1px 6px rgba(0,0,0,.5); }

.d-range { font-size: 13px; color: var(--mut); margin-top: -6px; }
.d-links { display: flex; gap: 8px; flex-wrap: wrap; }
.d-links .btn { background: #f0fdfa; border-color: #99f6e4; color: var(--brand-2); text-decoration: none; display: inline-flex; align-items: center; }
.d-links .btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.d-updated { font-size: 11px; color: var(--mut); margin: 0; }

.units-loading, .units-empty { font-size: 13px; color: var(--mut); padding: 6px 0; }
.units-table {
  border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
  font-size: 12px; max-height: 340px; overflow-y: auto;
}
.u-row {
  display: grid; grid-template-columns: minmax(110px,1.6fr) 62px 58px 74px 62px 44px;
  gap: 4px; padding: 5px 10px; border-bottom: 1px solid var(--line); align-items: baseline;
}
.u-row:last-child { border-bottom: 0; }
.u-head {
  position: sticky; top: 0; background: #f8fafc; font-weight: 700; color: var(--mut);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .3px;
}
.u-row:nth-child(even):not(.u-head) { background: #fbfdfe; }
.u-id { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.u-price { font-weight: 700; color: var(--brand-2); }
.u-cut { color: #b91c1c; font-weight: 700; }
#moreUnits { margin-top: 8px; }

.chips-stat { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-stat {
  font-size: 11.5px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa;
  border-radius: 999px; padding: 2px 10px;
}
.d-plans, .d-sa, .d-deals { font-size: 13px; margin-top: 10px; }
.d-sa div { color: #334155; }
.d-deals ul { margin: 0; padding: 0; list-style: none; }
.d-deals li { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.d-deals li:last-child { border-bottom: 0; }
.d-deals small { color: var(--mut); margin: 0 4px; }
.d-deals b { color: var(--brand-2); }
.d-doclinks { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.d-doclinks .btn { background: #f0fdfa; border-color: #99f6e4; color: var(--brand-2); text-decoration: none; display: inline-flex; align-items: center; font-size: 12.5px; }

/* v2 additions: freshness chip, sold-out toggle, unit chips, trend chart */
.fresh {
  display: inline-block; margin-left: 6px; font-size: 10px; color: #5eead4;
  background: rgba(15,118,110,.4); border-radius: 999px; padding: 1px 8px; vertical-align: middle;
}
.soldout-toggle { display: flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--mut); cursor: pointer; }
.u-chips { display: flex; gap: 5px; flex-wrap: wrap; margin: 0 0 8px; }
.u-chip { font-size: 11.5px; padding: 2px 10px; border-radius: 999px; }
.d-trend { font-size: 13px; margin-top: 10px; }
.d-trend svg { width: 100%; height: auto; }
.trend-cap { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--mut); margin-top: 2px; }

