:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e3e6eb;
  --brand: #1f4e8c;
  --brand-ink: #ffffff;
  --danger: #c0392b;
  --dark: #1b2130;
  --radius: 10px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
a { color: var(--brand); }
button, input { font: inherit; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.active { background: #f0b429; border-color: #f0b429; color: #1d2433; }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input[type=text]:focus { outline: 2px solid #9db8e0; border-color: var(--brand); }

.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px; background: var(--dark); color: #fff;
}
.topbar .logo { font-weight: 700; letter-spacing: .5px; }
.topbar .spacer { flex: 1; }
.topbar a.back { color: #cfd6e4; text-decoration: none; }

/* ---------- 導覽列表 ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card .cover { aspect-ratio: 2 / 1; background: #cdd5e2 center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: #5b6b85; font-size: 13px; cursor: pointer; }
.card .body { padding: 10px 12px; flex: 1; }
.card .name { font-weight: 700; margin-bottom: 4px; }
.card .meta { color: var(--muted); font-size: 13px; }
.card .actions { display: flex; gap: 6px; padding: 0 12px 12px; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }
select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; color: var(--ink);
}
select:disabled { color: var(--muted); background: #f4f5f7; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filters input[type=search] {
  flex: 1 1 240px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff;
}
.city-group { margin-bottom: 28px; }
.city-title { font-size: 18px; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--brand); }
.district-title { font-size: 15px; margin: 14px 0 8px; color: #3b4658; }
.city-title span, .district-title span { color: var(--muted); font-weight: 400; font-size: 13px; }
.loc-row { display: flex; gap: 10px; }
.loc-row > div { flex: 1; }
.loc-row select { width: 100%; }

/* ---------- 我的名片 ---------- */
.page.narrow { max-width: 760px; }
.page-title { font-size: 20px; margin: 4px 0 6px; }
.sub-title { font-size: 16px; margin: 24px 0 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.profile-grid { display: flex; gap: 24px; flex-wrap: wrap; }
.photo-col { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 140px; }
.form-col { flex: 1 1 280px; display: flex; flex-direction: column; gap: 12px; }
.form-col label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.sync-row { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.sync-row label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.form-col input[readonly] { background: #f4f5f7; color: #3b4658; }
.agent-license { font-size: 11px; color: var(--muted); }
.agent-links { width: 100%; display: flex; gap: 12px; font-size: 13px; padding-top: 6px; border-top: 1px solid var(--line); }
.agent-links a { color: var(--brand); text-decoration: none; font-weight: 700; }
/* ---------- 官網物件選擇 ---------- */
dialog.listing-dialog { width: min(640px, calc(100vw - 24px)); }
.listing-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.listing-tools input { flex: 1 1 200px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: #fff; padding: 8px 14px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; }
.listing-list { max-height: 55vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.listing-row { display: flex; gap: 10px; align-items: center; text-align: left; border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 6px; cursor: pointer; font: inherit; color: var(--ink); }
.listing-row:hover { border-color: var(--brand); background: #f5f8fd; }
.listing-row img { width: 96px; height: 64px; object-fit: cover; border-radius: 6px; background: #cdd5e2; flex: none; }
.listing-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.listing-row.taken { opacity: .55; cursor: not-allowed; background: #f4f5f7; }
.listing-row.taken:hover { border-color: var(--line); background: #f4f5f7; }
.bound-note { color: var(--danger) !important; font-weight: 700; }
.bound-note.mine { color: #15803d !important; }
.listing-text b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing-text small { font-size: 12px; color: var(--muted); }
.listing-text em, .badge { font-style: normal; background: #e8f6ee; color: #15803d; border-radius: 4px; padding: 0 5px; font-size: 11px; font-weight: 700; }
.badge.off { background: #fdecea; color: var(--danger); }
.bound { display: flex; gap: 10px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 8px; background: #f8f9fb; }
.bound img { width: 80px; height: 54px; object-fit: cover; border-radius: 6px; }
.bound .listing-text { flex: 1; }

.row-end { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; background: #cdd5e2; flex: none; }
.avatar.big { width: 120px; height: 120px; }
.logo-preview { width: 140px; height: 64px; object-fit: contain; background: #fff; border-radius: 8px; }
.preview-box { background: #2b2f38; border-radius: var(--radius); padding: 24px 16px; }
.banner { background: #fff7e0; border: 1px solid #f0d58a; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.banner span { flex: 1; }

/* ---------- 業務名片（分享頁） ---------- */
.agent-card {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(255,255,255,.96); color: var(--ink); border-radius: 12px; padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 420px;
}
.agent-info { flex: 1; min-width: 120px; }
.agent-name { font-weight: 700; font-size: 16px; }
.agent-sub { font-size: 13px; color: var(--muted); }
.agent-actions { display: flex; gap: 6px; }
.agent-btn { padding: 8px 12px; border-radius: 8px; font-size: 14px; font-weight: 700; text-decoration: none; color: #fff; white-space: nowrap; }
.agent-btn.call { background: var(--agent, var(--brand)); }
.agent-btn.book { width: 100%; text-align: center; background: var(--agent, var(--brand)); padding: 10px; font-size: 15px; }
.agent-card .agent-links a { color: var(--agent, var(--brand)); }
.agent-links { flex-wrap: wrap; }
.v-listing { margin-top: 6px; padding-top: 6px; border-top: 1px solid rgba(255,255,255,.2); font-size: 13px; line-height: 1.6; }
.v-listing .price { font-size: 16px; font-weight: 700; color: #ffd166; }
.v-listing a { color: #9ecbff; font-weight: 700; text-decoration: none; }
.v-listing .badge { margin-right: 4px; }
.agent-btn.line { background: #06c755; }
.stats { font-size: 13px; color: var(--brand); }
/* ---------- 編輯器 ---------- */
.editor { display: flex; height: calc(100vh - 56px); }
.sidebar { width: 300px; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar .side-head { padding: 12px; border-bottom: 1px solid var(--line); }
.upload-progress { margin-top: 8px; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; display: none; }
.upload-progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.upload-msg { font-size: 13px; color: var(--muted); margin-top: 6px; min-height: 1em; }
.scene-list { flex: 1; overflow-y: auto; padding: 8px; }
.scene { border: 2px solid transparent; border-radius: var(--radius); padding: 6px; margin-bottom: 6px; background: #f8f9fb; }
.scene.current { border-color: var(--brand); background: #eef3fb; }
.scene { cursor: grab; }
.scene.dragging { opacity: .85; box-shadow: 0 6px 18px rgba(0,0,0,.25); border-style: dashed; border-color: var(--brand); }
body.sorting, body.sorting * { cursor: grabbing !important; user-select: none; }
.scene .drag-handle { color: var(--muted); font-size: 14px; letter-spacing: -3px; padding: 0 4px; cursor: grab; }
.scene img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 6px; cursor: pointer; display: block; background: #cdd5e2; }
.scene .row { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.scene .row input { padding: 5px 8px; }
.scene .info { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.tag { background: #f0b429; color: #1d2433; border-radius: 4px; padding: 0 6px; font-size: 12px; font-weight: 700; }

.stage { flex: 1; position: relative; background: #222; }
#viewer { position: absolute; inset: 0; }
.toolbar { position: absolute; top: 12px; left: 12px; z-index: 20; display: flex; gap: 8px; flex-wrap: wrap; }
.hint { position: absolute; top: 60px; left: 50%; transform: translateX(-50%); z-index: 20; background: rgba(240,180,41,.95); color: #1d2433; padding: 8px 14px; border-radius: 8px; font-weight: 700; display: none; white-space: nowrap; }
.stage-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #aab3c2; flex-direction: column; gap: 10px; }

/* ---------- 熱點 ---------- */
.hs { display: flex; flex-direction: column; align-items: center; cursor: pointer; transform: translateY(-14px); }
.hs-dot {
  width: 44px; height: 44px; border-radius: 50%;
  background: rgba(255,255,255,.25); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s;
}
.hs-dot::after { content: ""; width: 14px; height: 14px; border-left: 4px solid #fff; border-top: 4px solid #fff; transform: translateY(3px) rotate(45deg); }
.hs:hover .hs-dot { transform: scale(1.12); background: rgba(31,78,140,.6); }
.hs-label { margin-top: 6px; background: rgba(0,0,0,.65); color: #fff; padding: 3px 10px; border-radius: 12px; font-size: 14px; white-space: nowrap; }

/* ---------- 對話框 ---------- */
dialog { border: none; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog .dlg-head { padding: 14px 18px; font-weight: 700; border-bottom: 1px solid var(--line); }
dialog .dlg-body { padding: 16px 18px; display: flex; flex-direction: column; gap: 12px; }
dialog .dlg-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
dialog label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
.pick-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-height: 50vh; overflow-y: auto; }
.pick-list button { border: 2px solid var(--line); border-radius: 8px; background: #fff; padding: 4px; cursor: pointer; text-align: left; }
.pick-list button:hover { border-color: var(--brand); }
.pick-list img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 5px; display: block; }
.pick-list span { display: block; padding: 4px 2px 0; font-size: 14px; }
.note { font-size: 13px; color: var(--muted); line-height: 1.6; }

/* ---------- 分享瀏覽頁 ---------- */
body.viewer-page { background: #000; overflow: hidden; }
.v-title { position: fixed; top: 12px; left: 12px; z-index: 30; color: #fff; background: rgba(0,0,0,.5); padding: 8px 14px; border-radius: 10px; max-width: calc(100vw - 24px); }
.v-title .n { font-weight: 700; font-size: 17px; }
.v-title .a { font-size: 13px; opacity: .8; }
.v-title .s { font-size: 13px; color: #f0b429; margin-top: 2px; }
.v-strip { position: fixed; left: 0; right: 0; bottom: 48px; z-index: 30; display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; scrollbar-width: none; }
.v-strip button { flex: 0 0 auto; width: 120px; border: 2px solid rgba(255,255,255,.4); border-radius: 8px; background: rgba(0,0,0,.55); color: #fff; padding: 3px; cursor: pointer; }
.v-strip button.current { border-color: #f0b429; }
.v-strip img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 5px; display: block; }
.v-strip span { display: block; font-size: 13px; padding-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.v-brand { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; margin-bottom: 4px; padding-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.2); }
.v-brand img { height: 28px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 4px; padding: 2px 4px; }
/* ---------- 預約看屋／業務回電（分享頁） ---------- */
dialog.lead-dialog { width: min(420px, calc(100vw - 24px)); padding: 18px; border-radius: 16px; --agent-c: var(--agent, var(--brand)); }
.lead-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 17px; }
.lead-head b { flex: 1; }
.lead-x { border: none; background: #eef1f5; border-radius: 50%; width: 32px; height: 32px; cursor: pointer; font-size: 14px; }
#leadForm { display: flex; flex-direction: column; gap: 12px; }
.lead-type { display: flex; gap: 22px; font-weight: 700; font-size: 16px; }
.lead-type label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.lead-type input { accent-color: var(--agent-c); width: 18px; height: 18px; }
.lead-input { width: 100%; padding: 12px 16px; border: 1px solid color-mix(in srgb, var(--agent-c) 60%, #fff); border-radius: 999px; font: inherit; background: #fff; }
.lead-input:focus { outline: 2px solid color-mix(in srgb, var(--agent-c) 40%, #fff); }
.lead-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.lead-consent { display: flex; align-items: center; gap: 8px; font-size: 14px; color: #3b4658; }
.lead-consent input { width: 18px; height: 18px; accent-color: var(--agent-c); }
.lead-link { border: none; background: none; padding: 0; font: inherit; font-weight: 700; color: var(--agent-c); text-decoration: underline; cursor: pointer; }
.lead-error { margin: 0; color: var(--danger); font-size: 14px; font-weight: 700; }
.lead-submit { width: 100%; border: none; border-radius: 999px; padding: 13px; background: var(--agent-c); color: #fff; font: inherit; font-size: 17px; font-weight: 700; cursor: pointer; }
.lead-submit:disabled { opacity: .6; cursor: default; }
.lead-done { line-height: 1.7; font-size: 15px; margin: 0 0 14px; }
.privacy-text { font-size: 14px; line-height: 1.7; color: #3b4658; max-height: 60vh; overflow-y: auto; }
.privacy-text ol { padding-left: 20px; }

/* 名片列：和空間縮圖同一排（畫面最下方），縮圖列讓出右邊的位置，不擋看房視角 */
.v-agent { position: fixed; right: 12px; bottom: 56px; z-index: 32; max-width: min(560px, calc(100vw - 24px)); }
body.has-agent .v-strip { right: calc(var(--agent-w, 0px) + 20px); }
.agent-bar { background: rgba(255,255,255,.96); color: var(--ink); border-radius: 12px; padding: 8px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.agent-row { display: flex; align-items: center; gap: 8px; }
.agent-row .avatar { width: 44px; height: 44px; }
.agent-row .agent-info { flex: 1; min-width: 0; }
.agent-row .agent-name { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-row .agent-btn { padding: 8px 10px; font-size: 14px; }
.agent-row .agent-btn.book { width: auto; padding: 8px 12px; font-size: 14px; }
.agent-more { border: none; background: #eef1f5; color: var(--ink); border-radius: 8px; width: 32px; height: 34px; cursor: pointer; font-size: 14px; flex: none; }
.agent-more[aria-expanded="true"] { transform: rotate(180deg); }
.agent-extra { padding: 2px 4px 8px; margin-bottom: 8px; border-bottom: 1px solid var(--line); }
.agent-bar .agent-links { border-top: none; padding-top: 4px; }
.agent-bar .agent-links a { color: var(--agent, var(--brand)); }
.v-plan-btn { position: fixed; top: 12px; right: 12px; z-index: 31; background: rgba(0,0,0,.6); color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer; }
.v-plan-btn.active { background: #f0b429; color: #1d2433; border-color: #f0b429; }
.v-plan { position: fixed; top: 56px; right: 12px; z-index: 31; width: min(420px, calc(100vw - 24px)); background: #fff; border-radius: 10px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }

.plan-panel { position: absolute; top: 60px; right: 12px; bottom: 60px; z-index: 25; width: min(380px, calc(100% - 24px)); overflow-y: auto; background: #fff; border-radius: 10px; padding: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.35); }
.plan-head { display: flex; align-items: center; margin-bottom: 6px; }
.plan-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
#planView .plan-wrap { cursor: crosshair; border: 1px solid var(--line); }

/* ---------- 平面圖 ---------- */
.plan-wrap { position: relative; width: 100%; user-select: none; }
.plan-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.plan-dot { position: absolute; transform: translate(-50%, -50%); width: 22px; height: 22px; border-radius: 50%; border: 3px solid #fff; background: var(--brand); box-shadow: 0 1px 4px rgba(0,0,0,.5); cursor: pointer; padding: 0; }
.plan-dot span { position: absolute; left: 50%; top: 22px; transform: translateX(-50%); white-space: nowrap; font-size: 12px; background: rgba(0,0,0,.7); color: #fff; padding: 1px 6px; border-radius: 8px; pointer-events: none; }
.plan-dot.current { background: #f0b429; width: 28px; height: 28px; z-index: 2; }
.plan-dot.pending { background: #c0392b; }

@media (max-width: 760px) {
  /* 手機：名片列在空間縮圖上方一整行，縮圖列維持全寬 */
  .v-agent { left: 8px; right: 8px; bottom: 140px; max-width: none; }
  body.has-agent .v-strip { right: 0; }
  .agent-bar { padding: 6px 8px; }
  .agent-row { gap: 6px; }
  .agent-row .avatar { width: 36px; height: 36px; }
  .agent-row .agent-sub { display: none; }
  .agent-row .agent-btn { padding: 7px 8px; font-size: 13px; }
  .agent-row .agent-btn.book { padding: 7px 9px; font-size: 13px; }
  .v-listing .facts-extra { display: none; }
  .v-title { max-width: calc(100vw - 110px); }
}

.v-error { color: #fff; display: flex; align-items: center; justify-content: center; height: 100vh; font-size: 18px; }

@media (max-width: 760px) {
  .editor { flex-direction: column-reverse; height: auto; }
  .sidebar { width: 100%; border-right: none; }
  .stage { height: 60vh; flex: none; }
}
