/* ===== KhaiThidin — สไตล์หลัก ===== */
:root {
  --green: #2e7d32;
  --green-dark: #1b5e20;
  --green-light: #e8f5e9;
  --line: #06c755;
  --ink: #1f2933;
  --muted: #6b7280;
  --bg: #f5f7f5;
  --card: #ffffff;
  --border: #e3e8e3;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0,0,0,.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Sarabun", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
}
a { color: var(--green-dark); text-decoration: none; }
img { max-width: 100%; display: block; }
.container { max-width: 1200px; margin: 0 auto; padding: 0 16px; }

/* ---- Header ---- */
.site-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.site-header .container {
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.logo { font-size: 1.3rem; font-weight: 800; color: var(--green-dark); display: flex; gap: 8px; align-items: center; }
.logo-img { height: 44px; width: auto; display: block; }

/* ---- ไอคอน SVG (แทนอิโมจิ) ---- */
.icon { display: inline-block; vertical-align: -0.15em; flex: 0 0 auto; }
.card-meta .icon { color: var(--green); }
.tag .icon { color: var(--green-dark); }
.btn .icon { vertical-align: -0.15em; }
.badge .icon, .img-count .icon { vertical-align: -0.15em; }
.badge.featured .icon { color: #fff; }
.header-line-btn {
  background: var(--line); color: #fff; padding: 8px 16px; border-radius: 999px;
  font-weight: 700; display: inline-flex; gap: 6px; align-items: center; font-size: .95rem;
}

/* ---- Hero ---- */
.hero {
  background: linear-gradient(135deg, var(--green-dark), var(--green));
  color: #fff; padding: 48px 0 40px;
}
.hero h1 { margin: 0 0 8px; font-size: 2rem; }
.hero p { margin: 0; opacity: .92; font-size: 1.05rem; }

/* ---- Filter bar ---- */
.filters {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-top: -28px; position: relative; z-index: 10;
  border: 1px solid var(--border);
}
.filters form { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.field.col-3 { grid-column: span 3; }
.field.col-2 { grid-column: span 2; }
.field.col-4 { grid-column: span 4; }
.field.col-6 { grid-column: span 6; }
.field.col-12 { grid-column: span 12; }
input, select, textarea {
  font-family: inherit; font-size: .95rem; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--ink);
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-light); border-color: var(--green); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 10px; border: none; cursor: pointer;
  font-family: inherit; font-weight: 700; font-size: .95rem; transition: .15s;
}
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }
.btn-line { background: var(--line); color: #fff; }
.btn-line:hover { filter: brightness(.95); }
.btn-danger { background: #e53935; color: #fff; }
.btn-danger:hover { background: #c62828; }
.btn-sm { padding: 6px 12px; font-size: .85rem; }

/* ---- Results ---- */
.results-head { display: flex; justify-content: space-between; align-items: center; margin: 28px 0 16px; flex-wrap: wrap; gap: 8px; }
.results-head h2 { margin: 0; font-size: 1.3rem; }
.results-count { color: var(--muted); }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 20px;
}
.card {
  background: var(--card); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid var(--border);
  display: flex; flex-direction: column; transition: .18s;
}
.card:hover { box-shadow: var(--shadow-lg); transform: translateY(-3px); }
.card-media { position: relative; aspect-ratio: 4 / 3; background: var(--green-light); overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute; top: 10px; left: 10px; background: rgba(0,0,0,.6); color: #fff;
  padding: 4px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.badge.featured { background: #ff9800; left: auto; right: 10px; }
.badge.sold { background: #e53935; }
.img-count {
  position: absolute; bottom: 10px; right: 10px; background: rgba(0,0,0,.55); color: #fff;
  padding: 3px 9px; border-radius: 999px; font-size: .78rem;
}
.card-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card-title { font-weight: 700; font-size: 1.05rem; margin: 0; line-height: 1.35; }
.card-price { color: var(--green-dark); font-weight: 800; font-size: 1.15rem; }
.card-meta { color: var(--muted); font-size: .88rem; display: flex; gap: 6px; align-items: center; }
.card-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-top: 8px; }
.tag { background: var(--green-light); color: var(--green-dark); padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }

.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ---- Detail page ---- */
.detail { display: grid; grid-template-columns: 1.4fr 1fr; gap: 28px; margin: 28px 0 40px; }
.gallery-main { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--green-light); aspect-ratio: 4/3; box-shadow: var(--shadow); }
.gallery-main img { width: 100%; height: 100%; object-fit: cover; }
.gallery-thumbs { display: flex; gap: 8px; margin-top: 10px; overflow-x: auto; padding-bottom: 4px; }
.gallery-thumbs img { width: 88px; height: 66px; object-fit: cover; border-radius: 8px; cursor: pointer; border: 2px solid transparent; flex: 0 0 auto; }
.gallery-thumbs img.active { border-color: var(--green); }
.gallery-nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.45); color:#fff; border:none; width:40px; height:40px; border-radius:50%; cursor:pointer; font-size:1.2rem; }
.gallery-nav.prev { left: 10px; } .gallery-nav.next { right: 10px; }

.detail-info h1 { margin: 0 0 4px; font-size: 1.6rem; }
.detail-price { font-size: 1.8rem; font-weight: 800; color: var(--green-dark); margin: 8px 0; }
.spec-table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.spec-table th, .spec-table td { text-align: left; padding: 10px 4px; border-bottom: 1px solid var(--border); font-size: .95rem; }
.spec-table th { color: var(--muted); font-weight: 600; width: 38%; }
.detail-desc { white-space: pre-wrap; margin: 16px 0; }
.contact-box { background: var(--green-light); border-radius: var(--radius); padding: 20px; margin-top: 16px; }
.contact-box h3 { margin: 0 0 12px; }
.contact-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---- ปุ่มแชร์ ---- */
.share-box { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
.share-label { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--ink); margin-bottom: 10px; }
.share-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.share-btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 999px; font-weight: 600; font-size: .9rem; cursor: pointer; border: 1px solid var(--border); background: #fff; color: var(--ink); font-family: inherit; transition: .15s; }
.share-btn:hover { filter: brightness(.97); }
.share-btn.fb { background: #1877f2; color: #fff; border-color: #1877f2; }
.share-btn.line { background: var(--line); color: #fff; border-color: var(--line); }
.share-btn.copy.copied { background: var(--green-light); color: var(--green-dark); border-color: var(--green); }

/* ---- รายการเอกสารแนบ (แอดมิน) ---- */
.doc-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.doc-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.doc-item .doc-ic { color: var(--green-dark); flex: 0 0 auto; display: inline-flex; }
.doc-item .doc-name { font-weight: 600; word-break: break-all; }
.doc-item .doc-size { flex: 1; text-align: right; white-space: nowrap; }

/* ---- Admin ---- */
.admin-body { background: var(--bg); }
.admin-topbar { background: var(--green-dark); color: #fff; }
.admin-topbar .container { display: flex; justify-content: space-between; align-items: center; height: 58px; }
.admin-topbar a { color: #fff; }
.admin-nav { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.admin-nav a { display: inline-flex; align-items: center; gap: 5px; opacity: .9; }
.admin-nav a:hover, .admin-nav a.active { opacity: 1; text-decoration: underline; }
.admin-main { padding: 24px 0 60px; }
.panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }

/* การ์ดสรุปสถิติ */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.stat-card .stat-label { color: var(--muted); font-size: .85rem; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 800; color: var(--green-dark); margin-top: 6px; }
.panel h2 { margin: 0 0 16px; font-size: 1.2rem; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; font-size: .92rem; vertical-align: middle; }
.table th { background: var(--bg); color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: #fafcfa; }
.table .thumb { width: 60px; height: 45px; object-fit: cover; border-radius: 6px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.pill.available { background: #e8f5e9; color: #1b5e20; }
.pill.sold { background: #ffebee; color: #c62828; }
.pill.hidden { background: #eceff1; color: #546e7a; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.help { font-size: .8rem; color: var(--muted); }
.login-wrap { max-width: 380px; margin: 8vh auto; }
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: .92rem; }
.alert-error { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.alert-success { background: #e8f5e9; color: #1b5e20; border: 1px solid #c8e6c9; }
.alert-info { background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb; }

/* รูปในฟอร์มแอดมิน (จัดลำดับด้วยการลาก) */
.image-manager { display: flex; flex-wrap: wrap; gap: 12px; }
.image-item { position: relative; width: 130px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; cursor: grab; }
.image-item.dragging { opacity: .5; }
.image-item img { width: 100%; height: 98px; object-fit: cover; }
.image-item .img-actions { display: flex; justify-content: space-between; align-items: center; padding: 4px 6px; font-size: .75rem; }
.image-item .cover-tag { background: var(--green); color: #fff; padding: 1px 6px; border-radius: 4px; font-size: .7rem; }
.image-item .del { color: #e53935; cursor: pointer; border: none; background: none; font-weight: 700; }
.drag-hint { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }

/* ---- Footer ---- */
.site-footer { background: #fff; border-top: 1px solid var(--border); padding: 28px 0; margin-top: 40px; color: var(--muted); }
.site-footer .container { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; }

/* ---- Responsive ---- */
@media (max-width: 860px) {
  .detail { grid-template-columns: 1fr; }
  .filters form { grid-template-columns: repeat(2, 1fr); }
  .field.col-3, .field.col-2, .field.col-4, .field.col-6 { grid-column: span 1; }
  .field.col-12 { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.5rem; }
}

/* ---- Admin mobile ---- */
@media (max-width: 760px) {
  .admin-topbar .container {
    height: auto;
    min-height: 58px;
    padding-top: 10px;
    padding-bottom: 10px;
    align-items: flex-start;
    flex-direction: column;
    gap: 9px;
  }
  .admin-topbar .logo { font-size: 1.08rem; }
  .admin-nav {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 6px;
    padding-bottom: 3px;
    scrollbar-width: thin;
  }
  .admin-nav::-webkit-scrollbar { display: none; }
  .admin-nav { scrollbar-width: none; }
  .admin-nav a {
    flex: 0 0 auto;
    padding: 7px 9px;
    border-radius: 8px;
    font-size: .84rem;
    text-decoration: none !important;
  }
  .admin-nav a.active { background: rgba(255,255,255,.15); }
  .admin-main { padding: 14px 0 40px; }
  .panel { padding: 14px; border-radius: 12px; }

  .admin-list-wrap { overflow: visible !important; }
  .admin-property-list,
  .admin-property-list tbody { display: block; width: 100%; }
  .admin-property-list thead { display: none; }
  .admin-property-list tbody { display: grid; grid-template-columns: 1fr; gap: 14px; }
  .admin-property-list tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    box-shadow: var(--shadow);
  }
  .admin-property-list tbody tr:hover { background: #fff; }
  .admin-property-list td {
    display: block;
    border: 0;
    padding: 8px 14px;
    min-width: 0;
    font-size: .88rem;
  }
  .admin-property-list td[data-label]::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 2px;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 600;
  }
  .admin-property-list .admin-card-media,
  .admin-property-list .admin-card-main,
  .admin-property-list .admin-card-actions { grid-column: 1 / -1; }
  .admin-property-list .admin-card-media { padding: 0; }
  .admin-property-list .admin-card-media .thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 0;
  }
  .admin-property-list .admin-card-main { padding-top: 12px; padding-bottom: 6px; }
  .admin-property-list .admin-card-main strong { display: block; font-size: 1rem; line-height: 1.4; }
  .admin-property-list .admin-card-price { color: var(--green-dark); font-weight: 800; }
  .admin-property-list .admin-card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 7px;
    padding-top: 11px;
    padding-bottom: 13px;
    border-top: 1px solid var(--border);
    margin-top: 3px;
  }
  .admin-property-list .admin-card-actions .btn { width: 100%; }
  .admin-property-list .admin-card-actions form { display: block !important; }
  .admin-property-list .admin-card-actions form .btn { min-width: 44px; }
  .admin-property-list tbody tr:only-child td[colspan] { grid-column: 1 / -1; }

  .image-manager { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .image-item { width: 100%; }
  .image-item img { height: auto; aspect-ratio: 4 / 3; }
  .doc-item { align-items: flex-start; flex-wrap: wrap; }
  .doc-item .doc-name { flex: 1; min-width: 0; }
  .doc-item .doc-size { flex: 0 0 auto; }
}
