/* Image Search Camera Button - Inline with Search Box */

.ist-camera-button {
    position: absolute;
    right: 40px;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    color: #666;
    transition: all 0.2s ease;
    z-index: 10;
}

.ist-camera-button:hover {
    background: #f0f0f0;
    color: #0073aa;
}

.ist-camera-button:active {
    transform: translateY(-50%) scale(0.95);
}

.ist-camera-button svg {
    width: 20px;
    height: 20px;
}

/* Modal Overlay */
.ist-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.ist-modal--open {
    opacity: 1;
    visibility: visible;
}

.ist-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
}

/* Modal Container */
.ist-modal-container {
    position: relative;
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    background: white;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.ist-modal--open .ist-modal-container {
    transform: scale(1);
}

/* Modal Header */
.ist-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e5e5;
    background: #fafafa;
}

.ist-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.ist-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 24px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ist-modal-close:hover {
    background: #eee;
    color: #333;
}

/* Modal Body */
.ist-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* Upload Area in Modal */
.ist-modal .ist-upload-area {
    border: 2px dashed #ccc;
    border-radius: 12px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #fafafa;
}

.ist-modal .ist-upload-area:hover,
.ist-modal .ist-upload-area.drag-over {
    border-color: #0073aa;
    background: #f0f7fc;
}

.ist-modal .ist-upload-icon {
    width: 48px;
    height: 48px;
    color: #999;
    margin-bottom: 16px;
}

.ist-modal .ist-upload-area:hover .ist-upload-icon {
    color: #0073aa;
}

.ist-modal .ist-upload-area p {
    margin: 8px 0;
    color: #666;
}

.ist-modal .ist-browse {
    color: #0073aa;
    text-decoration: underline;
    cursor: pointer;
}

.ist-modal .ist-hint {
    font-size: 13px;
    color: #999 !important;
}

/* Preview in Modal */
.ist-modal-preview {
    position: relative;
    text-align: center;
    margin-bottom: 20px;
}

.ist-modal-preview img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.ist-modal-preview .ist-clear-btn {
    position: absolute;
    top: -10px;
    right: calc(50% - 110px);
    width: 28px;
    height: 28px;
    border: none;
    border-radius: 50%;
    background: #e74c3c;
    color: white;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
}

.ist-modal-preview .ist-clear-btn:hover {
    background: #c0392b;
}

/* Loading State */
.ist-modal-loading {
    text-align: center;
    padding: 30px;
}

.ist-modal-loading .ist-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #0073aa;
    border-radius: 50%;
    animation: ist-spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes ist-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Results Section */
.ist-modal-results {
    margin-top: 20px;
}

.ist-modal-results h4 {
    margin: 0 0 16px 0;
    font-size: 14px;
    color: #666;
}

.ist-modal-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

/* Result Card */
.ist-result-card {
    display: block;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    text-decoration: none;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ist-result-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.ist-result-thumb {
    width: 100%;
    aspect-ratio: 1;
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.ist-result-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ist-result-thumb span {
    padding: 10px;
    text-align: center;
    font-size: 11px;
    color: #666;
}

.ist-result-meta {
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.ist-result-name {
    font-size: 12px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.ist-result-match {
    font-size: 11px;
    font-weight: 600;
    color: #27ae60;
    background: #e8f8f0;
    padding: 2px 6px;
    border-radius: 10px;
    flex-shrink: 0;
}

/* Error State */
.ist-modal-error {
    text-align: center;
    padding: 20px;
    background: #fff3cd;
    border-radius: 8px;
    color: #856404;
    margin-top: 20px;
}

/* Mobile Responsive */
@media (max-width: 600px) {
    .ist-modal-container {
        width: 95%;
        max-height: 90vh;
    }

    .ist-modal-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .ist-camera-button {
        right: 35px;
        width: 32px;
        height: 32px;
    }

    .ist-camera-button svg {
        width: 18px;
        height: 18px;
    }
}
