/* =======================================================================
   Mobile for U — ระบบจัดการเว็บไซต์ (หลังบ้าน)
   ======================================================================= */
:root {
  /* โทนเดียวกับหน้าเว็บ: แดง = สีหลัก · เหลือง/ทอง = สีรอง · เขียว = สถานะ "เปิด/เสร็จ" */
  --g: #d0301f; --g7: #b02418; --g8: #8a1c12; --g1: #ffdcd6; --g0: #fff5f3;
  --y: #ffc717; --o: #c98a0c; --o1: #fff2cf; --r: #99110c;
  --ok: #1f8a4d; --ok1: #ddf3e4; --ok8: #14663a;
  --ink: #2c2320; --muted: #8a7a74; --line: #ece2dd; --bg: #fdf8f5; --card: #fff;
  --sh: 0 1px 3px rgba(60,35,30,.07); --sh2: 0 10px 30px rgba(60,35,30,.1); --sh3: 0 28px 70px rgba(60,35,30,.2);
  --rad: 14px;
  --font: 'Anuphan', 'IBM Plex Sans Thai', -apple-system, system-ui, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-family: var(--font); background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.65; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
ul { margin: 0; padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: none; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.ic { flex: none; }
:focus-visible { outline: 3px solid var(--y); outline-offset: 2px; border-radius: 6px; }

/* ----------------------------------------------------------- buttons */
.a-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 10px 18px; border-radius: 11px;
  font-weight: 600; font-size: .9rem; transition: .2s; border: 1.5px solid transparent; white-space: nowrap;
}
.a-btn.sm { padding: 7px 13px; font-size: .83rem; }
.a-btn.primary { background: var(--g); color: #fff; box-shadow: 0 6px 18px rgba(208,48,31,.28); }
.a-btn.primary:hover { background: var(--g7); transform: translateY(-2px); }
.a-btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.a-btn.ghost:hover { border-color: var(--g); color: var(--g7); }
.a-btn.danger { background: #fff; border-color: #e6b8b5; color: var(--r); }
.a-btn.danger:hover { background: var(--r); color: #fff; border-color: var(--r); }
.a-btn[disabled] { opacity: .55; pointer-events: none; }

/* -------------------------------------------------------------- auth */
.a-auth { display: grid; place-items: center; min-height: 100vh; padding: 24px;
  background: radial-gradient(120% 130% at 20% 0%, #e0503c, #8a1c12 72%); }
.auth-card { width: min(100%, 430px); background: #fff; border-radius: 22px; box-shadow: var(--sh3); padding: 34px; }
.a-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.a-mark { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 13px; background: linear-gradient(135deg, var(--g), var(--o)); color: #fff; }
.a-logo strong { display: block; font-size: 1.02rem; }
.a-logo small { display: block; font-size: .74rem; color: var(--muted); }
.auth-card h1 { font-size: 1.3rem; margin-bottom: 6px; }
.muted { color: var(--muted); font-size: .87rem; margin: 0 0 20px; }
.auth-card form { display: grid; gap: 14px; }
.auth-card label { display: grid; gap: 6px; font-size: .85rem; font-weight: 600; }
.auth-card input { padding: 12px 14px; border: 1.6px solid var(--line); border-radius: 11px; background: var(--bg); }
.auth-card input:focus { outline: none; border-color: var(--g); background: #fff; box-shadow: 0 0 0 4px var(--g1); }
.err { color: var(--r); font-size: .85rem; min-height: 1.2em; margin: 0; font-weight: 600; }
.back { text-align: center; font-size: .84rem; color: var(--muted); margin: 18px 0 0; }

/* -------------------------------------------------------------- shell */
.a-app { display: grid; grid-template-columns: 258px 1fr; min-height: 100vh; }
.a-side {
  background: #fff; border-right: 1px solid var(--line); padding: 20px 16px; display: flex; flex-direction: column;
  gap: 18px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.a-nav { display: grid; gap: 3px; flex: 1; }
.a-navb {
  display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 13px; border-radius: 11px;
  font-size: .9rem; font-weight: 500; color: #5a4a44; text-align: left; transition: .18s;
}
.a-navb:hover { background: var(--g0); color: var(--g7); }
.a-navb.on { background: var(--g); color: #fff; box-shadow: 0 6px 16px rgba(208,48,31,.26); }
.a-navb .badge { margin-left: auto; background: var(--o); color: #fff; font-size: .7rem; font-style: normal; padding: 1px 7px; border-radius: 999px; }
.a-side-foot { display: grid; gap: 8px; }

.a-main { display: flex; flex-direction: column; min-width: 0; }
.a-top {
  display: flex; align-items: center; gap: 14px; padding: 16px 26px; background: #fff;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.a-top h1 { font-size: 1.15rem; flex: 1; }
.a-user { display: inline-flex; align-items: center; gap: 7px; font-size: .85rem; color: var(--muted); }
.a-burger { display: none; }
.a-body { padding: 26px; flex: 1; }
.a-loading { text-align: center; padding: 60px; color: var(--muted); }

/* ---------------------------------------------------------- dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 26px; }
.dash-card { background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 20px; box-shadow: var(--sh); transition: .25s; }
.dash-card:hover { transform: translateY(-4px); box-shadow: var(--sh2); }
.dash-card .dc-ic { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 13px; background: var(--g0); color: var(--g); margin-bottom: 12px; }
.dash-card strong { display: block; font-size: 1.9rem; line-height: 1.1; }
.dash-card span { font-size: .84rem; color: var(--muted); }
.dash-card.hot .dc-ic { background: var(--o1); color: var(--o); }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--sh); margin-bottom: 22px; overflow: hidden; }
.panel-h { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-h h2 { font-size: 1rem; flex: 1; }
.panel-b { padding: 20px; }
.tips { display: grid; gap: 10px; }
.tips li { display: flex; gap: 10px; align-items: flex-start; font-size: .88rem; color: var(--muted); }
.tips .ic { color: var(--g); margin-top: 3px; }

/* -------------------------------------------------------------- table */
.tbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 16px; }
.tbar .search { flex: 1; min-width: 180px; position: relative; }
.tbar .search input { width: 100%; padding: 10px 14px 10px 38px; border: 1.5px solid var(--line); border-radius: 11px; background: #fff; }
.tbar .search .ic { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--muted); }
.tbar .search input:focus { outline: none; border-color: var(--g); box-shadow: 0 0 0 4px var(--g1); }

.rows { display: grid; gap: 10px; }
.row {
  display: flex; align-items: center; gap: 14px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 16px; box-shadow: var(--sh); transition: .2s;
}
.row:hover { border-color: #cfe6da; box-shadow: var(--sh2); }
.row.dragging { opacity: .4; }
.row .grip { cursor: grab; color: #c2d3ca; }
.row .thumb { width: 54px; height: 54px; border-radius: 11px; object-fit: cover; background: var(--g0); flex: none; }
.row .rmain { flex: 1; min-width: 0; }
.row .rmain strong { display: block; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .rmain small { display: block; font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .ract { display: flex; gap: 7px; flex: none; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.pill.on { background: var(--ok1); color: var(--ok8); }
.pill.off { background: #f0f0f0; color: #888; }
.pill.new { background: var(--o1); color: var(--o); }
.pill.done { background: var(--ok1); color: var(--ok8); }
.iconbtn { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--bg); color: #56705f; transition: .18s; }
.iconbtn:hover { background: var(--g); color: #fff; }
.iconbtn.del:hover { background: var(--r); }
.empty-note { text-align: center; padding: 44px; color: var(--muted); background: #fff; border: 1px dashed var(--line); border-radius: 16px; }

/* -------------------------------------------------------------- forms */
.a-form { display: grid; gap: 16px; }
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.f { display: grid; gap: 6px; }
.f > label { font-size: .84rem; font-weight: 600; }
.f .hint { font-size: .76rem; color: var(--muted); }
.f input[type=text], .f input[type=number], .f select, .f textarea {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--line); border-radius: 11px; background: var(--bg); transition: .18s;
}
.f textarea { resize: vertical; min-height: 92px; }
.f input:focus, .f select:focus, .f textarea:focus { outline: none; border-color: var(--g); background: #fff; box-shadow: 0 0 0 4px var(--g1); }
.f.wide { grid-column: 1 / -1; }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch i { width: 46px; height: 26px; border-radius: 999px; background: #d7e2db; position: relative; transition: .22s; flex: none; }
.switch i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .22s; box-shadow: var(--sh); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }

.imgpick { display: flex; align-items: center; gap: 12px; }
.imgpick .prev { width: 74px; height: 74px; border-radius: 12px; object-fit: cover; background: var(--g0); border: 1px solid var(--line); flex: none; }
.imgpick .pbtns { display: grid; gap: 6px; }
.imgs { display: flex; flex-wrap: wrap; gap: 10px; }
.imgs .item { position: relative; width: 82px; }
.imgs .item img { width: 82px; height: 82px; border-radius: 11px; object-fit: cover; border: 1px solid var(--line); }
.imgs .item button { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; background: var(--r); color: #fff; display: grid; place-items: center; box-shadow: var(--sh); }
.iconpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 8px; max-height: 190px; overflow-y: auto; padding: 10px; border: 1.5px solid var(--line); border-radius: 12px; background: var(--bg); }
.iconpick button { display: grid; place-items: center; height: 46px; border-radius: 10px; background: #fff; border: 1.5px solid transparent; color: #4b6357; transition: .16s; }
.iconpick button:hover { border-color: var(--g); color: var(--g); }
.iconpick button.on { background: var(--g); color: #fff; }

.formbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding-top: 8px; border-top: 1px solid var(--line); margin-top: 4px; }
.formbar .spacer { flex: 1; }

/* -------------------------------------------------------------- modal */
.a-modal { position: fixed; inset: 0; z-index: 60; background: rgba(10,26,18,.5); backdrop-filter: blur(3px); display: grid; place-items: center; padding: 20px; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.a-modal-in { width: min(100%, 840px); max-height: 92vh; overflow-y: auto; background: #fff; border-radius: 20px; box-shadow: var(--sh3); animation: pop .28s cubic-bezier(.2,.85,.3,1); }
@keyframes pop { from { opacity: 0; transform: translateY(24px) scale(.97); } }
.m-head { display: flex; align-items: center; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.m-head h2 { font-size: 1.05rem; flex: 1; }
.m-body { padding: 24px; }

/* -------------------------------------------------------------- media */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 14px; }
.media-item { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: #fff; box-shadow: var(--sh); transition: .2s; }
.media-item:hover { transform: translateY(-4px); box-shadow: var(--sh2); }
.media-item img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.media-item .mi-bar { display: flex; gap: 4px; padding: 8px; }
.media-item .mi-bar button { flex: 1; font-size: .75rem; padding: 5px; border-radius: 8px; background: var(--bg); }
.media-item .mi-bar button:hover { background: var(--g); color: #fff; }
.media-item .mi-bar .del:hover { background: var(--r); }
.dropzone { border: 2px dashed var(--line); border-radius: 16px; padding: 30px; text-align: center; color: var(--muted); background: #fff; margin-bottom: 18px; transition: .2s; }
.dropzone.over { border-color: var(--g); background: var(--g0); color: var(--g7); }

/* -------------------------------------------------------------- toast */
.a-toast {
  position: fixed; bottom: 22px; left: 50%; translate: -50% 0; z-index: 90; padding: 13px 22px;
  border-radius: 12px; background: var(--ink); color: #fff; font-size: .88rem; font-weight: 600;
  box-shadow: var(--sh3); animation: up .3s cubic-bezier(.2,.85,.3,1);
}
.a-toast.bad { background: var(--r); }
@keyframes up { from { opacity: 0; transform: translate(-50%, 18px); } }

/* --------------------------------------------------------- responsive */
@media (max-width: 900px) {
  .a-app { grid-template-columns: 1fr; }
  .a-side { position: fixed; inset: 0 auto 0 0; width: 258px; z-index: 40; transform: translateX(-100%); transition: .28s; box-shadow: var(--sh3); }
  .a-side.open { transform: none; }
  .a-burger { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--bg); }
  .a-body { padding: 18px; }
  .a-top { padding: 14px 18px; }
}

/* ============================================ เว็บจำลอง (live preview) == */
.pv-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.pv-bar .spacer { flex: 1; }
.pv-sel { padding: 9px 12px; border-radius: 10px; border: 1px solid var(--a-line, #e3e0dc); background: #fff; font: inherit; font-size: .9rem; min-width: 190px; }
.pv-dev { display: inline-flex; background: #fff; border: 1px solid var(--a-line, #e3e0dc); border-radius: 10px; overflow: hidden; }
.pv-dev button { display: inline-flex; align-items: center; gap: 6px; padding: 9px 13px; border: 0; background: none; font: inherit; font-size: .85rem; cursor: pointer; color: #5a5450; }
.pv-dev button + button { border-left: 1px solid var(--a-line, #e3e0dc); }
.pv-dev button.on { background: #c02a1e; color: #fff; }
.pv-toggle { display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; background: #fff; border: 1px solid var(--a-line, #e3e0dc); border-radius: 10px; font-size: .85rem; cursor: pointer; }
.pv-toggle span { display: inline-flex; align-items: center; gap: 5px; }
.pv-tip { display: flex; align-items: flex-start; gap: 8px; margin: 0 0 14px; padding: 11px 14px; border-radius: 11px; background: #fff6f4; border: 1px solid #ffd2ca; color: #7d1d15; font-size: .85rem; line-height: 1.6; }
.pv-tip .ic { flex: none; margin-top: 2px; }
.pv-stage { display: grid; place-items: start center; padding: 4px 0 24px; }
.pv-frame { width: 100%; background: #fff; border: 1px solid var(--a-line, #e3e0dc); border-radius: 16px; overflow: hidden; box-shadow: 0 10px 34px rgba(34,48,42,.1); }
.pv-frame iframe { display: block; width: 100%; height: min(78vh, 900px); border: 0; }
.pv-stage.phone .pv-frame { max-width: 412px; border-radius: 26px; }
.pv-stage.tablet .pv-frame { max-width: 830px; border-radius: 20px; }
.pv-stage.desk .pv-frame { max-width: 100%; }
.ck-reset { margin-left: 6px; padding: 1px 5px; border: 0; border-radius: 6px; background: #f1eeea; color: #7a7068; cursor: pointer; vertical-align: middle; }
.ck-reset:hover { background: #ffe9e5; color: #c02a1e; }
@media (max-width: 700px) {
  .pv-dev button span { display: none; }
  .pv-stage.phone .pv-frame, .pv-stage.tablet .pv-frame { max-width: 100%; }
}
