:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-alt: #1c222b;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --ok: #22c55e;
  --warn: #f59e0b;
  --err: #ef4444;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

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

.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #ec4899);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.5px;
}

.brand-title { font-size: 16px; font-weight: 700; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 18px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav-item {
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--panel-alt); color: var(--text); }
.nav-item.active { background: rgba(99, 102, 241, 0.18); color: #a5b4fc; font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.status-pill {
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--panel-alt);
  color: var(--muted);
}
.status-pill.ok { color: #86efac; background: rgba(34, 197, 94, 0.14); }
.status-pill.err { color: #fca5a5; background: rgba(239, 68, 68, 0.14); }

.main {
  flex: 1;
  padding: 24px 28px;
  overflow-x: auto;
}

.auth-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.hidden { display: none !important; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-header h1 { margin: 0 0 4px; font-size: 21px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.header-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-val { font-size: 24px; font-weight: 700; }
.stat-val.accent { color: #818cf8; }
.stat-val.warn { color: var(--warn); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar-left, .toolbar-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.table-wrap { padding: 0; overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-alt); }
tr:hover td { background: rgba(255,255,255,0.02); }
.empty-cell { text-align: center; padding: 36px; color: var(--muted); }

.text-input, .select-input, .textarea-input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 11px;
  font-size: 13px;
}
.textarea-input { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.flex-1 { flex: 1; }

.btn {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { border-color: #4b5563; background: #262e3a; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  margin: 2px 3px 2px 0;
  background: var(--panel-alt);
  color: var(--text);
  border: 1px solid var(--border);
}
.badge-code { background: rgba(99,102,241,0.18); border-color: rgba(99,102,241,0.4); color: #c7d2fe; font-weight: 700; font-family: monospace; }
.badge-tag { background: rgba(14,165,233,0.15); border-color: rgba(14,165,233,0.35); color: #7dd3fc; }
.badge-warn { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.35); color: #fcd34d; }
.badge-err { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.35); color: #fca5a5; }
.badge-ok { background: rgba(34,197,94,0.15); border-color: rgba(34,197,94,0.35); color: #86efac; }

.search-bar-card { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.scrape-result { margin-top: 16px; display: grid; grid-template-columns: 280px 1fr; gap: 20px; }
@media (max-width: 860px) { .scrape-result { grid-template-columns: 1fr; } }

.poster-img { width: 100%; border-radius: 10px; border: 1px solid var(--border); display: block; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 960px) { .two-col { grid-template-columns: 1fr; } }

.form-group { margin-bottom: 12px; display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; color: var(--muted); }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; }
.checkbox-label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.checkbox-stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.card-head-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

.muted-small { color: var(--muted); font-size: 12px; word-break: break-all; }
.chip-list, .health-list, .logs-list, .cache-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  gap: 10px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  background: #1f2937;
  border: 1px solid var(--accent);
  color: #fff;
  padding: 11px 16px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  z-index: 999;
}

.job-banner {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.job-banner-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
}
.progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--bg);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #22c55e);
  transition: width 0.25s ease;
}

.nav-group-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  padding: 10px 10px 4px;
  opacity: 0.75;
}

.subtab-bar { display: flex; gap: 6px; flex-wrap: wrap; }

/* Movie Discovery & Recommendation Cards */
.movie-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(225px, 1fr));
  gap: 16px;
}

.movie-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s, border-color 0.15s;
}
.movie-card:hover { transform: translateY(-2px); border-color: #4b5563; }

.movie-cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  background: #0b0e14;
  overflow: hidden;
}
.movie-cover-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.cover-top-left {
  position: absolute;
  top: 8px;
  left: 8px;
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.cover-top-right {
  position: absolute;
  top: 8px;
  right: 8px;
}
.match-pill {
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(236, 72, 153, 0.55);
  color: #f9a8d4;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.owned-pill {
  background: rgba(22, 163, 74, 0.9);
  color: #fff;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.movie-card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.movie-card-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.movie-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.movie-card-actions {
  margin-top: auto;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

/* Radar Chart Layout */
.radar-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 18px;
}
@media (max-width: 960px) { .radar-layout { grid-template-columns: 1fr; } }

.radar-svg-box {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 360px;
}
.radar-legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); align-items: center; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.dot-all { background: #6366f1; }
.dot-recent { background: #ec4899; }

.delta-list { display: flex; flex-direction: column; gap: 10px; }
.delta-row { display: flex; flex-direction: column; gap: 4px; }
.delta-head { display: flex; justify-content: space-between; font-size: 12px; }
.delta-bars { display: flex; flex-direction: column; gap: 3px; }
.mini-bar-track { height: 5px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.mini-bar-all { height: 100%; background: #6366f1; border-radius: 999px; }
.mini-bar-recent { height: 100%; background: #ec4899; border-radius: 999px; }
.delta-up { color: #86efac; font-weight: 600; }
.delta-down { color: #fca5a5; font-weight: 600; }

.chip-wrap { display: flex; flex-wrap: wrap; gap: 6px; }

.actors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.actor-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.actor-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-alt);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--muted);
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 680px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-card.modal-xl {
  max-width: 1040px;
  max-height: 90vh;
}

.clickable { cursor: pointer; }
.src-pill-jf { background: rgba(99, 102, 241, 0.9); color: #fff; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.src-pill-115 { background: rgba(14, 165, 233, 0.92); color: #fff; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; }

/* Immersive Movie Detail Layout */
.detail-hero {
  display: grid;
  grid-template-columns: 230px 1fr;
  gap: 20px;
  margin-bottom: 18px;
}
@media (max-width: 820px) { .detail-hero { grid-template-columns: 1fr; } }

.detail-poster {
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
}

.detail-action-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin: 12px 0;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.embed-player-wrap {
  margin: 14px 0;
  background: #000;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.embed-player-wrap video {
  width: 100%;
  max-height: 520px;
  display: block;
  background: #000;
}

.detail-radar-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 14px;
}
@media (max-width: 820px) { .detail-radar-grid { grid-template-columns: 1fr; } }

.badge-hit {
  background: rgba(236, 72, 153, 0.2);
  border-color: rgba(236, 72, 153, 0.55);
  color: #f9a8d4;
  font-weight: 600;
}

.stills-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-top: 10px;
}
.stills-strip img {
  height: 120px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  flex-shrink: 0;
  transition: transform 0.15s, border-color 0.15s;
}
.stills-strip img:hover { transform: scale(1.03); border-color: var(--accent); }

/* In-page Image Lightbox */
.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1200;
  padding: 36px 64px;
}
.lb-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 90vh;
}
.lb-img {
  max-width: 90vw;
  max-height: 84vh;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.75);
}
.lb-caption {
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}
.lb-close {
  position: fixed;
  top: 18px;
  right: 22px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(22, 27, 34, 0.85);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
}
.lb-close:hover { background: rgba(99, 102, 241, 0.85); }
.lb-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 58px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(22, 27, 34, 0.75);
  color: #fff;
  font-size: 30px;
  line-height: 1;
  cursor: pointer;
}
.lb-nav:hover { background: rgba(99, 102, 241, 0.8); }
.lb-prev { left: 16px; }
.lb-next { right: 16px; }

/* Actress Classification Menu Bar in Unified Library */
.actor-menu-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.actor-menu-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.actor-menu-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.actor-menu-strip.expanded {
  flex-wrap: wrap;
  overflow-x: visible;
  max-height: 260px;
  overflow-y: auto;
}
.actor-pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.actor-pill-btn:hover { border-color: var(--accent); background: var(--panel-alt); }
.actor-pill-btn.active {
  background: rgba(99, 102, 241, 0.22);
  border-color: var(--accent);
  color: #c7d2fe;
  font-weight: 600;
}
.actor-pill-img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--panel-alt);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
}

/* Seed-Based Custom Recommender */
.seed-picker-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-height: 170px;
  overflow-y: auto;
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.seed-selected-bar {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.seed-actors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}
.seed-actor-rec-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.seed-actor-rec-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Full-screen Login Page */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.16), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.12), transparent 45%),
    var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.login-brand .brand-logo {
  width: 44px;
  height: 44px;
  font-size: 18px;
  border-radius: 12px;
}
.login-brand h2 {
  margin: 0;
  font-size: 20px;
}
.login-error {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  font-size: 13px;
}
.login-submit-btn {
  width: 100%;
  padding: 11px 16px;
  font-size: 15px;
  font-weight: 600;
  margin-top: 8px;
}

/* Sidebar User Card */
.user-account-card {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user-account-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.user-account-name {
  font-weight: 600;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-account-actions {
  display: flex;
  gap: 6px;
}
.user-account-actions .btn {
  flex: 1;
  padding: 4px 8px;
  font-size: 12px;
}
.badge-admin {
  background: rgba(99, 102, 241, 0.22);
  color: #c7d2fe;
}
.badge-user {
  background: rgba(34, 197, 94, 0.16);
  color: #86efac;
}
