/* ============================================================
   Chaipa — Online M3U Player (web)
   Catalog UI that mirrors the Android TV app's look, lifted from
   screenshot-gen/app.css and made fluid/responsive. Reuses the
   marketing site's CSS variables (styles.css :root). All classes are
   cp-* prefixed so component styles work both inside the catalog
   (.cplayer) and inside the body-level modals.
   ============================================================ */

/* ---------- loader panel (demo / upload / paste / url) ---------- */
.cp-loader {
  background: linear-gradient(180deg, rgba(30,29,40,0.5), rgba(20,20,26,0.5));
  border: 1px solid var(--border); border-radius: var(--r-card);
  padding: clamp(20px, 3vw, 34px); margin-top: 8px;
}
.cp-tabs { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.cp-tab {
  font-family: var(--font-display); font-size: 0.9rem; font-weight: 500;
  color: var(--text-mid); background: rgba(20,20,26,0.7);
  border: 1px solid var(--border); border-radius: var(--r-pill);
  padding: 9px 18px; transition: all .2s var(--ease);
}
.cp-tab:hover { color: var(--text-hi); border-color: var(--border-soft); }
.cp-tab.sel { color: #100B03; background: var(--accent); border-color: var(--accent); }
.cp-panel { display: none; }
.cp-panel.sel { display: block; }
.cp-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.cp-input, .cp-textarea {
  flex: 1 1 280px; min-width: 0; font-family: var(--font-display);
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-btn);
  color: var(--text-hi); padding: 13px 16px; font-size: 0.98rem;
}
.cp-textarea { width: 100%; min-height: 140px; resize: vertical; line-height: 1.5; font-size: 0.9rem; }
.cp-input:focus, .cp-textarea:focus { outline: none; border-color: var(--accent); }
.cp-file { display: none; }
.cp-hint { margin-top: 12px; font-size: 0.86rem; color: var(--text-lo); line-height: 1.6; }
.cp-hint a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.cp-privacy {
  display: flex; gap: 10px; align-items: flex-start; margin-top: 18px;
  font-size: 0.84rem; color: var(--text-lo); line-height: 1.55;
}
.cp-privacy svg { width: 17px; height: 17px; color: var(--success); flex: none; margin-top: 2px; }
.cp-loaderr { margin-top: 14px; color: var(--error); font-size: 0.9rem; display: none; }
.cp-loaderr.show { display: block; }

/* ---------- hero tweaks (no inline styles — CSP style-src 'self') ---------- */
.cp-hero-head { max-width: 760px; }
.cp-hero-head h1 { font-size: clamp(2.2rem, 5vw, 3.6rem); margin-top: 18px; }
.cp-hero-head .lead { margin-top: 18px; }
.cp-mt12 { margin-top: 12px; }

/* ---------- catalog shell ---------- */
.cplayer { --cp-rail: 264px; margin-top: clamp(28px, 5vh, 56px); }
.cplayer[hidden] { display: none; }
.cplayer-shell { display: grid; grid-template-columns: var(--cp-rail) 1fr; gap: 0; min-height: 70vh; }

.cplayer-sidebar {
  position: sticky; top: 72px; align-self: start;
  max-height: calc(100vh - 72px); overflow-y: auto;
  padding: 6px 16px 24px 0; border-right: 1px solid var(--border);
  scrollbar-width: thin;
}
.cp-sb-nav { display: flex; flex-direction: column; gap: 2px; }
.cp-sb-item {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  text-align: left; width: 100%; color: var(--text-mid);
  background: transparent; border: 0; border-radius: 14px;
  padding: 11px 14px; font-size: 0.95rem; transition: background .15s var(--ease), color .15s var(--ease);
}
.cp-sb-item:hover { background: var(--surface); color: var(--text-hi); }
.cp-sb-item.sel { background: rgba(232,181,96,0.13); color: var(--accent); }
.cp-sb-lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-sb-count { flex: none; font-size: 0.76rem; color: var(--text-lo); }
.cp-sb-item.sel .cp-sb-count { color: var(--accent-soft); }
.cp-sb-div { height: 1px; background: var(--border); margin: 12px 8px; }
.cp-sb-head {
  font-family: var(--font-display); font-size: 0.7rem; letter-spacing: 0.2em;
  text-transform: uppercase; color: var(--text-lo); padding: 4px 14px 8px;
}

.cplayer-main { min-width: 0; padding: 0 0 40px clamp(16px, 2.4vw, 34px); }
.cplayer-bar {
  position: sticky; top: 72px; z-index: 5; display: flex; gap: 14px; align-items: center;
  padding: 14px 0 16px; background: linear-gradient(180deg, var(--bg) 70%, rgba(10,10,13,0));
}
.cp-search {
  flex: 1 1 auto; max-width: 460px; font-family: var(--font-display);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill);
  color: var(--text-hi); padding: 11px 18px; font-size: 0.95rem;
}
.cp-search:focus { outline: none; border-color: var(--accent); }
.cp-count { font-size: 0.84rem; color: var(--text-lo); white-space: nowrap; }

/* ---------- poster grid ---------- */
.cp-grid {
  display: grid; gap: clamp(12px, 1.5vw, 22px);
  grid-template-columns: repeat(auto-fill, minmax(clamp(116px, 14vw, 178px), 1fr));
}
.cp-poster {
  display: flex; flex-direction: column; gap: 9px; text-align: left;
  background: transparent; border: 0; padding: 0; color: inherit; cursor: pointer;
}
.cp-art {
  position: relative; aspect-ratio: 2 / 3; width: 100%; border-radius: 12px; overflow: hidden;
  background: var(--surface-2); border: 1px solid rgba(255,255,255,0.05);
  transition: transform .2s var(--spring), box-shadow .25s var(--ease), outline-color .15s var(--ease);
  outline: 2px solid transparent; outline-offset: 0;
  display: grid; place-items: stretch;
}
.cp-poster:hover .cp-art, .cp-poster:focus-visible .cp-art {
  transform: translateY(-3px);
  outline-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 16px 40px rgba(232,181,96,0.26);
}
.cp-poster:focus-visible { outline: none; }
.cp-poster-img { width: 100%; height: 100%; object-fit: cover; }
.cp-logo-pad { width: 100%; height: 100%; display: grid; place-items: center; padding: 16%; background: radial-gradient(120% 120% at 50% 30%, #1c1c26, #121219); }
.cp-logo { max-width: 100%; max-height: 100%; object-fit: contain; }
.cp-cover {
  width: 100%; height: 100%; display: flex; align-items: flex-end; padding: 14px 12px; position: relative;
}
.cp-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(0deg, rgba(0,0,0,.5), rgba(0,0,0,.05) 55%); }
.cp-cover-t {
  position: relative; z-index: 1; font-family: var(--font-display); font-weight: 700;
  font-size: clamp(0.95rem, 1.5vw, 1.2rem); line-height: 1.1; color: #fff;
  text-shadow: 0 2px 14px rgba(0,0,0,.6);
}
.cp-badge {
  position: absolute; top: 9px; right: 9px; font-family: var(--font-display);
  font-size: 0.66rem; font-weight: 700; letter-spacing: .04em;
  background: var(--accent); color: #13100a; padding: 3px 8px; border-radius: 7px;
}
.cp-badge-live { background: var(--error); color: #fff; left: 9px; right: auto; }
.cp-year { position: absolute; bottom: 9px; right: 9px; background: rgba(0,0,0,.66); color: #fff; font-size: 0.7rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; }
.cp-label {
  font-size: 0.86rem; color: var(--text-mid); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.cp-poster:hover .cp-label { color: var(--text-hi); }
.cp-cap-note, .cp-empty { grid-column: 1 / -1; color: var(--text-lo); font-size: 0.92rem; padding: 24px 4px; }
.cp-sentinel { grid-column: 1 / -1; height: 1px; }

/* ---------- modals (series detail + video) — appended to <body> ---------- */
.cp-modal {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  padding: clamp(12px, 3vw, 40px); background: rgba(0,0,0,0.86);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.cp-modal[hidden] { display: none; }

/* series detail sheet */
.cp-sheet {
  width: min(900px, 96vw); max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  box-shadow: 0 40px 110px rgba(0,0,0,0.7);
}
.cp-sheet-head { display: flex; gap: clamp(16px, 3vw, 30px); padding: clamp(18px, 3vw, 30px); position: relative; border-bottom: 1px solid var(--border); }
.cp-sheet-poster { flex: none; width: clamp(96px, 16vw, 150px); aspect-ratio: 2/3; border-radius: 12px; overflow: hidden; background: var(--surface-2); }
.cp-sheet-main { min-width: 0; padding-right: 30px; }
.cp-sheet-kicker { font-family: var(--font-display); font-size: 0.72rem; letter-spacing: 0.24em; text-transform: uppercase; color: var(--accent); }
.cp-sheet-title { font-family: var(--font-display); font-weight: 300; font-size: clamp(1.5rem, 3.2vw, 2.2rem); color: var(--text-hi); margin: 8px 0; }
.cp-sheet-meta { color: var(--text-mid); font-size: 0.95rem; }
.cp-sheet-body { padding: clamp(14px, 2.4vw, 24px); }
.cp-season-h { font-family: var(--font-display); font-size: 0.95rem; color: var(--accent); margin: 14px 0 8px; }
.cp-eplist { display: flex; flex-direction: column; gap: 4px; }
.cp-ep {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  background: transparent; border: 0; border-radius: 12px; padding: 12px 14px;
  color: var(--text-mid); transition: background .15s var(--ease);
}
.cp-ep:hover { background: var(--surface-2); color: var(--text-hi); }
.cp-ep-num { flex: none; width: 44px; font-family: var(--font-display); font-weight: 600; color: var(--accent); }
.cp-ep-body { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.95rem; }
.cp-ep-play { flex: none; color: var(--accent); opacity: .7; }
.cp-ep:hover .cp-ep-play { opacity: 1; }

.cp-close {
  position: absolute; top: 14px; right: 14px; width: 38px; height: 38px; border-radius: 50%;
  background: rgba(20,20,26,0.9); border: 1px solid var(--border); color: var(--text-hi);
  font-size: 1rem; line-height: 1; display: grid; place-items: center; z-index: 3;
}
.cp-close:hover { border-color: var(--border-soft); background: var(--surface-2); }

/* video player modal */
.cp-player-box { width: min(1100px, 96vw); }
.cp-video-wrap { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 14px; overflow: hidden; border: 1px solid var(--border); }
.cp-video-wrap video { width: 100%; height: 100%; background: #000; }
.cp-player-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.cp-player-title { font-family: var(--font-display); font-size: 1.05rem; color: var(--text-hi); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-player-head .cp-close { position: static; margin-left: auto; }
.cp-spinner {
  position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-lo);
}
.cp-spinner i { width: 38px; height: 38px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: cp-spin .9s linear infinite; }
@keyframes cp-spin { to { transform: rotate(360deg); } }
.cp-error {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; text-align: center; padding: 24px; background: rgba(8,8,11,0.9);
}
.cp-error h4 { font-family: var(--font-display); font-weight: 400; font-size: 1.2rem; color: var(--text-hi); }
.cp-error p { color: var(--text-mid); font-size: 0.94rem; max-width: 46ch; }
.cp-error .cp-error-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 6px; }
.cp-hide { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cplayer-shell { grid-template-columns: 1fr; }
  .cplayer-sidebar {
    position: static; max-height: none; overflow: visible; border-right: 0;
    border-bottom: 1px solid var(--border); padding: 0 0 12px; margin-bottom: 14px;
  }
  .cp-sb-nav { flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .cp-sb-item { width: auto; border-radius: var(--r-pill); border: 1px solid var(--border); padding: 8px 14px; }
  .cp-sb-div, .cp-sb-head { display: none; }
  .cp-sb-count { display: none; }
  .cplayer-main { padding-left: 0; }
  .cplayer-bar { top: 72px; }
}
@media (max-width: 520px) {
  .cp-grid { grid-template-columns: repeat(2, 1fr); }
  .cp-sheet-head { flex-direction: column; }
}
