/* Watch later and playlists (Task 5.3, Figma "Components – Watch later / Playlist").
   Loaded on the video page and on /playlist pages. Theme-mode overrides are at the end. */
:root {
	--pl-accent: #a4388e;
	--pl-accent-soft: #fbeef8;
	--pl-chip: #f2f2f2;
	--pl-chip-hover: #e6e6e6;
	--pl-text: #1f1f1f;
	--pl-muted: #7a7a7a;
	--pl-line: #e6e6e6;
}

/* ---- Action buttons under the video ---- */
.view-like { position: relative; }
.video-actions { display: flex; align-items: center; gap: 10px; padding-right: 15px; }
.video-actions .like-status { display: flex; gap: 10px; }
.action-chip {
	display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px;
	border: 1px solid transparent; border-radius: 8px; background: var(--pl-chip); color: var(--pl-text);
	font: 600 15px/1 "LINE Seed Sans TH", Tahoma, sans-serif; white-space: nowrap; cursor: pointer;
	text-decoration: none; transition: background-color .15s, border-color .15s;
}
.action-chip:hover, .action-chip:focus { background: var(--pl-chip-hover); color: var(--pl-text); text-decoration: none; }
.action-chip:focus-visible { outline: 2px solid var(--pl-accent); outline-offset: 2px; }
.action-chip .ui-icon { flex: none; }
/* The like/dislike anchors used to be 30px image icons (dashboard.css); they are chips now. */
.video-actions .like-status a.action-chip { position: static; display: inline-flex; align-items: center; width: auto; height: 40px; background-image: none; vertical-align: middle; }
.video-actions .like-status a.action-chip span { position: static; display: inline; line-height: 1; }
.action-chip.like-active, .action-chip.unlike-active { color: var(--pl-accent); }
.action-chip.like-active .ui-icon path, .action-chip.unlike-active .ui-icon path { fill: currentColor; fill-opacity: .18; }
.video-actions .share-box { margin: 0; }
.view-like .video-actions .share-video { width: auto !important; height: 40px !important; padding: 0 14px; background-image: none; }
.video-actions .share-list { right: auto; left: 0; }
.view-like .video-actions .btn-watch-later { background-image: none; }
.btn-watch-later .wl-on, .btn-watch-later .wl-off { display: inline-flex; }
.btn-watch-later:not(.is-active) .wl-on, .btn-watch-later.is-active .wl-off { display: none; }
.btn-playlist-save.is-open { border-color: var(--pl-accent); background: #fff; }

@media (max-width: 767px) {
	.view-like { flex-wrap: nowrap; }
	.video-actions {
		flex: 1 1 auto; min-width: 0; gap: 8px; margin: 0 -15px; padding: 0 15px 2px;
		overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
	}
	.video-actions::-webkit-scrollbar { display: none; }
	.video-actions .like-status { gap: 8px; }
	.action-chip { height: 36px; padding: 0 12px; font-size: 14px; }
	.video-actions .like-status a.action-chip, .video-actions .share-video { height: 36px !important; }
	/* The share list would be clipped by the scrolling row, so it opens fixed above the page. */
	.video-actions .share-list { position: fixed !important; left: 16px; right: 16px; top: auto; bottom: 16px; width: auto; z-index: 1070; }
}

/* ---- Toast ---- */
.playlist-toast {
	position: fixed; left: 50%; bottom: 32px; z-index: 1080; display: flex; align-items: center; gap: 10px;
	max-width: calc(100vw - 32px); padding: 14px 18px; border-radius: 8px; background: #212121; color: #fff;
	box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 15px; font-weight: 600;
	transform: translate(-50%, 12px); opacity: 0; transition: opacity .2s, transform .2s;
}
.playlist-toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.playlist-toast .ui-icon { flex: none; color: #8fe3a9; }
.playlist-toast-link { color: #f3a8e2; text-decoration: underline; white-space: nowrap; }
.playlist-toast-link:hover { color: #fff; }

/* ---- "บันทึกไปยัง…" popover ---- */
.playlist-popover {
	position: absolute; z-index: 1065; width: 380px; max-width: calc(100vw - 32px);
	border-radius: 12px; background: #fff; color: var(--pl-text); box-shadow: 0 10px 32px rgba(0,0,0,.18);
}
.playlist-popover-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px 20px; }
.playlist-popover-head h2 { margin: 0; font-size: 17px; font-weight: 700; }
.playlist-popover-list { max-height: 300px; margin: 0; padding: 0 8px; list-style: none; overflow-y: auto; }
.playlist-popover-loading, .playlist-popover-empty { margin: 0; padding: 12px; color: var(--pl-muted); font-size: 14px; }
.playlist-save-toggle {
	display: flex; align-items: center; gap: 14px; width: 100%; min-height: 56px; padding: 8px 12px;
	border: 0; border-radius: 8px; background: none; color: inherit; text-align: left; cursor: pointer;
}
.playlist-save-toggle:hover, .playlist-save-toggle:focus-visible { background: #f6f6f6; outline: none; }
.playlist-save-thumb { flex: none; width: 64px; height: 40px; border-radius: 4px; background: #ddd center/cover no-repeat; }
.playlist-save-name { flex: 1; min-width: 0; overflow: hidden; font-size: 15px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.playlist-save-mark { flex: none; display: inline-flex; color: var(--pl-text); }
.playlist-save-toggle.is-saved .playlist-save-mark { color: var(--pl-accent); }
.playlist-save-toggle.is-saved .playlist-save-mark path { fill: currentColor; }
.playlist-popover-foot { margin-top: 8px; padding: 12px 16px 16px; border-top: 1px solid var(--pl-line); }
.playlist-btn-new {
	display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; height: 44px;
	border: 0; border-radius: 8px; background: var(--pl-chip); color: var(--pl-text); font-size: 15px; font-weight: 700; cursor: pointer;
}
.playlist-btn-new:hover { background: var(--pl-chip-hover); }
.playlist-icon-btn {
	display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
	border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer;
}
.playlist-icon-btn:hover, .playlist-icon-btn:focus-visible { background: #f0f0f0; outline: none; }
@media (max-width: 767px) {
	/* A bottom sheet on phones. */
	.playlist-popover { position: fixed; left: 0 !important; right: 0; bottom: 0; top: auto !important; width: auto; max-width: none; border-radius: 16px 16px 0 0; }
	html.playlist-popover-open::after { content: ''; position: fixed; inset: 0; z-index: 1064; background: rgba(0,0,0,.4); }
	.playlist-popover-list { max-height: 50vh; }
}

/* ---- New / edit playlist dialog ---- */
.playlist-modal { position: fixed; inset: 0; z-index: 1075; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0,0,0,.5); }
.playlist-modal[hidden] { display: none; }
html.playlist-modal-open { overflow: hidden; }
.playlist-modal-box { width: 480px; max-width: 100%; max-height: calc(100vh - 32px); overflow-y: auto; padding: 22px 24px 24px; border-radius: 12px; background: #fff; color: var(--pl-text); box-shadow: 0 16px 48px rgba(0,0,0,.25); }
.playlist-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.playlist-modal-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.playlist-field { position: relative; display: block; margin: 0; padding: 8px 12px; border: 1px solid #cfcfcf; border-radius: 8px; }
.playlist-field:focus-within { border-color: var(--pl-accent); box-shadow: 0 0 0 1px var(--pl-accent); }
.playlist-field.has-error { border-color: #d93025; box-shadow: 0 0 0 1px #d93025; }
.playlist-field-label { display: block; color: var(--pl-muted); font-size: 12px; }
.playlist-field.has-error .playlist-field-label { color: #d93025; }
.playlist-field input, .playlist-field select { width: 100%; padding: 2px 0 0; border: 0; background: none; color: var(--pl-text); font-size: 15px; font-weight: 600; outline: none; -webkit-appearance: none; appearance: none; }
.playlist-field-select .ui-icon { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.playlist-field-select select { padding-right: 28px; cursor: pointer; }
.playlist-field-meta { display: flex; justify-content: space-between; gap: 12px; min-height: 20px; margin: 6px 0 16px; font-size: 12px; color: var(--pl-muted); }
.playlist-field-count { margin-left: auto; }
.playlist-field-error { display: inline-flex; align-items: center; gap: 4px; color: #d93025; font-weight: 600; }
.playlist-field-error[hidden] { display: none; }
.playlist-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 20px 0 0; cursor: pointer; }
.playlist-switch-row strong { display: block; font-size: 15px; }
.playlist-switch-row small { display: block; color: var(--pl-muted); font-size: 12px; }
.playlist-switch { position: relative; flex: none; width: 40px; height: 22px; }
.playlist-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.playlist-switch span { position: absolute; inset: 0; border-radius: 11px; background: #cfcfcf; transition: background-color .2s; pointer-events: none; }
.playlist-switch span::before { content: ''; position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .2s; }
.playlist-switch input:checked + span { background: var(--pl-accent); }
.playlist-switch input:checked + span::before { transform: translateX(18px); }
.playlist-switch input:focus-visible + span { outline: 2px solid var(--pl-accent); outline-offset: 2px; }
.playlist-modal-share { margin-top: 18px; }
.playlist-modal-share[hidden] { display: none; }
.playlist-share-row { display: flex; gap: 8px; margin-top: 4px; }
.playlist-share-url { flex: 1; min-width: 0; height: 40px; padding: 0 10px; border: 1px solid #cfcfcf; border-radius: 8px; background: #f8f8f8; font-size: 13px; }
.playlist-btn-copy { display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 12px; border: 0; border-radius: 8px; background: var(--pl-chip); font-weight: 700; cursor: pointer; white-space: nowrap; }
.playlist-modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }
.playlist-btn-cancel, .playlist-btn-submit { height: 42px; padding: 0 20px; border: 0; border-radius: 8px; font-size: 15px; font-weight: 700; cursor: pointer; }
.playlist-btn-cancel { background: var(--pl-chip); color: var(--pl-text); }
.playlist-btn-submit { background: var(--pl-accent); color: #fff; }
.playlist-btn-submit:disabled { opacity: .6; cursor: default; }

/* ---- Playlist panel on the video page ---- */
.playlist-panel { overflow: hidden; border: 1px solid var(--pl-line); border-radius: 12px; background: #fff; }
.playlist-panel-head { display: flex; align-items: flex-start; gap: 8px; padding: 14px 10px 12px 16px; border-bottom: 1px solid var(--pl-line); }
.playlist-panel-title { flex: 1; min-width: 0; }
.playlist-panel-title a { display: block; overflow: hidden; color: var(--pl-text); font-size: 17px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.playlist-panel-title small { display: block; margin-top: 2px; color: var(--pl-muted); font-size: 13px; }
.playlist-panel-toggle { display: inline-flex; flex: none; align-items: center; justify-content: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; color: var(--pl-text); cursor: pointer; }
.playlist-panel-toggle:hover { background: #f0f0f0; }
.playlist-panel-toggle .pl-ico-open, .playlist-panel.is-folded .playlist-panel-toggle .pl-ico-close { display: none; }
.playlist-panel.is-folded .playlist-panel-toggle .pl-ico-open { display: inline-flex; }
.playlist-panel.is-folded .playlist-panel-head { border-bottom: 0; }
.playlist-panel.is-folded .playlist-panel-list { display: none; }
.playlist-panel-list { position: relative; max-height: 290px; margin: 0; padding: 0; list-style: none; overflow-y: auto; }
.playlist-panel-list a { display: flex; align-items: center; gap: 10px; padding: 8px 12px 8px 6px; color: var(--pl-text); text-decoration: none; }
.playlist-panel-list a:hover { background: #f7f7f7; }
.playlist-panel-list li.is-current a { background: var(--pl-accent-soft); }
.playlist-panel-index { flex: none; width: 20px; color: var(--pl-muted); font-size: 12px; text-align: center; }
.playlist-panel-list li.is-current .playlist-panel-index { color: var(--pl-accent); }
.playlist-panel-thumb { flex: none; width: 100px; height: 56px; border-radius: 4px; background: #ddd center/cover no-repeat; }
.playlist-panel-text { flex: 1; min-width: 0; }
.playlist-panel-name { display: -webkit-box; overflow: hidden; font-size: 14px; font-weight: 700; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.playlist-panel-cat { display: block; margin-top: 2px; color: var(--pl-muted); font-size: 12px; }
@media (max-width: 991px) {
	.playlist-panel { margin-top: 8px; }
}

/* ---- /playlist pages ---- */
.playlist-page { padding-bottom: 60px; }
.playlist-library, .playlist-detail { margin-top: 40px; padding: 32px 34px 40px; border-radius: 10px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.playlist-library-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.playlist-library-head h1, .playlist-detail-title h1 { margin: 0; color: var(--pl-text); font-size: 32px; font-weight: 700; }
.playlist-btn-new-inline { width: auto; padding: 0 18px; }
.playlist-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 32px 20px; }
.playlist-card-cover {
	position: relative; display: block; margin-top: 10px; padding-top: 56.25%; border-radius: 8px;
	background: #d9d9d9 center/cover no-repeat;
}
.playlist-card-cover::before { content: ''; position: absolute; left: 12px; right: 12px; top: -8px; height: 8px; border-radius: 4px 4px 0 0; background: #c4c4c4; }
.playlist-card-count { position: absolute; right: 8px; bottom: 8px; display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 4px; background: rgba(0,0,0,.8); color: #fff; font-size: 12px; font-weight: 700; }
.playlist-card-body { display: flex; gap: 4px; margin-top: 12px; }
.playlist-card-text { flex: 1; min-width: 0; }
.playlist-card-text h2 { margin: 0; overflow: hidden; font-size: 16px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.playlist-card-text h2 a { color: var(--pl-text); }
.playlist-card-text p { margin: 2px 0 2px; color: var(--pl-muted); font-size: 13px; }
.playlist-card-link { color: var(--pl-accent); font-size: 13px; font-weight: 700; }
.playlist-card-menu { position: relative; margin: -6px -8px 0 0; }
.playlist-menu { position: absolute; right: 0; top: 100%; z-index: 20; min-width: 210px; margin: 0; padding: 6px; list-style: none; border-radius: 8px; background: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.playlist-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 6px; background: none; color: var(--pl-text); font-size: 14px; text-align: left; cursor: pointer; }
.playlist-menu button:hover, .playlist-menu button:focus-visible { background: #f3f3f3; outline: none; }
.playlist-empty { padding: 60px 0; color: var(--pl-muted); text-align: center; }
.playlist-empty p { margin-top: 12px; font-size: 18px; font-weight: 700; color: var(--pl-text); }
.playlist-empty small { color: var(--pl-muted); font-size: 14px; font-weight: 400; }

.playlist-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.playlist-detail-title h1 { font-size: 28px; font-weight: 400; }
.playlist-detail-title p { margin: 6px 0 0; color: var(--pl-muted); font-size: 14px; }
.playlist-search { display: flex; flex: 0 1 440px; height: 40px; }
.playlist-search input { flex: 1; min-width: 0; padding: 0 12px; border: 0; border-radius: 4px 0 0 4px; background: #ebebeb; font-size: 14px; }
.playlist-search button { width: 44px; border: 0; border-radius: 0 4px 4px 0; background: #8d8d8d; color: #fff; }
.playlist-detail-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0 8px; }
.playlist-btn-play, .playlist-btn-secondary { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 16px; border: 0; border-radius: 8px; font-size: 15px; font-weight: 700; text-decoration: none; cursor: pointer; }
.playlist-btn-play { background: var(--pl-accent); color: #fff; }
.playlist-btn-play:hover { color: #fff; opacity: .9; text-decoration: none; }
.playlist-btn-secondary { background: var(--pl-chip); color: var(--pl-text); }
.playlist-btn-secondary:hover { background: var(--pl-chip-hover); color: var(--pl-text); text-decoration: none; }
.playlist-items { margin-top: 12px; }
.playlist-item { display: flex; align-items: flex-start; gap: 16px; padding: 18px 0; border-bottom: 2px solid transparent; border-image: linear-gradient(90deg, #8db7e1, #a4388e) 1; }
.playlist-item-index { flex: none; width: 24px; padding-top: 4px; color: var(--pl-muted); font-size: 14px; text-align: center; }
.playlist-item-thumb { position: relative; flex: none; width: 200px; padding-top: 112px; border-radius: 6px; background: #eee center/cover no-repeat; }
.playlist-item-thumb .sv-group { position: absolute; top: 6px; right: 6px; width: 30px !important; height: 28px !important; }
.playlist-item-time { position: absolute; right: 6px; bottom: 6px; padding: 1px 6px; border-radius: 3px; background: rgba(0,0,0,.75); color: #fff; font-size: 12px; }
.playlist-item-body { flex: 1; min-width: 0; }
.playlist-item-body h2 { margin: 2px 0 8px; font-size: 16px; font-weight: 600; line-height: 1.4; }
.playlist-item-body h2 a { color: var(--pl-text); word-break: break-word; }
.playlist-item-stats { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0; padding: 0; list-style: none; color: var(--pl-muted); font-size: 13px; }
.playlist-item-remove { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 0; border-radius: 4px; background: #e53935; color: #fff; cursor: pointer; }
.playlist-item-remove:hover { background: #c62828; }
.playlist-empty-text { padding: 40px 0; color: var(--pl-muted); text-align: center; }

@media (max-width: 991px) {
	.playlist-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 767px) {
	.playlist-library, .playlist-detail { margin-top: 16px; padding: 20px 16px 28px; }
	.playlist-library-head h1 { font-size: 24px; }
	.playlist-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px 12px; }
	.playlist-detail-head { flex-direction: column; gap: 12px; }
	.playlist-detail-title h1 { font-size: 22px; }
	.playlist-search { flex: none; width: 100%; }
	.playlist-item { gap: 10px; }
	.playlist-item-index { display: none; }
	.playlist-item-thumb { width: 128px; padding-top: 72px; }
	.playlist-item-body h2 { font-size: 14px; }
	.playlist-item-stats li:nth-child(n+2) { display: none; }
	.playlist-btn-new-inline { padding: 0 12px; font-size: 14px; }
}
@media (max-width: 400px) {
	.playlist-grid { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Theme modes ---- */
.dark-mode .action-chip, .blackwhite-mode .action-chip, .blackyellow-mode .action-chip { background: #2b2b2b; color: #fff; }
.blackyellow-mode .action-chip { color: #fff500; }
.dark-mode .btn-watch-later.is-active .wl-on, .blackwhite-mode .btn-watch-later.is-active .wl-on { color: #fff; }
.blackyellow-mode .btn-watch-later.is-active .wl-on { color: #fff500; }
.dark-mode .playlist-panel, .blackwhite-mode .playlist-panel, .blackyellow-mode .playlist-panel,
.dark-mode .playlist-library, .blackwhite-mode .playlist-library, .blackyellow-mode .playlist-library,
.dark-mode .playlist-detail, .blackwhite-mode .playlist-detail, .blackyellow-mode .playlist-detail { background: #1c1c1c; border-color: #3a3a3a; }
.dark-mode .playlist-panel a, .dark-mode .playlist-panel-toggle, .dark-mode .playlist-library h1, .dark-mode .playlist-detail h1, .dark-mode .playlist-card-text h2 a, .dark-mode .playlist-item-body h2 a,
.blackwhite-mode .playlist-panel a, .blackwhite-mode .playlist-panel-toggle, .blackwhite-mode .playlist-library h1, .blackwhite-mode .playlist-detail h1, .blackwhite-mode .playlist-card-text h2 a, .blackwhite-mode .playlist-item-body h2 a { color: #fff; }
.blackyellow-mode .playlist-panel a, .blackyellow-mode .playlist-panel-toggle, .blackyellow-mode .playlist-library h1, .blackyellow-mode .playlist-detail h1, .blackyellow-mode .playlist-card-text h2 a, .blackyellow-mode .playlist-item-body h2 a { color: #fff500; }
.dark-mode .playlist-panel-list li.is-current a, .blackwhite-mode .playlist-panel-list li.is-current a, .blackyellow-mode .playlist-panel-list li.is-current a { background: #3a2335; }
.dark-mode .playlist-panel-list a:hover, .blackwhite-mode .playlist-panel-list a:hover, .blackyellow-mode .playlist-panel-list a:hover { background: #2a2a2a; }
