/* Modal Base Styles */
.image-selector-modal,
.image-upload-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--color-overlay-dark-50);
    z-index: -1;
    cursor: pointer;
}

.modal-content {
    position: relative;
    background-color: white;
    border-radius: var(--radius-3xl);
    box-shadow: 0 4px 20px var(--color-overlay-dark-15);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    overflow: hidden;
}

/* Header */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-18);
    border-bottom: 1px solid var(--color-border-soft);
    flex-shrink: 0;
}

.modal-header h2 {
    margin: 0;
    font-size: var(--font-size-xl);
    font-weight: 600;
    color: var(--color-charcoal-900);
}

.close-btn {
    background: none;
    border: none;
    font-size: var(--font-size-3xl);
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

.close-btn:hover {
    background-color: var(--color-text-inverse);
    color: var(--color-charcoal-900);
}

/* Body */
.modal-body {
    padding: var(--space-18);
    overflow-y: auto;
    flex: 1;
    min-height: 300px;
}

/* Search Bar */
.search-bar {
    margin-bottom: var(--space-18);
}

.search-bar input {
    width: 100%;
    padding: var(--space-10) var(--space-11);
    border: var(--border-width-default) solid var(--color-border-soft);
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-family: inherit;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--color-success);
    box-shadow: 0 0 0 2px var(--color-success-rgba-10);
}

/* Footer */
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-10);
    padding: var(--space-18);
    border-top: 1px solid var(--color-border-soft);
    flex-shrink: 0;
}

.btn-cancel,
.btn-select,
.btn-upload {
    padding: var(--space-10) var(--space-22);
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-cancel {
    background-color: var(--color-text-inverse);
    color: var(--color-charcoal-900);
}

.btn-cancel:hover {
    background-color: var(--color-border-soft);
}

.btn-select,
.btn-upload {
    background-color: var(--color-success);
    color: white;
}

.btn-select:hover:not(:disabled),
.btn-upload:hover:not(:disabled) {
    background-color: var(--color-success-dark);
}

.btn-select:disabled,
.btn-upload:disabled {
    background-color: var(--color-neutral-600);
    cursor: not-allowed;
}

/* Image Selector Gallery */
.images-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-14);
}

.gallery-item {
    position: relative;
    border: var(--border-width-lg) solid var(--color-border-soft);
    border-radius: var(--radius-xl);
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s ease;
    background-color: var(--color-bg-surface-soft);
}

.gallery-item img {
    width: 100%;
    height: 120px;
    object-fit: cover;
    display: block;
}

.gallery-item p {
    padding: var(--space-8);
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    background-color: var(--color-bg-surface-muted);
}

.gallery-item:hover {
    border-color: var(--color-success);
    box-shadow: 0 2px 8px var(--color-success-rgba-20);
}

.gallery-item.selected {
    border-color: var(--color-success);
    box-shadow: 0 0 0 3px var(--color-success-rgba-20);
}

.gallery-item.selected::after {
    content: "✓";
    position: absolute;
    top: 5px;
    right: 8px;
    background-color: var(--color-success);
    color: white;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--font-size-sm);
    font-weight: bold;
}

/* Upload Zone */
.upload-zone {
    border: var(--border-width-lg) dashed var(--color-text-muted);
    border-radius: var(--radius-3xl);
    padding: var(--space-31) var(--space-18);
    text-align: center;
    background-color: var(--color-bg-surface-soft);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.upload-zone:hover {
    border-color: var(--color-success);
    background-color: var(--color-success-bg);
}

.upload-zone.dragover {
    border-color: var(--color-success);
    background-color: var(--color-neutral-300);
    box-shadow: 0 0 0 3px var(--color-success-rgba-10);
}

.upload-zone svg {
    margin-bottom: var(--space-11);
    color: var(--color-text-muted);
    transition: color 0.2s ease;
}

.upload-zone:hover svg {
    color: var(--color-success);
}

.upload-zone p {
    margin: 0 0 var(--space-8) 0;
    color: var(--color-charcoal-900);
    font-size: var(--font-size-md);
    font-weight: var(--font-weight-medium);
}

.upload-zone small {
    color: var(--color-text-muted);
    font-size: var(--font-size-xs);
    display: block;
}

/* Upload Preview */
.upload-preview {
    text-align: center;
    padding: var(--space-18);
    background-color: var(--color-bg-surface-soft);
    border-radius: var(--radius-xl);
}

.upload-preview img {
    max-width: 100%;
    max-height: 200px;
    margin-bottom: var(--space-14);
    border-radius: var(--radius-md);
    display: block;
}

.upload-preview .file-name {
    margin: 0 0 var(--space-5) 0;
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    color: var(--color-charcoal-900);
    word-break: break-word;
}

.upload-preview .file-size {
    margin: 0;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

/* Responsive Design */
@media (max-width: 768px) {
    .modal-content {
        width: 90%;
        max-width: 100%;
        max-height: 95vh;
    }

    .images-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: var(--space-10);
    }

    .gallery-item img {
        height: 100px;
    }

    .modal-header {
        padding: var(--space-14);
    }

    .modal-body {
        padding: var(--space-14);
        min-height: 250px;
    }

    .modal-footer {
        padding: var(--space-14);
        gap: var(--space-8);
    }

    .btn-cancel,
    .btn-select,
    .btn-upload {
        padding: var(--space-8) var(--space-15);
        font-size: 13px;
    }

    .upload-zone {
        padding: var(--space-27) var(--space-14);
        min-height: 150px;
    }
}

@media (max-width: 480px) {
    .images-gallery {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .gallery-item img {
        height: 80px;
    }

    .modal-footer {
        flex-direction: column;
    }

    .btn-cancel,
    .btn-select,
    .btn-upload {
        width: 100%;
    }
}