/* Custom CSS enhancements */
.listing-card {
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.listing-card:hover { border-color: #b8c9da; }

#hover-preview-modal {
  transform: translate(15px, 15px);
  will-change: transform, opacity;
}

/* Auto-hide Headbar on scroll */
#main-header {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
  will-change: transform, opacity;
}

#main-header.header-hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Floating Scroll to Top button enhancement */
#btn-scroll-top {
  will-change: transform, opacity;
}

/* Long source text must wrap inside every nested flex item. */
.listing-card, .listing-card * { min-width: 0; overflow-wrap: anywhere; }

button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 3px;
}
button, a, summary { touch-action: manipulation; }
button[aria-pressed="true"] { background: #4338ca !important; border-color: #4338ca !important; color: white !important; }
button[aria-pressed="false"] { background: #f8fafc !important; border-color: #e2e8f0 !important; color: #334155 !important; }
[id^="btn-post-type-"][aria-pressed="false"] [id^="badge-type-"] { background: #e2e8f0; color: #334155; }
[id^="btn-post-type-"][aria-pressed="true"] [id^="badge-type-"] { background: rgba(255,255,255,.2); color: white; }
.transaction-tabs { min-width: 0; max-width: 100%; padding: 6px; gap: 8px; }
#btn-advanced-filters { display: none; }
[role="dialog"] > div { max-height: 90dvh; overflow-y: auto; overscroll-behavior: contain; }
[role="dialog"] input { min-width: 0; }
#main-header:focus-within { transform: none; opacity: 1; pointer-events: auto; }
.inspection-field { padding: 14px 0; border-top: 1px solid #e2e8f0; overflow-wrap: anywhere; }
.inspection-field h4 { font-weight: 700; }
.inspection-status, .inspection-note { color: #475569; font-size: 13px; }
.inspection-notice { padding: 10px; background: #f1f5f9; }
.inspection-changed { color: #4338ca; font-weight: 600; }
.inspection-field blockquote { margin: 8px 0; padding: 8px; border-left: 2px solid #94a3b8; background: #f8fafc; white-space: pre-wrap; }
#extraction-body { overflow-wrap: anywhere; }
#extraction-body summary { cursor: pointer; color: #4338ca; font-size: 13px; }

.listing-assessment { padding: 12px 14px; background: #eaf2fc; border: 1px solid #d6e4f2; border-radius: 7px; font-size: 13px; line-height: 1.6; }
.listing-assessment p { margin: 0; }
.listing-assessment .assessment-reason { color: #475569; }
.assessment-reason > span { font-weight: 600; }
.assessment-purpose { font-weight: 600; }

@media (max-width: 639px) {
  #main-header p { display: none; }
  #main-header > div > div:last-child { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); gap: 8px; width: 100%; }
  #main-header > div > div:last-child > button { justify-content: center; padding: 8px 5px; font-size: 12px; }
  #btn-scrape-now, #btn-manage-groups { grid-column: span 3; }
  #btn-phone-connect, #btn-export-excel, #btn-clear-listings { grid-column: span 2; }
  #btn-phone-connect > span:not(.duo-icon), #btn-export-excel > span:not(.duo-icon) { font-size: 0; }
  #btn-phone-connect > span:not(.duo-icon)::after { content: 'Điện thoại'; font-size: 12px; }
  #btn-export-excel > span:not(.duo-icon)::after { content: 'Excel'; font-size: 12px; }
  main { padding-top: 12px !important; }
  main > .space-y-4 { margin-top: 12px !important; }
  main > .space-y-4:not(#listings-container) { padding: 12px; }
  main > .space-y-4:not(#listings-container) > :not([hidden]) ~ :not([hidden]) { margin-top: 10px; }
  .transaction-tabs { display: flex; flex-wrap: nowrap; width: 100%; overflow-x: auto; scroll-padding-inline: 6px; }
  #btn-post-type-sale, #btn-post-type-rent, #btn-post-type-all { flex: 0 0 auto; min-height: 44px; padding: 9px 10px; gap: 6px; justify-content: center; font-size: 12px; }
  .transaction-tabs [id^="badge-type-"] { padding: 2px 6px; font-size: 11px; }
  #btn-post-type-sale span, #btn-post-type-rent span, #btn-post-type-all span { white-space: nowrap; }
  #btn-post-type-sale svg, #btn-post-type-rent svg, #btn-post-type-all svg { display: none; }
  #filter-fields { grid-template-columns: repeat(2,minmax(0,1fr)); }
  #filter-fields > div:first-child { grid-column: 1 / -1; }
  #filter-fields input, #filter-fields select { min-height: 36px; }
  .filter-actions > div:last-child label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  #filter-sort-by { max-width: 150px; min-height: 36px; }
  #btn-advanced-filters { display: inline-flex; align-items: center; padding: 8px 12px; border: 1px solid #cbd5e1; border-radius: 8px; color: #334155; font-size: 14px; }
  #advanced-filters:not([data-open="true"]) { display: none; }
  #advanced-filters { width: 100%; }
  #advanced-filters { order: 2; }
  .listing-card { padding: 12px; }
  .listing-card .grid-cols-2 { grid-template-columns: 1fr; }
  .listing-card > .pt-3 { flex-wrap: wrap; gap: 10px; }
  .listing-card > .pt-3 > div:last-child { margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .listing-card:hover { transform: none; }
}

/* Approved hybrid feed: quiet chrome, balanced media, readable source details. */
body { font-family: "Segoe UI", system-ui, sans-serif; background: #f3f5f8; color: #182c40; }
#main-header { background: #172b48; }
#main-header > div:first-child { flex-wrap: wrap; }
#main-header h1 { flex-wrap: wrap; }
#main-header > div > div:last-child { flex-wrap: wrap; }
#btn-clear-listings span { display: inline; }
.listing-card { padding: 18px; background: #fff; border: 1px solid #dce3eb; border-radius: 11px; box-shadow: none; }
.listing-card:hover { transform: none; box-shadow: none; }
.listing-main { display: grid; grid-template-columns: minmax(0,42fr) minmax(0,58fr); align-items: start; gap: 25px; }
.listing-photo-block { align-self: center; }
.listing-photo { display: block; position: relative; width: 100%; aspect-ratio: 1.15; padding: 0; overflow: hidden; border-radius: 9px; border: 1px solid #dce3eb; background: #edf3f9; cursor: zoom-in; }
.listing-photo img { display: block; width: 100%; height: 100%; object-fit: contain; }
.listing-photo-empty .duo-icon { width: 36px; height: 36px; padding: 8px; background: #e3e9f0; color: #7a8899; }
.listing-photo-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; cursor: default; border-style: dashed; background: #f4f7fa; color: #7a8899; font-size: 13px; font-weight: 600; }
.listing-photo-tag { position: absolute; bottom: 10px; left: 10px; display: inline-flex; align-items: center; gap: 6px; background: #102236e8; color: white; border-radius: 5px; font-size: 12px; padding: 5px 8px; pointer-events: none; }
.listing-photo-hint { display: flex; gap: 6px; align-items: center; margin-top: 7px; color: #657589; font-size: 12px; }
.duo-icon { display: inline-flex; justify-content: center; align-items: center; flex-shrink: 0; width: 28px; height: 28px; padding: 5px; border-radius: 7px; color: #245a91; background: #eaf2fc; vertical-align: middle; }
.duo-icon svg { width: 18px; height: 18px; stroke-width: 1.8; fill: currentColor; fill-opacity: .12; }
.duo-green { color: #08735d; background: #e7f5ef; }
.duo-amber { color: #946016; background: #fff3da; }
.duo-rose { color: #ad3442; background: #fcecef; }
.listing-photo-tag .duo-icon { width: 20px; height: 20px; background: #ffffff20; color: white; padding: 3px; }
.listing-category { display: flex; align-items: center; gap: 8px; color: #657589; font-size: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.listing-category > span { display: inline-flex; align-items: center; gap: 6px; }
.listing-tag { border: 1px solid #dce3eb; border-radius: 999px; padding: 3px 10px 3px 5px; font-weight: 600; line-height: 1.4; }
.listing-tag .duo-icon { width: 22px; height: 22px; padding: 3px; background: transparent; }
.listing-tag-sale { color: #08735d; background: #e7f5ef; border-color: #c7e7d8; }
.listing-tag-rent { color: #946016; background: #fff3da; border-color: #f1dba6; }
.listing-tag-property { color: #245a91; background: #eaf2fc; border-color: #ccdef2; }
@media (min-width: 768px) { #filter-fields { grid-template-columns: minmax(0,1.5fr) minmax(0,1fr) minmax(0,1fr); } }
.listing-price { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: #ad3442; margin: 5px 0 8px; }
.listing-price strong { font-size: 27px; font-weight: 650; line-height: 1.3; letter-spacing: -.7px; }
.listing-price small { font-size: 12px; color: #657589; }
.listing-content h4 { color: #245aa2; font-size: 18px; font-weight: 650; line-height: 1.45; margin-bottom: 9px; }
.listing-content h4 a:hover { text-decoration: underline; }
.listing-location { display: flex; align-items: center; gap: 7px; color: #657589; font-size: 13px; margin-bottom: 10px; }
.listing-facts, .listing-legal { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 9px 0; }
.listing-fact { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.fact-label { color: #657589; }
.listing-legal { color: #536579; }
.listing-description { display: block; margin: 12px 0; font-size: 15px; line-height: 1.7; white-space: pre-line; color: #182c40; }
.listing-description summary { display: block; cursor: pointer; list-style: none; }
.listing-description summary::-webkit-details-marker { display: none; }
.listing-description .description-full, .listing-description .description-collapse { display: none; }
.listing-description[open] .description-full, .listing-description[open] .description-collapse { display: inline; }
.listing-description[open] .description-preview, .listing-description[open] .description-expand { display: none; }
.description-expand, .description-collapse { color: #174d7e; font-weight: 600; white-space: nowrap; }
.listing-description summary:hover .description-expand, .listing-description summary:hover .description-collapse { text-decoration: underline; }
.listing-contact { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; font-size: 13px; color: #657589; }
.listing-contact a { color: #08735d; font-weight: 600; }
.listing-footer { display: flex; justify-content: space-between; flex-wrap: wrap; align-items: center; gap: 12px; padding-top: 12px; margin-top: 13px; border-top: 1px solid #e4eaf0; font-size: 12px; color: #657589; }
.listing-time { display: flex; gap: 7px; align-items: center; }
.listing-actions { display: flex; gap: 7px; flex-wrap: wrap; }
.listing-actions button, .listing-actions a { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 40px; padding: 5px 8px; border: 1px solid #dce3eb; border-radius: 7px; color: #173f65; font-size: 12px; background: white; cursor: pointer; }
.listing-actions .duo-icon { width: 24px; height: 24px; padding: 4px; }
.listing-actions button:hover, .listing-actions a:hover { border-color: #8ba9c7; }
.listing-noimage .listing-main { display: block; }
.image-preview-dialog { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; padding: 16px; background: #102236df; }
.image-preview-dialog.hidden { display: none; }
.image-preview-dialog > div { width: min(1100px,100%); padding: 12px; background: #fff; border-radius: 10px; }
.image-preview-dialog button { display: block; margin: 0 0 10px auto; padding: 8px 14px; border: 1px solid #cbd5e1; border-radius: 7px; color: #173f65; }
.image-preview-dialog img { display: block; width: 100%; height: auto; max-height: 76dvh; object-fit: contain; }
@media (max-width: 767px) {
  .listing-card { padding: 13px; }
  .listing-main { grid-template-columns: minmax(0,1fr); gap: 14px; }
  .listing-photo-block { margin: -13px -13px 0; }
  .listing-photo { aspect-ratio: auto; border: 0; border-radius: 10px 10px 0 0; }
  .listing-photo img { height: auto; }
  .listing-photo-empty { min-height: 120px; }
  .listing-price strong { font-size: 25px; }
  .listing-actions { width: 100%; display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); }
  .listing-actions button, .listing-actions a { flex-direction: column; padding: 6px 3px; gap: 3px; }
}

.post-time-display { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px 6px; }
.post-time-dynamic { font-weight: 600; color: #173f65; }
.post-time-absolute:not(:empty) { color: #536579; }
.post-time-absolute:not(:empty)::before { content: '· '; }
.post-time-precision { flex-basis: 100%; font-size: 11px; color: #657589; }
.post-time-precision:empty { display: none; }

.listing-noimage .listing-description { max-width: 78ch; }

.duo-purple { color: #7152aa; background: #f1ebfc; }
.ptype-pill .duo-icon, #advanced-filters .duo-icon { width: 25px; height: 25px; padding: 4px; }
#main-header button > .duo-icon { width: 26px; height: 26px; padding: 4px; background: #ffffff1a; }
#btn-scrape-now > .duo-icon { color: #dcfff0; }
#btn-manage-groups > .duo-icon { color: #e8ddff; }
#btn-phone-connect > .duo-icon { color: #dcf3ff; }
#btn-export-excel > .duo-icon { color: #77eac3; }
#btn-clear-listings > .duo-icon { color: #fda4af; }
@media (max-width: 639px) {
  [id^="btn-post-type-"] .duo-icon { width: 22px; height: 22px; padding: 4px; }
  [id^="btn-post-type-"] .duo-icon svg { display: block !important; }
  .property-type-filters { scroll-padding-inline: 4px; }
}


/* ---- Design refresh v2: tokens, calmer header, scannable cards ---- */
:root {
  --c-bg: #f3f5f8; --c-surface: #fff; --c-border: #dce3eb; --c-text: #182c40; --c-muted: #5d6f82;
  --c-brand: #1f4e8c; --c-brand-soft: #eaf2fc; --c-price: #b3263b; --c-ok: #08735d; --c-ok-soft: #e7f5ef;
  --c-warn: #8a5a0c; --c-warn-soft: #fff3da; --radius: 12px; --shadow-1: 0 1px 2px rgba(16,34,54,.06);
}
body { background: var(--c-bg); color: var(--c-text); }
#main-header { background: #12263f !important; background-image: none !important; border-bottom: 1px solid #1d3a5f; box-shadow: 0 1px 0 rgba(255,255,255,.04), 0 6px 18px rgba(8,18,32,.18); }
#main-header h1 { font-size: 19px; letter-spacing: -.2px; }
#main-header h1 + p { color: #a9bbd0; }
/* One clear primary action; everything else is a quiet ghost button */
#main-header .flex.items-center.gap-2 > button { background: transparent !important; background-image: none !important; border: 1px solid #2c4a70 !important; color: #dbe6f3 !important; box-shadow: none !important; border-radius: 9px; min-height: 40px; }
#main-header .flex.items-center.gap-2 > button:hover { background: #1b3556 !important; border-color: #3f6595 !important; color: #fff !important; }
#main-header #btn-scrape-now { background: #0f9d7a !important; border-color: #0f9d7a !important; color: #fff !important; font-weight: 700; }
#main-header #btn-scrape-now:hover { background: #0c8668 !important; border-color: #0c8668 !important; }
#main-header #btn-clear-listings:hover { background: #4a1e2a !important; border-color: #8c3a4d !important; color: #ffb4c0 !important; }
#main-header button > .duo-icon { background: #ffffff14 !important; }
#scrape-progress-banner { background: #0d1d33 !important; }

main > div.bg-white, main .bg-white.rounded-2xl { border-color: var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.listing-card { border-radius: var(--radius); box-shadow: var(--shadow-1); transition: border-color .15s, box-shadow .15s; }
.listing-card:hover { border-color: #9db8d4; box-shadow: 0 4px 14px rgba(16,34,54,.08); }
.listing-price strong { color: var(--c-price); }
.listing-price small { color: var(--c-muted); font-weight: 600; background: #f1f5f9; padding: 2px 8px; border-radius: 999px; }
.listing-price .price-estimate { background: var(--c-warn-soft); color: var(--c-warn); border: 1px dashed #e4c27a; line-height: 1.5; }
.listing-content h4 { font-size: 17px; }
/* Key facts read as compact chips instead of loose lines */
.listing-facts .listing-fact, .listing-legal .listing-fact { background: #f6f8fb; border: 1px solid #e4eaf1; border-radius: 9px; padding: 4px 10px 4px 5px; }
.listing-legal .listing-fact { background: var(--c-ok-soft); border-color: #c7e7d8; }
.listing-description { color: #2b3f54; font-size: 14.5px; }
.listing-assessment { border-radius: 9px; }
.listing-actions button, .listing-actions a { border-radius: 9px; transition: background .12s, border-color .12s; }
.listing-actions button:hover, .listing-actions a:hover { background: #f4f8fc; }
.listing-actions button[aria-pressed="true"] { background: var(--c-brand) !important; border-color: var(--c-brand) !important; }
button:focus-visible, a:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible { outline-color: #1f6feb; }
@media (max-width: 639px) {
  #main-header h1 { font-size: 17px; }
  .listing-facts .listing-fact { padding: 3px 8px 3px 4px; }
}

/* ---- Card layout v3: photo top-aligned, title first, one row of key numbers, quiet details ---- */
.listing-main { grid-template-columns: minmax(0,34fr) minmax(0,66fr); gap: 22px; }
.listing-photo-block { align-self: start; }
/* Khung ôm sát ảnh chụp: đủ ảnh, đúng tỷ lệ, không dải trống hai bên; ảnh dài thì giới hạn chiều cao. */
.listing-photo { aspect-ratio: auto; width: fit-content; max-width: 100%; }
.listing-photo img { width: auto; max-width: 100%; height: auto; max-height: 600px; }
.listing-photo-empty { width: 100%; aspect-ratio: 4 / 3.4; }
.listing-category { margin-bottom: 6px; }
.listing-tag { font-size: 11.5px; padding: 1px 9px 1px 3px; }
.listing-tag .duo-icon { width: 20px; height: 20px; }
.listing-content h4 { font-size: 17px; line-height: 1.4; margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.listing-keyrow { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px 28px; padding: 10px 0; margin-bottom: 10px; border-top: 1px solid #edf1f5; border-bottom: 1px solid #edf1f5; }
.listing-stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label { font-size: 11.5px; color: var(--c-muted); text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.stat-value { font-size: 16px; font-weight: 650; color: var(--c-text); line-height: 1.35; }
.listing-keyrow .listing-price { margin: 0; color: var(--c-price); align-items: flex-start; flex-wrap: nowrap; }
.listing-keyrow .listing-price strong { font-size: 24px; line-height: 1.15; letter-spacing: -.5px; }
.listing-keyrow .listing-price small, .listing-keyrow .listing-price .price-estimate { background: none; border: 0; padding: 0; font-size: 12px; font-weight: 500; color: var(--c-muted); line-height: 1.4; }
.listing-location { margin-bottom: 8px; }
.listing-location .duo-icon, .listing-line .duo-icon { width: 22px; height: 22px; padding: 3px; background: transparent; }
.listing-details { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; font-size: 13px; color: #3c5066; }
.listing-legal { display: flex; flex-wrap: wrap; gap: 3px 16px; margin: 0; }
.listing-line { display: flex; align-items: flex-start; gap: 6px; line-height: 1.5; }
.listing-line > span { padding-top: 1px; }
.listing-details .listing-assessment { margin: 4px 0 0; padding: 0; background: none; border: 0; font-size: 12.5px; color: var(--c-muted); }
.listing-description { margin: 10px 0 0; font-size: 14px; line-height: 1.6; }
.listing-actions { align-items: center; }
.listing-actions .listing-call { border-color: #b9e0cf; background: var(--c-ok-soft); color: var(--c-ok); font-weight: 650; font-size: 13px; padding-right: 12px; text-decoration: none; }
.listing-actions .listing-call:hover { background: #d6efe3; border-color: #8fcfb4; }
.listing-actions .listing-call-text { display: inline-flex; align-items: center; gap: 5px; min-height: 40px; }
.listing-actions .listing-delete { margin-left: 14px; color: #8a3644; }
@media (max-width: 767px) {
  .listing-main { grid-template-columns: minmax(0,1fr); }
  /* Điện thoại: khung theo đúng tỷ lệ ảnh chụp, không cắt; ảnh quá dài thì thu nhỏ nguyên ảnh trong khung. */
  .listing-photo { margin: 0 auto; }
  .listing-photo img { max-height: 75vh; }
  .listing-photo-empty { aspect-ratio: auto; }
  .listing-keyrow { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(0,1fr) minmax(0,.7fr); gap: 8px 12px; }
  .stat-value { font-size: 15px; }
  .listing-keyrow .listing-price strong { font-size: 22px; }
  .listing-actions .listing-call { grid-column: 1 / -1; flex-direction: row; }
  .listing-actions .listing-delete { margin-left: 0; }
}
