:root {
  --bg: #10141c;
  --bg-2: #1a202c;
  --card: #1f2937;
  --card-2: #283243;
  --text: #e5e7eb;
  --text-dim: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #2d3748;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 22px;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #f97316;
  letter-spacing: 0.3px;
}
.brand-icon {
  width: 42px;
  height: 42px;
  display: block;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

.controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Label horizontal neben dem Select — damit passen alle Controls auf eine Zeile */
.field-label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.field-label select {
  font-size: 13px;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
}

.search-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}
.search-wrap input[type="search"] {
  padding-right: 28px;
}
/* Eingebautes Clear-Kreuz einiger Browser ausblenden — wir nutzen unser eigenes */
.search-wrap input[type="search"]::-webkit-search-cancel-button { display: none; }
.search-clear {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 14px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}
.search-clear:hover {
  color: var(--text);
  background: var(--card-2);
}

input, select, button {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
}
button { cursor: pointer; }
button:hover { background: var(--card-2); }
button.primary { background: var(--accent); border-color: var(--accent); }
button.primary:hover { background: var(--accent-hover); }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 4px;
  font-size: 20px;
  color: var(--text-dim);
  font-weight: 400;
}
.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
  cursor: pointer;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--text-dim); }
.breadcrumb .current { color: var(--text); font-weight: 600; }
.breadcrumb .count {
  color: var(--text-dim);
  font-weight: 400;
  font-size: 14px;
  margin-left: 6px;
}
.breadcrumb .back-btn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text);
  padding: 0;
  margin-right: 4px;
  transition: background .15s;
}
.breadcrumb .back-btn:hover { background: var(--card-2); border-color: var(--accent); }
.breadcrumb .toolbar {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}
.breadcrumb .toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  cursor: pointer;
}
.breadcrumb .toolbar .status {
  font-size: 12px;
  color: var(--text-dim);
}
.breadcrumb .toolbar .status .progress {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 4px;
  overflow: hidden;
}
.breadcrumb .toolbar .status .progress > div {
  height: 100%;
  background: var(--accent);
  transition: width .3s;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
  padding: 16px;
}

/* Folder tile */
.card.folder .thumb {
  position: relative;
  background-color: var(--card-2);
}
.card.folder .folder-gear {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.65);
  color: #fff;
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  padding: 0;
  cursor: pointer;
  font-size: 13px;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.card.folder:hover .folder-gear,
.card.folder:focus-within .folder-gear {
  opacity: 1;
}
.card.folder .folder-gear:hover { background: var(--accent); }

.card.folder .drilldown-indicator {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(59, 130, 246, 0.9);
  color: #fff;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 600;
}
.card.folder .folder-glyph {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 54px;
  color: rgba(255,255,255,0.85);
  text-shadow: 0 2px 8px rgba(0,0,0,0.6);
  pointer-events: none;
}
.card.folder .folder-count {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
}

.card {
  background: var(--card);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
  border: 1px solid var(--border);
  /* Natives Virtual-Scrolling: Browser rendert nur sichtbare Kacheln.
     intrinsic-size ist eine Schätzung für nicht-sichtbare Kacheln, damit die
     Scrollbar-Höhe stimmt. */
  content-visibility: auto;
  contain-intrinsic-size: 200px 260px;
}
.card.card--poster {
  contain-intrinsic-size: 200px 380px;
}
.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0,0,0,0.4);
  border-color: var(--accent);
}

.thumb {
  aspect-ratio: 16 / 9;
  background: #000 center/cover no-repeat;
  position: relative;
}
/* Bei Movies/TV-Libs sind die Bilder TMDB-Poster (2:3) — Kachelformat entsprechend */
.card.card--poster .thumb {
  aspect-ratio: 2 / 3;
}
.thumb .badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.thumb .duration {
  position: absolute;
  right: 6px;
  bottom: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.thumb .res-badge {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .3px;
}

.card-body { padding: 8px 10px 10px; }
.card-title {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-meta {
  margin-top: 2px;
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  gap: 8px;
}

.scanbar {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 420px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}
.scanbar .bar {
  height: 4px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.scanbar .bar > div {
  height: 100%;
  background: var(--accent);
  width: 0;
  transition: width .3s;
}
.scanbar.trickbar { bottom: 90px; }
.scanbar.trickbar .bar > div { background: #f59e0b; }

/* Dialogs */
dialog {
  border: none;
  color: var(--text);
  background: var(--card);
  border-radius: 10px;
  padding: 0;
  max-width: 90vw;
}
dialog::backdrop { background: rgba(0,0,0,0.6); }

.modal {
  padding: 20px 24px 18px;
  min-width: 360px;
  max-width: 520px;
  position: relative;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  padding: 0;
  line-height: 1;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); background: var(--card-2); }
.modal h2 { margin: 0 0 8px; }
.modal h3 { margin: 14px 0 8px; font-size: 14px; color: var(--text-dim); }

.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form input, .form select { width: 100%; }
.form .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.hint { color: var(--text-dim); font-size: 12px; margin: 4px 0 0; }

#libList { list-style: none; margin: 0; padding: 0; }
#libList li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
#libList li:last-child { border-bottom: 0; }
.lib-row-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.lib-paths {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.lib-path-row {
  display: flex;
  gap: 6px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.lib-path-row code {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  word-break: break-all;
}

/* Player dialog */
.player-dialog {
  width: min(1200px, 95vw);
  background: #000;
}
.player-wrap { display: flex; flex-direction: column; }
.player-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  background: #111;
  color: var(--text);
}
.player-title { font-weight: 600; }
.player-close {
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 18px;
}
#video {
  width: 100%;
  max-height: 75vh;
  background: #000;
  display: block;
}
.player-meta {
  padding: 10px 14px;
  background: #111;
  color: var(--text-dim);
  font-size: 12px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.player-meta strong { color: var(--text); }

.empty {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 20px;
  grid-column: 1 / -1;
}

/* Path input + browse dialog */
.path-input { display: flex; gap: 6px; }
.path-input input { flex: 1; }

.crumbs {
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  margin-bottom: 10px;
  word-break: break-all;
}

.browse-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
  max-height: 360px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-2);
}
.browse-list li {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.browse-list li:last-child { border-bottom: none; }
.browse-list li:hover { background: var(--card-2); }
.browse-list li.up { color: var(--text-dim); }

/* Player mode switch */
.player-modeswitch {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  margin-left: auto;
  margin-right: 44px;   /* Platz für den Schließen-Button */
  align-items: center;
  justify-content: flex-end;
  font-size: 12px;
  color: var(--text-dim);
  max-width: 100%;
  min-width: 0;
}
.player-modeswitch label {
  display: inline-flex;
  gap: 5px;
  align-items: center;
  min-width: 0;
}
.player-modeswitch select {
  padding: 4px 6px;
  font-size: 12px;
  max-width: 170px;
  min-width: 0;
  text-overflow: ellipsis;
}
.player-head { flex-wrap: wrap; gap: 8px; }
.player-close {
  position: absolute;
  top: 8px;
  right: 10px;
}
.player-head { position: relative; padding-right: 44px; }
/* Video.js-Controlbar-Buttons für Shuffle-Prev/Next: nutzen Unicode-Glyphen */
.video-js .vjs-shuffle-prev .vjs-icon-placeholder::before,
.video-js .vjs-shuffle-next .vjs-icon-placeholder::before {
  font-family: inherit;
  font-size: 1.4em;
  line-height: 1.67;
}
.video-js .vjs-shuffle-prev .vjs-icon-placeholder::before { content: "⏮"; }
.video-js .vjs-shuffle-next .vjs-icon-placeholder::before { content: "⏭"; }
.video-js .vjs-shuffle-prev.vjs-disabled,
.video-js .vjs-shuffle-next.vjs-disabled { opacity: 0.3; cursor: default; }

/* Favorit-Button in der Player-Control-Bar */
.video-js .vjs-favorite .vjs-icon-placeholder::before {
  font-family: inherit;
  font-size: 1.4em;
  line-height: 1.67;
  content: "♡";
}
.video-js .vjs-favorite.vjs-favorite--on .vjs-icon-placeholder::before {
  content: "♥";
  color: #ef4444;
}

/* Zu-Playlist-Button */
.video-js .vjs-addplaylist .vjs-icon-placeholder::before {
  font-family: inherit;
  font-size: 1.3em;
  line-height: 1.7;
  content: "📋";
}

details.hint summary { cursor: pointer; color: var(--text); font-weight: 500; }
details.hint[open] { color: var(--text-dim); }
details.hint p { margin: 6px 0; }

/* TMDB / Ratings / Detail */
.rating {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.75);
  color: #fbbf24;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.watched-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(34, 197, 94, 0.9);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  box-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.fav-badge {
  position: absolute;
  top: 6px;
  left: 34px;
  color: #ef4444;
  font-size: 18px;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.tp-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 11px;
  padding: 1px 4px;
  border-radius: 3px;
  line-height: 1.3;
}
.tp-pending { background: rgba(234, 88, 12, 0.85); }
.tp-failed  { background: rgba(220, 38, 38, 0.9); font-weight: 600; }

.card.watched .thumb { opacity: 0.6; }
.card.watched .card-title { color: var(--text-dim); }

button.danger { background: #7f1d1d; border-color: #7f1d1d; }
button.danger:hover { background: #991b1b; }

.btn-group {
  display: inline-flex;
  align-items: stretch;
}
.btn-group button { border-radius: 6px; }
.btn-group > button:first-child {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: 0;
}
.btn-group > button:last-child {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  padding: 6px 8px;
}

.dropdown {
  position: absolute;
  top: 52px;
  right: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
  padding: 4px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  min-width: 260px;
}
.dropdown button {
  background: transparent;
  border: none;
  text-align: left;
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--text);
}
.dropdown button:hover { background: var(--card-2); }

.detail-modal { min-width: 720px; max-width: 900px; padding: 0; }
.detail-wrap {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 20px;
  padding: 20px;
}
.detail-poster {
  width: 200px;
  aspect-ratio: 2/3;
  background: var(--card-2) center/cover no-repeat;
  border-radius: 8px;
}
.detail-body h2 { margin: 0 0 4px; font-size: 20px; }
.detail-body .sub {
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 10px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-body .sub .rating-pill {
  color: #fbbf24;
  font-weight: 600;
}
.detail-body .overview { line-height: 1.5; }
.detail-modal .row { padding: 12px 20px 16px; margin: 0; border-top: 1px solid var(--border); }

.match-results {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  max-height: 420px;
  overflow-y: auto;
}
.match-results li {
  display: grid;
  grid-template-columns: 60px 1fr;
  gap: 10px;
  padding: 10px 8px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  align-items: start;
}
.match-results li:hover { background: var(--card-2); }
.match-results .mini {
  width: 60px;
  aspect-ratio: 2/3;
  background: var(--bg-2) center/cover no-repeat;
  border-radius: 4px;
}
.match-results .meta { font-size: 12px; }
.match-results .meta strong { font-size: 13px; }
.match-results .meta p {
  margin: 4px 0 0;
  color: var(--text-dim);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.lib-kind {
  display: inline-block;
  padding: 1px 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 6px;
}

.user-menu {
  margin-left: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.user-menu strong { color: var(--text); }
.user-menu button {
  font-size: 12px;
  padding: 4px 8px;
}
.admin-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}
