:root {
  --ink: #1b1f24;
  --muted: #5d6670;
  --line: #e1e4e8;
  --soft: #f4f5f7;
  --accent: #1d5fd1;
  --accent-soft: #e8f0fd;
  --good: #1d7a3b;
  --good-soft: #e2f4e7;
  --warn: #9a5200;
  --warn-soft: #fdefd9;
  --danger: #b42318;
  --brand: #0e1f4b; /* logo navy */
  --brand-soft: #e7eaf3;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Sukhumvit Set", "Noto Sans Thai", "Segoe UI", sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; line-height: 1.3; margin: 8px 0; }
main { max-width: 680px; margin: 0 auto; padding: 0 16px 32px; }
.muted { color: var(--muted); }

/* header */
.top { display: flex; align-items: center; gap: 8px; max-width: 680px; margin: 0 auto; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.logo { width: 40px; height: 40px; border-radius: 50%; }
.brand-link { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; color: var(--ink); text-decoration: none; }
.brand { min-width: 0; }
.brand b { display: block; }
.brand small { display: block; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); text-decoration: none; font-size: 15px; }
.meta, .bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0; }
.hint { display: flex; gap: 8px; align-items: flex-start; margin: 12px 0 0; padding: 10px 12px; background: var(--soft); border-radius: 10px; font-size: 15px; }
.hint span { flex: 1; }
.hint button { border: 0; background: none; font-size: 18px; padding: 0 4px; }

/* filters */
.label { font-weight: 700; margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 999px; color: var(--ink); text-decoration: none; }
.chip.on { background: var(--accent-soft); border: 2px solid var(--accent); font-weight: 700; }
.chips.budget { display: grid; grid-template-columns: repeat(4, 1fr); }
.select { display: block; width: 100%; min-height: 48px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink); font: inherit; }
.chips.budget .chip { justify-content: center; padding: 0 4px; font-size: 15px; white-space: nowrap; }

/* cards */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card { display: block; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; color: var(--ink); text-decoration: none; }
.cover { position: relative; aspect-ratio: 4 / 3; background: var(--soft); }
.cover img { display: block; width: 100%; height: 100%; object-fit: cover; }
.cover .badge { position: absolute; left: 8px; top: 8px; }
.card-body { padding: 10px 12px 12px; }
.price { font-size: 20px; font-weight: 700; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 6px; font-size: 14px; font-weight: 700; }
.badge.ready { background: var(--good-soft); color: var(--good); }
.badge.renovating { background: var(--warn-soft); color: var(--warn); }
.badge.sold, .badge.reserved { background: var(--soft); color: var(--muted); }
.sold-list { margin-top: 24px; }
.sold-list summary { padding: 12px; background: var(--soft); border-radius: 10px; color: var(--muted); cursor: pointer; margin-bottom: 16px; }

/* room page: on a phone the side panel's parts fall into one column — title, photos, facts, more */
.room-layout { display: flex; flex-direction: column; }
.side { display: contents; }
.side > * { order: 3; }
.side > .title { order: 1; }
.gallery { order: 2; }
.more { order: 4; }
.head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.no-photo { display: block; width: 100%; border-radius: 12px; }
.photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; background: var(--soft); }
.facts { margin: 16px 0; padding: 4px 14px; border: 1px solid var(--line); border-radius: 12px; }
.facts div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; }
details > summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.detail { white-space: pre-line; }
video { display: block; width: 100%; margin: 12px 0; border-radius: 12px; background: #000; }
body.has-actions main { padding-bottom: 120px; }
.actions {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 680px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line);
}
.actions button {
  min-height: 60px; border: 2px solid var(--accent); border-radius: 12px; background: var(--accent-soft);
  color: var(--ink); font: inherit; font-size: 16px; font-weight: 700; line-height: 1.25; cursor: pointer;
}
.actions button:disabled { opacity: 0.4; }
/* full-screen photo viewer (gallery.js) */
.viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; background: rgba(0, 0, 0, 0.94); color: #fff; touch-action: pan-y; }
.viewer::backdrop { background: rgba(0, 0, 0, 0.94); }
.viewer[open] { display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; -webkit-user-select: none; -webkit-user-drag: none; }
.viewer button { position: absolute; width: 52px; height: 52px; border: 0; border-radius: 50%; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 30px; line-height: 1; cursor: pointer; }
.v-close { top: calc(12px + env(safe-area-inset-top)); right: 12px; font-size: 22px; }
.v-prev, .v-next { top: 50%; transform: translateY(-50%); }
.v-prev { left: 8px; }
.v-next { right: 8px; }
.v-count { position: absolute; left: 0; right: 0; bottom: calc(16px + env(safe-area-inset-bottom)); margin: 0; text-align: center; font-size: 15px; }
#toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); padding: 10px 18px; border-radius: 999px; background: var(--ink); color: #fff; }

/* admin */
body.admin { background: var(--soft); }
body.admin main { padding-top: 12px; }
.admin-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: var(--brand); }
.admin-bar a { color: #fff; text-decoration: none; }
.admin-brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; }
.admin-brand img { width: 36px; height: 36px; border-radius: 50%; }
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 48px; padding: 0 18px; border: 1px solid #c9ced4; border-radius: 12px; background: #fff; color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.big { width: 100%; min-height: 54px; font-size: 18px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.add { width: 100%; min-height: 56px; border: 2px dashed #b8bec6; background: var(--soft); color: var(--brand); }
.btn:disabled { opacity: 0.6; }
.link { border: 0; background: none; padding: 8px 0; color: var(--accent); font: inherit; cursor: pointer; }
.link.danger { color: var(--danger); }
.ok { padding: 12px 14px; background: var(--good-soft); color: var(--good); border-radius: 12px; font-weight: 600; }
.error { padding: 12px 14px; background: #fdecea; color: var(--danger); border-radius: 12px; }

/* admin: room list */
body.admin .chip { flex: none; background: #fff; }
body.admin .chip.on { background: var(--brand-soft); border-color: var(--brand); }
.chips.tabs { margin-top: 12px; }
.filter { margin-top: 10px; }
.chips.sort { align-items: center; margin-top: 8px; }
.chips.sort .chip { min-height: 36px; padding: 0 12px; font-size: 15px; }
.room-list { list-style: none; margin: 12px 0 24px; padding: 0; display: grid; gap: 12px; }
.room-list li { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.room-link { display: flex; align-items: center; gap: 12px; padding: 12px 12px 8px; color: var(--ink); text-decoration: none; }
.room-link img { flex: none; width: 84px; height: 84px; border-radius: 10px; object-fit: cover; background: var(--soft); }
.room-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room-price { font-size: 19px; font-weight: 700; }
.room-info small { color: var(--muted); font-size: 14px; }
.room-info small.warn { color: var(--warn); font-weight: 700; }
.chev { font-size: 30px; line-height: 1; color: var(--muted); }
.room-list form { padding: 0 12px 12px; }
.status-select { width: 100%; min-height: 46px; padding: 0 12px; border: 2px solid #c9ced4; border-radius: 10px; background: var(--soft); color: var(--muted); font: inherit; font-weight: 700; }
.status-select.ready { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.status-select.renovating { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }

/* admin: room form */
.box { margin: 12px 0; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.box h2 { margin: 0 0 12px; font-size: 19px; }
.field { display: block; margin: 0 0 16px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; margin-bottom: 6px; font-weight: 600; }
.req { color: var(--danger); }
.field input:not([type="radio"]), .field textarea { display: block; width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid #c9ced4; border-radius: 10px; background: #fff; color: var(--ink); font: inherit; }
.cols { display: flex; gap: 12px; }
.cols .field { flex: 1; min-width: 0; }
.subtext { margin: -10px 0 16px; color: var(--muted); }
.subtext:empty { display: none; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg label { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: 4px 14px; border: 1px solid #c9ced4; border-radius: 10px; background: #fff; text-align: center; cursor: pointer; }
.seg input:checked + span { border: 2px solid var(--brand); background: var(--brand-soft); font-weight: 700; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg.status { display: grid; grid-template-columns: 1fr 1fr; margin-bottom: 16px; }
.seg.status input[value="ready"]:checked + span { border-color: var(--good); background: var(--good-soft); color: var(--good); }
.seg.status input[value="renovating"]:checked + span { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.seg.status input[value="reserved"]:checked + span, .seg.status input[value="sold"]:checked + span { border-color: var(--muted); background: var(--soft); }
.photo-grid { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.photo-grid li { position: relative; overflow: hidden; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.photo-grid img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; cursor: pointer; }
.photo-grid .tag { position: absolute; left: 6px; top: 6px; padding: 2px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 13px; font-weight: 700; }
.photo-grid li:first-child { border: 2px solid var(--brand); }
.photo-grid li:first-child .tag { background: var(--brand); }
.photo-grid .tools { display: grid; grid-template-columns: repeat(3, 1fr); }
.photo-grid .tools button { min-height: 44px; border: 0; border-top: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 20px; }
.photo-grid .tools button + button { border-left: 1px solid var(--line); }
.photo-grid .tools [data-a="del"] { color: var(--danger); }
#video-current video { margin-top: 0; }
progress { width: 100%; height: 12px; margin-top: 8px; }
.box p:empty { display: none; }
.save-bar { position: sticky; bottom: 0; z-index: 1; margin: 12px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: rgba(244, 245, 247, 0.96); border-top: 1px solid var(--line); }

/* admin: login */
.login { max-width: 420px; padding-top: 40px; text-align: center; }
.login-logo { width: 96px; height: 96px; border-radius: 50%; }
.login .box { text-align: left; }

/* computer: mouse feedback */
@media (hover: hover) {
  .card { transition: border-color 0.15s, box-shadow 0.15s; }
  .card:hover { border-color: #c9ced4; box-shadow: 0 6px 20px rgba(14, 31, 75, 0.1); }
  .chip:hover, .pill:hover { border-color: var(--accent); }
  .photos a:hover img { opacity: 0.85; }
  .actions button:not(:disabled):hover { background: #d6e4fb; }
  .btn:not(:disabled):hover { border-color: var(--brand); }
  .btn.primary:not(:disabled):hover { background: #1a3170; }
  .room-list li:hover { box-shadow: 0 6px 20px rgba(14, 31, 75, 0.1); }
}

/* computer: wide screens get side-by-side layouts */
@media (min-width: 960px) {
  .top, main.home, main.room, body.admin main.wide { max-width: 1180px; }
  h1 { font-size: 26px; }

  .home-layout { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 32px; align-items: start; }
  .filters { position: sticky; top: 16px; }
  .filters .chips.budget { grid-template-columns: 1fr 1fr; }
  .results > .muted:first-child { margin-top: 14px; }

  .room-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-areas: "gallery side" "more side"; gap: 0 32px; align-items: start; }
  .gallery { grid-area: gallery; }
  .more { grid-area: more; }
  .side { display: block; grid-area: side; position: sticky; top: 16px; }
  .side h1 { margin-top: 0; }
  .photos { gap: 8px; }
  .photos a:first-child { grid-column: span 2; grid-row: span 2; } /* cover photo big */
  body.has-actions main { padding-bottom: 32px; }
  .actions { position: static; max-width: none; margin: 16px 0 0; padding: 0; border: 0; background: none; }
  #toast { bottom: 32px; }
  .viewer img { max-width: calc(100% - 160px); max-height: calc(100% - 96px); } /* room for ‹ › beside the photo */
  .v-prev { left: 24px; }
  .v-next { right: 24px; }

  .admin-bar { padding-left: max(16px, calc((100% - 1180px) / 2 + 16px)); padding-right: max(16px, calc((100% - 1180px) / 2 + 16px)); }
  .room-list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
  .filter .select { max-width: 360px; }
}
