/* 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;
}

.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;
}