:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232732;
  --text: #f1f3f5;
  --muted: #9aa3b2;
  --accent: #e50914;
  --accent-hover: #ff1f2b;
  --border: #2d323e;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Noto Sans Thai", "Sarabun", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
main { flex: 1; }

.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---------- Header / Footer ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.brand { font-size: 1.3rem; font-weight: 700; white-space: nowrap; }
.header-inner { gap: 16px; }

/* ---------- Search ---------- */
.search-form {
  display: flex;
  flex: 1;
  max-width: 420px;
  margin: 0 auto;
}
.search-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 8px 0 0 8px;
  font: inherit;
  font-size: 0.95rem;
}
.search-form input:focus { outline: none; border-color: var(--accent); }
.search-form button {
  padding: 0 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0 8px 8px 0;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
}
.search-form button:hover { background: var(--accent); border-color: var(--accent); }
.tags { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.search-tip { color: var(--muted); margin-top: -8px; }
.nav a { margin-left: 18px; font-weight: 500; }
.nav a:hover { color: var(--accent-hover); }
.muted { color: var(--muted); }

/* ---------- Dropdown (เมนูหมวดหมู่) ---------- */
.nav { display: flex; align-items: center; gap: 18px; }
.nav a { margin-left: 0; }
.dropdown { position: relative; }
.dropdown-toggle {
  background: none; border: none; color: inherit; font: inherit; font-weight: 500;
  cursor: pointer; padding: 0;
}
.dropdown-toggle:hover { color: var(--accent-hover); }
.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  padding-top: 10px;
  min-width: 180px;
  z-index: 20;
}
.dropdown-menu a {
  display: block;
  background: var(--surface);
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-top: none;
  white-space: nowrap;
}
.dropdown-menu a:first-child { border-top: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.dropdown-menu a:last-child { border-radius: 0 0 8px 8px; }
.dropdown-menu a:hover { background: var(--surface-2); color: var(--accent-hover); }
.dropdown:hover .dropdown-menu,
.dropdown.open .dropdown-menu { display: block; }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.85rem;
}
.chip:hover { border-color: var(--accent); color: var(--accent-hover); }
.meta .chip + .chip { margin-left: 4px; }
.meta a.chip::before { content: none; }

.label-text { display: block; font-weight: 500; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.category-picker {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 44px;
}
.category-picker label {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0; padding: 4px 10px;
  border: 1px solid var(--border); border-radius: 999px;
  cursor: pointer; font-weight: 400; font-size: 0.9rem;
}
.category-picker label:has(input:checked) { border-color: var(--accent); background: #3b1217; }
.category-picker input { margin: 0; }
.quick-add {
  display: flex; gap: 8px; align-items: center; margin-top: 8px;
}
.quick-add input[type="text"] { margin: 0; flex: 1; padding: 8px 10px; font-size: 0.9rem; }
.quick-add .btn { padding: 8px 14px; font-size: 0.9rem; white-space: nowrap; }
.quick-add-msg { font-size: 0.85rem; margin: 4px 0 0; min-height: 1.2em; }
.quick-add-msg.err { color: #ffc2c7; }
.quick-add-msg.ok { color: #b6f0c8; }
.inline-form { display: flex; gap: 8px; align-items: center; }
.inline-form input[type="text"] { margin: 0; width: 220px; }
.inline-form input[type="number"] { margin: 0; width: 80px; }

.site-footer {
  margin-top: 48px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ---------- Hero ---------- */
.hero {
  padding: 48px 0 24px;
  text-align: center;
}
.hero h1 { margin: 0; font-size: 2.4rem; }
.tagline { color: var(--muted); margin: 8px 0 0; font-size: 1.1rem; }

.section-title {
  font-size: 1.3rem;
  margin: 32px 0 16px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.count { color: var(--muted); font-weight: 400; font-size: 0.95rem; }

/* ---------- Section boxes (กรอบแยกส่วนหน้าแรก) ---------- */
.section-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 24px;
}
.section-box .section-title { margin: 0; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.section-box .movie-card { background: var(--surface-2); }

/* ---------- Movie Row (แถวเดียว เลื่อนซ้ายขวา) ---------- */
.movie-row-wrap { position: relative; }
.movie-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  padding-bottom: 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.movie-row .movie-card {
  flex: 0 0 170px;
  scroll-snap-align: start;
}
.row-arrow {
  position: absolute;
  top: 40%;
  transform: translateY(-50%);
  width: 36px; height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: rgba(15, 17, 21, 0.9);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
  display: flex; align-items: center; justify-content: center;
}
.row-arrow:hover { background: var(--accent); border-color: var(--accent); }
.row-arrow-left { left: -12px; }
.row-arrow-right { right: -12px; }
.movie-row-wrap.at-start .row-arrow-left,
.movie-row-wrap.at-end .row-arrow-right { display: none; }

.badge-new {
  position: absolute;
  top: 8px; left: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0,0,0,.4);
}

/* ---------- Movie Grid ---------- */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 20px;
}
.movie-grid.small { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }

.movie-card {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform .15s, border-color .15s;
}
.movie-card:hover { transform: translateY(-4px); border-color: var(--accent); }
.poster { aspect-ratio: 1 / 1; background: var(--surface-2); position: relative; }
.poster img { width: 100%; height: 100%; object-fit: cover; }
.movie-info { padding: 10px 12px; }
.movie-info h3 {
  margin: 0;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meta { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; }
.meta span + span::before { content: " · "; }

/* ---------- Banners ---------- */
/* ป้ายขนาดมาตรฐาน 728x200 จัดกึ่งกลาง หลายป้ายเรียงต่อกันและขึ้นบรรทัดใหม่อัตโนมัติ */
.banners {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin: 0 0 20px;
}
.banner {
  display: block;
  width: 728px;
  max-width: 100%;
  aspect-ratio: 728 / 200;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface);
  flex: 0 0 auto;
}
.banner img { width: 100%; height: 100%; object-fit: cover; display: block; }
a.banner:hover { border-color: var(--accent); }
.hero + .banners { margin-top: 8px; }

.banner-thumb { width: 182px; height: 50px; object-fit: cover; background: #000; border-radius: 6px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.75rem; }
.badge-on { background: #10361e; color: #b6f0c8; }
.badge-off { background: #3a3d45; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin-top: 28px; }
.check input { width: auto; margin: 0; }
select,
input[type="number"],
input[type="url"] {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
@media (max-width: 640px) {
  .row-3 { grid-template-columns: 1fr; }
}

/* ---------- Movie page ---------- */
.back { display: inline-block; margin: 20px 0; color: var(--muted); }
.back:hover { color: var(--text); }
.player-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.player { width: 100%; max-height: 75vh; display: block; }
.movie-detail { margin-top: 20px; }
.movie-detail h1 { margin: 0 0 4px; }
.description {
  color: #d0d5dd;
  white-space: pre-line;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin: 0;
  line-height: 1.8;
}

/* ---------- กรอบเรื่องย่อ + รูปประกอบ ---------- */
.synopsis-box { margin-top: 20px; }
.synopsis-body { display: grid; gap: 20px; }
.synopsis-body.has-gallery { grid-template-columns: 320px 1fr; }
.gallery {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-content: start;
}
.gallery-item {
  display: block;
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.gallery-item img { width: 100%; height: 100%; object-fit: cover; transition: transform .2s; }
.gallery-item:hover img { transform: scale(1.05); }
.gallery-item:first-child:nth-last-child(1) { grid-column: span 2; }

/* Lightbox */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, .92);
  display: flex; align-items: center; justify-content: center;
}
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 92vw; max-height: 88vh; border-radius: 8px; box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.lightbox-close, .lightbox-nav {
  position: absolute; background: rgba(255,255,255,.1); color: #fff; border: none;
  width: 44px; height: 44px; border-radius: 50%; font-size: 1.8rem; line-height: 1; cursor: pointer;
}
.lightbox-close:hover, .lightbox-nav:hover { background: var(--accent); }
.lightbox-close { top: 16px; right: 16px; }
.lightbox-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lightbox-count { position: absolute; bottom: 16px; color: var(--muted); font-size: .9rem; }

/* จัดการรูปประกอบในหลังบ้าน */
.gallery-preview { display: flex; flex-wrap: wrap; gap: 8px; margin: -8px 0 16px; }
.gallery-preview img { width: 110px; height: 82px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.gallery-manage { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.gallery-manage-item {
  display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 6px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--bg); font-weight: 400; font-size: .85rem;
}
.gallery-manage-item img { width: 130px; height: 96px; object-fit: cover; border-radius: 6px; }
.gallery-manage-item span { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.gallery-manage-item:has(input:checked) { border-color: #a02020; opacity: .6; }
.gallery-manage-item input { margin: 0; width: auto; }

/* ---------- Empty / Flash ---------- */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty h1 { font-size: 4rem; margin: 0; color: var(--text); }
.flash {
  margin: 20px 0 0;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid;
}
.flash-success { background: #10361e; border-color: #1f7a3c; color: #b6f0c8; }
.flash-error { background: #3b1217; border-color: #8a1f28; color: #ffc2c7; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: var(--accent-hover); }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: #6b1a1a; }
.btn-danger:hover { background: #a02020; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.link {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link:hover { color: var(--text); }

/* ---------- Forms ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-top: 24px;
}
.card.narrow { max-width: 420px; margin: 60px auto; }
.card h1 { margin-top: 0; font-size: 1.5rem; }
.card h2 { font-size: 1.1rem; margin-bottom: 4px; }
.card hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

label { display: block; margin-bottom: 16px; font-weight: 500; }
label small { color: var(--muted); font-weight: 400; }
.req { color: var(--accent); }
input[type="text"],
input[type="password"],
input[type="tel"],
input[type="email"],
input[type="url"],
input[type="number"],
textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="file"] { margin-top: 6px; color: var(--muted); font: inherit; }
textarea { resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; gap: 10px; margin-top: 8px; }
.preview { margin-top: 10px; width: 140px; height: 140px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }

/* ---------- Admin ---------- */
.admin-nav {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-top: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.admin-nav a:hover { color: var(--accent-hover); }
.admin-nav .logout { margin-left: auto; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 16px;
}
.page-head h1 { margin: 0; font-size: 1.5rem; }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
.table tr:last-child td { border-bottom: none; }
.table td a:hover { color: var(--accent-hover); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions form { display: inline-block; margin-left: 6px; }
.current-file { margin-top: 8px; display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; font-weight: 400; }
.current-file img { width: 100px; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); background: var(--surface-2); }
.thumb { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }

@media (max-width: 640px) {
  .synopsis-body.has-gallery { grid-template-columns: 1fr; }
  .section-box { padding: 14px; }
  .movie-row .movie-card { flex-basis: 140px; }
  .row-arrow { display: none; }
  .header-inner { height: auto; flex-wrap: wrap; padding: 10px 0; row-gap: 10px; }
  .search-form { order: 3; flex-basis: 100%; max-width: none; }
  .row { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.8rem; }
  .admin-nav { flex-wrap: wrap; gap: 12px; }
  .table th:nth-child(5), .table td:nth-child(5) { display: none; }
}
.preview.wide { width: 100%; max-width: 728px; height: auto; aspect-ratio: 728 / 200; object-fit: cover; }

/* ======================================================
   ส่วนเสริม: แถบความคืบหน้า สถานะ แบ่งหน้า ตอน สถิติ ตัวเล่น
   ====================================================== */

/* แถบความคืบหน้าอัปโหลด */
.upload-progress {
  margin: 12px 0 16px;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.upload-progress .bar { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.upload-progress .bar > span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.upload-progress .label { display: flex; justify-content: space-between; font-size: .9rem; margin-top: 8px; }
.upload-progress .detail { font-size: .82rem; margin-top: 2px; }
.upload-progress.error { border-color: #8a1f28; }
.upload-progress.error .bar > span { background: #a02020; }

/* ป้ายสถานะ */
.badge-published { background: #10361e; color: #b6f0c8; }
.badge-draft { background: #3a3d45; color: var(--muted); }
.badge-series { background: #1d2b4a; color: #9cc4ff; }
.badge-movie { background: #2a2d35; color: #d0d5dd; }

/* แถบกรอง / เลือกหลายเรื่อง (หลังบ้าน) */
.filter-bar, .bulk-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 12px 0; }
.filter-bar input[type="search"], .filter-bar select, .bulk-bar select {
  margin: 0; width: auto; padding: 8px 10px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; font: inherit;
}
.filter-bar input[type="search"] { min-width: 220px; }
.bulk-bar { padding: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.check-inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 500; }
.check-inline input { width: auto; margin: 0; }
.table .col-check { width: 32px; }
.table input[type="checkbox"] { width: auto; margin: 0; }
.table .title-cell small { display: block; color: var(--muted); }

/* แถบเรียงลำดับ + แบ่งหน้า (หน้าบ้าน) */
.sort-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.sort-bar label { display: flex; align-items: center; gap: 6px; margin: 0; font-size: .9rem; color: var(--muted); font-weight: 400; }
.sort-bar select { margin: 0; width: auto; padding: 6px 10px; font-size: .9rem; }
.section-head { flex-wrap: wrap; gap: 10px; }
.link-more { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.link-more:hover { color: var(--accent-hover); }
.pagination { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 20px; }
.pagination a, .pagination span { padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px; }
.pagination a:hover { border-color: var(--accent); color: var(--accent-hover); }
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination .dots { border: none; }
.pagination-info { text-align: center; font-size: .85rem; margin: 8px 0 0; }

/* ตอน (ซีรีส์) */
.ep-current { display: block; font-size: 1rem; color: var(--muted); font-weight: 400; margin-top: 2px; }
.episode-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.episode-btn { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.episode-btn:hover { border-color: var(--accent); }
.episode-btn.active { border-color: var(--accent); background: #3b1217; }
.ep-num { font-size: .8rem; color: var(--muted); }
.ep-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.episode-table input[type="text"], .episode-table input[type="number"] { margin: 0; padding: 6px 8px; }
.episode-table input[type="number"] { width: 70px; }

/* ซับไตเติล (หลังบ้าน) */
.sub-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.sub-item { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.sub-item input[type="text"] { margin: 0; flex: 1; min-width: 160px; }
.sub-item .file-name { color: var(--muted); font-size: .85rem; }

/* สถิติ */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-top: 20px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--muted); font-size: .9rem; }
.disk-bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.disk-bar > span { display: block; height: 100%; background: var(--accent); }

/* ตัวเล่น Plyr */
.plyr { --plyr-color-main: #e50914; width: 100%; }
.player-wrap .plyr--video, .player-wrap .plyr__video-wrapper { max-height: 75vh; }
.player-wrap .plyr__video-wrapper video { max-height: 75vh; }

/* ข้อความแจ้งสั้น ๆ */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(26, 29, 36, .96); border: 1px solid var(--border); color: var(--text);
  padding: 10px 18px; border-radius: 999px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

.meta .views { color: var(--muted); }
.meta .badge { margin-right: 4px; }
.users-table input[type="password"] { margin: 0; padding: 6px 8px; width: 150px; }
.type-toggle { display: flex; gap: 16px; }
.type-toggle label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
.type-toggle input { width: auto; margin: 0; }
.hint-box { background: var(--bg); border: 1px dashed var(--border); border-radius: 8px; padding: 10px 12px; color: var(--muted); font-size: .9rem; margin-bottom: 16px; }

@media (max-width: 640px) {
  .filter-bar input[type="search"] { min-width: 0; flex: 1; }
  .episode-list { grid-template-columns: 1fr 1fr; }
}

/* ---------- โฆษณาก่อนเริ่มหนัง (pre-roll) ---------- */
.player-wrap { position: relative; }
.ad-overlay {
  position: absolute; inset: 0; z-index: 30;
  background: #000; display: flex; align-items: center; justify-content: center;
}
.ad-overlay[hidden] { display: none; }
.ad-overlay video { width: 100%; height: 100%; object-fit: contain; }
.ad-label {
  position: absolute; top: 12px; left: 12px;
  background: rgba(0, 0, 0, .7); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: .8rem;
}
.ad-link {
  position: absolute; bottom: 16px; left: 16px;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.ad-link:hover { background: var(--accent-hover); }
.ad-skip {
  position: absolute; bottom: 16px; right: 16px;
  background: rgba(0, 0, 0, .75); color: #fff; border: 1px solid rgba(255, 255, 255, .45);
  padding: 10px 16px; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer;
}
.ad-skip:disabled { cursor: default; opacity: .85; }
.ad-skip:not(:disabled):hover { background: var(--accent); border-color: var(--accent); }
.ad-overlay.needs-tap::after {
  content: '▶ แตะเพื่อเล่นโฆษณา';
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 1.2rem; font-weight: 600; background: rgba(0, 0, 0, .55); cursor: pointer;
}
.plyr .ad-overlay { z-index: 30; }

/* ---------- หน้าแท็ก ---------- */
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-chip { padding: 6px 12px; font-size: .95rem; }
.tag-count { color: var(--muted); font-size: .8rem; margin-left: 4px; }
.dropdown-menu .menu-more { color: var(--muted); font-size: .85rem; }

/* ======================================================
   เมนูหลังบ้านแบบ Sidebar ด้านซ้าย
   ====================================================== */
.admin-nav-title { display: none; }

body.has-sidebar .admin-nav {
  position: fixed;
  top: 60px;              /* ใต้แถบบนสาธารณะ */
  left: 0;
  bottom: 0;
  width: 220px;
  margin: 0;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 16px 12px;
  border-radius: 0;
  border-width: 0 1px 0 0;
  overflow-y: auto;
  z-index: 9;
}
body.has-sidebar .admin-nav-title {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 4px 10px 10px;
}
body.has-sidebar .admin-nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.has-sidebar .admin-nav a:hover { background: var(--surface-2); color: var(--text); }
body.has-sidebar .admin-nav a.active { background: var(--accent); color: #fff; }
body.has-sidebar .admin-nav .logout {
  margin: auto 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}
body.has-sidebar .admin-nav .logout .muted { padding: 0 10px; font-size: .85rem; }
body.has-sidebar .admin-nav .logout .link { padding: 8px 10px; }

/* ดันเนื้อหาหลักให้พ้น sidebar */
body.has-sidebar > main.container {
  width: auto;          /* สำคัญ: ยกเลิก width:100% ของ .container ไม่ให้เกินจอเท่าความกว้าง sidebar */
  margin-left: 220px;
  margin-right: 0;
  max-width: none;
  padding: 0 24px;
}

@media (max-width: 900px) {
  /* จอแคบ: กลับไปเป็นแถบปกติด้านบน ไม่ลอยทับเนื้อหา */
  body.has-sidebar .admin-nav {
    position: static;
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    padding: 12px 16px;
    border-width: 1px;
    border-radius: var(--radius);
  }
  body.has-sidebar .admin-nav-title { display: none; }
  body.has-sidebar .admin-nav a { padding: 6px 10px; }
  body.has-sidebar .admin-nav .logout {
    margin: 0 0 0 auto;
    padding-top: 0;
    border-top: none;
    flex-direction: row;
    align-items: center;
  }
  body.has-sidebar > main.container { width: 100%; margin-left: 0; max-width: 1200px; padding: 0 16px; }
}

/* ---------- รูปนักแสดง ---------- */
.cast-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 16px;
}
.cast-card {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px;
  padding: 12px 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
}
.cast-card:hover { border-color: var(--accent); }
.cast-avatar {
  width: 84px; height: 84px; border-radius: 50%; object-fit: cover;
  background: var(--bg); border: 2px solid var(--border);
}
.cast-avatar-empty { display: flex; align-items: center; justify-content: center; font-size: 1.8rem; color: var(--muted); }
.cast-name { font-weight: 600; font-size: .9rem; }
.cast-avatar-sm {
  width: 40px; height: 40px; border-radius: 50%; object-fit: cover;
  background: var(--bg); border: 1px solid var(--border); flex: 0 0 auto;
}
span.cast-avatar-sm { display: inline-flex; align-items: center; justify-content: center; font-size: 1rem; }
.cast-head { display: flex; align-items: center; gap: 10px; }
.cast-cell { display: flex; align-items: center; gap: 10px; }
.cast-img-form { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.cast-img-form input[type="file"] { font-size: .78rem; width: 170px; }

/* ---------- แก้หน้าหลังบ้านล้นจอด้านขวา ---------- */
body.has-sidebar > main.container { min-width: 0; overflow-x: auto; }
body.has-sidebar .table { max-width: 100%; }
/* ฟอร์มในตารางยืดหยุ่น ไม่ดันตารางให้กว้างเกิน */
.users-table .inline-form, .cast-img-form { flex-wrap: wrap; }
.users-table .inline-form input[type="password"] { width: 120px; }
.users-table .inline-form input[type="text"] { width: 130px; }

/* ---------- ตารางรายการหนังหลังบ้าน (กระชับ ไม่ล้นจอ) ---------- */
.movie-table { table-layout: fixed; width: 100%; }
.movie-table .col-check { width: 36px; }
.movie-table .col-cat { width: 200px; }
.movie-table .col-actions { width: 150px; white-space: nowrap; }
.movie-row-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.movie-row-cell .thumb { width: 46px; height: 46px; flex: 0 0 auto; }
.movie-row-info { min-width: 0; }
.movie-row-info > a {
  display: block; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.movie-row-info > a:hover { color: var(--accent-hover); }
.movie-row-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  margin-top: 4px; color: var(--muted); font-size: .8rem;
}
.movie-row-meta .badge { font-size: .72rem; }
.movie-table .col-cat {
  color: var(--muted); font-size: .9rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.col-cat-inline { display: none; }        /* หมวดแบบ inline (โชว์เฉพาะจอแคบ) */
.movie-table .row-actions .btn { margin-bottom: 4px; }

/* จอแคบ: ซ่อนคอลัมน์หมวดแยก แล้วโชว์หมวดใต้ชื่อแทน */
@media (max-width: 820px) {
  .movie-table .col-cat { display: none; }
  .col-cat-inline { display: inline; }
}
@media (max-width: 560px) {
  .movie-row-meta .hide-sm { display: none; }
  .movie-table .col-actions { width: 70px; }
  .movie-table .col-actions .btn { display: block; width: 100%; margin: 0 0 4px; }
}

/* ---------- ปุ่มกดถูกใจ ---------- */
.like-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); font: inherit; font-size: .9rem; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.like-btn:hover { border-color: var(--accent); }
.like-btn.liked { background: #3b1217; border-color: var(--accent); color: #ffd0d4; }
.like-btn.liked .like-icon { filter: none; }
.like-btn .like-icon { filter: grayscale(0.3); }
.like-btn:disabled { opacity: .7; cursor: default; }
.like-btn.pop { animation: likePop .3s ease; }
@keyframes likePop { 0%{transform:scale(1)} 40%{transform:scale(1.25)} 100%{transform:scale(1)} }

/* ---------- โลโก้แบรนด์ ---------- */
.brand { display: inline-flex; align-items: center; }
.brand-logo { height: 40px; width: auto; max-width: 220px; display: block; }
.brand-preview {
  display: flex; align-items: center; justify-content: center;
  min-height: 70px; padding: 10px; margin-bottom: 8px;
  background: var(--bg); border: 1px dashed var(--border); border-radius: 8px;
}
.brand-preview img { max-height: 60px; max-width: 100%; }
.brand-preview-sm img { max-height: 48px; max-width: 48px; }

/* ---------- หน้ายืนยันอายุ 18+ ---------- */
.age-gate {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: radial-gradient(circle at 50% 30%, #1a1d24, #0b0c10);
}
.age-box {
  max-width: 460px; width: 100%; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px 28px;
}
.age-logo { height: 54px; width: auto; margin: 0 auto 12px; display: block; }
.age-brand { margin: 0 0 8px; font-size: 1.6rem; }
.age-box h2 { margin: 8px 0 14px; font-size: 1.3rem; }
.age-warn { color: var(--muted); font-size: .9rem; line-height: 1.7; }
.age-warn a { color: var(--accent-hover); text-decoration: underline; }
.age-q { font-weight: 600; margin: 18px 0 14px; }
.age-actions { margin: 0; }
.age-yes { width: 100%; padding: 14px; font-size: 1rem; }
.age-no { display: inline-block; margin-top: 14px; color: var(--muted); }
.age-no:hover { color: var(--text); }
.age-fine { margin-top: 20px; font-size: .78rem; color: #6b7383; }

/* ---------- หน้ากฎหมาย + footer ---------- */
.legal { max-width: 820px; margin-left: auto; margin-right: auto; }
.legal h1 { margin-top: 0; }
.legal h2 { font-size: 1.1rem; margin: 22px 0 6px; }
.legal p, .legal li { color: #d0d5dd; line-height: 1.8; }
.legal ul { padding-left: 20px; }
.legal-disclaimer { margin-top: 24px; font-size: .85rem; border-top: 1px solid var(--border); padding-top: 14px; }
.footer-links { display: flex; gap: 18px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }
.footer-links a:hover { color: var(--accent-hover); }
.footer-note { margin-top: 6px; font-size: .8rem; color: #6b7383; }

/* ---------- จัดการแบนเนอร์แบบแยกกล่องตามตำแหน่ง ---------- */
.banner-group { margin-top: 18px; }
.pos-code {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--accent); color: #fff; font-size: .85rem; font-weight: 700; margin-right: 4px;
}
.banner-rows { display: flex; flex-direction: column; gap: 10px; }
.banner-item {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
}
.banner-code {
  flex: 0 0 auto; font-weight: 700; color: var(--muted); font-size: .9rem;
  min-width: 36px; text-align: center;
}
.banner-item .banner-thumb { width: 160px; height: 44px; object-fit: cover; border-radius: 4px; background: #000; flex: 0 0 auto; }
.banner-meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 200px; }
.banner-meta small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.banner-meta .badge { align-self: flex-start; margin-top: 2px; }
.banner-order { display: flex; flex-direction: column; gap: 4px; flex: 0 0 auto; }
.banner-order .btn { padding: 2px 10px; line-height: 1.3; }
.banner-actions { display: flex; gap: 6px; flex: 0 0 auto; flex-wrap: wrap; }
@media (max-width: 640px) {
  .banner-item .banner-thumb { width: 120px; height: 34px; }
  .banner-order { flex-direction: row; }
}

/* ---------- ปุ่มการกระทำ / แจ้งปัญหา / เรตติ้ง / คอมเมนต์ ---------- */
.nav-badge { background: var(--accent); color:#fff; border-radius:999px; padding:0 6px; font-size:.7rem; }
.rating-badge { display:inline-block; background:#3a2d12; color:#ffd36b; border-radius:6px; padding:1px 8px; font-weight:600; font-size:.9rem; }
.movie-actions { display:flex; flex-wrap:wrap; gap:10px; margin-top:14px; }
.act-btn {
  display:inline-flex; align-items:center; gap:6px; padding:8px 14px; border-radius:999px;
  background:var(--surface-2); border:1px solid var(--border); color:var(--text); font:inherit; font-size:.9rem; cursor:pointer;
}
.act-btn:hover { border-color:var(--accent); }
.act-btn.on { background:#3b1217; border-color:var(--accent); color:#ffd0d4; }
.act-btn:disabled { opacity:.6; }
.report-form { display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-top:12px; padding:12px; background:var(--surface); border:1px solid var(--border); border-radius:8px; }
.report-form[hidden] { display:none; }
.report-form select, .report-form input[type="text"] { margin:0; width:auto; }
.report-form input[type="text"] { flex:1; min-width:180px; }
.report-msg { color:var(--muted); font-size:.85rem; }

/* คอมเมนต์ */
.comment-form { display:flex; flex-direction:column; gap:10px; margin-bottom:20px; max-width:640px; }
.comment-form input, .comment-form textarea { margin:0; }
.star-input { font-size:1.6rem; color:var(--muted); cursor:pointer; user-select:none; display:inline-flex; gap:2px; }
.star-input .star:hover, .star-input .star.lit { color:#ffd36b; }
.comment-list { display:flex; flex-direction:column; gap:14px; }
.comment { padding:12px 14px; background:var(--surface); border:1px solid var(--border); border-radius:8px; }
.comment-head { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.comment-time { font-size:.8rem; }
.comment-text { margin:6px 0 0; color:#d0d5dd; white-space:pre-line; overflow-wrap:anywhere; }
.comment-del { margin-left:auto; }
.row-dim { opacity:.55; }

/* ---------- ป็อปอัปชวนสมัครสมาชิก ---------- */
.member-popup { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.82); display: flex; align-items: center; justify-content: center; padding: 20px; }
.member-popup-box { position: relative; max-width: 420px; width: 100%; text-align: center; background: var(--surface); border: 1px solid var(--accent); border-radius: 14px; padding: 30px 26px; }
.member-popup-icon { font-size: 2.4rem; }
.member-popup-box h2 { margin: 8px 0 12px; font-size: 1.25rem; }
.member-benefits { color: #ffd0d4; background: #3b1217; border-radius: 8px; padding: 10px 12px; font-size: .92rem; line-height: 1.7; }
.member-popup-actions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 10px; }
.member-popup-actions .btn { width: 100%; padding: 12px; }
.member-popup-close { position: absolute; top: 10px; right: 14px; background: none; border: none; color: var(--muted); font-size: 1.6rem; cursor: pointer; }
.member-popup-skip { background: none; border: none; color: var(--muted); font-size: .9rem; cursor: pointer; text-decoration: underline; }
.member-popup-skip:hover { color: var(--text); }
.member-login-link { font-weight: 600; }

/* ---------- กล่องชวนสมัครสมาชิก (หน้าล็อกอิน) ---------- */
.register-cta {
  margin-top: 22px; padding-top: 20px; border-top: 1px dashed var(--border);
  text-align: center;
}
.register-cta-text { margin: 0 0 10px; color: var(--muted); }
.register-btn {
  display: block; width: 100%; padding: 13px; font-size: 1rem;
  background: linear-gradient(135deg, #ff1f2b, #b80c15);
}
.register-btn:hover { filter: brightness(1.1); }
.register-benefits {
  margin: 12px 0 0; font-size: .88rem; color: #ffd0d4;
  background: #3b1217; border-radius: 8px; padding: 10px 12px; line-height: 1.7;
}

/* ---------- กล่องตั้งค่าฐานข้อมูลสมาชิก ---------- */
.auth-block { border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin: 4px 0 16px; }
.auth-block legend { padding: 0 8px; color: var(--muted); font-size: .85rem; }

/* คลิกโฆษณาก่อนเริ่มได้ทั้งพื้นที่ */
.ad-overlay.ad-clickable { cursor: pointer; }
.ad-overlay.ad-clickable .ad-link { pointer-events: none; }
