:root {
  --bg: #eef1f8;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #818cf8;
  --accent: #059669;
  --accent-light: #34d399;
  --danger: #dc2626;
  --warn: #d97706;
  --sidebar-bg: #1a1f2e;
  --sidebar-text: #a8b0c4;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06), 0 1px 1px rgba(17, 24, 39, 0.04);
  --shadow-md: 0 4px 10px rgba(17, 24, 39, 0.07), 0 2px 4px rgba(17, 24, 39, 0.05);
  --shadow-lg: 0 12px 28px rgba(17, 24, 39, 0.12), 0 4px 10px rgba(17, 24, 39, 0.06);
  --glow-primary: 0 8px 20px rgba(79, 70, 229, 0.35);
  --glow-accent: 0 8px 20px rgba(5, 150, 105, 0.3);
  --glow-danger: 0 8px 20px rgba(220, 38, 38, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Kanit", "Segoe UI", "Sarabun", "Noto Sans Thai", Tahoma, sans-serif;
  background: radial-gradient(1200px 600px at 0% 0%, #eef0fb 0%, var(--bg) 45%), var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  background: linear-gradient(195deg, #232a3d 0%, #171b28 65%, #12151f 100%);
  color: var(--sidebar-text);
  padding: 24px 16px;
  flex-shrink: 0;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.25);
  position: relative;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 24px;
  padding-left: 4px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 4px; }

.sidebar nav a {
  color: var(--sidebar-text);
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.sidebar nav a:hover { background: rgba(255,255,255,0.08); color: #fff; transform: translateX(2px); }
.sidebar nav a.active {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  box-shadow: var(--glow-primary);
}

.content {
  flex: 1;
  padding: 32px 40px;
  max-width: 1100px;
}

h1 {
  margin: 0 0 4px;
  font-size: 26px;
  position: relative;
  padding-left: 14px;
}
h1::before {
  content: "";
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 5px;
  border-radius: 4px;
  background: linear-gradient(180deg, var(--primary) 0%, #a855f7 100%);
}
h2 { margin: 0 0 16px; font-size: 18px; }
.subtitle { color: var(--muted); margin: 0 0 24px 14px; }

.panel {
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfe 100%);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-md);
  transition: box-shadow 0.2s ease;
}
.panel:hover { box-shadow: var(--shadow-lg); }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 28px;
}

.stat-card {
  border: none;
  border-radius: 18px;
  padding: 22px;
  text-decoration: none;
  display: block;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
  color: #fff;
}
.stat-card:hover { transform: translateY(-4px) scale(1.015); }

.stat-grid .stat-card:nth-child(1) {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 55%, #a855f7 100%);
  box-shadow: 0 10px 24px rgba(99, 102, 241, 0.35), var(--shadow-sm);
}
.stat-grid .stat-card:nth-child(2) {
  background: linear-gradient(135deg, #ec4899 0%, #f43f5e 55%, #fb7185 100%);
  box-shadow: 0 10px 24px rgba(236, 72, 153, 0.32), var(--shadow-sm);
}
.stat-grid .stat-card:nth-child(3) {
  background: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 55%, #22d3ee 100%);
  box-shadow: 0 10px 24px rgba(14, 165, 233, 0.32), var(--shadow-sm);
}
.stat-grid .stat-card:nth-child(4) {
  background: linear-gradient(135deg, #f59e0b 0%, #f97316 55%, #fb923c 100%);
  box-shadow: 0 10px 24px rgba(245, 158, 11, 0.32), var(--shadow-sm);
}
.stat-card::after {
  content: "";
  position: absolute;
  top: -30%; right: -20%;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
}
.stat-number {
  font-size: 32px;
  font-weight: 700;
  color: #fff;
  position: relative;
  z-index: 1;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
.stat-label { color: rgba(255,255,255,0.85); font-size: 13px; margin-top: 4px; position: relative; z-index: 1; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  background: linear-gradient(180deg, #f8f9fd 0%, #f1f2f9 100%);
}
.table tbody tr { transition: background 0.15s ease; }
.table tbody tr:hover { background: #f6f7fe; }
.table td.actions { white-space: nowrap; text-align: right; }
.table td.actions form { display: inline-block; margin: 0 0 0 6px; vertical-align: middle; }
.media-card form.media-delete-form { display: inline-block; margin: 0; }
.table td.truncate { color: var(--muted); }

.empty { color: var(--muted); padding: 16px 0; }

.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.form-row input[type=text], .form-row input[type=date], .form-row select, .form-row textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.form-row input[type=text]:focus, .form-row input[type=date]:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.form-row textarea { resize: vertical; }
.hint { color: var(--muted); font-size: 12px; margin: 6px 0 0; }
.form-actions { display: flex; gap: 8px; margin-top: 8px; }

.inline-form .form-row { display: inline-block; width: 48%; vertical-align: top; }

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.btn:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--glow-primary);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark) 0%, #6d28d9 100%); box-shadow: var(--glow-primary); }
.btn-accent {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-light) 100%);
  border-color: transparent;
  color: #fff;
  box-shadow: var(--glow-accent);
}
.btn-accent:hover { box-shadow: var(--glow-accent); }
.btn-danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: linear-gradient(135deg, var(--danger) 0%, #ef4444 100%); color: #fff; box-shadow: var(--glow-danger); }
.btn-warn { background: #fff; color: var(--warn); border-color: var(--warn); }
.btn-active { background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%); color: #fff; border-color: transparent; box-shadow: var(--glow-primary); }

.flash {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 14px;
  box-shadow: var(--shadow-sm);
}
.flash.success { background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%); color: #166534; }
.flash.error { background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%); color: #991b1b; }

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.media-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
  text-align: center;
  background: linear-gradient(180deg, #ffffff 0%, #fafbff 100%);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.media-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.media-card img, .media-card video {
  width: 100%;
  height: 100px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.06);
}
.media-name {
  font-size: 12px;
  margin: 8px 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.media-rename-form {
  display: flex;
  gap: 4px;
  margin: 8px 0;
}
.media-name-input {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
}
.media-name-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,0.15); }
.media-rename-form .btn { padding: 5px 9px; }

.table-thumb-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.table-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
}
.table-thumb-name {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.bg-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 10px;
  margin-top: 4px;
  max-height: 340px;
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #fafbff;
}
.bg-picker-item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 6px;
  border: 2px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.bg-picker-item:hover { border-color: var(--primary-light); transform: translateY(-1px); }
.bg-picker-item:has(input:checked) { border-color: var(--primary); box-shadow: var(--glow-primary); }
.bg-picker-item input { position: absolute; opacity: 0; width: 0; height: 0; }
.bg-picker-thumb {
  width: 100%;
  height: 72px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
  display: block;
}
.bg-picker-none {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: var(--muted);
  background: linear-gradient(180deg, #f3f4f8 0%, #e9ebf3 100%);
}
.bg-picker-caption {
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
  color: var(--muted);
}

/* Compact variant used inside the narrow "เพิ่มรายการ" boxes on the playlist page */
.bg-picker-compact {
  grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
  max-height: 220px;
  gap: 8px;
}
.bg-picker-compact .bg-picker-thumb { height: 48px; }
.bg-picker-compact .bg-picker-caption { font-size: 10px; }

.add-item-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.add-item-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #fafbff 100%);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.add-item-box:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.add-item-box label { font-size: 13px; font-weight: 600; }
.add-item-box select, .add-item-box input, .add-item-box textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
}

/* ===== Help / guide page ===== */
.guide-toc {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
  margin: 0 0 8px;
  padding: 0;
  list-style: none;
}
.guide-toc a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f7f8ff 100%);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: box-shadow 0.15s ease, transform 0.15s ease, border-color 0.15s ease;
}
.guide-toc a:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--primary-light); }
.guide-toc .num {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.guide-step {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 24px;
  align-items: start;
  padding-bottom: 28px;
  margin-bottom: 28px;
  border-bottom: 1px dashed var(--border);
  scroll-margin-top: 16px;
}
.guide-step:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.guide-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary) 0%, #7c3aed 100%);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  box-shadow: var(--glow-primary);
  margin-right: 10px;
}
.guide-step h2 {
  display: flex;
  align-items: center;
  margin: 0 0 12px;
  font-size: 18px;
}
.guide-step ol, .guide-step ul { margin: 0 0 10px; padding-left: 20px; }
.guide-step li { margin-bottom: 6px; line-height: 1.55; }
.guide-step p { line-height: 1.6; }
.guide-note {
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  border: 1px solid #ddd6fe;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #4338ca;
  margin-top: 10px;
}
.guide-warn {
  background: linear-gradient(135deg, #fff7ed 0%, #fef3c7 100%);
  border: 1px solid #fde68a;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #92400e;
  margin-top: 10px;
}
.guide-shot {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  background: #0f1115;
}
.guide-shot img { display: block; width: 100%; height: auto; }
.guide-shot-caption {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  margin-top: 8px;
}
@media (max-width: 860px) {
  .guide-step { grid-template-columns: 1fr; }
}

.guide-faq { display: flex; flex-direction: column; gap: 10px; }
.guide-faq details {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  background: #fff;
}
.guide-faq summary {
  cursor: pointer;
  font-weight: 700;
  font-size: 14px;
}
.guide-faq p { margin: 10px 0 0; color: var(--muted); line-height: 1.6; font-size: 13px;
}
