async function Q(){try{if((await chrome.runtime.sendMessage({action:"CHECK_AUTH"}))?.isAuthenticated)return!0}catch{}await new Promise(r=>setTimeout(r,500));try{return!!(await chrome.runtime.sendMessage({action:"CHECK_AUTH"}))?.isAuthenticated}catch{return!1}}function X(r){r.innerHTML="",r.style.cssText=`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      height: 100%;
      padding: 24px;
      text-align: center;
      background: #171717;
    `;const e=document.createElement("h2");e.textContent="Sign in required",e.style.cssText=`
      color: #fafafa;
      font-size: 18px;
      font-weight: 600;
      margin: 0 0 8px 0;
    `;const t=document.createElement("p");t.textContent="You need to sign in to access your saved content and search functionality.",t.style.cssText=`
      color: #a1a1aa;
      font-size: 14px;
      line-height: 1.5;
      margin: 0 0 24px 0;
    `;const n=document.createElement("button");n.textContent="Sign In",n.style.cssText=`
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 12px 24px;
      background: #3795BD;
      border: none;
      border-radius: 8px;
      color: #0a0a0a;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: background-color 0.2s ease;
      margin-bottom: 12px;
      width: 100%;
      max-width: 200px;
    `;const i=document.createElement("button");i.textContent="Create Account",i.style.cssText=`
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 12px 24px;
      background: transparent;
      border: 1px solid #3795BD;
      border-radius: 8px;
      color: #3795BD;
      font-size: 14px;
      font-weight: 500;
      cursor: pointer;
      transition: all 0.2s ease;
      width: 100%;
      max-width: 200px;
    `,n.addEventListener("mouseenter",()=>{n.style.background="#2E7A9A"}),n.addEventListener("mouseleave",()=>{n.style.background="#3795BD"}),i.addEventListener("mouseenter",()=>{i.style.background="#2E7A9A",i.style.color="#0a0a0a"}),i.addEventListener("mouseleave",()=>{i.style.background="transparent",i.style.color="#3795BD"}),n.addEventListener("click",async()=>{try{const s=chrome?.runtime?.getURL?chrome.runtime.getURL("login.html"):"login.html";await chrome.tabs.create({url:s})}catch(s){console.error("Failed to open login page:",s)}}),i.addEventListener("click",async()=>{try{const s=chrome?.runtime?.getURL?chrome.runtime.getURL("signup.html"):"signup.html";await chrome.tabs.create({url:s})}catch(s){console.error("Failed to open signup page:",s)}}),r.appendChild(e),r.appendChild(t),r.appendChild(n),r.appendChild(i)}class x{static create(e){const t=document.createElement("button");if(e.id&&(t.id=e.id),e.className&&(t.className=e.className),e.title&&(t.title=e.title),e.ariaLabel&&t.setAttribute("aria-label",e.ariaLabel),e.disabled&&(t.disabled=e.disabled),e.icon&&e.text){const i=document.createElement("div");i.innerHTML=e.icon,i.style.cssText="display: inline-flex; align-items: center; margin-right: 6px;",t.appendChild(i);const s=document.createElement("div");s.textContent=e.text,s.style.cssText="display: inline;",t.appendChild(s)}else if(e.icon){const i=document.createElement("div");i.innerHTML=e.icon,i.style.cssText="display: flex; align-items: center; justify-content: center;",t.appendChild(i)}else e.text&&(t.textContent=e.text);const n=this.getVariantStyles(e.variant||"primary");return t.style.cssText=n,e.style&&Object.assign(t.style,e.style),e.onClick&&t.addEventListener("click",e.onClick),e.onMouseEnter&&t.addEventListener("mouseenter",e.onMouseEnter),e.onMouseLeave&&t.addEventListener("mouseleave",e.onMouseLeave),this.addDefaultHoverEffects(t,e.variant||"primary"),t}static getVariantStyles(e){const t=`
      border: none;
      cursor: pointer;
      transition: all 0.2s ease;
      font-family: inherit;
    `,n={primary:`
        background: #3795BD;
        color: #0a0a0a;
        border-radius: 8px;
        padding: 12px 24px;
        font-size: 14px;
        font-weight: 500;
      `,secondary:`
        background: transparent;
        color: #3795BD;
        border: 1px solid #3795BD;
        border-radius: 8px;
        padding: 12px 24px;
        font-size: 14px;
        font-weight: 500;
      `,icon:`
        display: flex;
        align-items: center;
        justify-content: center;
        width: 24px;
        height: 24px;
        background: transparent;
        color: #888;
        border-radius: 4px;
        flex-shrink: 0;
        margin-right: 4px;
      `,danger:`
        background: none;
        border: 1px solid #404040;
        color: #ef4444;
        border-radius: 6px;
        padding: 4px;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
      `,tab:`
        flex: 1;
        padding: 12px 16px;
        background: transparent;
        color: #9ca3af;
        font-size: 14px;
        font-weight: 500;
        border-bottom: 2px solid transparent;
      `,search:`
        position: absolute;
        right: 6px;
        top: 50%;
        transform: translateY(-50%);
        width: 32px;
        height: 32px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #3795BD;
        border-radius: 6px;
      `,copy:`
        background: none;
        border: 1px solid #404040;
        color: #d4d4d8;
        border-radius: 6px;
        padding: 4px;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
      `,delete:`
        background: none;
        border: 1px solid #404040;
        color: #ef4444;
        border-radius: 6px;
        padding: 4px;
        width: 28px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
      `,toggle:`
        background: none;
        border: none;
        color: #888;
        cursor: pointer;
        padding: 0;
        margin: 0 0 8px 0;
        font-size: 12px;
        text-decoration: underline;
      `,save:`
        display: flex;
        align-items: center;
        gap: 6px;
        padding: 8px 12px;
        background: #3795BD;
        border: none;
        border-radius: 6px;
        color: #0a0a0a;
        font-size: 12px;
        font-weight: 500;
      `};return t+(n[e]||n.primary)}static addDefaultHoverEffects(e,t){switch(t){case"icon":e.addEventListener("mouseenter",()=>{e.style.background="#333",e.style.color="#fafafa"}),e.addEventListener("mouseleave",()=>{e.style.background="transparent",e.style.color="#888"});break;case"primary":case"save":e.addEventListener("mouseenter",()=>{e.style.background="#2E7A9A"}),e.addEventListener("mouseleave",()=>{e.style.background="#3795BD"});break;case"search":e.addEventListener("mouseenter",()=>{e.style.background="#2E7A9A"}),e.addEventListener("mouseleave",()=>{e.style.background="#3795BD"});break;case"tab":e.addEventListener("mouseenter",()=>{e.classList.contains("active")||(e.style.color="#d4d4d8",e.style.background="#262626")}),e.addEventListener("mouseleave",()=>{e.classList.contains("active")||(e.style.color="#9ca3af",e.style.background="transparent")});break;case"toggle":e.addEventListener("mouseenter",()=>{e.style.color="#666"}),e.addEventListener("mouseleave",()=>{e.style.color="#888"});break}}static createSettingsButton(e){return this.create({icon:`
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <path d="M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"/>
        <circle cx="12" cy="12" r="3"/>
      </svg>
    `,variant:"icon",onClick:e||(()=>chrome.tabs.create({url:chrome.runtime.getURL("settings.html")}))})}static createQuickGuideButton(e){return this.create({icon:`
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <path d="M4 19.5A2.5 2.5 0 0 1 6.5 17H20"/>
        <path d="M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"/>
      </svg>
    `,variant:"icon",onClick:e||(()=>chrome.tabs.create({url:chrome.runtime.getURL("quickGuide.html")}))})}static createTabButton(e,t=!1,n){const i=this.create({text:e,variant:"tab",onClick:n});return t&&(i.classList.add("active"),i.style.color="#fafafa",i.style.borderBottomColor="#3795BD"),i}static createSearchButton(e){return this.create({icon:`
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="#0a0a0a" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
        <circle cx="11" cy="11" r="8"/>
        <path d="M21 21l-4.35-4.35"/>
      </svg>
    `,variant:"search",ariaLabel:"Search",onClick:e})}static createCopyButton(e){return this.create({icon:`
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <rect x="9" y="9" width="13" height="13" rx="2"/>
        <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>
      </svg>
    `,variant:"copy",title:"Copy content",onClick:e})}static createDeleteButton(e){return this.create({icon:`
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <polyline points="3 6 5 6 21 6"/>
        <path d="M19 6l-1 14a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2L5 6"/>
        <path d="M10 11v6"/>
        <path d="M14 11v6"/>
        <path d="M9 6V4a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2"/>
      </svg>
    `,variant:"delete",title:"Delete",onClick:e})}static createToggleButton(e,t){return this.create({text:e,variant:"toggle",onClick:t})}static createSaveButton(e="Save Page",t){return this.create({text:e,icon:`
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z"/>
        <polyline points="17,21 17,13 7,13 7,21"/>
        <polyline points="7,3 7,8 15,8"/>
      </svg>
    `,variant:"save",id:"save-current-page-btn",onClick:t})}static createPropertiesToggleButton(e){const t=`
      <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <polyline points="6,9 12,15 18,9"/>
      </svg>
    `,n=this.create({text:"Properties",variant:"primary",id:"properties-toggle",onClick:e});n.style.cssText=`
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 6px 8px;
      background: #262626;
      border: 1px solid #404040;
      border-radius: 4px;
      color: #d4d4d8;
      font-size: 11px;
      cursor: pointer;
      transition: all 0.2s ease;
    `;const i=document.createElement("div");return i.innerHTML=t,i.style.cssText="transition: transform 0.2s ease; display: inline-flex; align-items: center;",n.appendChild(i),n}static createDisabledRefreshButton(){return this.create({text:"Refresh Page",icon:`
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
      </svg>
    `,variant:"primary",disabled:!0,style:{display:"flex",alignItems:"center",gap:"6px",padding:"8px 12px",background:"#404040",border:"none",borderRadius:"6px",color:"#888",fontSize:"12px",fontWeight:"500",cursor:"not-allowed"}})}static createRefreshButton(e){return this.create({text:"Refresh Page",icon:`
      <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
        <path d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
      </svg>
    `,variant:"save",onClick:e})}}x.create.bind(x);x.createSettingsButton.bind(x);x.createQuickGuideButton.bind(x);x.createTabButton.bind(x);x.createSearchButton.bind(x);x.createCopyButton.bind(x);x.createDeleteButton.bind(x);x.createToggleButton.bind(x);x.createSaveButton.bind(x);x.createPropertiesToggleButton.bind(x);x.createDisabledRefreshButton.bind(x);x.createRefreshButton.bind(x);class b{static animationStyleAdded=!1;static ensureAnimationStyle(){if(!this.animationStyleAdded&&!document.getElementById("contextdb-spin-animation")){const e=document.createElement("style");e.id="contextdb-spin-animation",e.textContent=`
        @keyframes spin { 
          0% { transform: rotate(0deg); } 
          100% { transform: rotate(360deg); } 
        }
      `,document.head.appendChild(e),this.animationStyleAdded=!0}}static createSpinner(e={}){this.ensureAnimationStyle();const{size:t="medium",color:n="#3795BD"}=e,i={small:"12px",medium:"16px",large:"24px"},s=document.createElement("div");return s.style.cssText=`
      width: ${i[t]};
      height: ${i[t]};
      border: 2px solid ${n}40;
      border-top: 2px solid ${n};
      border-radius: 50%;
      animation: spin 1s linear infinite;
      display: inline-block;
    `,s}static createCenteredLoader(e={}){this.ensureAnimationStyle();const{size:t="large",color:n="#3795BD",message:i="Loading...",subMessage:s=""}=e,p={small:"16px",medium:"20px",large:"24px"},h=document.createElement("div");h.style.cssText=`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 32px 16px;
      text-align: center;
    `;const d=document.createElement("div");d.style.cssText=`
      width: ${p[t]};
      height: ${p[t]};
      border: 2px solid ${n}40;
      border-top: 2px solid ${n};
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin-bottom: 12px;
    `;const c=document.createElement("div");if(c.style.cssText=`
      color: ${n};
      font-size: 14px;
      font-weight: 500;
      margin-bottom: 4px;
    `,c.textContent=i,h.appendChild(d),h.appendChild(c),s){const u=document.createElement("div");u.style.cssText=`
        color: #888;
        font-size: 12px;
        line-height: 1.3;
      `,u.textContent=s,h.appendChild(u)}return h}static createSaveLoader(e="auto"){this.ensureAnimationStyle();const t=document.createElement("div");t.style.cssText=`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 12px 16px;
      text-align: center;
      height: ${e};
      min-height: 60px;
    `;const n=document.createElement("div");n.style.cssText=`
      width: 24px;
      height: 24px;
      border: 2px solid rgba(55, 149, 189, 0.3);
      border-top: 2px solid #3795BD;
      border-radius: 50%;
      animation: spin 1s linear infinite;
      margin-bottom: 12px;
    `;const i=document.createElement("div");i.style.cssText=`
      color: #3795BD;
      font-size: 13px;
      font-weight: 500;
      margin-bottom: 4px;
    `,i.textContent="Saving page...";const s=document.createElement("div");return s.style.cssText=`
      color: #888;
      font-size: 11px;
      line-height: 1.3;
    `,s.textContent="Content is being saved. You can close this popup.",t.appendChild(n),t.appendChild(i),t.appendChild(s),t}static createButtonSpinner(){this.ensureAnimationStyle();const e=document.createElement("div");return e.style.cssText=`
      width: 16px;
      height: 16px;
      border: 2px solid rgba(10, 10, 10, 0.25);
      border-top: 2px solid #0a0a0a;
      border-radius: 50%;
      animation: spin 1s linear infinite;
    `,e}static setButtonLoading(e,t){const n=this.createButtonSpinner();e.innerHTML="",e.appendChild(n),e.disabled=!0,e.setAttribute("aria-disabled","true"),e.__originalContent=t}static restoreButton(e){const t=e,n=t.__originalContent;n&&(e.innerHTML=n),e.disabled=!1,e.removeAttribute("aria-disabled"),delete t.__originalContent}static showInContainer(e,t={}){const n=this.createCenteredLoader(t);e.innerHTML="",e.appendChild(n)}static showSaveLoadingInContainer(e){const t=e.style.height||"auto",n=this.createSaveLoader(t);e.innerHTML="",e.appendChild(n)}}b.createSpinner.bind(b);b.createCenteredLoader.bind(b);b.createSaveLoader.bind(b);b.createButtonSpinner.bind(b);b.setButtonLoading.bind(b);b.restoreButton.bind(b);b.showInContainer.bind(b);b.showSaveLoadingInContainer.bind(b);class U{static create(e={}){const{placeholder:t="Search your saved content...",onSearch:n,onFocus:i,onBlur:s,disabled:p=!1,className:h,id:d,style:c}=e,u=document.createElement("div");u.style.cssText=`
      position: relative;
      flex-shrink: 0;
    `,h&&(u.className=h),d&&(u.id=d),c&&Object.assign(u.style,c);const a=document.createElement("input");a.type="text",a.placeholder=t,a.disabled=p,a.style.cssText=`
      width: 100%;
      padding: 12px 44px 12px 14px; /* space for inline button */
      background: #262626;
      border: 2px solid #404040;
      border-radius: 8px;
      color: #fafafa;
      font-size: 14px;
      outline: none;
      transition: border-color 0.2s ease;
      box-sizing: border-box;
    `;const o=x.createSearchButton();a.addEventListener("focus",()=>{a.style.borderColor="#3795BD",i?.()}),a.addEventListener("blur",()=>{a.style.borderColor="#404040",s?.()});const y=async()=>{if(o.disabled||!n)return;const l=a.value.trim();if(l){g(!0);try{await n(l)}catch(E){console.error("Search failed:",E)}finally{g(!1)}}};o.addEventListener("click",y),a.addEventListener("keydown",l=>{l.key==="Enter"&&(o.disabled||y())});const g=l=>{if(l){const E=o.innerHTML;b.setButtonLoading(o,E),a.disabled=!0,a.setAttribute("aria-disabled","true"),a.style.opacity="0.7"}else b.restoreButton(o),a.disabled=!1,a.removeAttribute("aria-disabled"),a.style.opacity="1"},v=l=>{a.disabled=l,o.disabled=l,l?(a.setAttribute("aria-disabled","true"),o.setAttribute("aria-disabled","true"),a.style.opacity="0.7",o.style.opacity="0.7"):(a.removeAttribute("aria-disabled"),o.removeAttribute("aria-disabled"),a.style.opacity="1",o.style.opacity="1")},k=()=>a.value,w=l=>{a.value=l},C=()=>a.focus(),B=()=>a.blur(),f=()=>{a.value=""};return u.appendChild(a),u.appendChild(o),{input:a,button:o,wrapper:u,setLoading:g,setDisabled:v,getValue:k,setValue:w,focus:C,blur:B,clear:f}}static createSimple(e={}){const{placeholder:t="Search...",onFocus:n,onBlur:i,disabled:s=!1,className:p,id:h,style:d}=e,c=document.createElement("input");return c.type="text",c.placeholder=t,c.disabled=s,p&&(c.className=p),h&&(c.id=h),c.style.cssText=`
      width: 100%;
      padding: 12px 14px;
      background: #262626;
      border: 2px solid #404040;
      border-radius: 8px;
      color: #fafafa;
      font-size: 14px;
      outline: none;
      transition: border-color 0.2s ease;
      box-sizing: border-box;
    `,d&&Object.assign(c.style,d),c.addEventListener("focus",()=>{c.style.borderColor="#3795BD",n?.()}),c.addEventListener("blur",()=>{c.style.borderColor="#404040",i?.()}),c}static createWithCustomButton(e,t={}){const{placeholder:n="Search your saved content...",onSearch:i,onFocus:s,onBlur:p,disabled:h=!1,className:d,id:c,style:u}=t,a=document.createElement("div");a.style.cssText=`
      position: relative;
      flex-shrink: 0;
    `,d&&(a.className=d),c&&(a.id=c),u&&Object.assign(a.style,u);const o=document.createElement("input");o.type="text",o.placeholder=n,o.disabled=h,o.style.cssText=`
      width: 100%;
      padding: 12px 44px 12px 14px; /* space for inline button */
      background: #262626;
      border: 2px solid #404040;
      border-radius: 8px;
      color: #fafafa;
      font-size: 14px;
      outline: none;
      transition: border-color 0.2s ease;
      box-sizing: border-box;
    `,o.addEventListener("focus",()=>{o.style.borderColor="#3795BD",s?.()}),o.addEventListener("blur",()=>{o.style.borderColor="#404040",p?.()});const y=async()=>{if(e.disabled||!i)return;const l=o.value.trim();if(l){g(!0);try{await i(l)}catch(E){console.error("Search failed:",E)}finally{g(!1)}}};e.addEventListener("click",y),o.addEventListener("keydown",l=>{l.key==="Enter"&&(e.disabled||y())});const g=l=>{if(l){const E=e.innerHTML;b.setButtonLoading(e,E),o.disabled=!0,o.setAttribute("aria-disabled","true"),o.style.opacity="0.7"}else b.restoreButton(e),o.disabled=!1,o.removeAttribute("aria-disabled"),o.style.opacity="1"},v=l=>{o.disabled=l,e.disabled=l,l?(o.setAttribute("aria-disabled","true"),e.setAttribute("aria-disabled","true"),o.style.opacity="0.7",e.style.opacity="0.7"):(o.removeAttribute("aria-disabled"),e.removeAttribute("aria-disabled"),o.style.opacity="1",e.style.opacity="1")},k=()=>o.value,w=l=>{o.value=l},C=()=>o.focus(),B=()=>o.blur(),f=()=>{o.value=""};return a.appendChild(o),a.appendChild(e),{input:o,button:e,wrapper:a,setLoading:g,setDisabled:v,getValue:k,setValue:w,focus:C,blur:B,clear:f}}}U.create.bind(U);U.createSimple.bind(U);U.createWithCustomButton.bind(U);class J{static create(e){const t=e.asset||{},n=t.original_filename||t.uploaded_filename||null,i=(()=>{const I=t.metadata_json?.url||e.url||"";if(!I)return null;try{return new URL(I).hostname}catch{return I}})(),s=t.metadata_json?.title,p=te(s||e.title||n||i||e.source||"Unknown"),h=t.textcontent||"",d=t.metadata_json?.url||e.url||"",c=P(d)?d:"",u=e.context_id||"",a=e.similarity||e.relevance_score||0,o=document.createElement("div");o.style.cssText=`
      background: #262626;
      border: 1px solid #404040;
      border-radius: 8px;
      padding: 12px;
      margin-bottom: 10px;
      cursor: default;
      transition: all 0.2s ease;
    `,o.addEventListener("mouseenter",()=>{o.style.background="#404040",o.style.borderColor="#3795BD"}),o.addEventListener("mouseleave",()=>{o.style.background="#262626",o.style.borderColor="#404040"});const y=document.createElement("div");y.style.cssText=`
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0 0 6px 0;
    `;const g=document.createElement("h4");g.style.cssText=`
      margin: 0;
      font-size: 14px;
      font-weight: 600;
      color: #fafafa;
      flex: 1;
      min-width: 0;
      display: flex;
      align-items: center;
    `;const v=document.createElement("a");v.textContent=String(p),v.href=c||"#",v.target="_blank",v.rel="noopener noreferrer",v.style.cssText=`
      color: inherit;
      text-decoration: none;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-block;
      max-width: 100%;
      flex: 1;
      min-width: 0;
    `,g.appendChild(v);const k=this.createRelevanceBadge(a);g.appendChild(k);const w=document.createElement("div");w.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
    `;const C=x.createCopyButton();C.addEventListener("click",async S=>{S.stopPropagation();const I=String(h||"").replace(/<[^>]*>/g,"").replace(/#{1,6}\s+/g,"").replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/`(.*?)`/g,"$1").replace(/\[(.*?)\]\(.*?\)/g,"$1").replace(/\n\s*\n/g,`
`).trim(),W=new Date(e.created_at||"").toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),K=`[Context]
Title: ${p}
Source URL: ${c||"N/A"}
Saved date: ${W}
"""
${I}
"""`;try{await navigator.clipboard.writeText(K),C.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#3795BD" stroke-width="2"><polyline points="20,6 9,17 4,12"/></svg>',setTimeout(()=>{C.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>'},2e3)}catch(Y){console.error("Failed to copy:",Y)}});const B=x.createDeleteButton();B.addEventListener("click",async S=>{if(S.stopPropagation(),!(!u||!window.confirm("Delete this context? This action cannot be undone.")))try{await this.deleteContext(u),o.remove()}catch($){console.error("Delete failed",$)}}),w.appendChild(C),u&&w.appendChild(B),y.appendChild(g),y.appendChild(w);const f=t.metadata_json?.tags??[],l=Array.isArray(f)?f:typeof f=="string"&&f.trim()?f.split(",").map(S=>S.trim()):[];if(l.length>0){const S=document.createElement("div");S.style.cssText=`
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 4px 0 8px 0;
      `,l.forEach(I=>{const $=document.createElement("span");$.textContent=I,$.style.cssText=`
          font-size: 10px;
          color: #93c5fd;
          background: #1f2937;
          border: 1px solid #374151;
          border-radius: 9999px;
          padding: 2px 8px;
        `,S.appendChild($)}),o.appendChild(S)}const E=document.createElement("div");E.style.cssText=`
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 11px;
      color: #a3a3a3;
      margin: 0 0 8px 0;
    `;const D=document.createElement("span");D.textContent="Source URL:",D.style.cssText=`
      color: #a3a3a3;
      font-weight: 500;
    `;let H="";c&&(H=c.length>40?c.substring(0,40)+"...":c);const A=document.createElement("a");A.href=c||"#",A.target="_blank",A.rel="noopener noreferrer",A.textContent=H,A.style.cssText=`
      color: #3795BD;
      text-decoration: none;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      flex: 1;
      min-width: 0;
    `,E.appendChild(D),E.appendChild(A);const R=document.createElement("div");R.style.cssText=`
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0 0 6px 0;
      font-size: 11px;
      color: #a3a3a3;
    `;const M=document.createElement("span");M.textContent="Saved:",M.style.cssText=`
      color: #a3a3a3;
      font-weight: 500;
    `;const z=document.createElement("span"),V=new Date(e.created_at||"");z.textContent=V.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"}),z.style.cssText=`
      color: #d4d4d8;
    `,R.appendChild(M),R.appendChild(z);const m=document.createElement("p");m.textContent=String(h||"No content available"),m.style.cssText=`
      margin: 0 0 6px 0;
      font-size: 12px;
      color: #d4d4d8;
      line-height: 1.4;
      cursor: default;
    `;const L=(h||"").length>200,T=x.createToggleButton("Read more");T.style.cssText=`
      background: none;
      border: none;
      color: #3795BD;
      cursor: pointer;
      font-size: 12px;
      padding: 4px 0;
      margin-top: 4px;
      text-decoration: underline;
      display: ${L?"inline":"none"};
    `;let _=!1;const j=S=>{S.stopPropagation(),_=!_,_?(m.style.display="block",m.style.webkitLineClamp="unset",m.style.webkitBoxOrient="vertical",m.style.overflow="visible",T.textContent="Read less"):(m.style.display="-webkit-box",m.style.webkitLineClamp="3",m.style.webkitBoxOrient="vertical",m.style.overflow="hidden",T.textContent="Read more")};return L&&(m.style.display="-webkit-box",m.style.webkitLineClamp="3",m.style.webkitBoxOrient="vertical",m.style.overflow="hidden"),T.addEventListener("click",j),m.addEventListener("click",j),o.appendChild(y),o.appendChild(E),o.appendChild(R),o.appendChild(m),o.appendChild(T),o}static createRelevanceBadge(e){const t=ee(e),n=document.createElement("div");return n.textContent=t.level,n.style.cssText=`
      display: inline-flex;
      align-items: center;
      padding: 2px 6px;
      border-radius: 4px;
      font-size: 9px;
      font-weight: 600;
      text-transform: uppercase;
      letter-spacing: 0.5px;
      color: ${t.color};
      background: ${t.bgColor};
      border: 1px solid ${t.color}40;
      margin-left: 8px;
      flex-shrink: 0;
    `,n}static async deleteContext(e){return new Promise((t,n)=>{chrome.runtime.sendMessage({action:"DELETE_CONTEXT",contextId:e},i=>{if(chrome.runtime.lastError){n(new Error(chrome.runtime.lastError.message));return}i&&i.success?t(!0):n(new Error("Delete failed"))})})}}function Z(r){const e=document.createElement("div");return e.textContent=r,e.innerHTML}function P(r){try{const e=new URL(r);return e.protocol==="http:"||e.protocol==="https:"}catch{return!1}}function ee(r){return r>=.5?{level:"High",color:"#22c55e",bgColor:"rgba(34, 197, 94, 0.1)"}:r>=.3?{level:"Med",color:"#f59e0b",bgColor:"rgba(245, 158, 11, 0.1)"}:{level:"Low",color:"#ef4444",bgColor:"rgba(239, 68, 68, 0.1)"}}function te(r){let e=String(r).trim();return e=e.replace(/^https?:\/\/(www\.)?/i,""),e=e.replace(/\.(html|htm|pdf|txt|doc|docx|png|jpg|jpeg|gif|csv|md|json|xml|zip|rar|7z|mp4|mp3|avi|mov|wav|flv|webm|ogg|svg|ico|css|js|ts|py|java|cpp|c|h|php|rb|go|rs|swift|kt|scala|sh|bat|ps1|sql|yaml|yml|toml|ini|cfg|conf|log|bak|tmp|temp)$/i,""),e=e.replace(/[-_]/g," "),e=e.replace(/\b\w/g,t=>t.toUpperCase()),e=e.replace(/\s+/g," ").trim(),e||"Unknown Document"}function N(r,e){const t=document.createElement("div");t.style.cssText=`
      display: flex;
      flex-direction: column;
      gap: 2px;
    `;const n=document.createElement("div");n.textContent=r,n.style.cssText=`
      color: #888;
      font-size: 10px;
      font-weight: 500;
      text-transform: uppercase;
    `;const i=document.createElement("div");if(i.style.cssText=`
      color: #d4d4d8;
      font-size: 11px;
      line-height: 1.3;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    `,r==="URL"&&e!=="N/A"&&P(e)){const s=document.createElement("a");s.href=e,s.target="_blank",s.rel="noopener noreferrer",s.textContent=e,s.style.cssText=`
        color: #93c5fd;
        text-decoration: none;
        font-size: 11px;
        line-height: 1.3;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        display: block;
      `,s.addEventListener("mouseenter",()=>{s.style.textDecoration="underline"}),s.addEventListener("mouseleave",()=>{s.style.textDecoration="none"}),i.appendChild(s)}else i.textContent=r==="URL"&&e!=="N/A"&&!P(e)?"N/A":e;return t.appendChild(n),t.appendChild(i),t}function O(r){r.innerHTML=`
      <div style="
        text-align: center;
        padding: 32px 16px;
        color: #6b7280;
        font-size: 14px;
        line-height: 1.5;
      ">
        <h3 style="margin: 0 0 8px 0; font-size: 16px; font-weight: 600; color: #9ca3af;">Search Your Knowledge</h3>
        <p style="margin: 0 0 16px 0; font-size: 14px; line-height: 1.5; color: #6b7280;">
          Find articles, tutorials, and content you've saved.<br/>
          Try searching for topics, keywords, or specific titles.
        </p>
      </div>
    `}function G(r,e){r.innerHTML="";const t=document.createElement("div");t.style.cssText=`
      color: #ef4444;
      padding: 16px;
      font-size: 14px;
      text-align: center;
    `,t.textContent=e,r.appendChild(t)}function ne(r,e){if(e.innerHTML="",r.length===0){e.innerHTML=`
        <div style="text-align: center; color: #a3a3a3; padding: 20px;">
          <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" style="display:block;margin:0 auto 8px;">
            <circle cx="11" cy="11" r="8"></circle>
            <path d="M21 21l-4.35-4.35"></path>
          </svg>
          <p style="margin: 0; font-size: 14px;">No results found</p>
        </div>
      `;return}console.log("Results:",r);const t=r.slice().sort((n,i)=>{const s=n.relevance_score??0;return(i.relevance_score??0)-s});console.log("Sorted results:",t),t.forEach(n=>{const i=J.create(n);e.appendChild(i)})}function oe(r){b.showInContainer(r,{message:"Loading bookmarks...",subMessage:"Please wait while we fetch your saved content"})}function ie(r){r.innerHTML=`
      <div style="
        color: #6b7280;
        padding: 16px;
        font-size: 14px;
        text-align: center;
      ">No bookmarks yet</div>
    `}function q(r,e){r.innerHTML="";const t=document.createElement("div");t.style.cssText=`
      color: #ef4444;
      padding: 16px;
      font-size: 14px;
      text-align: center;
    `,t.textContent=e,r.appendChild(t)}class ae{static create(e){const t=e,n=m=>{if(!m)return"N/A";const L=new Date(m);return isNaN(L.getTime())?"N/A":L.toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"})};let s=t.metadata_json?.title||t.original_filename||t.uploaded_filename||"Untitled";s=s.replace(/\.html$/i,"").replace(/[-_]/g," ");const p=t.textcontent||"",h=t.metadata_json?.url||"",d=P(h)?h:"",c=t.id||"",u=t.context_id||"",a=document.createElement("div");a.style.cssText=`
      background: #262626;
      border: 1px solid #404040;
      border-radius: 8px;
      padding: 12px;
      margin-bottom: 10px;
      cursor: default;
      transition: all 0.2s ease;
    `,a.addEventListener("mouseenter",()=>{a.style.background="#404040",a.style.borderColor="#3795BD"}),a.addEventListener("mouseleave",()=>{a.style.background="#262626",a.style.borderColor="#404040"});const o=document.createElement("div");o.style.cssText=`
      display: flex;
      align-items: center;
      gap: 8px;
      margin: 0 0 6px 0;
    `;const y=document.createElement("h4");y.style.cssText=`
      margin: 0;
      font-size: 14px;
      font-weight: 600;
      color: #fafafa;
      flex: 1;
      min-width: 0;
      display: flex;
      align-items: center;
    `;const g=document.createElement("a");g.textContent=String(s),g.href=d||"#",g.target="_blank",g.rel="noopener noreferrer",g.style.cssText=`
      color: inherit;
      text-decoration: none;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      display: inline-block;
      max-width: 100%;
      flex: 1;
      min-width: 0;
    `,y.appendChild(g);const v=document.createElement("div");v.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
    `;const k=x.createCopyButton();k.addEventListener("click",async m=>{m.stopPropagation();const L=String(p||"").replace(/<[^>]*>/g,"").replace(/#{1,6}\s+/g,"").replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/`(.*?)`/g,"$1").replace(/\[(.*?)\]\(.*?\)/g,"$1").replace(/\n\s*\n/g,`
`).trim(),T=n(t.created_at),_=`[Context]
        Title: ${s}
        Source URL: ${d||"N/A"}
        Saved date: ${T}
        """
        ${L}
        """`;try{await navigator.clipboard.writeText(_),k.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#3795BD" stroke-width="2"><polyline points="20,6 9,17 4,12"/></svg>',setTimeout(()=>{k.innerHTML='<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/></svg>'},2e3)}catch(j){console.error("Failed to copy:",j)}});const w=x.createDeleteButton();w.addEventListener("click",async m=>{if(m.stopPropagation(),!(!u||!window.confirm("Delete this bookmark? This action cannot be undone.")))try{await this.deleteContext(u),a.remove()}catch(T){console.error("Delete failed",T)}}),v.appendChild(k),c&&v.appendChild(w),o.appendChild(y),o.appendChild(v);const C=t.metadata_json?.tags??[],B=Array.isArray(C)?C:typeof C=="string"&&C.trim()?C.split(",").map(m=>m.trim()):[];if(B.length>0){const m=document.createElement("div");m.style.cssText=`
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 4px 0 8px 0;
      `,B.forEach(L=>{const T=document.createElement("span");T.textContent=L,T.style.cssText=`
          font-size: 10px;
          color: #93c5fd;
          background: #1f2937;
          border: 1px solid #374151;
          border-radius: 9999px;
          padding: 2px 8px;
        `,m.appendChild(T)}),a.appendChild(m)}const f=document.createElement("div");f.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
      margin: 0 0 4px 0;
      font-size: 12px;
    `;const l=document.createElement("span");l.textContent="Source URL:",l.style.cssText=`
      color: #a3a3a3;
      font-weight: 500;
    `;let E="";d&&(E=d.length>40?d.substring(0,40)+"...":d);const D=document.createElement("a");D.href=d||"#",D.target="_blank",D.rel="noopener noreferrer",D.textContent=E,D.style.cssText=`
      color: #3795BD;
      text-decoration: none;
      flex: 1;
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    `,f.appendChild(l),f.appendChild(D);const H=document.createElement("div");H.style.cssText=`
      display: flex;
      align-items: center;
      gap: 6px;
      margin: 0 0 8px 0;
      font-size: 12px;
    `;const A=document.createElement("span");A.textContent="Saved:",A.style.cssText=`
      color: #a3a3a3;
      font-weight: 500;
    `;const R=document.createElement("span");R.textContent=n(t.created_at),R.style.cssText=`
      color: #d4d4d8;
    `,H.appendChild(A),H.appendChild(R);const M=document.createElement("div");M.style.cssText=`
      margin-top: 8px;
    `;const z=document.createElement("p");if(z.textContent=String(p||"No content available"),z.style.cssText=`
      margin: 0;
      font-size: 13px;
      line-height: 1.4;
      color: #d4d4d8;
      word-wrap: break-word;
    `,M.appendChild(z),p.length>150){z.style.cssText=`
        margin: 0;
        font-size: 13px;
        line-height: 1.4;
        color: #d4d4d8;
        word-wrap: break-word;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
      `;const m=x.createToggleButton("Read more");m.style.cssText=`
        background: none;
        border: none;
        color: #3795BD;
        cursor: pointer;
        font-size: 12px;
        padding: 4px 0;
        margin-top: 4px;
        text-decoration: underline;
      `;let L=!1;const T=_=>{_.stopPropagation(),L=!L,L?(z.style.cssText=`
            margin: 0;
            font-size: 13px;
            line-height: 1.4;
            color: #d4d4d8;
            word-wrap: break-word;
          `,m.textContent="Read less"):(z.style.cssText=`
            margin: 0;
            font-size: 13px;
            line-height: 1.4;
            color: #d4d4d8;
            word-wrap: break-word;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
          `,m.textContent="Read more")};m.addEventListener("click",T),M.addEventListener("click",T),a.appendChild(o),a.appendChild(f),a.appendChild(H),a.appendChild(M),a.appendChild(m)}else a.appendChild(o),a.appendChild(f),a.appendChild(H),a.appendChild(M);return a}static async deleteContext(e){return new Promise((t,n)=>{chrome.runtime.sendMessage({action:"DELETE_CONTEXT",contextId:e},i=>{if(chrome.runtime.lastError){n(new Error(chrome.runtime.lastError.message));return}i&&i.success?t(!0):n(new Error("Delete failed"))})})}}function re(r,e){const t=document.createElement("div");t.style.cssText="display: flex; align-items: flex-start; gap: 8px; margin-bottom: 6px;";const n=document.createElement("div");n.style.cssText="color: #888; font-size: 11px; font-weight: 500; min-width: 40px; margin-top: 1px;",n.textContent=r;const i=document.createElement("div");if(i.setAttribute("role","list"),i.style.cssText="display: flex; flex-wrap: wrap; gap: 4px; flex: 1;",e.length===0){const s=document.createElement("div");s.style.cssText="color: #888; font-size: 12px; font-style: italic;",s.textContent="No tags available",i.appendChild(s)}else e.forEach(s=>{const p=document.createElement("span");p.setAttribute("role","listitem"),p.style.cssText=`
        background: #3795BD;
        color: #ffffff;
        font-size: 10px;
        font-weight: 500;
        padding: 2px 6px;
        border-radius: 3px;
        white-space: nowrap;
      `,p.textContent=s,i.appendChild(p)});return t.appendChild(n),t.appendChild(i),t}class se{static async update(e){try{const[t]=await chrome.tabs.query({active:!0,currentWindow:!0});if(!t){e.innerHTML=`
          <div style="color: #888; font-size: 12px;">No active tab found</div>
        `;return}let n=null;try{const l=await chrome.tabs.sendMessage(t.id,{action:"EXTRACT_PAGE_CONTENT"});l?.success&&l?.data&&(n=l.data)}catch{console.error("Failed to extract page content")}const i=n?.title||t.title||"Untitled";if(i==="Untitled"||!i.trim()){e.innerHTML=`
          <div style="display: flex; flex-direction: column; gap: 8px;">
            <div style="display: flex; align-items: flex-start; gap: 8px;">
              <div style="color: #888; font-size: 11px; font-weight: 500; min-width: 40px; margin-top: 1px;">TITLE</div>
              <div style="color: #f59e0b; font-size: 13px; font-weight: 500; line-height: 1.3; flex: 1;">
                Unable to detect page title - try refreshing the page
              </div>
            </div>
            <div style="display: flex; justify-content: flex-end; margin-top: 4px;">
              ${x.createDisabledRefreshButton().outerHTML}
            </div>
          </div>
        `;return}const p=document.createElement("div");p.style.cssText="display: flex; flex-direction: column; gap: 8px;";const h=document.createElement("div");h.style.cssText="display: flex; align-items: flex-start; gap: 8px;";const d=document.createElement("div");d.style.cssText="color: #888; font-size: 11px; font-weight: 500; min-width: 40px; margin-top: 1px;",d.textContent="TITLE";const c=document.createElement("div");c.style.cssText=`
        color: #fafafa; 
        font-size: 13px; 
        font-weight: 500; 
        line-height: 1.3; 
        flex: 1;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      `,c.textContent=i,h.appendChild(d),h.appendChild(c);const u=document.createElement("div");u.style.cssText="display: flex; flex-direction: column; gap: 4px; margin-top: 8px;";const a=x.createPropertiesToggleButton(),o=document.createElement("div");o.id="properties-content",o.style.cssText=`
        display: none;
        flex-direction: column;
        gap: 6px;
        padding: 8px;
        background: #1f1f1f;
        border: 1px solid #404040;
        border-radius: 4px;
        margin-top: 4px;
      `;const y=N("URL",n?.url||t.url||"N/A"),g=N("Description",n?.metadata?.description||n?.excerpt||"No description available"),v=N("Title",n?.title||"No title available"),k=N("Category",n?.category||"Uncategorized"),w=re("Tags",n?.tags||[]);o.appendChild(v),o.appendChild(y),o.appendChild(g),o.appendChild(k),o.appendChild(w),u.appendChild(a),u.appendChild(o);let C=!1;a.addEventListener("click",()=>{C=!C;const l=a.querySelector("span:last-child");C?(o.style.display="flex",l&&(l.style.transform="rotate(180deg)"),a.style.background="#404040"):(o.style.display="none",l&&(l.style.transform="rotate(0deg)"),a.style.background="#262626")}),a.addEventListener("mouseenter",()=>{C||(a.style.background="#404040")}),a.addEventListener("mouseleave",()=>{C||(a.style.background="#262626")});const B=document.createElement("div");B.style.cssText="display: flex; justify-content: flex-end; margin-top: 4px;";const f=x.createSaveButton();B.appendChild(f),p.appendChild(h),p.appendChild(u),p.appendChild(B),e.innerHTML="",e.appendChild(p),f&&(f.addEventListener("mouseenter",()=>{f.style.background="#2E7A9A"}),f.addEventListener("mouseleave",()=>{f.style.background="#3795BD"}),f.addEventListener("click",async()=>{if(!f.disabled)try{if(!t?.id){this.showSaveError(e,"No active tab found");return}b.showSaveLoadingInContainer(e);const l=await chrome.runtime.sendMessage({action:"SAVE_CURRENT_PAGE",tabId:t.id});if(l?.success){const E=n?.wordCount||0;this.showSaveSuccess(e,i,E)}else this.showSaveError(e,l?.error||"Failed to save page")}catch(l){console.error("Save failed:",l),this.showSaveError(e,"Failed to save page. Please try again.")}}))}catch(t){console.error("Failed to update page info:",t),e.innerHTML=`
        <div style="color: #ef4444; font-size: 12px;">Failed to load page information</div>
      `}}static showSaveSuccess(e,t,n=0){const i=t.length>30?t.substring(0,30)+"...":t,s=e.style.height||"auto";e.innerHTML="";const p=document.createElement("div");p.style.cssText=`
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 12px 16px;
      text-align: center;
      height: ${s};
      min-height: 60px;
    `;const h=document.createElement("div");h.style.cssText=`
      width: 32px;
      height: 32px;
      background: #3795BD;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-bottom: 12px;
    `;const d=document.createElementNS("http://www.w3.org/2000/svg","svg");d.setAttribute("width","18"),d.setAttribute("height","18"),d.setAttribute("viewBox","0 0 24 24"),d.setAttribute("fill","none"),d.setAttribute("stroke","#ffffff"),d.setAttribute("stroke-width","2");const c=document.createElementNS("http://www.w3.org/2000/svg","polyline");c.setAttribute("points","20,6 9,17 4,12"),d.appendChild(c),h.appendChild(d);const u=document.createElement("div");u.style.cssText=`
      color: #3795BD;
      font-size: 14px;
      font-weight: 600;
      margin-bottom: 6px;
    `,u.textContent="Page Saved Successfully!";const a=document.createElement("div");a.style.cssText=`
      color: #fafafa;
      font-size: 12px;
      font-weight: 500;
      margin-bottom: 2px;
    `,a.textContent=i;const o=document.createElement("div");o.style.cssText=`
      color: #888;
      font-size: 10px;
      margin-bottom: 4px;
    `,o.textContent=`(${n} words)`,p.appendChild(h),p.appendChild(u),p.appendChild(a),p.appendChild(o),e.appendChild(p),setTimeout(()=>{this.update(e)},3e3)}static showSaveError(e,t){const n=Z(t),i=e.style.height||"auto";e.innerHTML=`
      <div style="
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 12px 16px;
        text-align: center;
        height: ${i};
        min-height: 60px;
      ">
        <div style="
          width: 32px;
          height: 32px;
          background: #ef4444;
          border-radius: 50%;
          display: flex;
          align-items: center;
          justify-content: center;
          margin-bottom: 12px;
        ">
          <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="#ffffff" stroke-width="2">
            <line x1="18" y1="6" x2="6" y2="18"/>
            <line x1="6" y1="6" x2="18" y2="18"/>
          </svg>
        </div>
        <div style="
          color: #ef4444;
          font-size: 14px;
          font-weight: 600;
          margin-bottom: 6px;
        ">Save Failed</div>
        <div style="
          color: #fafafa;
          font-size: 12px;
          line-height: 1.3;
          margin-bottom: 12px;
        ">${n}</div>
      </div>
    `}}let F=!1;document.addEventListener("DOMContentLoaded",()=>{le()});async function le(){const r=document.getElementById("popup-container");if(!r)return;await Q()?ce(r):X(r)}function ce(r){const e=document.createElement("div");e.style.cssText=`
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #1a1a1a;
  `;const t=document.createElement("div");t.style.cssText=`
    display: flex;
    align-items: center;
    gap: 4px;
  `;try{const v=chrome.runtime.getURL("icons/Eidexa_default.png"),k=document.createElement("img");k.src=v,k.alt="Eidexa AI",k.style.cssText=`
      width: 24px;
      height: 24px;
      display: block;
    `,t.appendChild(k)}catch{}const n=document.createElement("span");n.textContent="Eidexa",n.style.cssText=`
    font-size: 14px;
    font-weight: 600;
    color: #fafafa;
  `,t.appendChild(n);const i=x.createSettingsButton(),s=x.createQuickGuideButton(),p=document.createElement("div");p.style.cssText=`
    display: flex;
    align-items: center;
    gap: 4px;
  `,p.appendChild(s),p.appendChild(i),e.appendChild(t),e.appendChild(p);const h=document.createElement("div");h.id="page-info-section",h.style.cssText=`
    padding: 12px 16px;
    background: #1f1f1f;
    border-bottom: 1px solid #262626;
  `;const d=document.createElement("div");d.id="eidexa-ai-navigation",d.style.cssText=`
    display: flex;
    border-bottom: 1px solid #262626;
    background: #1a1a1a;
  `;const c=x.createTabButton("Search",!0,()=>g("search")),u=x.createTabButton("Bookmarks",!1,()=>g("bookmarks"));d.appendChild(c),d.appendChild(u);const a=document.createElement("div");a.id="eidexa-ai-content-area",a.style.cssText=`
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 16px;
  `;const o=document.createElement("div");o.id="eidexa-ai-search-section",o.style.cssText=`
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  `;const y=document.createElement("div");y.id="eidexa-ai-bookmarks-section",y.style.cssText=`
    display: none;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  `,de(o),pe(y),a.appendChild(o),a.appendChild(y);function g(v){[c,u].forEach(w=>{w.classList.remove("active"),w.style.color="#9ca3af",w.style.background="transparent",w.style.borderBottomColor="transparent"}),[o,y].forEach(w=>{w.style.display="none"}),v==="search"?(c.classList.add("active"),c.style.color="#fafafa",c.style.borderBottomColor="#3795BD",o.style.display="flex"):v==="bookmarks"&&(u.classList.add("active"),u.style.color="#fafafa",u.style.borderBottomColor="#3795BD",y.style.display="flex",xe())}r.appendChild(e),r.appendChild(h),r.appendChild(d),r.appendChild(a),se.update(h),g("search")}function de(r){r.innerHTML="";const e=document.createElement("div");e.id="eidexa-ai-search-results",e.style.cssText=`
    flex: 1;
    overflow-y: auto;
    margin-bottom: 16px;
    min-height: 0;
  `,O(e);const n=U.create({placeholder:"Search your saved content...",onSearch:async i=>{if(!i){O(e);return}try{const s=await chrome.runtime.sendMessage({action:"PERFORM_SEARCH",query:i});s.success&&s.results?ne(s.results,e):G(e,"No results found")}catch{G(e,"Search failed. Please try again.")}}}).wrapper;r.appendChild(e),r.appendChild(n)}function pe(r){r.innerHTML="";const e=document.createElement("h3");e.textContent="Bookmarks",e.style.cssText=`
    margin: 0 0 16px 0;
    font-size: 16px;
    font-weight: 600;
    color: #fafafa;
    flex-shrink: 0;
  `;const t=document.createElement("div");t.id="eidexa-ai-bookmarks-list",t.style.cssText=`
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  `,r.appendChild(e),r.appendChild(t)}async function xe(){const r=document.getElementById("eidexa-ai-bookmarks-list");if(r){F||oe(r);try{const e=await chrome.runtime.sendMessage({action:"GET_BOOKMARKS"});if(e.success){const t=e.bookmarks||[];if(t.length===0){ie(r),F=!0;return}r.innerHTML="",t.forEach(n=>{const i=ae.create(n);r.appendChild(i)}),F=!0}else q(r,"Failed to load bookmarks")}catch{q(r,"Failed to load bookmarks")}}}
//# sourceMappingURL=popup.js.map
