
* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  background: #020617;
  color: #e5e7eb;
}

a {
  color: inherit;
  text-decoration: none;
}

.navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.25rem;
  background: #020617;
  border-bottom: 1px solid #1f2937;
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
}

.nav-right a {
  margin-left: 1rem;
  font-size: 0.9rem;
  opacity: 0.8;
}

.nav-right a:hover {
  opacity: 1;
}

.container {
  max-width: 1100px;
  margin: 1.5rem auto;
  padding: 0 1rem;
}

.back-row {
  margin-bottom: 0.5rem;
}

.back-btn {
  border-color: #4b5563;
  color: #e5e7eb;
}

.back-btn:hover {
  background-color: #4b5563;
  color: #ffffff;
}

/* Footer */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.8rem;
  color: #9ca3af;
  border-top: 1px solid #1f2937;
  margin-top: 2rem;
  background: #020617;
}

h1, h2 {
  margin-bottom: 0.75rem;
}

/* Flash */
.flash-container {
  margin-bottom: 1rem;
}

.flash {
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
}

.flash.success {
  background: #064e3b;
  color: #a7f3d0;
}

.flash.error {
  background: #7f1d1d;
  color: #fecaca;
}

.flash.info {
  background: #1d4ed8;
  color: #bfdbfe;
}

/* Grid cards */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.card {
  background: #020617;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
}

.thumb {
  width: 100%;
  height: auto;
  max-height: 260px;
  object-fit: contain;
  background: #111827;
  display: block;
}

.thumb.placeholder,
.series-thumb.placeholder,
.episode-thumb.placeholder-small {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #6b7280;
  font-size: 0.8rem;
}

/* Episode thumb small */
.episode-thumb {
  width: 72px;
  height: 72px;
  border-radius: 0.5rem;
  object-fit: cover;
  background: #111827;
}

.episode-thumb-wrapper {
  flex: 0 0 72px;
  margin-right: 0.75rem;
}

.card-body {
  padding: 0.75rem 0.9rem 1rem;
}

.card-title {
  font-size: 1rem;
  margin: 0 0 0.4rem;
}

.card-text {
  font-size: 0.85rem;
  color: #9ca3af;
  margin-bottom: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  border: 1px solid #1d4ed8;
  font-size: 0.85rem;
  background: transparent;
  color: #bfdbfe;
  cursor: pointer;
  text-align: center;
}

.btn.primary {
  background: #1d4ed8;
  color: #e5e7eb;
}

.btn.danger {
  border-color: #b91c1c;
  color: #fecaca;
}

.btn.danger:hover {
  background: #b91c1c;
  color: #fee2e2;
}

.btn:hover {
  filter: brightness(1.1);
}

/* Forms */
.form {
  max-width: 540px;
  background: #020617;
  border-radius: 0.75rem;
  padding: 1rem 1.2rem 1.3rem;
  border: 1px solid #1f2937;
}

.form label {
  display: block;
  font-size: 0.85rem;
  margin: 0.5rem 0 0.25rem;
}

.form input,
.form textarea {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 0.5rem;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  font-size: 0.9rem;
}

.form input:focus,
.form textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

.divider {
  margin: 1rem 0;
  border: none;
  border-top: 1px solid #1f2937;
}

.form-section-title {
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

/* Mode selector — pill toggle buttons */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.mode-selector label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  border: 1.5px solid #2d3550;
  background: #131826;
  cursor: pointer;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s;
}

.mode-selector label:has(input:checked) {
  border-color: #4a6cf7;
  background: #1a2240;
  color: #fff;
}

.mode-selector input[type="radio"] {
  accent-color: #4a6cf7;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.mode-block {
  margin-top: 0.75rem;
}

.hint {
  font-size: 0.75rem;
  color: #9ca3af;
}

/* Series header */

.series-header {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.series-thumb-wrapper {
  flex: 0 0 180px;
}

/* ปกเรื่องในหน้ารายละเอียด: รองรับทั้งแนวนอนและแนวตั้ง */
.series-thumb {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  max-height: 260px;
  object-fit: contain; /* เห็นรูปครบ ไม่ตัดหัว/หาง */
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  background: #111827;
}

.series-info {
  flex: 1;
}

.episode-list,
.episode-list-admin {
  list-style: none;
  padding: 0;
  margin: 0;
}

.episode-item,
.episode-item-admin {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  background: #020617;
  margin-bottom: 0.5rem;
}

.episode-main {
  flex: 1;
  min-width: 0;
}

.episode-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.episode-desc {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 0.25rem;
}

.episode-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex-shrink: 0;
  align-self: center;
  margin-left: 0.5rem;
}

.episode-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-width: 0;
}

.episode-content .episode-title {
  flex: 1;
  min-width: 0;
}

.episode-item-admin .episode-actions {
  flex-wrap: wrap;
  flex-direction: row;
  gap: 0.4rem;
  max-width: 55%;
}

.episode-item-admin .episode-main {
  min-width: 120px;
  max-width: 40%;
}

/* Admin series list */
.series-admin-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.series-admin-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.7rem 0.8rem;
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  background: #020617;
  margin-bottom: 0.5rem;
}

.series-admin-main {
  max-width: 70%;
}

.series-admin-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.series-admin-desc {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-top: 0.25rem;
}

.series-admin-actions {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

/* Watch page */
.breadcrumb {
  font-size: 0.8rem;
  color: #9ca3af;
  margin-bottom: 0.75rem;
}

.breadcrumb a {
  color: #93c5fd;
}

.watch-page {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(280px, 1fr);
  gap: 1rem;
  align-items: start;
}

.player-column {
  min-width: 0;
}

.player-wrapper {
  background: #020617;
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  padding: 0.75rem;
  overflow: hidden;
}

.video-shell {
  width: 100%;
  aspect-ratio: 16 / 9;
  max-height: min(70vh, 760px);
  background: #000;
  border-radius: 0.75rem;
  overflow: hidden;
}

.video-player {
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  object-fit: contain;
}

.video-info {
  background: #020617;
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  padding: 1rem;
}

.video-info .meta {
  font-size: 0.8rem;
  color: #9ca3af;
}

/* Sections on backup page */
.backup-section {
  margin-bottom: 1.5rem;
}

/* Mobile */
@media (max-width: 768px) {
  .watch-page {
    grid-template-columns: 1fr;
  }

  .navbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .nav-right a {
    margin-left: 0.5rem;
  }

  .series-header {
    flex-direction: column;
  }

  .episode-main,
  .series-admin-main {
    max-width: 100%;
  }
}


/* Search bar at top */
.search-form {
  max-width: 640px;
  margin: 0.75rem auto 0.5rem;
  display: flex;
  gap: 0.5rem;
  padding: 0 1rem;
}

.search-input {
  flex: 1;
  padding: 0.5rem 0.75rem;
  border-radius: 999px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
}

.search-input::placeholder {
  color: #6b7280;
}

.search-btn {
  border-radius: 999px;
}


/* Navbar center brand + hamburger */
.navbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  background: #020617;
  border-bottom: 1px solid #1f2937;
  position: sticky;
  top: 0;
  z-index: 20;
}

.nav-center {
  flex: 0 0 auto;
}

.nav-right {
  position: absolute;
  right: 1.25rem;
  display: flex;
  align-items: center;
}

/* Hamburger button */
.menu-toggle {
  position: absolute;
  left: 1.25rem;
  background: transparent;
  border: none;
  padding: 0;
  width: 28px;
  height: 24px;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  cursor: pointer;
}

.menu-toggle span {
  display: block;
  height: 3px;
  border-radius: 999px;
  background: #e5e7eb;
}

/* Side menu */
.side-menu-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease-out;
  z-index: 30;
}

.side-menu-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.side-menu {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  max-width: 75%;
  height: 100%;
  background: #020617;
  border-right: 1px solid #1f2937;
  transform: translateX(-100%);
  transition: transform 0.2s ease-out;
  z-index: 40;
  display: flex;
  flex-direction: column;
}

.side-menu.open {
  transform: translateX(0);
}

.side-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid #1f2937;
}

.side-menu-title {
  font-weight: 600;
}

.side-menu-close {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 1.2rem;
  cursor: pointer;
}

.side-menu-links {
  display: flex;
  flex-direction: column;
  padding: 0.5rem 0.75rem;
}

.side-menu-links a {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 0.95rem;
}

.side-menu-links a:hover {
  background: #111827;
}
.side-menu-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
  margin: 0.5rem 0.75rem 0.25rem;
}

.side-menu-admin-box {
  border-radius: 0.75rem;
  border: 1px solid #1f2937;
  padding: 0.4rem 0.4rem;
  margin: 0.25rem 0.75rem 0.5rem;
  background: #020617;
}

.side-menu-admin-box a {
  display: block;
  margin-bottom: 0.2rem;
  text-align: left;
}

.side-menu-admin-box a:last-child {
  margin-bottom: 0;
}

.side-menu-logout {
  color: #f97373;
}


/* History list */
.history-list {
  list-style: none;
  padding-left: 0;
  margin: 0.5rem 0 0;
}

.history-item {
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}

.history-item a {
  color: #bfdbfe;
}

@media (max-width: 1024px) {
  .watch-page {
    grid-template-columns: 1fr;
  }

  .video-shell {
    max-height: min(65vh, 620px);
  }
}

@media (max-width: 768px) {
  .player-wrapper {
    padding: 0.5rem;
  }

  .video-shell {
    border-radius: 0.5rem;
    max-height: none;
  }

  .episode-item,
  .episode-item-admin {
    align-items: center;
    gap: 0.75rem;
  }

  .episode-actions {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .search-form {
    flex-direction: column;
  }

  .search-btn {
    width: 100%;
  }
}


/* ═══════════════════════════════════════════════════
   Admin Card (container for forms)
══════════════════════════════════════════════════════ */
.admin-card {
  background: #0d1224;
  border: 1px solid #1f2937;
  border-radius: 1rem;
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.admin-card-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.85rem 1.1rem;
  background: #111827;
  border-bottom: 1px solid #1f2937;
}

.admin-card-icon { font-size: 1rem; }

.admin-card-title {
  font-size: 1rem;
  font-weight: 600;
  color: #e5e7eb;
}

/* ═══════════════════════════════════════════════════
   Episode Form (inside admin-card)
══════════════════════════════════════════════════════ */
.ep-form {
  padding: 1rem 1.1rem 1.3rem;
}

.ep-form label {
  display: block;
  font-size: 0.82rem;
  color: #9ca3af;
  margin: 0.65rem 0 0.25rem;
}

.ep-form input[type="text"],
.ep-form input[type="number"],
.ep-form input[type="url"],
.ep-form input[type="file"],
.ep-form textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid #374151;
  background: #020617;
  color: #e5e7eb;
  font-size: 0.9rem;
}

.ep-form input:focus,
.ep-form textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

.ep-form-row {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}

.ep-form-col-sm { flex: 0 0 110px; }
.ep-form-col-lg { flex: 1; }

.ep-cover-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.ep-cover-col { flex: 1; min-width: 200px; }

.ep-divider {
  margin: 1rem 0;
  border: none;
  border-top: 1px solid #1f2937;
}

.ep-section-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: #e5e7eb;
  margin: 0 0 0.6rem;
}

.ep-hint {
  font-size: 0.78rem;
  color: #6b7280;
  margin: 0.35rem 0 0;
}

.ep-submit-btn {
  margin-top: 1rem;
  width: 100%;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  border-radius: 0.6rem;
}

/* ═══════════════════════════════════════════════════
   Mode Selector — new clean style
══════════════════════════════════════════════════════ */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-bottom: 0.75rem;
}

.mode-opt {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.9rem;
  border-radius: 0.65rem;
  border: 1.5px solid #1f2937;
  background: #0a0f1e;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.mode-opt:has(input:checked) {
  border-color: #3b82f6;
  background: #0f1f3d;
}

.mode-opt input[type="radio"] {
  accent-color: #3b82f6;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.mode-opt-content {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.mode-opt-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #e5e7eb;
}

.mode-opt-desc {
  font-size: 0.75rem;
  color: #6b7280;
}

/* ═══════════════════════════════════════════════════
   Episode List Cards
══════════════════════════════════════════════════════ */
.ep-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ep-card {
  background: #0d1224;
  border: 1px solid #1f2937;
  border-radius: 0.85rem;
  overflow: hidden;
  transition: border-color 0.15s;
}

.ep-card:hover { border-color: #374151; }

.ep-card--inactive {
  opacity: 0.65;
  border-color: #374151;
  border-style: dashed;
}

.ep-card-top {
  display: flex;
  gap: 0.85rem;
  padding: 0.85rem 0.9rem 0.7rem;
  align-items: flex-start;
}

.ep-card-thumb {
  flex: 0 0 72px;
}

.ep-thumb-img {
  width: 72px;
  height: 72px;
  border-radius: 0.5rem;
  object-fit: cover;
  background: #111827;
  display: block;
}

.ep-thumb-placeholder {
  width: 72px;
  height: 72px;
  border-radius: 0.5rem;
  background: #111827;
  border: 1px dashed #374151;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: #6b7280;
  text-align: center;
  line-height: 1.3;
}

.ep-card-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.ep-card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: #e5e7eb;
  line-height: 1.35;
}

.ep-card-desc {
  font-size: 0.78rem;
  color: #6b7280;
  line-height: 1.4;
}

/* Status badges */
.ep-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  line-height: 1.4;
}

.ep-badge--processing {
  background: #422006;
  color: #fed7aa;
}

.ep-badge--error {
  background: #450a0a;
  color: #fca5a5;
}

.ep-badge--hidden {
  background: #1c1c2e;
  color: #a5b4fc;
}

/* Action buttons row */
.ep-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0 0.9rem 0.85rem;
}

.ep-btn {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  background: transparent;
  color: #e5e7eb;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}

.ep-btn--watch {
  border-color: #1d4ed8;
  color: #93c5fd;
}
.ep-btn--watch:hover { background: #1d3a6e; }

.ep-btn--edit {
  border-color: #4b5563;
  color: #d1d5db;
}
.ep-btn--edit:hover { background: #374151; }

.ep-btn--toggle {
  border-color: #92400e;
  color: #fbbf24;
}
.ep-btn--toggle:hover { background: #451a03; }

.ep-btn--retry {
  border-color: #065f46;
  color: #6ee7b7;
}
.ep-btn--retry:hover { background: #022c22; }

.ep-btn--delete {
  border-color: #7f1d1d;
  color: #fca5a5;
}
.ep-btn--delete:hover { background: #450a0a; }

/* Empty state */
.ep-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #6b7280;
  font-size: 0.9rem;
  background: #0d1224;
  border: 1px dashed #1f2937;
  border-radius: 0.85rem;
}

/* ── YouTube Download Mode Options (admin_episodes / admin_edit_episode) ── */
.yt-dl-options {
  margin-top: 0.9rem;
  padding: 1rem 1.1rem;
  background: #0e1320;
  border: 1px solid #232a40;
  border-radius: 8px;
}

.yt-mode-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.yt-mode-opt {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
  padding: 0.5rem 0.85rem;
  border-radius: 6px;
  background: #141926;
  border: 1px solid #252e44;
  transition: border-color 0.15s;
}
.yt-mode-opt:hover { border-color: #4a6fa5; }
.yt-mode-opt input[type="radio"] { accent-color: #4a8df8; }
.yt-mode-opt span { font-size: 0.91rem; color: #d0d8f0; }


/* === Responsive + media compatibility improvements === */
:root {
  color-scheme: dark;
}

html, body {
  min-height: 100%;
  overflow-x: hidden;
}

img, video, iframe, audio {
  max-width: 100%;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid #1f2937;
  vertical-align: top;
  text-align: left;
}

.table thead th {
  position: sticky;
  top: 0;
  background: #020617;
  z-index: 1;
}

.video-shell.embed-shell {
  aspect-ratio: 16 / 9;
}

.embed-player {
  width: 100%;
  height: 100%;
  display: block;
  border: 0;
  background: #000;
}

.audio-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  min-height: 120px;
  background: #000;
  border-radius: 0.75rem;
}

.audio-player {
  width: 100%;
}

.card, .form, .video-info, .player-wrapper, .admin-card, .ep-card, .settings-card {
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.2);
}

.container {
  width: min(1100px, calc(100vw - 1rem));
}

.navbar,
.footer {
  width: 100%;
}

@media (max-width: 640px) {
  .container {
    margin: 1rem auto;
    padding: 0 0.5rem;
  }

  .brand {
    font-size: 1rem;
  }

  .card-body, .video-info, .form, .admin-card, .ep-form {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .table th,
  .table td {
    padding: 0.55rem 0.6rem;
    font-size: 0.85rem;
  }

  .menu-toggle {
    left: 0.75rem;
  }

  .nav-right {
    right: 0.75rem;
  }

  .side-menu {
    width: min(280px, 85vw);
  }
}

@media (max-width: 480px) {
  .watch-page {
    gap: 0.75rem;
  }

  .video-shell {
    aspect-ratio: 16 / 9;
    max-height: 56vh;
  }

  .audio-shell {
    min-height: 96px;
    padding: 0.75rem;
  }
}
