/* ============================================================
   Craftfiti TV Admin — "Gallery" theme (จาก CI จริง)
   mobile-first · ครีม + serif + graffiti อำพัน
   ============================================================ */

:root {
  --cream: #F3EEE5;
  --card: #FBFAF6;
  --ink: #1A1714;
  --amber: #E8A33D;
  --amber-dark: #b9802a;
  --muted: #8a7d6b;
  --sand: #9a8b75;
  --soft: #5b5249;
  --line: rgba(26, 23, 20, 0.12);
  --line-input: rgba(26, 23, 20, 0.18);
  --off: #c8bba4;
  --green: #1F8A5B;
  --danger: #c0563f;
  --serif: 'Cinzel', 'Kanit', serif;
  --garamond: 'Cormorant Garamond', 'Kanit', serif;
  --marker: 'Permanent Marker', 'Kanit', cursive;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: var(--cream);
  color: var(--ink);
  font-family: 'Kanit', 'Segoe UI', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

/* ---------- Login / setup ---------- */

.screen { min-height: 100vh; }

#screen-login, #screen-setup {
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  position: relative;
}
#screen-login.hidden, #screen-setup.hidden { display: none; }

.login-box {
  width: 100%; max-width: 360px;
  text-align: center;
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { display: none; }
.login-brand-serif {
  font-family: var(--serif);
  font-size: 34px; letter-spacing: 0.18em; font-weight: 700; line-height: 1;
}
.login-brand-marker { font-family: var(--marker); font-size: 34px; color: var(--amber); margin-top: 2px; }
.login-box h1 { font-size: 24px; }
.login-sub {
  font-family: var(--garamond); font-style: italic;
  font-size: 17px; color: var(--sand);
  margin: 6px 0 24px;
}
.login-sub a { color: var(--amber-dark); }
.login-error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

input, select, textarea {
  background: var(--card);
  border: 1px solid var(--line-input);
  border-radius: 12px;
  color: var(--ink);
  font-family: inherit;
  font-size: 16px;
  padding: 14px;
  width: 100%;
}
input::placeholder { color: #b5a890; }
input:focus, textarea:focus { outline: 2px solid var(--amber); outline-offset: -1px; }

.btn-primary {
  background: var(--ink);
  color: var(--cream);
  border: none; border-radius: 14px;
  font-family: inherit; font-size: 16px; font-weight: 600;
  padding: 15px;
  cursor: pointer;
  box-shadow: 0 12px 24px -8px rgba(26, 23, 20, 0.5);
}
.btn-primary:active { opacity: 0.85; }

.btn-ghost {
  background: none;
  border: 1px solid var(--line-input);
  border-radius: 9px;
  color: var(--ink);
  font-family: inherit; font-size: 14px;
  padding: 6px 12px;
  cursor: pointer;
  text-decoration: none;
}

/* ---------- Header / nav ---------- */

header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px 12px;
  background: rgba(243, 238, 229, 0.96);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.head-title {
  font-size: 18px;
  display: flex; align-items: baseline; gap: 6px;
}
.head-title .t-serif { font-family: var(--serif); font-weight: 700; letter-spacing: 0.12em; font-size: 19px; }
.head-title .t-marker { font-family: var(--marker); color: var(--amber); font-size: 16px; }
.head-actions { display: flex; gap: 8px; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px 96px;
}

#bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  background: none; border: none;
  color: #a99c87;
  font-family: inherit; font-size: 19px;
  padding: 10px 0 8px;
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.nav-btn span { font-size: 11px; }
.nav-btn.active { color: var(--amber-dark); }
.nav-btn.active span { font-weight: 600; }

.demo-banner {
  background: var(--ink);
  color: var(--amber);
  text-align: center;
  font-size: 13px;
  padding: 6px;
}

/* ---------- Sections / cards ---------- */

.sec-title {
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.sec-title::after { content: ''; flex: 1; height: 1px; background: var(--line); order: 1; }
.sec-title > span:last-child { order: 2; }
.sec-title:first-child { margin-top: 4px; }
.sec-hint { font-size: 12px; color: #b5a890; font-weight: 300; letter-spacing: 0; text-transform: none; }

.card-list { display: flex; flex-direction: column; gap: 10px; }

.row-card {
  display: flex; align-items: center; gap: 11px;
  background: var(--card);
  border: 1px solid rgba(26, 23, 20, 0.1);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 6px 14px -8px rgba(26, 23, 20, 0.2);
}
.row-card.inactive { opacity: 0.55; box-shadow: none; }
.row-card.dragging { border-color: var(--amber); }

.drag-handle {
  font-size: 18px; color: #b5a890;
  padding: 8px 2px;
  cursor: grab;
  touch-action: none;
}

.thumb {
  width: 50px; height: 50px;
  border-radius: 9px;
  object-fit: cover;
  background: #ECE4D4;
  flex-shrink: 0;
}
.thumb-ph {
  width: 50px; height: 50px;
  border-radius: 9px;
  background: repeating-linear-gradient(45deg, #ECE4D4 0 6px, #F4EFE6 6px 12px);
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
}

.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.row-name { font-size: 14.5px; font-weight: 500; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 11px; color: var(--sand); }

.chip {
  font-size: 11px;
  border: none;
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--sand);
  background: rgba(26, 23, 20, 0.05);
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

/* switch */
.switch {
  position: relative;
  width: 46px; height: 27px;
  border-radius: 999px;
  background: var(--off);
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.switch::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 21px; height: 21px;
  border-radius: 50%;
  background: var(--card);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: all 0.15s;
}
.switch.on { background: var(--amber); }
.switch.on::after { left: 22px; }

/* star (beer of the day) */
.star-btn {
  background: none; border: none;
  font-size: 22px;
  cursor: pointer;
  filter: grayscale(1) opacity(0.35);
  padding: 4px;
}
.star-btn.on { filter: none; }

.badge {
  font-family: var(--marker);
  font-size: 10px; border-radius: 5px; padding: 2px 7px; margin-left: 5px;
}
.badge.new { background: var(--ink); color: var(--cream); }
.badge.pick { background: var(--amber); color: var(--card); }

.add-btn {
  width: 100%;
  background: rgba(232, 163, 61, 0.08);
  border: 2px dashed rgba(232, 163, 61, 0.7);
  border-radius: 16px;
  color: var(--amber-dark);
  font-family: inherit; font-size: 15px; font-weight: 600;
  padding: 15px;
  cursor: pointer;
  margin-top: 10px;
}

.icon-btn {
  background: none; border: none;
  color: var(--danger);
  font-size: 16px;
  padding: 6px 2px;
  cursor: pointer;
}

/* stepper */
.stepper { display: flex; align-items: center; gap: 12px; }
.stepper button {
  width: 38px; height: 38px;
  border-radius: 11px;
  background: var(--card);
  border: 1px solid var(--line-input);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
}
.stepper button:last-child { background: var(--amber); border-color: var(--amber); }
.stepper .step-val {
  font-family: var(--garamond); font-weight: 600;
  font-size: 24px; min-width: 2ch; text-align: center;
}

/* promo / top editor */
.edit-card {
  background: var(--card);
  border: 1px solid rgba(26, 23, 20, 0.1);
  border-radius: 16px;
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 8px 18px -10px rgba(26, 23, 20, 0.2);
}
.edit-card input { background: var(--cream); }
.edit-row { display: flex; gap: 10px; align-items: center; }
.edit-row input { flex: 1; }
.edit-row input.narrow { flex: 0 0 84px; }
.edit-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

label.fld { font-size: 12px; color: var(--muted); display: block; margin-bottom: 6px; }

/* ---------- Modal (bottom sheet) ---------- */

#modal-root {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 17, 14, 0.5);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  width: 100%; max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--cream);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -20px 50px -10px rgba(0, 0, 0, 0.5);
  padding: 14px 22px calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px;
}
.modal::before {
  content: '';
  width: 42px; height: 5px; border-radius: 999px;
  background: rgba(26, 23, 20, 0.22);
  align-self: center;
  margin-bottom: 4px;
}
.modal h2 {
  font-family: var(--serif);
  font-size: 18px; letter-spacing: 0.1em; font-weight: 600;
}
.modal .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 10px; margin-top: 8px; }
.modal-actions .btn-primary { flex: 1; }
.btn-danger {
  background: none;
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 14px;
  font-family: inherit; font-size: 14px;
  padding: 14px 18px;
  cursor: pointer;
}

/* ---------- Preview iframe (จอ TV ย่อส่วน) ---------- */

.prev-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(26, 23, 20, 0.25);
  border-radius: 10px;
  background: var(--ink);
  display: block;
}

/* ---------- Media picker (การ์ด feature) ---------- */

.pick-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.pick-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid rgba(26, 23, 20, 0.12);
  border-radius: 12px;
  padding: 9px;
  font-family: inherit; font-size: 13px;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
  min-width: 0;
}
.pick-item.picked { border-color: var(--amber); background: rgba(232, 163, 61, 0.1); }
.pick-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  background: var(--green);
  border: none;
  color: #fff;
  font-size: 14px; font-weight: 500;
  padding: 9px 20px;
  border-radius: 999px;
  z-index: 60;
  white-space: nowrap;
  max-width: 92vw;
  overflow: hidden; text-overflow: ellipsis;
  box-shadow: 0 12px 26px -8px rgba(31, 138, 91, 0.6);
}

/* ---------- คลังเบียร์ picker (ค้นหาจาก Google Sheet) ---------- */
.sheet-picker {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(26, 23, 20, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 14px 14px;
}
.sp-box {
  background: #fff; width: 100%; max-width: 520px; max-height: 82vh;
  border-radius: 14px; overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 70px -10px rgba(0, 0, 0, 0.4);
}
.sp-head { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid #eee; }
.sp-head input { flex: 1; }
.sp-head .btn-ghost { flex: 0 0 auto; }
.sp-list { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sp-item { padding: 11px 14px; border-bottom: 1px solid #f3f3f3; cursor: pointer; }
.sp-item:hover, .sp-item:active { background: #faf5ec; }
.sp-row { display: flex; align-items: center; gap: 8px; }
.sp-name { font-weight: 600; flex: 1; }
.sp-tier { flex: 0 0 auto; font-size: 11px; font-weight: 600; background: var(--marker, #E8A33D); color: #fff; padding: 2px 9px; border-radius: 999px; }
.sp-notes { font-size: 12px; color: #8a8a8a; margin-top: 3px; line-height: 1.35; }
.sp-msg { padding: 18px; text-align: center; color: #999; font-size: 14px; }

/* ---------- เลือกเบียร์จากคลัง: เข้าใหม่ / สตาฟแนะนำ (20 ก.ย.) ---------- */
.sp-note { padding: 9px 14px; font-size: 12px; line-height: 1.5; color: #7a7a7a; background: #faf7f1; border-bottom: 1px solid #eee; }
.bp-item { display: flex; align-items: center; gap: 10px; cursor: default; }
.bp-item.has { background: #f7fbf8; }
.sp-thumb { flex: 0 0 auto; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }
.sp-thumb img, .sp-thumb .thumb { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; }
.sp-thumb .thumb-ph { font-size: 20px; opacity: 0.35; }
.sp-txt { flex: 1; min-width: 0; }
.bp-item .sp-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sp-in { font-size: 10px; font-weight: 600; color: var(--green, #1F8A5B); border: 1px solid currentColor; border-radius: 999px; padding: 1px 6px; }
.sp-dim { opacity: 0.5; font-style: italic; }
.sp-acts { flex: 0 0 auto; display: flex; gap: 6px; }
.sp-b {
  width: 44px; height: 44px; border-radius: 10px; font-size: 19px; line-height: 1;
  border: 1px solid #e2ddd4; background: #fff; cursor: pointer;
  filter: grayscale(1); opacity: 0.45; transition: all .12s;
}
.sp-b:active { transform: scale(0.94); }
.sp-b.on { filter: none; opacity: 1; background: #fff6e6; border-color: var(--marker, #E8A33D); }

/* ---------- Help guide (❔ ขวาบน) ---------- */
.btn-help { padding: 6px 10px; font-size: 15px; line-height: 1; }
.help-guide { gap: 6px; }
.help-guide details { border: 1px solid var(--line); border-radius: 12px; padding: 0; background: rgba(255,255,255,0.45); }
.help-guide summary { cursor: pointer; padding: 12px 14px; font-weight: 600; font-size: 15px; list-style: none; }
.help-guide summary::-webkit-details-marker { display: none; }
.help-guide summary::after { content: '▾'; float: right; color: var(--muted); }
.help-guide details[open] summary::after { content: '▴'; }
.help-guide .help-body { padding: 0 14px 12px; font-size: 14px; line-height: 1.6; }
.help-guide .help-body p { margin: 4px 0; }
.help-guide .help-body ul { margin: 4px 0 6px; padding-left: 18px; }
.help-guide .help-body li { margin: 3px 0; }
.help-guide kbd { display: inline-block; border: 1px solid var(--line-input); border-radius: 6px; padding: 0 6px; font-family: inherit; font-size: 13px; background: #fff; }
.help-guide .help-tip { background: rgba(232,163,61,0.14); border-left: 3px solid var(--amber); padding: 8px 12px; border-radius: 8px; font-size: 13.5px; }
@media (max-width: 480px) { .head-title > span:last-child { display: none; } .btn-ghost { padding: 6px 9px; } }
