:root {
  --bg: #0f1424;
  --bg-grad: radial-gradient(1200px 600px at 10% -10%, #1e3c72 0%, transparent 60%),
             radial-gradient(900px 500px at 110% 10%, rgba(249,115,22,.25) 0%, transparent 60%), #0f1424;
  --card: rgba(255,255,255,.06);
  --card-border: rgba(255,255,255,.14);
  --text: #f4f5f8;
  --muted: rgba(244,245,248,.62);
  --accent: #e5a00d;       /* Plex orange */
  --yt-red: #ff0033;
  --ok: #4ade80;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 14px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; background: var(--bg-grad); background-attachment: fixed;
  color: var(--text); font: 14px/1.45 Inter, -apple-system, "Segoe UI", sans-serif;
  padding: 0 16px 90px;
}
a { color: var(--accent); }
code { font-size: .9em; background: rgba(255,255,255,.08); padding: 1px 5px; border-radius: 4px; }
button, .button {
  font: inherit; border-radius: 9px; border: 1px solid var(--card-border); padding: 6px 12px;
  background: rgba(255,255,255,.08); color: var(--text); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { background: rgba(255,255,255,.16); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #1a1a1a; border-color: var(--accent); font-weight: 600; }
button.primary:hover:not(:disabled) { background: #f5b52a; }
button.ghost, .button.ghost { background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: rgba(0,0,0,.28); border: 1px solid var(--card-border);
  border-radius: 9px; padding: 6px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(229,160,13,.55); outline-offset: 0; }
select option { background: #1b2238; }

header.top {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px;
  max-width: 1100px; margin: 0 auto; padding: 18px 0 14px;
}
h1 { margin: 0; font-weight: 300; letter-spacing: 3px; text-transform: uppercase; font-size: 22px; }
.wordmark { font-weight: 800; font-size: 28px; letter-spacing: 2px; display: flex; align-items: baseline; gap: .35em; line-height: 1; }
.wordmark .yt { color: var(--yt-red); }
.wordmark .arr { color: var(--muted); font-weight: 400; }
.wordmark .px { color: var(--accent); }
.brand { display: flex; align-items: center; gap: 12px; }
.bug { height: 40px; width: auto; display: block; }
@media (min-width: 760px) { .bug { height: 30px; } .brand { gap: 10px; } }
.viewtabs { display: inline-flex; gap: 2px; margin-right: 8px; padding: 2px; border-radius: 11px; background: rgba(0,0,0,.25); }
.viewtabs button { border-color: transparent; }
.viewtabs button.on { background: rgba(229,160,13,.18); color: var(--accent); }
.bug-lg { height: 72px; width: auto; display: block; margin: 0 auto 4px; }
nav { display: flex; gap: 6px; flex-wrap: wrap; }

#warnings, main, .adder { max-width: 1100px; margin-left: auto; margin-right: auto; }
.warning { background: rgba(251,191,36,.12); border: 1px solid rgba(251,191,36,.4); color: var(--warn);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }

.card {
  background: var(--card); border: 1px solid var(--card-border); border-radius: var(--radius);
  backdrop-filter: blur(12px); margin-bottom: 12px;
}
.item { display: grid; grid-template-columns: 210px 1fr; gap: 16px; padding: 12px; position: relative; border-width: 2px; }
.item.status-done { border: 3px solid rgba(74,222,128,.85); }
.item.status-error, .item.status-probe_error { border-color: rgba(248,113,113,.75); }
.item.status-downloading, .item.status-queued, .item.status-finalizing { border-color: rgba(229,160,13,.6); }
.item:not(.in-history) .hist-only, .item.in-history .queue-only { display: none; }
.side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side .thumb { margin-bottom: 5px; }
.side label, .ep-row label { display: flex; flex-direction: column; align-items: stretch; gap: 3px; font-size: 11.5px; color: var(--muted); text-align: left; }
.side label > select { display: block; width: 100%; }
.side .label-line { display: block; }
.paren { font-size: 11px; }
.paren a { color: var(--accent); }
.thumb { position: relative; }
.thumb img { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 9px; background: rgba(0,0,0,.3); display: block; }
.thumb .dur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.75); padding: 0 5px; border-radius: 4px; font-size: 12px; }
.thumb .skeleton { width: 100%; aspect-ratio: 16/9; border-radius: 9px; background: linear-gradient(90deg, rgba(255,255,255,.05), rgba(255,255,255,.12), rgba(255,255,255,.05)); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.body { min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.head { display: flex; gap: 8px; align-items: flex-start; }
.head .title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; color: var(--yt-red); text-decoration: none; overflow-wrap: anywhere; }
.head .title:hover { text-decoration: underline; }
.meta { color: var(--muted); font-size: 12.5px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; padding: 1px 7px; border-radius: 99px; background: rgba(255,255,255,.1); color: var(--muted); }
.badge.done { background: rgba(74,222,128,.18); color: var(--ok); }
.badge.error, .badge.probe_error { background: rgba(248,113,113,.18); color: var(--err); }
.badge.downloading, .badge.finalizing, .badge.queued { background: rgba(229,160,13,.18); color: var(--accent); }
.item.in-history:not(.status-done) .badge { background: rgba(255,255,255,.08); color: var(--muted); }
details.desc summary { cursor: pointer; color: var(--muted); font-size: 12.5px; }
details.desc pre { white-space: pre-wrap; font: inherit; font-size: 12.5px; color: var(--muted); max-height: 220px; overflow: auto; margin: 6px 0 0; padding: 8px; background: rgba(0,0,0,.2); border-radius: 8px; }
.ep-row { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: end; }
.ep-row label { flex: 1 1 300px; min-width: 0; max-width: 480px; }
.ep-wrap { display: flex; gap: 4px; min-width: 0; }
.ep-wrap .ep { flex: 1; min-width: 0; width: 100%; }
.ep-row .match { padding-bottom: 6px; }
.namerow { display: flex; gap: 6px; flex-wrap: wrap; }
.namerow input { flex: 1 1 260px; font-size: 14.5px; }
.item select, .namerow input.name { border-color: rgba(229,160,13,.65); color: var(--accent); }
.item select option { color: var(--text); }
.namerow input.name { font-weight: 500; }
.target { font-size: 12px; color: var(--muted); font-family: ui-monospace, Menlo, monospace; overflow-wrap: anywhere; }
.note { font-size: 12.5px; color: var(--muted); }
.note.warn { color: var(--warn); }
.note.err { color: var(--err); }
.progress-row { display: flex; gap: 8px; align-items: center; }
.progress-row .progress { flex: 1; min-width: 0; }
.progress { position: relative; height: 22px; border-radius: 7px; background: rgba(0,0,0,.3); overflow: hidden; }
.progress .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, #2a5298, #f97316); transition: width .4s; }
.status-done .progress .fill { background: rgba(74,222,128,.45); }
.progress .ptext { position: relative; font-size: 12px; line-height: 22px; padding: 0 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.tvonly[hidden] { display: none; }
.radarr { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center;
  padding: 6px 10px; border-radius: 9px; background: rgba(255,255,255,.04); border: 1px dashed rgba(255,255,255,.14); }
.radarr.strong { color: var(--text); border-color: rgba(229,160,13,.5); background: rgba(229,160,13,.07); }
.radarr select { font-size: 12px; padding: 2px 6px; }
.ok { color: var(--ok); }
.danger:hover { color: var(--err); }

.adder { padding: 10px; margin-bottom: 16px; }
.view-hint { max-width: 1100px; margin: 0 auto 12px; }
#history-empty { text-align: center; }
.adder textarea { width: 100%; resize: vertical; font-size: 15px; padding: 10px 12px; }

footer.bar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px max(16px, calc((100vw - 1100px) / 2)); padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: rgba(15,20,36,.88); backdrop-filter: blur(10px); border-top: 1px solid var(--card-border);
}
#summary { color: var(--muted); font-size: 13px; }
footer.bar button { font-size: 15px; padding: 8px 20px; }

dialog { background: #161d33; color: var(--text); border: 1px solid var(--card-border); border-radius: var(--radius); width: min(760px, calc(100vw - 32px)); padding: 18px; }
dialog::backdrop { background: rgba(0,0,0,.6); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; }
.dlg-head h2 { margin: 0; font-weight: 400; }
.hint { color: var(--muted); font-size: 13px; }
#shows-table { width: 100%; border-collapse: collapse; }
#shows-table th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 500; padding: 4px; }
#shows-table td { padding: 4px; border-top: 1px solid rgba(255,255,255,.07); }
#shows-table input { width: 100%; }
.add-show { display: flex; gap: 6px; flex-wrap: wrap; }
.add-show input { flex: 1 1 200px; }
#show-results { list-style: none; padding: 0; }
#show-results li { display: flex; justify-content: space-between; align-items: center; padding: 5px 0; border-top: 1px solid rgba(255,255,255,.07); gap: 8px; }

#toasts { position: fixed; right: 16px; bottom: 70px; display: flex; flex-direction: column; gap: 6px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: #2b1620; border: 1px solid rgba(248,113,113,.5); color: #fecaca; padding: 8px 12px; border-radius: 9px; font-size: 13px; }
.toast.info { background: #16233a; border-color: rgba(96,165,250,.5); color: #dbeafe; }

body.login { display: grid; place-items: center; padding: 16px; }
.login-card { display: flex; flex-direction: column; gap: 10px; padding: 26px; width: min(340px, 100%); }
.login-card h1 { text-align: center; margin-bottom: 8px; }
.bad { color: var(--err); margin: 0; text-align: center; }

/* settings dialog */
dialog#settings { width: min(920px, calc(100vw - 32px)); height: min(640px, calc(100vh - 40px)); max-height: none;
  display: flex; flex-direction: column; padding-bottom: 0; }
dialog#settings:not([open]) { display: none; }
dialog#settings .tab { flex: 1; overflow-y: auto; padding-bottom: 18px; }
dialog#settings .tab > .hint:first-child { margin-top: 6px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin: 10px 0 6px; border-bottom: 1px solid var(--card-border); padding-bottom: 8px; }
.tabs button { background: transparent; border-color: transparent; }
.tabs button.on { background: rgba(229,160,13,.15); border-color: rgba(229,160,13,.45); color: var(--accent); }
.tab h3 { font-weight: 500; font-size: 14px; margin: 16px 0 6px; }
.hint.attention { color: var(--accent); }
.lib-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 0; border-top: 1px solid rgba(255,255,255,.07); }
.lib-form > input:first-child { flex: 0 1 150px; }
.lib-form .path-wrap { display: flex; gap: 4px; flex: 1 1 260px; min-width: 0; }
.lib-form .path-wrap input { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 12.5px; }
.lib-form .note { flex-basis: 100%; }
.browser { flex-basis: 100%; background: rgba(0,0,0,.25); border-radius: 9px; padding: 8px; }
.browser-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.browser-head code { flex: 1; overflow-wrap: anywhere; }
.browser ul { list-style: none; margin: 6px 0 0; padding: 0; max-height: 240px; overflow: auto; columns: 2 200px; }
.browser li a { color: var(--text); text-decoration: none; display: block; padding: 2px 4px; border-radius: 5px; }
.browser li a:hover { background: rgba(255,255,255,.08); }
.conn { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.conn h3 { flex-basis: 100%; }
.conn input { flex: 1 1 220px; }
.conn-msg { font-size: 12.5px; color: var(--muted); }
.conn-msg.ok { color: var(--ok); } .conn-msg.err { color: var(--err); }
.stack { display: flex; flex-direction: column; gap: 16px; max-width: 380px; margin-top: 10px; }
.stack p { margin: 0; }
.stack label { display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; color: var(--muted); }
.scroll-x { overflow-x: auto; }

@media (max-width: 640px) {
  .item { grid-template-columns: 1fr; }
  .side .thumb { max-width: 320px; }
}
