/* ===== Image Search - Overlay ===== */
.img-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 99998;
    transition: opacity .25s;
    opacity: 0;
}
.img-search-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== Modal ===== */
.img-search-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 700px;
    max-width: 94vw;
    max-height: 85vh;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0,0,0,.2);
    z-index: 99999;
    overflow: hidden;
    flex-direction: column;
}
.img-search-modal.active {
    display: flex;
}

/* mobile full-screen */
.img-search-modal.img-search-modal-mobile {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
}

/* header */
.img-search-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}
.img-search-modal-title {
    font-size: 16px;
    font-weight: 600;
    color: #222;
}
.img-search-close {
    background: none;
    border: none;
    font-size: 26px;
    color: #666;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    transition: color .15s;
}
.img-search-close:hover {
    color: #000;
}

/* body */
.img-search-modal-body {
    overflow-y: auto;
    padding: 16px 20px 20px;
    flex: 1;
}

/* ===== Drop Zone ===== */
.img-search-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 36px 20px 28px;
    border: 2px dashed #d5d5d5;
    border-radius: 12px;
    background: #f8f9fa;
    text-align: center;
    transition: border-color .25s, background .25s;
    margin-bottom: 14px;
}
.img-search-dropzone-active {
    border-color: #4a90d9;
    background: #eef5ff;
}
.img-search-dropzone-icon {
    font-size: 36px;
    color: #bbb;
    margin-bottom: 16px;
}
.img-search-dropzone-active .img-search-dropzone-icon {
    color: #4a90d9;
}
.img-search-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 11px 30px;
    background: linear-gradient(135deg, #333 0%, #1a1a1a 100%);
    color: #fff;
    border: none;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    box-shadow: 0 2px 10px rgba(0,0,0,.15);
    margin-bottom: 16px;
}
.img-search-upload-btn:hover {
    background: linear-gradient(135deg, #555 0%, #333 100%);
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
    transform: translateY(-1px);
}
.img-search-upload-btn i {
    font-size: 15px;
}
.img-search-dropzone-hint {
    font-size: 13px;
    color: #888;
    line-height: 1.7;
    margin: 0 0 10px;
}
.img-search-dropzone-formats {
    font-size: 11px;
    color: #aaa;
    font-weight: 500;
    margin: 0 0 18px;
}
.img-search-dropzone-divider {
    width: 100%;
    max-width: 340px;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
    color: #bbb;
    font-size: 12px;
}
.img-search-dropzone-divider::before,
.img-search-dropzone-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #ddd;
}
.img-search-url-row {
    display: flex;
    width: 100%;
    max-width: 400px;
    gap: 8px;
}
.img-search-url-input {
    flex: 1;
    height: 38px;
    padding: 0 12px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    color: #333;
    background: #fff;
    outline: none;
    transition: border-color .2s;
}
.img-search-url-input:focus {
    border-color: #4a90d9;
}
.img-search-url-input::placeholder {
    color: #bbb;
}
.img-search-url-btn {
    height: 38px;
    padding: 0 18px;
    background: linear-gradient(135deg, #333 0%, #1a1a1a 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    white-space: nowrap;
}
.img-search-url-btn:hover {
    background: linear-gradient(135deg, #555 0%, #333 100%);
}
@media (max-width: 768px) {
    .img-search-dropzone {
        padding: 28px 16px 22px;
    }
    .img-search-dropzone-icon {
        font-size: 30px;
        margin-bottom: 12px;
    }
    .img-search-upload-btn {
        padding: 10px 24px;
        font-size: 13px;
    }
    .img-search-dropzone-hint {
        font-size: 12px;
    }
    .img-search-url-row {
        flex-direction: column;
    }
    .img-search-url-btn {
        width: 100%;
    }
}

/* ===== Preview ===== */
.img-search-preview {
    text-align: center;
    margin-bottom: 12px;
}
.img-search-preview img {
    max-height: 160px;
    max-width: 100%;
    border-radius: 8px;
    object-fit: contain;
    border: 1px solid #eee;
}

/* ===== Cropper Section ===== */
.img-search-crop-section {
    margin-bottom: 14px;
}
.img-search-crop-wrap {
    max-height: 400px;
    overflow: hidden;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
    background: #f5f5f5;
}
.img-search-crop-wrap img {
    display: block;
    max-width: 100%;
}
.img-search-crop-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 14px;
}
.img-search-crop-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 22px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s ease;
    line-height: 1.4;
}
.img-search-crop-confirm {
    background: linear-gradient(135deg, #333 0%, #1a1a1a 100%);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.img-search-crop-confirm:hover {
    background: linear-gradient(135deg, #555 0%, #333 100%);
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.img-search-crop-skip {
    background: #f0f0f0;
    color: #444;
    border: 1px solid #d5d5d5;
}
.img-search-crop-skip:hover {
    background: #e5e5e5;
    border-color: #bbb;
    color: #222;
}

@media (max-width: 768px) {
    .img-search-crop-wrap {
        max-height: 280px;
    }
    .img-search-crop-actions {
        flex-direction: column;
        gap: 8px;
    }
    .img-search-crop-btn {
        width: 100%;
        justify-content: center;
        padding: 11px 16px;
        font-size: 14px;
    }
}

/* ===== Progress Bar ===== */
.img-search-progress {
    margin-bottom: 16px;
    padding: 0 4px;
}
.img-search-progress-text {
    font-size: 13px;
    color: #555;
    margin-bottom: 6px;
}
.img-search-progress-bar {
    width: 100%;
    height: 8px;
    background: #e9ecef;
    border-radius: 4px;
    overflow: hidden;
}
.img-search-progress-fill {
    height: 100%;
    width: 0%;
    border-radius: 4px;
    background: linear-gradient(90deg, #4a90d9, #34c759);
    transition: width .25s ease;
}
.img-search-progress-pct {
    font-size: 12px;
    color: #888;
    text-align: right;
    margin-top: 4px;
}

/* queue hint */
.img-search-queue-hint {
    margin-top: 10px;
    padding: 10px 14px;
    background: #fff8e1;
    border: 1px solid #ffe082;
    border-radius: 6px;
    font-size: 13px;
    color: #795548;
    text-align: center;
    animation: imgSearchQueuePulse 2s ease-in-out infinite;
}
.img-search-queue-hint i {
    margin-right: 6px;
    color: #ff9800;
}
@keyframes imgSearchQueuePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ===== Login Prompt ===== */
.img-search-login-prompt {
    text-align: center;
    padding: 30px 10px;
}
.img-search-login-icon {
    font-size: 40px;
    color: #ccc;
    margin-bottom: 12px;
}
.img-search-login-prompt p {
    font-size: 14px;
    color: #555;
    margin-bottom: 18px;
    line-height: 1.6;
}
.img-search-login-btn {
    display: inline-block;
    padding: 10px 36px;
    background: #222;
    color: #fff !important;
    text-decoration: none !important;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    transition: background .2s;
}
.img-search-login-btn:hover {
    background: #444;
}

/* ===== Results Grid ===== */
.img-search-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}
.img-search-modal-mobile .img-search-grid {
    grid-template-columns: repeat(2, 1fr);
}

/* card */
.img-search-card {
    display: block;
    text-decoration: none !important;
    color: #222 !important;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #eee;
    transition: box-shadow .2s, transform .15s;
    background: #fff;
}
.img-search-card:hover {
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    transform: translateY(-2px);
}

/* card image */
.img-search-card-img {
    position: relative;
    width: 100%;
    padding-top: 100%;
    overflow: hidden;
    background: #f5f5f5;
}
.img-search-card-img img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* similarity score tag */
.img-search-score {
    position: absolute;
    top: 6px;
    right: 6px;
    background: rgba(0,0,0,.55);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    line-height: 1.4;
}

/* card info */
.img-search-card-info {
    padding: 8px 10px 10px;
}
.img-search-card-name {
    font-size: 12px;
    color: #333;
    line-height: 1.4;
    max-height: 2.8em;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.img-search-card-price {
    margin-top: 5px;
    font-size: 13px;
}
.img-search-price-now {
    color: #e74c3c;
    font-weight: 700;
}
.img-search-price-old {
    color: #999;
    font-size: 11px;
    margin-left: 5px;
}

/* ===== Empty & Error ===== */
.img-search-empty {
    text-align: center;
    padding: 30px 10px;
    color: #999;
}
.img-search-empty i {
    font-size: 48px;
    margin-bottom: 10px;
    display: block;
}
.img-search-empty p {
    font-size: 14px;
}
.img-search-error {
    text-align: center;
    padding: 20px;
    color: #e74c3c;
    font-size: 14px;
}

/* ===== Camera Button (in search bar) ===== */
.img-search-btn {
    background: none !important;
    border: none !important;
    box-shadow: none !important;
    cursor: pointer;
    padding: 0 10px;
    font-size: 16px;
    color: #666;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    transition: color .2s;
    vertical-align: middle;
}
.img-search-btn:hover {
    color: #222;
}
.img-search-btn i {
    font-size: 17px;
    color: #666 !important;
}
.img-search-btn:hover i {
    color: #222 !important;
}

/* position inside .typeahead-input-form (header) */
.typeahead-input-form {
    position: relative;
}
.typeahead-input-form .img-search-btn {
    position: absolute;
    right: 46px;
    top: 0;
    height: 100%;
    z-index: 2;
}

/* position inside mobile .input-group search form */
.input-group .img-search-btn {
    position: absolute;
    right: 46px;
    top: 50%;
    transform: translateY(-50%);
    height: auto;
    z-index: 2;
}

/* position inside .typeahead-inputform (homepage, flex layout) */
.typeahead-inputform .img-search-btn {
    background: none !important;
    width: auto !important;
    height: 42px !important;
    padding: 0 10px !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    flex-shrink: 0;
    position: relative;
    right: auto;
    top: auto;
}
.typeahead-inputform .img-search-btn i {
    color: #666 !important;
    font-size: 18px;
}
.typeahead-inputform .img-search-btn:hover i {
    color: #333 !important;
}

/* ===== Sort Bar ===== */
.img-search-sort-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}
.img-search-sort-label {
    font-size: 13px;
    color: #888;
    margin-right: 2px;
    font-weight: 500;
}
.img-search-sort-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    border: 1.5px solid #d5d5d5;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
    color: #666;
    text-decoration: none !important;
    cursor: pointer;
    transition: all 0.25s ease;
}
.img-search-sort-tab:hover {
    border-color: #888;
    color: #222;
    background: rgba(0,0,0,0.03);
}
.img-search-sort-tab.active {
    background: linear-gradient(135deg, #333 0%, #1a1a1a 100%);
    color: #fff !important;
    border-color: transparent;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.img-search-sort-tab i.fa {
    font-size: 11px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .img-search-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .img-search-preview img {
        max-height: 120px;
    }
    .img-search-modal-body {
        padding: 12px 14px 16px;
    }
    .img-search-card-name {
        font-size: 11px;
    }
    .img-search-card-price {
        font-size: 12px;
    }
    .img-search-sort-bar {
        gap: 6px;
        margin-bottom: 10px;
        padding-bottom: 8px;
    }
    .img-search-sort-tab {
        padding: 4px 10px;
        font-size: 11px;
    }
    .img-search-sort-label {
        font-size: 11px;
    }
}

/* ===== Category Page Search Bar (PC) ===== */
.cat-search-wrap {
    display: flex;
    justify-content: center;
    padding: 16px 20px 20px;
}
.cat-search-wrap .cat-search-box {
    max-width: 520px;
    width: 100%;
}

/* ===== Mobile Header Search Bar ===== */
.mobile-search-bar {
    display: none;
    padding: 0 12px 10px;
}
.mobile-search-form {
    display: flex;
    align-items: center;
    height: 40px;
    background: #f5f5f5;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid #e8e8e8;
}
.mobile-search-input {
    flex: 1;
    height: 100%;
    border: none !important;
    background: transparent !important;
    padding: 0 14px !important;
    font-size: 14px;
    color: #333;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}
.mobile-search-input::placeholder {
    color: #999;
}
.mobile-search-cam {
    background: none !important;
    border: none !important;
    padding: 0 8px !important;
    height: 100% !important;
    width: auto !important;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
}
.mobile-search-cam i {
    font-size: 16px !important;
    color: #666 !important;
}
.mobile-search-submit {
    background: none !important;
    border: none !important;
    padding: 0 14px 0 6px !important;
    height: 100%;
    cursor: pointer;
    flex-shrink: 0;
}
.mobile-search-submit i {
    font-size: 15px;
    color: #666;
}
@media (max-width: 768px) {
    .mobile-search-bar {
        display: block;
    }
}

/* ===== Tooltip Bubble ===== */
.img-search-tooltip {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(6px);
    white-space: nowrap;
    background: #222;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 6px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .35s ease, transform .35s ease;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,.18);
    line-height: 1.4;
}
.img-search-tooltip::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: #222;
}
.img-search-tooltip-show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
@media (max-width: 768px) {
    .img-search-tooltip {
        font-size: 11px;
        padding: 5px 10px;
        left: auto;
        right: -4px;
        transform: translateX(0) translateY(6px);
    }
    .img-search-tooltip::after {
        left: auto;
        right: 12px;
        transform: none;
    }
    .img-search-tooltip-show {
        transform: translateX(0) translateY(0);
    }
}
