/* ==========================================
   KidsTube - Stylesheet
   Playful, Safe, Kids-First Design
   ========================================== */

:root {
  --primary: #FF6B6B;
  --primary-dark: #e85555;
  --secondary: #FFE066;
  --accent: #66EDCF;
  --accent2: #A78BFA;
  --bg: #FFF8F0;
  --bg2: #ffffff;
  --card-bg: #ffffff;
  --text: #2D2D2D;
  --text-light: #777;
  --border: #f0e6dc;
  --shadow: 0 4px 20px rgba(255,107,107,0.12);
  --shadow-hover: 0 8px 30px rgba(255,107,107,0.25);
  --radius: 20px;
  --radius-sm: 12px;
  --header-h: 64px;
}

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

html, body {
  height: 100%;
  overflow: hidden; /* player handles its own scroll */
}

body {
  font-family: 'Nunito', sans-serif;
  background: #000;
  color: var(--text);
  overflow-x: hidden;
}

/* ==================== HEADER ==================== */
#main-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: linear-gradient(to bottom, rgba(0,0,0,0.55) 0%, transparent 100%);
  box-shadow: none;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: var(--header-h);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.logo-icon {
  width: 38px; height: 38px;
  background: rgba(255,255,255,0.2);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  padding: 4px;
  transition: transform 0.2s;
}
.logo:hover .logo-icon { transform: scale(1.1) rotate(-5deg); }

#app-name-header {
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  color: white;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
}

.search-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 40px; height: 40px;
  border-radius: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.search-btn:hover { background: rgba(255,255,255,0.3); }
.search-btn svg { width: 20px; height: 20px; }

.search-bar {
  display: none;
  padding: 0 16px 12px;
  gap: 8px;
  align-items: center;
}
.search-bar.open { display: flex; }
.search-bar input {
  flex: 1;
  padding: 10px 16px;
  border: none;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  background: rgba(255,255,255,0.95);
  outline: none;
}
.search-bar button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 36px; height: 36px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
}

/* ==================== PAGES ==================== */
#app { padding-top: 0; }

.page { display: none; min-height: calc(100vh - var(--header-h)); }
.page.active { display: block; }

/* ==================== CATEGORIES ==================== */
.categories-scroll {
  overflow-x: auto;
  padding: 16px 16px 0;
  -webkit-overflow-scrolling: touch;
}
.categories-scroll::-webkit-scrollbar { display: none; }
.categories {
  display: flex;
  gap: 8px;
  padding-bottom: 4px;
  width: max-content;
}

.cat-btn {
  padding: 8px 18px;
  border: 2.5px solid var(--border);
  background: white;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  color: var(--text-light);
}
.cat-btn:hover { border-color: var(--primary); color: var(--primary); }
.cat-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 4px 12px rgba(255,107,107,0.35);
}

/* ==================== VIDEO GRID ==================== */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  padding: 14px 16px 24px;
}

@media (min-width: 600px) {
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}
@media (min-width: 900px) {
  .video-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 18px; }
}

.video-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  border: 2px solid transparent;
}
.video-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: var(--shadow-hover);
  border-color: var(--primary);
}
.video-card:active { transform: scale(0.97); }

.video-thumb {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  display: block;
  background: linear-gradient(135deg, #ffe4e4, #fff0cc);
}

.thumb-placeholder {
  width: 100%;
  aspect-ratio: 9/16;
  background: linear-gradient(135deg, #ffe4e4 0%, #fff0cc 50%, #e4f0ff 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.thumb-placeholder .play-icon {
  width: 48px; height: 48px;
  background: var(--primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.thumb-placeholder .play-icon svg {
  width: 22px; height: 22px; fill: white; margin-left: 3px;
}

.video-info {
  padding: 10px 12px 12px;
}
.video-info h3 {
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.3;
  margin-bottom: 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.video-category {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  background: #fff0f0;
  padding: 2px 8px;
  border-radius: 50px;
  display: inline-block;
}

/* ==================== LOADING ==================== */
.loading {
  grid-column: 1/-1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 0;
  color: var(--text-light);
  font-weight: 700;
}
.spinner {
  width: 48px; height: 48px;
  border: 4px solid #ffdddd;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  grid-column: 1/-1;
  text-align: center;
  padding: 48px 24px;
}
.empty-state .emoji { font-size: 4rem; margin-bottom: 12px; }
.empty-state p { font-size: 1.1rem; font-weight: 700; color: var(--text-light); }

/* ==================== PLAYER ==================== */
#page-player { background: #1a1a2e; min-height: 100vh; }

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.1);
  border: none;
  color: white;
  padding: 10px 16px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}
.back-btn:hover { background: rgba(255,255,255,0.15); }
.back-btn svg { width: 20px; height: 20px; }

.player-container { padding: 0 0 32px; }

.player-frame {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
  aspect-ratio: 9/16;
  background: black;
}
.player-frame iframe {
  width: 100%; height: 100%;
  border: none;
  display: block;
}

.player-info {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 20px 0;
  color: white;
}
.player-info h2 {
  font-size: 1.25rem;
  font-weight: 800;
  margin-bottom: 8px;
  line-height: 1.3;
}
.player-category {
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--primary);
  color: white;
  padding: 3px 12px;
  border-radius: 50px;
  display: inline-block;
  margin-bottom: 10px;
}
#player-description { font-size: 0.9rem; color: rgba(255,255,255,0.7); line-height: 1.5; }

.related-section {
  max-width: 600px;
  margin: 24px auto 0;
  padding: 0 20px;
}
.related-section h3 { color: white; font-size: 1rem; font-weight: 800; margin-bottom: 12px; }

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.related-card {
  background: rgba(255,255,255,0.08);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: background 0.2s;
}
.related-card:hover { background: rgba(255,255,255,0.14); }
.related-card img, .related-card .related-thumb {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  background: rgba(255,255,255,0.05);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.related-card p { font-size: 0.72rem; color: rgba(255,255,255,0.8); padding: 6px 8px; font-weight: 600; line-height: 1.2; }

/* ==================== ADMIN LOGIN ==================== */
#page-admin-login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--header-h));
  padding: 24px;
}

.admin-login-box {
  background: white;
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.1);
  text-align: center;
}
.admin-logo { font-size: 3rem; margin-bottom: 12px; }
.admin-login-box h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.8rem;
  color: var(--primary);
  margin-bottom: 4px;
}
.admin-login-box > p { color: var(--text-light); margin-bottom: 24px; }

/* ==================== ADMIN DASHBOARD ==================== */
#page-admin { background: #f4f6fa; }

.admin-shell {
  display: flex;
  min-height: calc(100vh - var(--header-h));
}

.admin-sidebar {
  width: 220px;
  background: white;
  border-right: 2px solid #f0f0f5;
  padding: 20px 12px;
  flex-shrink: 0;
}

@media (max-width: 600px) {
  .admin-sidebar {
    width: 60px;
    padding: 16px 8px;
  }
  .admin-sidebar .admin-brand,
  .admin-sidebar .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 10px; font-size: 1.2rem; }
}

.admin-brand {
  font-family: 'Fredoka One', cursive;
  color: var(--primary);
  font-size: 1.1rem;
  padding: 8px 12px 20px;
}

.admin-sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--text-light);
  text-align: left;
  transition: all 0.15s;
  width: 100%;
}
.nav-item:hover { background: #fff0f0; color: var(--primary); }
.nav-item.active { background: var(--primary); color: white; }
.nav-item.logout { margin-top: 16px; color: #e55; }
.nav-item.logout:hover { background: #fff0f0; }

.admin-content { flex: 1; padding: 24px; overflow-y: auto; }

.admin-tab { display: none; }
.admin-tab.active { display: block; }

.admin-tab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.admin-tab-header h2 { font-size: 1.4rem; font-weight: 900; }
.admin-tab-header input {
  padding: 8px 14px;
  border: 2px solid var(--border);
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  outline: none;
  font-size: 0.9rem;
}
.admin-tab-header input:focus { border-color: var(--primary); }

.admin-tab h2 { font-size: 1.4rem; font-weight: 900; margin-bottom: 20px; }

.admin-video-item {
  background: white;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
  border: 2px solid transparent;
  transition: border-color 0.15s;
}
.admin-video-item:hover { border-color: var(--primary); }
.admin-video-item img {
  width: 50px; height: 50px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
  background: #f0f0f0;
}
.admin-video-item .item-info { flex: 1; min-width: 0; }
.admin-video-item .item-info h4 { font-weight: 800; font-size: 0.92rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.admin-video-item .item-info span { font-size: 0.78rem; color: var(--text-light); }
.item-actions { display: flex; gap: 6px; flex-shrink: 0; }

.badge-approved { color: #22c55e; font-size: 0.75rem; font-weight: 700; background: #f0fdf4; padding: 2px 8px; border-radius: 50px; }
.badge-hidden { color: #f59e0b; font-size: 0.75rem; font-weight: 700; background: #fffbeb; padding: 2px 8px; border-radius: 50px; }

/* ==================== FORMS ==================== */
.admin-form { max-width: 520px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 700; font-size: 0.88rem; margin-bottom: 6px; color: var(--text); }
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 11px 14px;
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'Nunito', sans-serif;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  background: white;
}
.form-group input[type="color"] { height: 46px; padding: 4px 8px; cursor: pointer; }
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { min-height: 90px; resize: vertical; }
.form-group small { display: block; color: var(--text-light); font-size: 0.78rem; margin-top: 4px; }
.form-group input[type="checkbox"] { width: auto; margin-right: 8px; }

/* ==================== BUTTONS ==================== */
.btn-primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-2px); box-shadow: 0 6px 16px rgba(255,107,107,0.4); }

.btn-secondary {
  background: #f0f0f5;
  color: var(--text);
  border: none;
  padding: 10px 20px;
  border-radius: 50px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover { background: #e0e0e8; }

.btn-edit, .btn-delete, .btn-toggle {
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-edit { background: #eff6ff; color: #3b82f6; }
.btn-edit:hover { background: #3b82f6; color: white; }
.btn-delete { background: #fff5f5; color: #ef4444; }
.btn-delete:hover { background: #ef4444; color: white; }
.btn-toggle { background: #f0fdf4; color: #22c55e; }
.btn-toggle:hover { background: #22c55e; color: white; }
.btn-toggle.hide { background: #fffbeb; color: #f59e0b; }
.btn-toggle.hide:hover { background: #f59e0b; color: white; }

/* ==================== MESSAGES ==================== */
.error-msg { color: #ef4444; font-size: 0.85rem; font-weight: 700; margin: 8px 0; min-height: 20px; }
.success-msg { color: #22c55e; font-size: 0.85rem; font-weight: 700; margin: 8px 0; min-height: 20px; }

/* ==================== MODAL ==================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-box {
  background: white;
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h3 { font-size: 1.2rem; font-weight: 900; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn-secondary, .modal-actions .btn-primary { width: auto; flex: 1; }

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ffcccc; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ==================== ANIMATIONS ==================== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.video-card { animation: fadeInUp 0.3s ease both; }
.video-card:nth-child(1) { animation-delay: 0.05s; }
.video-card:nth-child(2) { animation-delay: 0.10s; }
.video-card:nth-child(3) { animation-delay: 0.15s; }
.video-card:nth-child(4) { animation-delay: 0.20s; }
.video-card:nth-child(5) { animation-delay: 0.25s; }
.video-card:nth-child(6) { animation-delay: 0.30s; }

/* ==================== SHORTS PLAYER ==================== */

/* Player fullscreen menutupi seluruh layar */
#page-player {
  position: fixed !important;
  top: 0 !important; left: 0 !important;
  right: 0 !important; bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: #000;
  z-index: 50;
  overflow: hidden;
}

/* Empty state */
.empty-shorts {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: rgba(255,255,255,0.6);
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}
.empty-shorts .emoji { font-size: 4rem; }
.empty-shorts p { font-size: 1.1rem; text-align: center; line-height: 1.5; }

.shorts-back-btn { display: none; }

/* Scroll container — sama persis dengan #page-player */
.shorts-scroll {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.shorts-scroll::-webkit-scrollbar { display: none; }

/* Setiap slide = satu layar penuh */
.short-slide {
  width: 100%;
  height: 100vh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  position: relative;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* === WRAPPER VIDEO ===
   HP portrait  : lebar penuh, tinggi penuh (video memenuhi layar)
   Laptop/Desktop: tinggi penuh, lebar = tinggi × (9/16) → portrait di tengah
*/
.short-video-wrap {
  position: relative;
  /* tinggi selalu penuh */
  height: 100%;
  /* lebar = min(lebar layar, tinggi-layar × 9/16) → portrait */
  width: 100%;
  max-width: calc(100vh * 9 / 16);
}

/* Iframe mengisi penuh wrapper — TIDAK pakai aspect-ratio agar tidak confict */
.short-iframe {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  border: none;
  display: block;
  background: #000;
}

/* Overlay info di bawah video */
.short-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 20px 16px 28px;
  background: linear-gradient(to top, rgba(0,0,0,0.75) 0%, transparent 100%);
  pointer-events: none;
}

.short-info { margin-bottom: 6px; }

.short-cat {
  display: none;
}

.short-title {
  color: #fff;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.3;
  text-shadow: 0 1px 4px rgba(0,0,0,0.5);
  margin-bottom: 4px;
}

.short-desc {
  color: rgba(255,255,255,0.75);
  font-size: 0.82rem;
  line-height: 1.4;
}

/* Penanda nomor video (misal: 3 / 12) */
.short-counter {
  position: absolute;
  top: 16px;
  right: 14px;
  background: rgba(0,0,0,0.5);
  color: rgba(255,255,255,0.85);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 50px;
  pointer-events: none;
}

/* Hint scroll pertama kali */
.short-slide:first-child::after {
  content: "Gulir ke atas ↑ untuk video berikutnya";
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.7);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 50px;
  white-space: nowrap;
  pointer-events: none;
  animation: fadeHint 4s ease 1.5s forwards;
  opacity: 0;
}

@keyframes fadeHint {
  0%   { opacity: 0; transform: translateX(-50%) translateY(0); }
  15%  { opacity: 1; }
  75%  { opacity: 1; transform: translateX(-50%) translateY(-6px); }
  100% { opacity: 0; }
}

/* Desktop: styling tambahan */
@media (min-width: 600px) {
  .shorts-back-btn { top: 20px; left: 20px; }
}
