/* ── หลังบ้าน บ้านอากง โฮมสเตย์ ─────────────────────────── */
:root {
  --w900: #2A1B10; --w800: #3D2817; --w700: #5B3A22; --w500: #8B5E3C; --w200: #D9C0A5;
  --c50: #FDFAF5; --c100: #FBF5EC; --c200: #F5EADB; --c300: #EDDFCB;
  --g600: #A8801F; --g500: #C29A32; --g400: #D9B45C;
  --gr600: #63755A; --gr700: #4E5C45;
  --red: #B4472F; --red-bg: #FBEAE6;
  --ink: #241811; --ink2: #55443A; --ink3: #7C6A5D; --line: #E3D5C2;
  --f: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fd: 'Noto Serif Thai', Georgia, serif;
  --sh1: 0 1px 3px rgba(42,27,16,.06), 0 5px 18px rgba(42,27,16,.07);
  --sh2: 0 8px 22px rgba(42,27,16,.1), 0 26px 60px rgba(42,27,16,.14);
  --ease: cubic-bezier(.22,.68,.32,1);
}
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
body { font-family: var(--f); font-size: 15px; line-height: 1.6; color: var(--ink); background: var(--c100); -webkit-font-smoothing: antialiased; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; cursor: pointer; }
ul { list-style: none; padding: 0; }
h1,h2,h3,h4 { font-family: var(--fd); font-weight: 600; line-height: 1.3; }
a { color: var(--w700); }
:focus-visible { outline: 2.5px solid var(--g500); outline-offset: 2px; border-radius: 5px; }
.ico { width: 1.15em; height: 1.15em; flex: 0 0 auto; }
.hidden { display: none !important; }

/* ── login ─────────────────────────────────────────────── */
.login-wrap { min-height: 100svh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, var(--c200), var(--c100)); }
.login-card { width: min(100%, 400px); background: var(--c50); border: 1px solid var(--line); border-radius: 22px; padding: 2.4rem 2rem; box-shadow: var(--sh2); text-align: center; }
.login-card img { width: 74px; height: 74px; margin: 0 auto 1.2rem; border-radius: 50%; }
.login-card h1 { font-size: 1.3rem; color: var(--w800); }
.login-card p { color: var(--ink3); font-size: .9rem; margin-top: .35rem; margin-bottom: 1.6rem; }
.login-card input { width: 100%; padding: .8rem 1rem; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; text-align: center; letter-spacing: .1em; }
.login-card input:focus { outline: 0; border-color: var(--g400); box-shadow: 0 0 0 3.5px rgba(217,180,92,.2); }
.login-card .btn { width: 100%; margin-top: .9rem; }
.login-err { color: var(--red); font-size: .88rem; margin-top: .8rem; min-height: 1.2em; }
.login-hint { margin-top: 1.4rem; font-size: .8rem; color: var(--ink3); line-height: 1.55; }

/* ── shell ─────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100svh; }
.side { background: var(--w900); color: rgba(245,234,219,.8); display: flex; flex-direction: column; position: sticky; top: 0; height: 100svh; }
.side-head { padding: 1.2rem 1.1rem; border-bottom: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: .7rem; }
.side-head img { width: 40px; height: 40px; border-radius: 50%; background: var(--c100); padding: 2px; }
.side-head b { font-family: var(--fd); color: var(--c100); font-size: .96rem; display: block; line-height: 1.25; }
.side-head span { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--g400); }
.side-nav { flex: 1; overflow-y: auto; padding: .8rem .7rem 1.4rem; }
.side-nav button {
  width: 100%; display: flex; align-items: center; gap: .65rem; text-align: left;
  padding: .6rem .75rem; border-radius: 10px; font-size: .9rem; color: rgba(245,234,219,.78);
  transition: background .22s var(--ease), color .22s var(--ease); margin-bottom: 2px;
}
.side-nav button:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-nav button.on { background: var(--g500); color: #fff; font-weight: 600; }
.side-nav .sep { margin: .9rem .75rem .45rem; font-size: .68rem; letter-spacing: .13em; text-transform: uppercase; color: rgba(217,180,92,.75); }
.side-foot { padding: .9rem 1.1rem; border-top: 1px solid rgba(255,255,255,.08); display: flex; gap: .5rem; }
.side-foot a, .side-foot button { flex: 1; display: flex; align-items: center; justify-content: center; gap: .35rem; padding: .5rem; border-radius: 9px; background: rgba(255,255,255,.07); color: rgba(245,234,219,.85); font-size: .82rem; }
.side-foot a:hover, .side-foot button:hover { background: rgba(255,255,255,.14); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 1rem;
  padding: .85rem clamp(1rem, 3vw, 2rem); background: rgba(251,245,236,.9);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.15rem; color: var(--w800); margin-right: auto; }
.burger-a { display: none; }
.savebar { display: flex; align-items: center; gap: .6rem; }
.dot-state { font-size: .82rem; color: var(--ink3); display: flex; align-items: center; gap: .4rem; }
.dot-state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--gr600); }
.dot-state.dirty::before { background: var(--g500); box-shadow: 0 0 0 4px rgba(194,154,50,.18); }
.content { padding: clamp(1.1rem, 3vw, 2rem); max-width: 1080px; width: 100%; }

/* ── buttons ───────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .58rem 1.15rem; border-radius: 100px; background: var(--w700); color: #fff; font-size: .89rem; font-weight: 600; transition: transform .22s var(--ease), box-shadow .22s var(--ease), background .22s var(--ease); }
.btn:hover { transform: translateY(-1px); box-shadow: var(--sh1); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-gold { background: linear-gradient(135deg, var(--g500), var(--g600)); }
.btn-line { background: transparent; color: var(--w700); border: 1.5px solid var(--line); }
.btn-line:hover { background: var(--c200); }
.btn-red { background: transparent; color: var(--red); border: 1.5px solid #E8C8BF; }
.btn-red:hover { background: var(--red-bg); }
.btn-sm { padding: .38rem .8rem; font-size: .82rem; }
.btn-xs { padding: .28rem .6rem; font-size: .76rem; border-radius: 8px; }

/* ── cards / groups ────────────────────────────────────── */
.group { background: var(--c50); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 1.1rem; overflow: hidden; }
.group > header { display: flex; align-items: center; gap: .6rem; padding: .95rem 1.2rem; background: var(--c200); border-bottom: 1px solid var(--line); }
.group > header h2 { font-size: 1rem; color: var(--w800); margin-right: auto; }
.group-help { padding: .8rem 1.2rem; background: #FFF8E8; border-bottom: 1px solid var(--line); font-size: .84rem; color: var(--ink2); display: flex; gap: .5rem; }
.group-help .ico { color: var(--g600); margin-top: .18em; }
.group-body { padding: 1.2rem; }

.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .95rem; }
.f { display: flex; flex-direction: column; gap: .3rem; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f > label { font-size: .82rem; font-weight: 600; color: var(--ink2); }
.f .help { font-size: .76rem; color: var(--ink3); line-height: 1.45; }
.f input[type=text], .f input[type=tel], .f input[type=url], .f input[type=number], .f textarea, .f select {
  width: 100%; padding: .58rem .8rem; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; font-size: .92rem;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.f textarea { resize: vertical; min-height: 76px; line-height: 1.6; }
.f input:focus, .f textarea:focus, .f select:focus { outline: 0; border-color: var(--g400); box-shadow: 0 0 0 3.5px rgba(217,180,92,.16); }
.count { font-size: .72rem; color: var(--ink3); text-align: right; }
.count.over { color: var(--red); }

.switch { display: flex; align-items: center; gap: .6rem; cursor: pointer; user-select: none; padding-top: .3rem; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i { width: 42px; height: 24px; border-radius: 100px; background: var(--w200); position: relative; transition: background .25s var(--ease); flex: 0 0 auto; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .25s var(--ease); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + i { background: var(--gr600); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch span { font-size: .88rem; }

/* ── image field ───────────────────────────────────────── */
.imgf { display: flex; gap: .8rem; align-items: flex-start; }
.imgf-prev {
  width: 132px; flex: 0 0 132px; aspect-ratio: 4/3; border-radius: 11px; overflow: hidden;
  background: var(--c300) center/cover no-repeat; border: 1.5px solid var(--line);
  display: grid; place-items: center; color: var(--ink3); font-size: .74rem; text-align: center; padding: .4rem;
}
.imgf-prev img { width: 100%; height: 100%; object-fit: cover; }
.imgf-side { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: .4rem; }
.imgf-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.imgf-path { font-size: .74rem; color: var(--ink3); word-break: break-all; }

/* ── list editor ───────────────────────────────────────── */
.list { display: grid; gap: .6rem; }
.li { border: 1.5px solid var(--line); border-radius: 13px; background: #fff; overflow: hidden; }
.li.open { border-color: var(--w200); box-shadow: var(--sh1); }
.li-head { display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; cursor: pointer; }
.li-head:hover { background: var(--c100); }
.li-thumb { width: 46px; height: 34px; flex: 0 0 auto; border-radius: 7px; background: var(--c300) center/cover no-repeat; }
.li-title { flex: 1; min-width: 0; font-size: .9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li-title small { display: block; font-weight: 400; color: var(--ink3); font-size: .76rem; }
.li-off { font-size: .7rem; padding: .1rem .5rem; border-radius: 6px; background: var(--c300); color: var(--ink3); }
.li-tools { display: flex; gap: .2rem; align-items: center; }
.li-tools button { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; color: var(--ink3); }
.li-tools button:hover { background: var(--c200); color: var(--w700); }
.li-tools button.del:hover { background: var(--red-bg); color: var(--red); }
.li-body { padding: 1rem .95rem 1.1rem; border-top: 1px dashed var(--line); background: var(--c50); }
.sublist { margin-top: 1.1rem; padding-top: .9rem; border-top: 1px dashed var(--line); }
.sublist > h4 { font-size: .88rem; color: var(--w700); margin-bottom: .6rem; display: flex; align-items: center; gap: .4rem; }
.add-row { margin-top: .6rem; }
.empty { padding: 1.4rem; text-align: center; color: var(--ink3); font-size: .88rem; border: 1.5px dashed var(--line); border-radius: 12px; }

/* strings list */
.slist { display: grid; gap: .5rem; }
.srow { display: flex; gap: .4rem; align-items: flex-start; }
.srow textarea, .srow input { flex: 1; }
.srow .li-tools { padding-top: .3rem; }

/* gallery list */
.glist { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: .6rem; }
.gcell { border: 1.5px solid var(--line); border-radius: 11px; overflow: hidden; background: #fff; }
.gcell-img { aspect-ratio: 4/3; background: var(--c300) center/cover no-repeat; cursor: pointer; }
.gcell-bar { display: flex; align-items: center; gap: .2rem; padding: .3rem .35rem; }
.gcell-bar input { flex: 1; min-width: 0; border: 0; background: transparent; font-size: .74rem; padding: .15rem .2rem; }
.gcell-bar input:focus { outline: 0; background: var(--c200); border-radius: 5px; }
.gcell-bar button { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; color: var(--ink3); }
.gcell-bar button:hover { background: var(--c200); }
.gcell-bar button.del:hover { background: var(--red-bg); color: var(--red); }

/* ── icon picker ───────────────────────────────────────── */
.iconpick { display: flex; align-items: center; gap: .5rem; }
.iconpick-btn { width: 42px; height: 42px; border-radius: 11px; border: 1.5px solid var(--line); background: #fff; display: grid; place-items: center; color: var(--w600); }
.iconpick-btn .ico { width: 1.4rem; height: 1.4rem; }
.iconpick select { flex: 1; }
.icongrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: .4rem; max-height: 50vh; overflow-y: auto; }
.icongrid button { aspect-ratio: 1; border: 1.5px solid var(--line); border-radius: 10px; display: grid; place-items: center; gap: .1rem; color: var(--w700); background: #fff; font-size: .6rem; padding: .3rem; }
.icongrid button:hover { border-color: var(--g400); background: var(--c200); }
.icongrid button.on { border-color: var(--g500); background: var(--c200); box-shadow: 0 0 0 2px rgba(194,154,50,.25); }
.icongrid .ico { width: 1.3rem; height: 1.3rem; }

/* ── focal picker ──────────────────────────────────────── */
.focal { position: relative; width: 100%; max-width: 320px; border-radius: 11px; overflow: hidden; cursor: crosshair; border: 1.5px solid var(--line); background: var(--c300); }
.focal img { width: 100%; display: block; }
.focal-dot { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.4), 0 3px 10px rgba(0,0,0,.4); pointer-events: none; }

/* ── modal ─────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(36,24,17,.6); padding: 1rem; backdrop-filter: blur(4px); }
.modal[hidden] { display: none; }
.modal-box { background: var(--c50); border-radius: 20px; width: min(100%, 940px); max-height: 92svh; display: flex; flex-direction: column; overflow: hidden; box-shadow: var(--sh2); }
.modal-box.narrow { width: min(100%, 520px); }
.modal-head { display: flex; align-items: center; gap: .8rem; padding: 1rem 1.3rem; border-bottom: 1px solid var(--line); background: var(--c200); }
.modal-head h3 { font-size: 1.05rem; color: var(--w800); margin-right: auto; }
.modal-body { padding: 1.2rem; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; gap: .6rem; justify-content: flex-end; padding: .9rem 1.3rem; border-top: 1px solid var(--line); background: var(--c100); flex-wrap: wrap; }
.x { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: var(--ink3); }
.x:hover { background: rgba(0,0,0,.06); color: var(--ink); }

.tabs { display: flex; gap: .35rem; padding: .8rem 1.3rem 0; background: var(--c200); }
.tabs button { padding: .5rem 1rem; border-radius: 10px 10px 0 0; font-size: .87rem; color: var(--ink2); }
.tabs button.on { background: var(--c50); color: var(--w800); font-weight: 600; }

.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.pick { border: 2px solid transparent; border-radius: 11px; overflow: hidden; background: #fff; box-shadow: var(--sh1); text-align: left; }
.pick:hover { border-color: var(--g400); }
.pick-img { aspect-ratio: 4/3; background: var(--c300) center/cover no-repeat; }
.pick-cap { padding: .3rem .45rem; font-size: .7rem; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop { border: 2px dashed var(--w200); border-radius: 14px; padding: 2rem 1rem; text-align: center; color: var(--ink3); background: #fff; }
.drop.over { border-color: var(--g500); background: #FFF8E8; }
.drop .ico { width: 2.2rem; height: 2.2rem; color: var(--w500); margin: 0 auto .6rem; }

/* ── cropper ───────────────────────────────────────────── */
.crop-stage { position: relative; background: #2A1B10; border-radius: 12px; overflow: hidden; display: grid; place-items: center; min-height: 260px; max-height: 56svh; }
.crop-stage canvas { max-width: 100%; max-height: 56svh; display: block; touch-action: none; cursor: crosshair; }
.crop-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .9rem; }
.crop-tools .ratios { display: flex; flex-wrap: wrap; gap: .3rem; }
.crop-tools .ratios button { padding: .32rem .7rem; border-radius: 8px; border: 1.5px solid var(--line); font-size: .8rem; background: #fff; }
.crop-tools .ratios button.on { background: var(--w700); border-color: var(--w700); color: #fff; }
.crop-note { font-size: .82rem; color: var(--ink3); margin-top: .6rem; display: flex; gap: .45rem; }
.crop-note .ico { color: var(--g600); margin-top: .18em; }

/* ── dashboard ─────────────────────────────────────────── */
.dash { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .9rem; margin-bottom: 1.2rem; }
.stat { background: var(--c50); border: 1px solid var(--line); border-radius: 15px; padding: 1.2rem; }
.stat b { display: block; font-family: var(--fd); font-size: 1.9rem; color: var(--w800); line-height: 1.1; }
.stat span { font-size: .84rem; color: var(--ink3); }
.quick { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .7rem; }
.quick button { display: flex; align-items: center; gap: .7rem; padding: 1rem; border: 1px solid var(--line); border-radius: 13px; background: var(--c50); text-align: left; font-size: .9rem; transition: transform .2s var(--ease), box-shadow .2s var(--ease); }
.quick button:hover { transform: translateY(-2px); box-shadow: var(--sh1); }
.quick .ico { width: 1.4rem; height: 1.4rem; color: var(--g600); }
.tip { display: flex; gap: .6rem; padding: 1rem 1.2rem; background: #FFF8E8; border: 1px solid #F0DFB4; border-radius: 13px; font-size: .88rem; color: var(--ink2); margin-bottom: 1.1rem; }
.tip .ico { color: var(--g600); margin-top: .2em; }
.warn { background: var(--red-bg); border-color: #E8C8BF; }
.warn .ico { color: var(--red); }

/* ── leads ─────────────────────────────────────────────── */
.lead { background: var(--c50); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.2rem; margin-bottom: .7rem; }
.lead-top { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; margin-bottom: .6rem; }
.lead-top b { font-family: var(--fd); font-size: 1.02rem; color: var(--w800); }
.lead-top time { font-size: .78rem; color: var(--ink3); margin-left: auto; }
.lead-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .5rem .9rem; font-size: .86rem; }
.lead-grid div span { color: var(--ink3); display: block; font-size: .74rem; }
.lead-msg { margin-top: .7rem; padding-top: .7rem; border-top: 1px dashed var(--line); font-size: .88rem; color: var(--ink2); white-space: pre-wrap; }

/* ── media library ─────────────────────────────────────── */
.medgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .7rem; }
.med { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--c50); }
.med-img { aspect-ratio: 4/3; background: var(--c300) center/cover no-repeat; }
.med-bar { padding: .45rem .55rem; font-size: .72rem; color: var(--ink3); display: flex; align-items: center; gap: .3rem; }
.med-bar span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.med-bar button { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; }
.med-bar button:hover { background: var(--red-bg); color: var(--red); }

/* ── preview ───────────────────────────────────────────── */
.pv-bar { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: .8rem; }
.pv-bar .devs { display: flex; gap: .3rem; }
.pv-bar .devs button { padding: .35rem .8rem; border: 1.5px solid var(--line); border-radius: 9px; font-size: .82rem; background: #fff; }
.pv-bar .devs button.on { background: var(--w700); border-color: var(--w700); color: #fff; }
.pv-frame { border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; box-shadow: var(--sh1); margin-inline: auto; transition: max-width .3s var(--ease); }
.pv-frame iframe { width: 100%; height: 74svh; border: 0; display: block; }

/* ── json ──────────────────────────────────────────────── */
.jsonbox { width: 100%; min-height: 55svh; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; line-height: 1.55; padding: 1rem; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; }

/* ── toast ─────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 1.6rem; transform: translate(-50%, 20px); z-index: 200; padding: .75rem 1.3rem; border-radius: 100px; background: var(--w800); color: #fff; font-size: .89rem; box-shadow: var(--sh2); opacity: 0; pointer-events: none; transition: opacity .25s var(--ease), transform .25s var(--ease); display: flex; align-items: center; gap: .5rem; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--red); }

/* ── responsive ────────────────────────────────────────── */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 60; transform: translateX(-100%); transition: transform .3s var(--ease); }
  .side.open { transform: none; }
  .burger-a { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: var(--w700); }
  .burger-a:hover { background: var(--c200); }
  .scrim { position: fixed; inset: 0; z-index: 55; background: rgba(36,24,17,.5); }
  .fgrid { grid-template-columns: 1fr; }
  .topbar h1 { font-size: 1rem; }
  .savebar .dot-state { display: none; }
}
