/* ── Variables ── */
:root.light {
  --bg: #f5f5f7;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f0f2;
  --bg-glass: rgba(255,255,255,.82);
  --bg-glass-hover: rgba(240,240,245,.88);
  --border: #e1e1e6;
  --border-focus: #58a6ff;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --text-dim: #aeaeb2;
  --accent: #2563eb;
  --accent-green: #16a34a;
  --accent-red: #dc2626;
  --accent-orange: #d97706;
}

:root {
  --bg: #0a0c10;
  --bg-card: #14181f;
  --bg-card-hover: #1a1f2a;
  --bg-glass: rgba(22, 27, 34, .82);
  --bg-glass-hover: rgba(30, 36, 46, .88);
  --border: #21262d;
  --border-focus: #58a6ff;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --text-dim: #484f58;
  --accent: #58a6ff;
  --accent-green: #2ea043;
  --accent-red: #f85149;
  --accent-orange: #d29922;
  --radius: 10px;
  --radius-lg: 16px;
  --font: "Manrope", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "JetBrains Mono", monospace;
  --dock-width: 210px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; }
html.light { color-scheme: light; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #30363d; border-radius: 99px; }

/* ═══ DESKTOP DOCK ═══ */
.dock {
  display: none;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--dock-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  flex-direction: column;
  padding: 0;
  gap: 0;
  z-index: 100;
}

.dock-icon {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 18px 14px;
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  flex-shrink: 0;
}
.dock-icon-badge {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.dock-item {
  background: none; border: none; cursor: pointer; color: var(--text-dim);
  display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; margin: 1px 8px;
  border-radius: var(--radius);
  transition: all .15s ease;
  position: relative; min-height: auto;
  font-size: 14px; font-weight: 500;
}
.dock-item:hover { color: var(--text); background: var(--bg-glass-hover); }
.dock-item.active { color: var(--accent); background: rgba(24,24,27,.06); }
.dock-item svg { flex-shrink: 0; }
.dock-item span { font-size: 14px; font-weight: 500; }

/* ═══ MOBILE DOCK ═══ */
.dock-mobile {
  display: flex;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: 72px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  align-items: center; justify-content: space-around;
  padding: 0 4px; z-index: 100;
}
.dock-mobile-item {
  background: none; border: none; padding: 8px 4px; border-radius: var(--radius);
  cursor: pointer; color: var(--text-dim);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  transition: all .15s; min-height: auto;
  flex: 1; min-width: 0;
}
.dock-mobile-item:hover { color: var(--text); background: var(--bg-glass-hover); }
.dock-mobile-item.active { color: var(--accent); background: rgba(88,166,255,.1); }
.dock-mobile-item span { font-size: 11px; font-weight: 500; }

/* ═══ MAIN CONTENT ═══ */
.main-content {
  min-height: 100vh;
}
.main-content > .view {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 32px 80px;
}
.view { display: none; }
.view.active { display: block; }

.header-actions {
  display: flex; gap: 8px; align-items: center;
}
.btn-danger {
  background: var(--accent-red); color: #fff; border-color: var(--accent-red);
}
.btn-danger:hover { background: #dc2626; }
.test-btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; cursor: pointer;
  margin-left: 0; min-height: 40px; transition: all .15s;
}
.test-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ═══ TOAST ═══ */
.toast {
  position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card); color: var(--text); border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 10px 24px; font-size: 14px; font-weight: 500;
  z-index: 999; animation: toast-in .25s ease; box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.toast-err { border-color: var(--accent-red); color: var(--accent-red); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.view-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid var(--border);
}
.view-header h1 { font-size: 22px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.view-badge {
  font-size: 12px; color: var(--text-muted); background: var(--bg-card);
  padding: 4px 14px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap;
}

/* ═══ GALLERY ═══ */
.gallery {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.gallery-empty {
  text-align: center;
  padding: 60px 0;
  color: var(--text-dim);
  font-size: 14px;
}

.gallery-pagination {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 24px 0;
}

.gallery-pagination button {
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}

.gallery-pagination button:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--accent-green);
}

.gallery-pagination button.active {
  background: var(--accent-green);
  color: #fff;
  border-color: var(--accent-green);
  cursor: default;
}

.gallery-pagination button:disabled:not(.active) {
  opacity: .35;
  cursor: default;
}

/* Section 日期标题 */
.gallery-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 0 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}
.pack-btn {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-glass);
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.pack-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* 横向滚动行 */
.gallery-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 4px;
  scrollbar-width: thin;
}
.gallery-row::-webkit-scrollbar { height: 4px; }
.gallery-row::-webkit-scrollbar-thumb { background: var(--text-dim); border-radius: 99px; }

/* Emby 继续观看卡片 */
/* 首次渲染播动画，后续刷新跳过 */
.gallery.no-animate .gallery-card { animation: none; opacity: 1; }

.gallery-card {
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-card);
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  animation: fadeUp .5s ease both;
  border: 1px solid var(--border);
  flex: 0 0 240px;
}
.gallery-card:nth-child(2) { animation-delay: 60ms; }
.gallery-card:nth-child(3) { animation-delay: 120ms; }
.gallery-card:nth-child(4) { animation-delay: 180ms; }
.gallery-card:nth-child(5) { animation-delay: 240ms; }
.gallery-card:nth-child(6) { animation-delay: 300ms; }
.gallery-card:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
  z-index: 2;
}

.gallery-poster {
  position: relative;
  width: 100%;
  padding-top: 67%; /* 3:2 ≈ 800/536 */
  background: var(--border);
  overflow: hidden;
}
.gallery-poster::before {
  content: '';
  position: absolute; inset: 0; z-index: 0;
  background: linear-gradient(90deg, transparent 0%, var(--bg-glass-hover) 50%, transparent 100%);
  animation: poster-shimmer 1.4s infinite;
}
@keyframes poster-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}
.gallery-poster img {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity .3s;
}
.gallery-poster img:not([src]),
.gallery-poster img[src=""] { opacity: 0; }
.gallery-poster img[src] { opacity: 1; }

.gallery-poster-fallback {
  display: none;
  position: absolute;
  inset: 5px;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
  word-break: break-all;
}
.gallery-poster-failed .gallery-poster-fallback {
  display: flex;
}

.gallery-footer {
  padding: 8px 10px;
  background: var(--bg-card);
}
.gallery-footer .av {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-footer .meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gallery-footer .fmt-badge {
  display: inline-block;
  margin-top: 3px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
  background: rgba(46,160,67,.12);
  color: var(--accent-green);
  border: 1px solid rgba(46,160,67,.2);
}

.gallery-card::before {
  content: ''; position: absolute; top: -1px; left: 20%; right: 20%; height: 1px;
  background: linear-gradient(to right, transparent, var(--accent-green), transparent);
  opacity: 0; transition: opacity .4s ease;
}
.gallery-card:hover {
  border-color: rgba(46,160,67,.3);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(0,0,0,.4), 0 0 40px rgba(46,160,67,.04);
}
.gallery-card:hover::before { opacity: 1; }



.gallery-card .fmt-badge {
  display: inline-block; margin-top: auto; align-self: flex-start; padding: 2px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  background: rgba(46,160,67,.12); color: var(--accent-green); border: 1px solid rgba(46,160,67,.2);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ═══ CARD / FORM ═══ */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 22px; }
label { display: block; color: var(--text-muted); font-size: 13px; margin: 14px 0; }
label:first-child { margin-top: 0; }

.config-label-row {
  display: flex;
  align-items: baseline;
  justify-content: flex-start;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.config-label-row small {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  white-space: normal;
}

.config-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 0;
}

.config-actions .test-btn,
.config-actions .config-save-btn {
  min-height: 40px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
  margin: 0;
}

.config-actions .config-save-btn {
  margin-left: auto;
}

input, select {
  width: 100%; margin-top: 5px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: 14px;
  transition: border-color .15s, box-shadow .15s; outline: none;
}
input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px rgba(88,166,255,.15); }
input::placeholder { color: var(--text-dim); }

.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; margin-top: 0; }

button {
  border: 0; border-radius: var(--radius); padding: 10px 18px;
  background: var(--accent); color: #fff; font-weight: 600;
  font-size: 14px; font-family: inherit; cursor: pointer;
  transition: opacity .15s, transform .1s; min-height: 40px;
}
button:hover { opacity: .88; }
button:active { transform: scale(.97); }

pre {
  white-space: pre-wrap; background: var(--bg-glass); color: var(--text-muted);
  padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border);
  margin-top: 12px; font-size: 12px; font-family: var(--font-mono); min-height: 20px; overflow: auto;
}

/* ═══ TABS ═══ */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--border); overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: 0 0 auto; background: none; border: none; border-radius: 0;
  padding: 10px 18px; color: var(--text-muted); font-weight: 500; font-size: 13px;
  font-family: inherit; cursor: pointer; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color .15s, border-color .15s; white-space: nowrap; min-height: auto;
}
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-btn:hover:not(.active) { color: var(--text); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ═══ JOBS ═══ */
.jobs { display: grid; gap: 8px; padding-top: 12px; }
.job { background: var(--bg-card); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: var(--radius); padding: 14px; transition: border-color .2s; }
.job.done { border-left-color: var(--accent-green); }
.job.failed { border-left-color: var(--accent-red); }
.job.running { border-left-color: var(--accent); }
.job.cancelled { border-left-color: var(--text-dim); }
.job.cancelling { border-left-color: var(--accent-orange); }

.job-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.job-head > strong { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.job.done .job-head > strong { color: var(--accent-green); }
.job.failed .job-head > strong { color: var(--accent-red); }
.job.running .job-head > strong { color: var(--accent); }
.job.cancelled .job-head > strong { color: var(--text-dim); }
.job.cancelling .job-head > strong { color: var(--accent-orange); }
.job-head > span { color: var(--text-dim); font-size: 11px; font-family: var(--font-mono); }
.head-spacer { flex: 1; }
.job-actions { display: flex; gap: 6px; }
.job-path { font-size: 12px; color: var(--text-muted); word-break: break-all; margin: 2px 0; font-family: var(--font-mono); }
.job-msg { font-size: 13px; margin: 4px 0; color: var(--text); }
.job small { display: block; color: var(--text-dim); font-size: 11px; font-family: var(--font-mono); word-break: break-all; margin-top: 4px; }

/* ═══ PROGRESS ═══ */
.progress-bar { height: 5px; background: #21262d; border-radius: 99px; margin: 8px 0 6px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width .6s ease; }
.progress-fill.progress-local { background: linear-gradient(to right, #d29922, #e3b341); }
.progress-fill.progress-cloud { background: linear-gradient(to right, #58a6ff, #79c0ff); }
.progress-fill.progress-final { background: linear-gradient(to right, #2ea043, #3fb950); }

.timing { color: var(--text-muted); font-size: 12px; margin-left: auto; font-family: var(--font-mono); }
.completed-time { display: block; color: var(--text-muted); font-size: 12px; margin-top: 2px; font-family: var(--font-mono); }

/* ═══ PAGER ═══ */
.pager { display: flex; justify-content: center; align-items: center; gap: 10px; padding: 16px 0 0; }
.pager button { padding: 8px 20px; font-size: 13px; border-radius: var(--radius); background: var(--bg-card); color: var(--text-muted); border: 1px solid var(--border); font-family: inherit; min-height: 40px; }
.pager button:disabled { opacity: .3; cursor: default; }
.pager button:disabled:active { transform: none; }
.pager span { color: var(--text-muted); font-size: 13px; }

/* ═══ TOOLS ═══ */
.jobs-tools { margin: 10px 0 14px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }
.jobs-tools.hidden { display: none; }
.retry-all-btn { background: var(--accent-red); color: #fff; border: 0; border-radius: var(--radius); padding: 8px 14px; font-size: 12px; font-weight: 600; cursor: pointer; }

.cancel-btn { background: transparent; color: var(--accent-red); border: 1px solid var(--accent-red); border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; min-height: auto; font-weight: 500; }
.cancel-btn:hover { background: rgba(248,81,73,.12); }
.retry-btn { background: transparent; color: var(--accent); border: 1px solid var(--accent); border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; min-height: auto; font-weight: 500; }
.retry-btn:hover { background: rgba(88,166,255,.12); }
.delete-btn { background: transparent; color: var(--text-dim); border: 1px solid var(--border); border-radius: 6px; padding: 4px 12px; font-size: 12px; cursor: pointer; min-height: auto; font-weight: 500; }
.delete-btn:hover { color: var(--accent-red); border-color: var(--accent-red); background: rgba(248,81,73,.08); }

.empty { color: var(--text-dim); text-align: center; padding: 40px 0; font-size: 14px; }

/* ═══ SPLASH ═══ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  background: var(--bg);
  transition: opacity .4s ease;
}
.splash.is-hidden {
  opacity: 0;
  pointer-events: none;
}
.splash-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}
.splash-icon {
  width: 64px;
  height: 64px;
  background: var(--accent);
  border-radius: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 8px 32px rgba(37,99,235,.25);
}
.splash-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: .02em;
}
.splash-dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: splashPulse 1.2s ease-in-out infinite;
}
@keyframes splashPulse {
  0%, 100% { opacity: .3; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

/* ═══ THEME TOGGLE ═══ */
.theme-btn .sun-icon,
.theme-btn .moon-icon {
  display: none;
}
:root .theme-btn .moon-icon { display: block; }
:root.light .theme-btn .sun-icon { display: block; }
:root.light .theme-btn .moon-icon { display: none; }
.theme-btn { margin-top: auto; margin-bottom: 12px; }

/* ═══ RESPONSIVE ═══ */
@media (min-width: 768px) {
  .dock { display: flex; }
  .dock-mobile { display: none; }
  .main-content { margin-left: var(--dock-width); }
  .main-content > .view { max-width: none; padding: 32px 40px 80px; }
}
@media (max-width: 767px) {
  .dock { display: none; }
  .dock-mobile { display: flex; }
  .main-content > .view { padding: 16px 14px 88px; }
  .gallery-card { flex: 0 0 calc(50vw - 18px); }
  .gallery-section-header { font-size: 14px; }
  .view-header h1 { font-size: 18px; }
  .view-header { margin-bottom: 14px; padding-bottom: 12px; }
  .card { padding: 16px; }
  .config-label-row { flex-wrap: wrap; }
  .job { padding: 12px; }
  input { padding: 12px; font-size: 16px; }
  button { min-height: 44px; }
  .gallery { grid-template-columns: 1fr; gap: 10px; }
  .jobs-tools { flex-direction: column; align-items: stretch; }
  .retry-all-btn { width: 100%; text-align: center; }
}
