/* Web Search Sidebar Styling - Sliding from Right */
.search-sidebar-container {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    z-index: var(--z-overlay);
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    /* Keep the container LTR so flex-end stays on the physical right
       even when the document is dir="rtl" (Arabic). */
    direction: ltr;
}

.search-sidebar {
    width: 450px;
    height: 100%;
    background: var(--bg-surface-solid);
    border-left: 1px solid var(--border-glass);
    box-shadow: var(--shadow-main);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--tr-smooth), width 0.3s ease;
    pointer-events: auto;
    z-index: var(--z-modal);
    position: relative;
}

.search-sidebar.expanded {
    width: 700px;
}

.search-sidebar-container.open .search-sidebar {
    transform: translateX(0);
}

/* iOS WebKit fix: parent pe:none blocks child touch events */
.search-sidebar-container.open {
    pointer-events: auto;
}

/* Header */
.search-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
}

.search-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-main);
}

.search-title i {
    color: #de5833;
    /* DuckDuckGo Orange-ish */
}

/* Search Result Area */
.search-results-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-app);
}

.search-item {
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-glass);
    border-radius: 12px;
    padding: 16px;
    transition: all 0.2s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
    display: block;
}

.search-item:hover {
    transform: translateY(-2px);
    border-color: #8b5cf6;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.1);
}

.search-item-title {
    color: #8b5cf6;
    font-weight: 600;
    font-size: 1.05rem;
    margin-bottom: 4px;
    display: block;
}

.search-item-url {
    font-size: 0.75rem;
    color: #10b981;
    margin-bottom: 8px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-item-snippet {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Footer & Input */
.search-footer {
    padding: 16px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-glass);
}

.search-input-container {
    display: flex;
    gap: 10px;
    background: var(--bg-item);
    padding: 10px 16px;
    border-radius: 24px;
    border: 1px solid var(--border-glass);
    align-items: center;
}

#webSearchInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 0.95rem;
    outline: none;
}

.btn-run-search {
    background: #8b5cf6;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-loading {
    display: none;
    justify-content: center;
    padding: 20px;
}

.search-sidebar-container.loading .search-loading {
    display: flex;
}

/* Empty State */
.search-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.search-empty i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

/* Tab Navigation */
.search-tabs {
    display: flex;
    padding: 0 16px;
    gap: 8px;
    border-bottom: 1px solid var(--border-glass);
    background: var(--bg-surface);
    overflow-x: auto;
    scrollbar-width: none; /* Firefox */
    -webkit-overflow-scrolling: touch;
}

.search-tabs::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.search-tab {
    padding: 14px 16px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
}

.search-tab i {
    font-size: 1rem;
}

.search-tab.active {
    color: #8b5cf6;
}

.search-tab.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: #8b5cf6;
    border-radius: 3px 3px 0 0;
}

.search-tab:hover {
    color: var(--text-main);
    background: rgba(139, 92, 246, 0.05);
    /* Subtle hover bg */
}

/* Image Search Grid */
.search-results-body {
    /* Ensure scrollbar doesn't cover content */
    scrollbar-gutter: stable;
    /* Add touch scrolling */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
    min-height: 0;
}

/* Specific Style for Image Grid Mode - JS adds a class or we style children */
/* But WebSearchManager sets grid via inline style. Let's rely on that or improve it. */
/* Actually, let's target the item class directly. */

.search-image-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    background: #1e293b;
    /* Dark placeholder */
    width: 100%;
    aspect-ratio: 1;
    /* Square */
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.search-image-item:hover {
    transform: translateY(-2px);
    z-index: 10;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.25);
}

.search-image-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s;
}

.search-image-item:hover img {
    transform: scale(1.05);
}

/* Overlay */
.search-image-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95) 0%, rgba(0, 0, 0, 0.5) 50%, transparent 100%);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 12px;
    opacity: 0;
    transition: opacity 0.2s;
}

.search-image-item:hover .search-image-overlay {
    opacity: 1;
}

/* Touch Device Support: Always show overlay or show on active */
@media (hover: none) {
    .search-image-overlay {
        opacity: 1;
        background: linear-gradient(to top, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0.4) 40%, transparent 100%);
    }
}

.search-image-source {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.9);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px;
    font-weight: 500;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.search-image-actions {
    display: flex;
    gap: 8px;
}

.btn-img-action {
    flex: 1;
    height: 32px;
    border: none;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: filter 0.2s, transform 0.1s;
    outline: none;
}

.btn-img-action:active {
    transform: scale(0.95);
}

.btn-img-action.add {
    background: #8b5cf6;
    color: white;
    box-shadow: 0 2px 4px rgba(139, 92, 246, 0.3);
}

.btn-img-action.add:hover {
    filter: brightness(1.1);
}

.btn-img-action.bg {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(4px);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-img-action.bg:hover {
    background: rgba(255, 255, 255, 0.25);
}

.search-empty i {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.3;
}

/* Safe Search Badge */
.safe-search-badge {
    margin-left: 10px;
    background: rgba(16, 185, 129, 0.1);
    /* Emerald green translucent */
    color: #10b981;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(16, 185, 129, 0.2);
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: help;
}

.safe-search-badge i {
    font-size: 0.7rem;
    color: #10b981 !important;
    /* Override parent icon color */
}

/* ========= PNG Transparency Verification ========= */
.png-verify-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 4px;
    z-index: 20;
    pointer-events: none;
    backdrop-filter: blur(6px);
    transition: all 0.3s ease;
}

.png-verify-badge.verifying {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.png-verify-badge.verified {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

.png-verify-badge.failed {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Dim non-transparent images */
.search-image-item.png-not-transparent {
    opacity: 0.35;
    filter: grayscale(0.5);
    order: 999; /* Push to bottom of grid */
    transition: opacity 0.3s ease, filter 0.3s ease;
}

.search-image-item.png-not-transparent:hover {
    opacity: 0.7;
    filter: grayscale(0);
}

/* Verified transparent images get a subtle green glow */
.search-image-item.png-verified {
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.4);
}

/* Checkerboard preview background (set via inline style in JS) */
.search-image-item.png-check-pending img,
.search-image-item.png-verified img {
    /* Let the checkerboard show through for truly transparent areas */
    mix-blend-mode: normal;
}

/* ─── Search Sidebar Scrollbar ─── */
.search-results-body::-webkit-scrollbar {
    width: 8px;
}

.search-results-body::-webkit-scrollbar-track {
    background: rgba(128, 128, 128, 0.06);
    border-radius: 4px;
}

.search-results-body::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
    min-height: 40px;
}

.search-results-body::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.5);
    border: 2px solid transparent;
    background-clip: padding-box;
}
/* ── "Search + AI" tab (ToolManager's best photo / AI insight / web sources, inside this sidebar) ──
      Those blocks were styled for the old dark panel; give them light-panel colours here. */
.search-sidebar .ai-search-section-head { color: var(--text-muted, #64748b) !important; margin: 4px 2px 10px; }
.search-sidebar .ai-search-hero { background: #fff; border: 1px solid rgba(100, 116, 139, .22); border-radius: 16px; }
.search-sidebar .ai-search-thumbs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0 16px; }
.search-sidebar .ai-search-thumb { aspect-ratio: 4 / 3; height: auto !important; width: auto !important; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: #fff; }
.search-sidebar .ai-search-thumb.active { border-color: #0ea5e9; }
.search-sidebar .ai-search-comment { background: #fff !important; border: 1px solid rgba(14, 165, 233, .3) !important; border-inline-start: 4px solid #0ea5e9 !important; border-radius: 14px; }
.search-sidebar .ai-search-comment-head { color: #0369a1 !important; font-weight: 800; }
.search-sidebar .ai-search-comment-body { color: var(--text-main, #1e293b) !important; font-size: .95rem; line-height: 1.6; }
.search-sidebar .ai-search-cmt-btn { background: #f1f5f9 !important; color: #334155 !important; border: 1px solid rgba(100, 116, 139, .25) !important; min-height: 36px; }
.search-sidebar .ai-search-cmt-btn:hover { background: #e2e8f0 !important; }
.search-sidebar .ai-search-cmt-btn.primary { background: linear-gradient(135deg, #0ea5e9, #0284c7) !important; color: #fff !important; border-color: transparent !important; }
.search-sidebar .ai-search-result { background: #fff !important; border: 1px solid rgba(100, 116, 139, .22) !important; }
.search-sidebar .ai-search-result-title { color: #0369a1 !important; }
.search-sidebar .ai-search-result-snippet { color: #475569 !important; }
.search-sidebar .ai-search-loading, .search-sidebar .ai-search-empty { color: var(--text-muted, #64748b); }
body.touch-device .search-sidebar .ai-search-cmt-btn { min-height: 42px; }
.search-sidebar .ai-search-thumbs-hint { font-size: .74rem; color: var(--text-muted, #64748b); margin: 10px 2px 0; }
.search-sidebar .ai-search-thumb { position: relative; cursor: zoom-in; padding: 0; transition: transform .15s ease; }
.search-sidebar .ai-search-thumb:hover { transform: translateY(-2px); }
.search-sidebar .ai-search-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }


/* ── Full-screen photo viewer (ToolManager._openPhotoViewer) — lives outside the zoomed body ── */
.fx-viewer {
    position: fixed; inset: 0; z-index: 2147483200;
    display: grid; grid-template-columns: 72px 1fr 72px; grid-template-rows: 1fr auto auto; align-items: center;
    padding: 24px 16px 18px; box-sizing: border-box;
    background: rgba(9, 12, 28, .9); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    font-family: 'Outfit', 'Cairo', system-ui, sans-serif; color: #fff;
    opacity: 0; transition: opacity .2s ease;
}
.fx-viewer.show { opacity: 1; }
.fx-v-stage { grid-column: 2; grid-row: 1; margin: 0; height: 100%; min-height: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; }
.fx-v-frame { position: relative; max-width: 100%; max-height: calc(100% - 30px); display: flex; border-radius: 14px; overflow: hidden; background: #fff; box-shadow: 0 30px 80px rgba(0, 0, 0, .5); touch-action: pan-y; }
.fx-v-frame img { display: block; max-width: min(1100px, 100%); max-height: calc(100vh - 220px); object-fit: contain; user-select: none; -webkit-user-drag: none; }
.fx-v-spin { position: absolute; inset: 0; display: none; place-items: center; color: #6366f1; font-size: 26px; background: #fff; }
.fx-v-frame.loading .fx-v-spin { display: grid; }
.fx-v-cap { max-width: 80%; font-size: 14px; color: rgba(255, 255, 255, .75); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-v-close { position: absolute; top: 16px; right: 16px; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); color: #fff; font-size: 20px; cursor: pointer; }
.fx-v-nav { width: 56px; height: 56px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14); color: #fff; font-size: 20px; cursor: pointer; justify-self: center; transition: background .15s ease, transform .15s ease; }
.fx-v-nav.prev { grid-column: 1; grid-row: 1; }
.fx-v-nav.next { grid-column: 3; grid-row: 1; }
.fx-v-close:hover, .fx-v-nav:hover { background: rgba(255, 255, 255, .26); }
.fx-v-nav:active { transform: scale(.94); }
.fx-v-nav[hidden], .fx-v-strip[hidden] { display: none !important; }
.fx-v-bar { grid-column: 1 / -1; grid-row: 2; display: flex; align-items: center; justify-content: center; gap: 16px; margin: 14px 0 10px; }
.fx-v-count { min-width: 56px; text-align: center; font-weight: 700; color: rgba(255, 255, 255, .7); }
.fx-v-add {
    display: inline-flex; align-items: center; gap: 10px; min-height: 54px; padding: 0 28px; border: 0; border-radius: 999px;
    background: linear-gradient(135deg, #0ea5e9, #6366f1); color: #fff; font: 800 17px/1 inherit; font-family: inherit; cursor: pointer;
    box-shadow: 0 10px 30px rgba(14, 165, 233, .45); transition: transform .12s ease, filter .15s ease;
}
.fx-v-add:hover { filter: brightness(1.08); }
.fx-v-add:active { transform: scale(.97); }
.fx-v-add:disabled { cursor: wait; filter: saturate(.7); }
.fx-v-strip { grid-column: 1 / -1; grid-row: 3; display: flex; gap: 8px; justify-content: center; overflow-x: auto; padding: 2px 4px 4px; scrollbar-width: none; }
.fx-v-strip::-webkit-scrollbar { display: none; }
.fx-v-strip button { flex: none; width: 74px; height: 54px; padding: 0; border-radius: 10px; overflow: hidden; border: 2px solid transparent; opacity: .55; cursor: pointer; background: #fff; transition: opacity .15s ease, border-color .15s ease; }
.fx-v-strip button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fx-v-strip button.on { opacity: 1; border-color: #38bdf8; }
@media (max-width: 640px) {
    .fx-viewer { grid-template-columns: 0 1fr 0; padding: 60px 10px 14px; }
    .fx-v-nav { display: none; }
    .fx-v-frame img { max-height: calc(100vh - 240px); }
}
@media (prefers-reduced-motion: reduce) { .fx-viewer { transition: none; } }
