:root {
  --bg: #0a0e15;
  --surface: #121926;
  --surface-2: #182133;
  --line: #232f44;
  --text: #e9eff9;
  --muted: #8b9bb4;
  --accent: #6c8dff;
  --accent-ink: #0b1220;
  --good: #3ddc97;
  --warn: #ffba63;
  --bad: #ff7a7a;
  --radius: 14px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  background: radial-gradient(1200px 600px at 20% -10%, #16213a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  padding-bottom: 96px;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: 17px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 18px;
}

a {
  color: var(--accent);
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background: linear-gradient(160deg, var(--accent), #3a5bd9);
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  flex: none;
}

.brand-text p {
  margin: 2px 0 0;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.btn:hover {
  background: var(--surface-2);
  border-color: #33415c;
}

.btn:active {
  transform: translateY(1px);
}

.btn.ghost {
  background: transparent;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0b1220;
  font-weight: 650;
}

.btn.primary:hover {
  background: #82a0ff;
}

.btn.danger {
  color: var(--bad);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn.key {
  gap: 9px;
}

.btn.key .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 20%, transparent);
}

.btn.key.ok .dot {
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent);
}

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 22px 0;
}

.tab {
  padding: 8px 14px;
  border-radius: 10px 10px 0 0;
  border: 1px solid transparent;
  border-bottom: 0;
  background: none;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.tab.active {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.pill {
  display: inline-block;
  min-width: 22px;
  padding: 1px 7px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

/* ---------- toolbar ---------- */

main {
  padding: 0 22px 40px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px;
  padding: 14px 0;
  position: sticky;
  top: 65px;
  z-index: 10;
  background: linear-gradient(var(--bg) 70%, color-mix(in srgb, var(--bg) 0%, transparent));
}

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 280px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
}

.search svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  flex: none;
}

.search input {
  flex: 1;
  padding: 10px 0;
  border: 0;
  background: none;
  color: var(--text);
  font: inherit;
  outline: none;
}

select {
  padding: 9px 10px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  max-width: 100%;
}

select:focus-visible,
.search:focus-within,
.btn:focus-visible,
input:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: 1px;
}

.lang {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
}

.lang button {
  padding: 9px 12px;
  border: 0;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.lang button.active {
  background: var(--surface-2);
  color: var(--text);
}

#resultCount {
  margin-left: auto;
  white-space: nowrap;
}

/* ---------- grid ---------- */

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

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card:hover {
  border-color: #3a4a68;
  transform: translateY(-2px);
}

.card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.thumb {
  position: relative;
  aspect-ratio: 1;
  background: #f2f5fa;
  overflow: hidden;
}

.thumb img,
.thumb video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.thumb video {
  opacity: 0;
  transition: opacity 0.2s ease;
}

.thumb video.on {
  opacity: 1;
}

/* Quelle des Bilds/Clips, damit man im Raster sieht, woher die Datei kommt.
   Im Ruhezustand das Standbild, während der Clip läuft dessen Quelle. */
.thumb .source {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 3;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #dbe6f5;
  background: color-mix(in srgb, #0a0e15 68%, transparent);
  border: 1px solid color-mix(in srgb, #dbe6f5 18%, transparent);
}

.thumb .source .source-hover {
  display: none;
}

.thumb video.on ~ .source .source-rest {
  display: none;
}

.thumb video.on ~ .source .source-hover {
  display: inline;
}

.kv dd.media-path {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  word-break: break-all;
}

.pick {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: color-mix(in srgb, #0a0e15 72%, transparent);
  border: 1px solid #3a4a68;
  cursor: pointer;
}

.pick input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 3;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.01em;
  background: color-mix(in srgb, #0a0e15 70%, transparent);
  color: var(--muted);
  border: 1px solid var(--line);
}

.badge.good {
  color: #062b1e;
  background: var(--good);
  border-color: var(--good);
}

.badge.accent {
  color: #08122b;
  background: var(--accent);
  border-color: var(--accent);
}

.badge.bad {
  color: #2b0707;
  background: var(--bad);
  border-color: var(--bad);
}

.card-body {
  padding: 10px 12px 12px;
}

.card-body h3 {
  font-size: 14px;
  font-weight: 620;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-body .sub {
  margin: 2px 0 8px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.meta span {
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.grid-foot {
  display: grid;
  place-items: center;
  padding: 22px 0;
}

/* ---------- cart ---------- */

.cart {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 10px 12px 10px 18px;
  border-radius: 14px;
  border: 1px solid #33415c;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.9);
}

.cart-info {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.cart-info strong {
  color: var(--text);
  font-size: 17px;
}

/* ---------- dialogs ---------- */

.dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.95);
}

.dialog.wide {
  width: min(760px, calc(100vw - 32px));
}

.dialog::backdrop {
  background: rgba(4, 7, 12, 0.72);
  backdrop-filter: blur(3px);
}

.dialog-body {
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.lang-field {
  max-width: 280px;
  margin-bottom: 10px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input[type="password"],
input[type="text"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

.dialog-foot #importProgress {
  margin-right: auto;
}

/* ---------- detail ---------- */

.detail-top {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
}

.detail-media {
  border-radius: 12px;
  overflow: hidden;
  background: #f2f5fa;
  aspect-ratio: 1;
}

.detail-media video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ---------- Vorschau und Quellenwahl ---------- */

.preview-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.preview-media {
  margin-top: 14px;
  display: grid;
  place-items: center;
  max-height: 58vh;
  border-radius: 12px;
  background: #f2f5fa;
  overflow: hidden;
}

.preview-media video,
.preview-media img {
  display: block;
  max-width: 100%;
  max-height: 58vh;
}

.preview-path {
  margin: 10px 0 0;
  word-break: break-all;
}

.media-choices {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-left: 8px;
  vertical-align: middle;
}

.preview-head .media-choices {
  margin-left: 0;
}

.media-choices button {
  padding: 1px 7px;
  border-radius: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  cursor: pointer;
}

.media-choices button:hover {
  color: var(--text);
}

.media-choices button.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
}

.detail-title h2 {
  font-size: 20px;
}

.detail-title .sub {
  margin: 4px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 13px;
}

.kv dt {
  color: var(--muted);
}

.kv dd {
  margin: 0;
}

.detail-text {
  font-size: 14px;
  color: #cfdaeb;
}

.detail-text ol {
  margin: 8px 0 0;
  padding-left: 20px;
}

.detail-text li {
  margin-bottom: 5px;
}

.payload {
  padding: 12px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: var(--bg);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: #b9c8dd;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- created ---------- */

.created-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 12px;
}

.created-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.created-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}

.created-row .created-thumb {
  position: relative;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  overflow: hidden;
  background: #f2f5fa;
  flex: none;
}

.created-row .created-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 0;
  object-fit: contain;
}

/* Quelle von Bild und Clip, im Stil des Raster-Labels. Auf 46 px passen die
   Pills nicht aufs Bild, deshalb sitzen sie direkt daneben unter der Zeile. */
.created-row .media-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.created-row .media-sources .source {
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.created-row .grow {
  flex: 1;
  min-width: 0;
}

.created-row strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.created-row .line {
  font-size: 12px;
  color: var(--muted);
}

.section-title {
  margin: 26px 0 10px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

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

.chips span {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
}

/* ---------- import ---------- */

.import-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 46vh;
  overflow: auto;
  padding-right: 4px;
}

.imp-row {
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
}

.imp-row img {
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: #f2f5fa;
  object-fit: contain;
}

/* Miniatur ist der Einstieg in die Vorschau mit Video und Quellenwahl. */
.imp-thumb {
  width: 46px;
  height: 46px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f5fa;
  cursor: zoom-in;
}

.imp-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 0;
  object-fit: contain;
}

.imp-thumb:hover {
  border-color: color-mix(in srgb, var(--accent) 60%, var(--line));
}

.imp-row input {
  font-size: 14px;
  padding: 7px 9px;
}

.imp-row .imp-meta {
  margin-top: 4px;
  font-size: 11.5px;
  color: var(--muted);
}

.imp-state {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.imp-row.created {
  border-color: color-mix(in srgb, var(--good) 55%, var(--line));
}

.imp-row.created .imp-state {
  color: var(--good);
}

.imp-row.skipped .imp-state {
  color: var(--warn);
}

.imp-row.error {
  border-color: color-mix(in srgb, var(--bad) 55%, var(--line));
}

.imp-row.error .imp-state {
  color: var(--bad);
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 92px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(560px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 11px;
  border: 1px solid #33415c;
  background: #1b2436;
  color: var(--text);
  font-size: 14px;
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.9);
}

.toast.error {
  border-color: color-mix(in srgb, var(--bad) 60%, var(--line));
}

.toast.good {
  border-color: color-mix(in srgb, var(--good) 60%, var(--line));
}

@media (max-width: 760px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .toolbar {
    top: 0;
  }

  .detail-top {
    grid-template-columns: 1fr;
  }

  .detail-media {
    max-width: 240px;
  }
}
