+ `,e.appendChild(u),u.querySelector("#auth-gate-email-alt-link").addEventListener("click",o=>{o.preventDefault(),b(r)})}t.classList.add("show")}window.__dc_049_handled=!0;function f(w){try{const r=new URL(w,window.location.origin);if(!["http:","https:"].includes(r.protocol))return!1;if(r.origin===window.location.origin)return!0;if(r.protocol!=="https:")return!1;const t=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`;return r.hostname===t.slice(1)||r.hostname.endsWith(t)}catch{return!1}}function d(w,r){const t=new URL(w,window.location.origin);if(t.origin===window.location.origin)return t.toString();const e=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`,n=t.hostname===e.slice(1)||t.hostname.endsWith(e);if(t.protocol!=="https:"||!n||!r)return null;const u=`${t.pathname}${t.search}${t.hash}`;return t.pathname="/dashcaddy-sso",t.search="",t.hash="",t.searchParams.set("token",r),t.searchParams.set("return",u),t.toString()}async function i(w){if(!w||!f(w))return!1;try{const r=new URL(w,window.location.origin),t=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`,e=r.hostname.slice(0,-t.length);if(!/^[a-z0-9][a-z0-9-]*$/.test(e))return!1;const n=await fetch(`/api/v1/auth/sso-handoff?serviceId=${encodeURIComponent(e)}`,{credentials:"include",cache:"no-store"});if(!n.ok)return!1;const u=await n.json(),o=u.success&&d(w,u.ssoToken);if(!o)return!1;try{sessionStorage.removeItem("totp_redirect")}catch{}return window.location.replace(o),!0}catch{return!1}}const m=new URLSearchParams(window.location.search);if(m.get("auth")==="required"){const w=m.get("return");if(w&&f(w))try{sessionStorage.setItem("totp_redirect",w)}catch{}window.history.replaceState({},"",window.location.pathname),setTimeout(async()=>{await i(w)||await g()},0)}window._showAuthGate=g,window._authGateMethods=a})(),(function(){const l=new WeakSet;document.addEventListener("error",d=>{const i=d.target;i&&i.tagName==="IMG"&&i.classList.contains("totp-logo")&&(l.add(i),i.style.display="none")},!0),document.querySelectorAll(".totp-logo").forEach(d=>{d.complete&&d.naturalWidth===0&&(l.add(d),d.style.display="none")});function a(){const d=document.querySelector(".totp-card");if(!d)return;const m=getComputedStyle(d).backgroundColor.match(/\d+/g);if(!m)return;const w=(.299*+m[0]+.587*+m[1]+.114*+m[2])/255,r=d.querySelector(".totp-logo-dark"),t=d.querySelector(".totp-logo-light");r&&(r.style.display=w>.5||l.has(r)?"none":""),t&&(t.style.display=w<=.5||l.has(t)?"none":"")}function p(){const d=document.getElementById("totp-overlay");if(d){d.classList.add("show"),setTimeout(a,50);const i=d.querySelector(".totp-digits input");i&&setTimeout(()=>i.focus(),100)}typeof window._refreshRecoveryLink=="function"&&window._refreshRecoveryLink()}function h(){const d=document.getElementById("totp-overlay");d&&d.classList.remove("show")}function b(d,i){const m=new URL(d,window.location.origin);if(m.origin===window.location.origin)return m.toString();const w=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`,r=m.hostname===w.slice(1)||m.hostname.endsWith(w);if(m.protocol!=="https:"||!r)return null;if(!i)return m.toString();const t=`${m.pathname}${m.search}${m.hash}`;return m.pathname="/dashcaddy-sso",m.search="",m.hash="",m.searchParams.set("token",i),m.searchParams.set("return",t),m.toString()}const g=document.getElementById("totp-digits");if(g){const d=g.querySelectorAll("input");d.forEach((i,m)=>{i.addEventListener("input",w=>{const r=w.target.value.replace(/\D/g,"");w.target.value=r.slice(0,1),r&&m
e.value).join("");t.length===6&&v(t)}),i.addEventListener("keydown",w=>{w.key==="Backspace"&&!w.target.value&&m>0&&(d[m-1].focus(),d[m-1].value="")}),i.addEventListener("paste",w=>{w.preventDefault();const r=(w.clipboardData.getData("text")||"").replace(/\D/g,"");r.length>=6&&(d.forEach((t,e)=>{t.value=r[e]||""}),d[5].focus(),v(r.slice(0,6)))})})}async function v(d){const i=document.getElementById("totp-error");i.textContent="Verifying...",i.className="totp-error verifying";const m=safeSessionGet("totp_redirect");let w=null;if(m)try{const r=new URL(m,window.location.origin),t=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`,e=r.hostname.slice(0,-t.length);r.hostname.endsWith(t)&&/^[a-z0-9][a-z0-9-]*$/.test(e)&&(w=e)}catch{}try{const t=await(await secureFetch("/api/v1/totp/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:d,serviceId:w})})).json();if(t.success){if(i.textContent="",t.csrfToken&&(csrfToken=t.csrfToken),h(),m){try{sessionStorage.removeItem("totp_redirect")}catch{}const e=b(m,t.ssoToken);if(!e)return;window.location.href=e;return}typeof window.initializeDashboard=="function"&&window.initializeDashboard(),window._dcAuthLost=!1,typeof window._sseResume=="function"?window._sseResume():typeof window._sseReconnect=="function"&&window._sseReconnect(),typeof window.refreshAll=="function"&&window.refreshAll()}else{i.textContent=t.error||"Invalid code",i.className="totp-error";const e=document.querySelectorAll("#totp-digits input");e.forEach(n=>{n.value=""}),e[0]?.focus()}}catch{i.textContent="Connection error",i.className="totp-error"}}if(!!!window.__dc_049_handled&&urlParams.get("auth")==="required"){const d=urlParams.get("return");if(d)try{const i=new URL(d,window.location.origin),m=i.hostname,w=i.origin===window.location.origin,r=SITE.tld.startsWith(".")?SITE.tld:"."+SITE.tld,t=m.endsWith(r)||m===r.substring(1);(w||t)&&safeSessionSet("totp_redirect",d)}catch{}window.history.replaceState({},"",window.location.pathname)}window._showTotpOverlay=p})(),(function(){"use strict";async function l(){try{return await(await fetch("/api/v1/totp/recovery-info",{cache:"no-store"})).json()}catch{return{success:!1,status:"unknown",hint:"Could not contact server"}}}function a(v){const f=document.getElementById("totp-recovery-link");f&&(f.style.display=v?"":"none")}function p(){const v=document.getElementById("totp-recovery-panel");v&&(v.style.display="");const f=document.getElementById("totp-recovery-status"),d=document.getElementById("totp-recovery-import"),i=document.getElementById("totp-recovery-verify");d&&(d.style.display=""),i&&(i.style.display="none"),document.getElementById("totp-recovery-error").textContent="",document.getElementById("totp-recovery-confirm-error").textContent="",document.getElementById("totp-recovery-secret").value="",document.getElementById("totp-recovery-code").value="",l().then(m=>{f.textContent=m.hint||"",m.status==="healthy"?f.style.borderColor="var(--ok-fg, #7ef2ff)":m.status==="unreadable"?(f.style.borderColor="var(--bad-fg, #ff9aa3)",f.style.background="color-mix(in srgb, var(--bad-fg) 6%, transparent)"):m.status==="not_configured"?f.style.borderColor="var(--muted)":f.style.borderColor="var(--border)"}),setTimeout(()=>{document.getElementById("totp-recovery-secret")?.focus()},100)}function h(){const v=document.getElementById("totp-recovery-panel");v&&(v.style.display="none")}async function b(){const v=document.getElementById("totp-recovery-secret").value.trim(),f=document.getElementById("totp-recovery-error");if(f.textContent="",!v){f.textContent="Paste your Base32 key first";return}if(!/^[A-Za-z2-7\s]+=*$/.test(v)){f.textContent="Invalid Base32 format \u2014 should be letters A-Z and digits 2-7 only";return}try{const d=await fetch("/api/v1/totp/setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({secret:v})}),i=await d.json();if(!d.ok||!i.success){f.textContent=i.error||i.message||"Restore failed";return}document.getElementById("totp-recovery-import").style.display="none",document.getElementById("totp-recovery-verify").style.display="",setTimeout(()=>document.getElementById("totp-recovery-code")?.focus(),100)}catch{f.textContent="Network error \u2014 try again"}}async function g(){const v=document.getElementById("totp-recovery-code").value.trim(),f=document.getElementById("totp-recovery-confirm-error");if(f.textContent="",!/^\d{6}$/.test(v)){f.textContent="Enter a 6-digit code";return}try{const d=await fetch("/api/v1/totp/verify-setup",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:v})}),i=await d.json();if(!d.ok||!i.success){f.textContent=i.error||i.message||"Invalid code",document.getElementById("totp-recovery-code").value="",document.getElementById("totp-recovery-code")?.focus();return}h();const m=document.getElementById("totp-overlay");m&&m.classList.remove("show"),typeof window.initializeDashboard=="function"&&window.initializeDashboard()}catch{f.textContent="Network error \u2014 try again"}}document.getElementById("totp-show-recovery")?.addEventListener("click",v=>{v.preventDefault(),p()}),document.getElementById("totp-recovery-close")?.addEventListener("click",h),document.getElementById("totp-recovery-submit")?.addEventListener("click",b),document.getElementById("totp-recovery-confirm")?.addEventListener("click",g),document.getElementById("totp-recovery-secret")?.addEventListener("keydown",v=>{v.key==="Enter"&&(v.preventDefault(),b())}),document.getElementById("totp-recovery-code")?.addEventListener("keydown",v=>{v.key==="Enter"&&(v.preventDefault(),g())}),window._refreshRecoveryLink=async function(){const v=await l();return v&&v.success&&v.status&&v.status!=="healthy"?a(!0):a(!1),v}})(),(function(){function l(h,b){if(!h||!b||!/^[a-z0-9][a-z0-9-]*$/.test(b))return!1;try{const g=new URL(h,window.location.origin),v=SITE.tld.startsWith(".")?SITE.tld:`.${SITE.tld}`,f=`${b}${v}`;return g.protocol==="https:"&&g.hostname===f}catch{return!1}}function a(h,b,g){if(!l(h,g))return null;const v=new URL(h,window.location.origin);if(!b)return null;const f=`${v.pathname}${v.search}${v.hash}`;return v.pathname="/dashcaddy-sso",v.search="",v.hash="",v.searchParams.set("token",b),v.searchParams.set("return",f),v.toString()}async function p(h,b,g={}){if(!l(h,b))return!1;const v=g.fetch||window.fetch.bind(window),f=g.location||window.location;try{const d=await v(`/api/v1/auth/sso-handoff?serviceId=${encodeURIComponent(b)}`,{credentials:"include",cache:"no-store"});if(!d.ok)return!1;const i=await d.json(),m=i.success&&a(h,i.ssoToken,b);return m?(f.replace(m),!0):!1}catch{return!1}}window.DCCredentialVault={isAllowedReturnUrl:l,buildHandoffTarget:a,resume:p}})(),(function(){const l=new ErrorHandler;injectModal("folder-browser-modal",`
\u{1F4C2} Browse for Media Folders
@@ -179,7 +179,7 @@
- `);const a=document.getElementById("service-creds-modal");let p=null,h=null,b=!1;const g=["sonarr","radarr","prowlarr","overseerr"],v=["sonarr","radarr"];function f(e){return e.externalUrl||e.url||""}function d(e){const n=document.getElementById("svc-creds-error");n.textContent=e,n.style.display=""}function i(){const e=document.getElementById("svc-creds-error");e.textContent="",e.style.display="none"}async function m(e,n){if(!e)throw new Error(`${n} failed: no response`);let u;try{u=await e.json()}catch{throw new Error(`${n} failed: invalid server response`)}if(!e.ok||u?.success!==!0)throw new Error(u?.error||`${n} failed (${e.status||"unknown status"})`);return u}function w(e,n){return!!window.DCCredentialVault?.isAllowedReturnUrl(e,n)}window.openServiceCredsModal=async function(e,n={}){p=e,h=w(n.returnUrl,e.id)?n.returnUrl:null,b=!1,i();const u=document.getElementById("svc-creds-title"),o=document.getElementById("svc-creds-desc"),r=document.getElementById("svc-creds-seedhost"),c=document.getElementById("svc-creds-apikey"),y=document.getElementById("svc-creds-basic"),S=document.getElementById("svc-creds-quality");u.textContent=e.name+" \u2014 Encrypted Vault",document.getElementById("svc-creds-save").textContent=h?"Save to vault & open service":"Save to encrypted vault";const k=!!e.isExternal,L=g.includes(e.id)||g.includes(e.appTemplate),x=v.includes(e.id)||v.includes(e.appTemplate);r.style.display=k?"":"none",c.style.display=L?"":"none",S.style.display=x?"":"none",y.style.display=k?"none":"";const B=document.getElementById("svc-quality-select");B.innerHTML='No DNS servers configured.
';return}for(const c of r)o.insertAdjacentHTML("beforeend",`
+ `);function l(){return Object.keys(SITE.dnsServers||{})}function a(o){return(SITE.dnsServers||{})[o]?.name||o.toUpperCase()}async function p(o,s){if(!o)throw new Error(`${s} failed: no response`);let c;try{c=await o.json()}catch{throw new Error(`${s} failed: invalid server response`)}if(!o.ok||c?.success!==!0)throw new Error(c?.error||`${s} failed (${o.status||"unknown status"})`);return c}function h(){const o=document.getElementById("dns-cred-sections");if(!o)return;o.innerHTML="";const s=l();if(s.length===0){o.innerHTML='No DNS servers configured.
';return}for(const c of s)o.insertAdjacentHTML("beforeend",`