:root {
  --bg: #0b0e14;
  --bg-soft: #121620;
  --panel: #161b27;
  --panel-2: #1c2231;
  --line: #262e3f;
  --text: #e8ecf4;
  --muted: #9aa6bd;
  --accent: #ffcc4d;
  --accent-2: #ffb020;
  --ok: #34d399;
  --warn: #fbbf24;
  --info: #60a5fa;
  --danger: #f87171;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

/* The `hidden` attribute must always win, even over rules that set `display`
   (e.g. .modal { display: grid } / .toolbar { display: flex }). */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1200px 600px at 100% -10%, #1a2133 0%, transparent 60%),
    radial-gradient(900px 500px at -10% 0%, #1a1626 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  min-height: 100vh;
  line-height: 1.45;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.75);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(145deg, #1b1b1b 0%, #000 40%, #d00 40%, #d00 60%, #ffce00 60%, #ffce00 80%, #000 80%);
  color: transparent;
  font-weight: 800;
  font-size: 0;
  box-shadow: var(--shadow);
  flex: none;
}

.brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.conn {
  display: flex;
  gap: 8px;
  font-size: 0.78rem;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  white-space: nowrap;
}

.pill.on {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.35);
}

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

.pill.warn {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
}

/* ------------------------------- layout -------------------------------- */

main {
  padding: clamp(16px, 3vw, 32px) clamp(16px, 4vw, 40px) 80px;
  max-width: 1600px;
  margin: 0 auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-soft) 100%);
  box-shadow: var(--shadow);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 120px;
}

.field.grow {
  flex: 1 1 240px;
}

.field label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
  color: var(--text);
}

input[type="search"],
input[type="number"],
select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 204, 77, 0.15);
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--muted);
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  cursor: pointer;
  user-select: none;
  min-height: 41px;
}

.check input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 18px 2px 12px;
}

.count {
  color: var(--muted);
  font-size: 0.85rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px;
}

.link-btn:hover {
  text-decoration: underline;
}

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

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
  gap: clamp(12px, 1.6vw, 20px);
}

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

.card:hover {
  transform: translateY(-4px);
  border-color: #3a465e;
  box-shadow: var(--shadow);
}

.poster {
  position: relative;
  aspect-ratio: 2 / 3;
  background: linear-gradient(160deg, var(--panel-2), #0e1220);
  overflow: hidden;
}

.poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.poster .placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 12px;
  text-align: center;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  background:
    repeating-linear-gradient(-45deg, #141a28 0 12px, #171e2e 12px 24px);
}

.rating {
  position: absolute;
  top: 8px;
  left: 8px;
  background: rgba(0, 0, 0, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 0.74rem;
  font-weight: 700;
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.rating::before {
  content: "★";
  color: var(--accent);
}

.badge {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
  backdrop-filter: blur(4px);
}

.badge.available {
  background: rgba(52, 211, 153, 0.18);
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.4);
}

.badge.requested,
.badge.approved,
.badge.processing,
.badge.partial {
  background: rgba(96, 165, 250, 0.18);
  color: var(--info);
  border-color: rgba(96, 165, 250, 0.4);
}

.badge.declined {
  background: rgba(248, 113, 113, 0.16);
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.4);
}

.card-info {
  padding: 10px 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}

.card-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-year {
  font-size: 0.76rem;
  color: var(--muted);
}

.card .btn {
  margin-top: auto;
}

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

.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  width: 100%;
}

.btn:hover:not(:disabled) {
  background: #232b3d;
  border-color: #3a465e;
}

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

.btn.primary {
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #1a1400;
  border-color: var(--accent-2);
}

.btn.primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn.ghost {
  background: transparent;
}

a.btn {
  text-decoration: none;
}

/* Available movie: show "Verfügbar" normally, a Jellyfin play button on hover. */
.btn.play .play-on {
  display: none;
}

.card:hover .btn.play .play-off {
  display: none;
}

.card:hover .btn.play .play-on {
  display: inline;
}

.card:hover .btn.play {
  background: linear-gradient(180deg, var(--ok) 0%, #10b981 100%);
  color: #05231a;
  border-color: #10b981;
}

.detail-actions .btn.play {
  background: linear-gradient(180deg, var(--ok) 0%, #10b981 100%);
  color: #05231a;
  border-color: #10b981;
}

.btn.spin {
  color: transparent;
  position: relative;
}

.btn.spin::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: #1a1400;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loadmore-wrap {
  display: flex;
  justify-content: center;
  margin-top: 28px;
}

.loadmore {
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 999px;
  padding: 12px 28px;
  cursor: pointer;
  font-weight: 600;
}

.loadmore:hover {
  border-color: var(--accent);
}

.loadmore:disabled {
  opacity: 0.5;
  cursor: default;
}

/* -------------------------------- empty -------------------------------- */

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty h3 {
  color: var(--text);
  margin: 0 0 6px;
}

.empty code {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 0.82rem;
}

.setup {
  max-width: 620px;
  margin: 40px auto;
  text-align: left;
  line-height: 1.6;
}

.setup ol {
  padding-left: 20px;
}

/* -------------------------------- modal -------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 6, 10, 0.78);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: min(860px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}

.detail-hero {
  position: relative;
  aspect-ratio: 16 / 7;
  background: #0e1220;
  overflow: hidden;
}

.detail-hero img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.55;
}

.detail-hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 20%, var(--panel) 100%);
}

.detail-body {
  padding: 0 clamp(18px, 3vw, 30px) 28px;
  margin-top: -60px;
  position: relative;
  display: flex;
  gap: 22px;
}

.detail-poster {
  width: 150px;
  flex: none;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  background: var(--panel-2);
  aspect-ratio: 2 / 3;
}

.detail-poster img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-main {
  flex: 1;
  min-width: 0;
  padding-top: 54px;
}

.detail-main h2 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.detail-sub {
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 12px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0;
}

.chip {
  font-size: 0.74rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.chip.rating {
  position: static;
  border: 1px solid rgba(255, 204, 77, 0.35);
  color: var(--accent);
  background: rgba(255, 204, 77, 0.08);
}

.chip.rating::before {
  content: "★ ";
}

.detail-overview {
  margin: 14px 0 18px;
  font-size: 0.94rem;
  color: #cdd6e6;
}

.providers {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--muted);
}

.providers b {
  color: var(--text);
  font-weight: 600;
}

.detail-actions {
  margin-top: 18px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-actions .btn {
  width: auto;
  padding: 11px 22px;
}

.detail-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 10px;
}

/* -------------------------------- toasts ------------------------------- */

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 36px));
}

.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  font-size: 0.86rem;
  animation: slidein 0.2s ease;
}

.toast.success {
  border-left-color: var(--ok);
}

.toast.error {
  border-left-color: var(--danger);
}

.toast.info {
  border-left-color: var(--info);
}

@keyframes slidein {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
}

@media (max-width: 640px) {
  .detail-body {
    flex-direction: column;
    margin-top: -40px;
  }
  .detail-poster {
    width: 110px;
  }
  .detail-main {
    padding-top: 0;
  }
  .brand p {
    display: none;
  }
}
